Skip to content

Commit

Permalink
✨ MAX7219_REINIT_ON_POWERUP (#26163)
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelMcLure committed Mar 17, 2024
1 parent 983aee5 commit ea6a891
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions Marlin/Configuration_adv.h
Expand Up @@ -4308,6 +4308,7 @@
// See class CodeProfiler.
//#define MAX7219_DEBUG_MULTISTEPPING 6 // Show multi-stepping 1 to 128 on this LED matrix row.
//#define MAX7219_DEBUG_SLOWDOWN 6 // Count (mod 16) how many times SLOWDOWN has reduced print speed.
//#define MAX7219_REINIT_ON_POWERUP // Re-initialize MAX7129 when power supply turns on
#endif

/**
Expand Down
48 changes: 43 additions & 5 deletions Marlin/src/feature/max7219.cpp
Expand Up @@ -72,6 +72,26 @@
uint16_t CodeProfiler::call_count = 0;
#endif

#if defined(MAX7219_DEBUG_PLANNER_HEAD) && defined(MAX7219_DEBUG_PLANNER_TAIL) && MAX7219_DEBUG_PLANNER_HEAD == MAX7219_DEBUG_PLANNER_TAIL
static int16_t last_head_cnt = 0xF, last_tail_cnt = 0xF;
#else
#ifdef MAX7219_DEBUG_PLANNER_HEAD
static int16_t last_head_cnt = 0x1;
#endif
#ifdef MAX7219_DEBUG_PLANNER_TAIL
static int16_t last_tail_cnt = 0x1;
#endif
#endif
#ifdef MAX7219_DEBUG_PLANNER_QUEUE
static int16_t last_depth = 0;
#endif
#ifdef MAX7219_DEBUG_PROFILE
static uint8_t last_time_fraction = 0;
#endif
#ifdef MAX7219_DEBUG_MULTISTEPPING
static uint8_t last_multistepping = 0;
#endif

Max7219 max7219;

uint8_t Max7219::led_line[MAX7219_LINES]; // = { 0 };
Expand Down Expand Up @@ -550,6 +570,29 @@ void Max7219::init() {
#if MAX7219_INIT_TEST
start_test_pattern();
#endif

#ifdef MAX7219_REINIT_ON_POWERUP
#if defined(MAX7219_DEBUG_PLANNER_HEAD) && defined(MAX7219_DEBUG_PLANNER_TAIL) && MAX7219_DEBUG_PLANNER_HEAD == MAX7219_DEBUG_PLANNER_TAIL
last_head_cnt = 0xF;
last_tail_cnt = 0xF;
#else
#ifdef MAX7219_DEBUG_PLANNER_HEAD
last_head_cnt = 0x1;
#endif
#ifdef MAX7219_DEBUG_PLANNER_TAIL
last_tail_cnt = 0x1;
#endif
#endif
#ifdef MAX7219_DEBUG_PLANNER_QUEUE
last_depth = 0;
#endif
#ifdef MAX7219_DEBUG_PROFILE
last_time_fraction = 0;
#endif
#ifdef MAX7219_DEBUG_MULTISTEPPING
last_multistepping = 0;
#endif
#endif
}

/**
Expand Down Expand Up @@ -676,8 +719,6 @@ void Max7219::idle_tasks() {

#if defined(MAX7219_DEBUG_PLANNER_HEAD) && defined(MAX7219_DEBUG_PLANNER_TAIL) && MAX7219_DEBUG_PLANNER_HEAD == MAX7219_DEBUG_PLANNER_TAIL

static int16_t last_head_cnt = 0xF, last_tail_cnt = 0xF;

if (last_head_cnt != head || last_tail_cnt != tail) {
range16(MAX7219_DEBUG_PLANNER_HEAD, last_tail_cnt, tail, last_head_cnt, head, &row_change_mask);
last_head_cnt = head;
Expand All @@ -687,15 +728,13 @@ void Max7219::idle_tasks() {
#else

#ifdef MAX7219_DEBUG_PLANNER_HEAD
static int16_t last_head_cnt = 0x1;
if (last_head_cnt != head) {
mark16(MAX7219_DEBUG_PLANNER_HEAD, last_head_cnt, head, &row_change_mask);
last_head_cnt = head;
}
#endif

#ifdef MAX7219_DEBUG_PLANNER_TAIL
static int16_t last_tail_cnt = 0x1;
if (last_tail_cnt != tail) {
mark16(MAX7219_DEBUG_PLANNER_TAIL, last_tail_cnt, tail, &row_change_mask);
last_tail_cnt = tail;
Expand All @@ -714,7 +753,6 @@ void Max7219::idle_tasks() {
#endif

#ifdef MAX7219_DEBUG_PROFILE
static uint8_t last_time_fraction = 0;
const uint8_t current_time_fraction = (uint16_t(CodeProfiler::get_time_fraction()) * MAX7219_NUMBER_UNITS + 8) / 16;
if (current_time_fraction != last_time_fraction) {
quantity(MAX7219_DEBUG_PROFILE, last_time_fraction, current_time_fraction, &row_change_mask);
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/feature/power.cpp
Expand Up @@ -34,6 +34,10 @@
#include "../module/temperature.h"
#include "../MarlinCore.h"

#if ENABLED(MAX7219_REINIT_ON_POWERUP)
#include "max7219.h"
#endif

#if ENABLED(PS_OFF_SOUND)
#include "../libs/buzzer.h"
#endif
Expand Down Expand Up @@ -100,6 +104,9 @@ void Power::power_on() {
safe_delay(PSU_POWERUP_DELAY);

restore_stepper_drivers();

TERN_(MAX7219_REINIT_ON_POWERUP, max7219.init());

TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));

#ifdef PSU_POWERUP_GCODE
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/DUE
Expand Up @@ -27,7 +27,7 @@ opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \
FWRETRACT ARC_SUPPORT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \
PSU_CONTROL AUTO_POWER_CONTROL E_DUAL_STEPPER_DRIVERS \
PIDTEMPBED SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER \
PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL \
PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL MAX7219_REINIT_ON_POWERUP \
EXTENSIBLE_UI
opt_add EXTUI_EXAMPLE
exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options." "$3"
Expand Down

0 comments on commit ea6a891

Please sign in to comment.