From 47c98d09381d501ba6af64b8cf67a3668a158e9d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 23 Feb 2023 20:07:21 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Refactor=20STEP=20pin=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 22 +++---- Marlin/src/inc/Conditionals_adv.h | 8 +++ Marlin/src/inc/SanityCheck.h | 2 + Marlin/src/module/stepper.cpp | 96 +++++++++++++++---------------- 4 files changed, 69 insertions(+), 59 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 21e72b3db224..6d74a130c79c 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1104,17 +1104,17 @@ // Add a Duplicate option for well-separated conjoined nozzles //#define MULTI_NOZZLE_DUPLICATION -// By default pololu step drivers require an active high signal. However, some high power drivers require an active low signal as step. -#define INVERT_X_STEP_PIN false -#define INVERT_Y_STEP_PIN false -#define INVERT_Z_STEP_PIN false -#define INVERT_I_STEP_PIN false -#define INVERT_J_STEP_PIN false -#define INVERT_K_STEP_PIN false -#define INVERT_U_STEP_PIN false -#define INVERT_V_STEP_PIN false -#define INVERT_W_STEP_PIN false -#define INVERT_E_STEP_PIN false +// By default stepper drivers require an active-HIGH signal but some high-power drivers require an active-LOW signal to step. +#define STEP_STATE_X HIGH +#define STEP_STATE_Y HIGH +#define STEP_STATE_Z HIGH +#define STEP_STATE_I HIGH +#define STEP_STATE_J HIGH +#define STEP_STATE_K HIGH +#define STEP_STATE_U HIGH +#define STEP_STATE_V HIGH +#define STEP_STATE_W HIGH +#define STEP_STATE_E HIGH /** * Idle Stepper Shutdown diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index eacc5d191627..ff2e54e393da 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -99,6 +99,7 @@ #undef SHAPING_BUFFER_Y #undef SHAPING_FREQ_Y #undef STEALTHCHOP_Y + #undef STEP_STATE_Y #endif #if !HAS_Z_AXIS @@ -112,6 +113,7 @@ #undef NUM_Z_STEPPERS #undef SAFE_BED_LEVELING_START_Z #undef STEALTHCHOP_Z + #undef STEP_STATE_Z #undef Z_IDLE_HEIGHT #undef Z_PROBE_SLED #undef Z_SAFE_HOMING @@ -123,6 +125,7 @@ #undef DISABLE_INACTIVE_I #undef SAFE_BED_LEVELING_START_I #undef STEALTHCHOP_I + #undef STEP_STATE_I #endif #if !HAS_J_AXIS @@ -131,6 +134,7 @@ #undef DISABLE_INACTIVE_J #undef SAFE_BED_LEVELING_START_J #undef STEALTHCHOP_J + #undef STEP_STATE_J #endif #if !HAS_K_AXIS @@ -139,6 +143,7 @@ #undef DISABLE_INACTIVE_K #undef SAFE_BED_LEVELING_START_K #undef STEALTHCHOP_K + #undef STEP_STATE_K #endif #if !HAS_U_AXIS @@ -147,6 +152,7 @@ #undef DISABLE_INACTIVE_U #undef SAFE_BED_LEVELING_START_U #undef STEALTHCHOP_U + #undef STEP_STATE_U #endif #if !HAS_V_AXIS @@ -155,6 +161,7 @@ #undef DISABLE_INACTIVE_V #undef SAFE_BED_LEVELING_START_V #undef STEALTHCHOP_V + #undef STEP_STATE_V #endif #if !HAS_W_AXIS @@ -163,6 +170,7 @@ #undef DISABLE_INACTIVE_W #undef SAFE_BED_LEVELING_START_W #undef STEALTHCHOP_W + #undef STEP_STATE_W #endif // Disallowed with no extruders diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 2f7e389b497b..11d27d6eaf9c 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -674,6 +674,8 @@ #error "BABYSTEP_ZPROBE_GFX_OVERLAY is now BABYSTEP_GFX_OVERLAY." #elif defined(DISABLE_INACTIVE_E) #error "DISABLE_INACTIVE_E is now set with DISABLE_INACTIVE_EXTRUDER." +#elif defined(INVERT_X_STEP_PIN) || defined(INVERT_Y_STEP_PIN) || defined(INVERT_Z_STEP_PIN) || defined(INVERT_I_STEP_PIN) || defined(INVERT_J_STEP_PIN) || defined(INVERT_K_STEP_PIN) || defined(INVERT_U_STEP_PIN) || defined(INVERT_V_STEP_PIN) || defined(INVERT_W_STEP_PIN) || defined(INVERT_E_STEP_PIN) + #error "INVERT_*_STEP_PIN true is now STEP_STATE_* LOW, and INVERT_*_STEP_PIN false is now STEP_STATE_* HIGH." #endif // L64xx stepper drivers have been removed diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index f9de7498d72d..0750fd82aa74 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1664,7 +1664,7 @@ void Stepper::pulse_phase_isr() { do { #define _APPLY_STEP(AXIS, INV, ALWAYS) AXIS ##_APPLY_STEP(INV, ALWAYS) - #define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN + #define _STEP_STATE(AXIS) STEP_STATE_## AXIS // Determine if a pulse is needed using Bresenham #define PULSE_PREP(AXIS) do{ \ @@ -1714,14 +1714,14 @@ void Stepper::pulse_phase_isr() { #define PULSE_START(AXIS) do{ \ if (step_needed[_AXIS(AXIS)]) { \ count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \ - _APPLY_STEP(AXIS, !_INVERT_STEP_PIN(AXIS), 0); \ + _APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \ } \ }while(0) // Stop an active pulse if needed #define PULSE_STOP(AXIS) do { \ if (step_needed[_AXIS(AXIS)]) { \ - _APPLY_STEP(AXIS, _INVERT_STEP_PIN(AXIS), 0); \ + _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \ } \ }while(0) @@ -1933,7 +1933,7 @@ void Stepper::pulse_phase_isr() { #if ENABLED(MIXING_EXTRUDER) if (step_needed.e) { count_position[E_AXIS] += count_direction[E_AXIS]; - E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN); + E_STEP_WRITE(mixer.get_next_stepper(), STEP_STATE_E); } #elif HAS_E0_STEP PULSE_START(E); @@ -1977,7 +1977,7 @@ void Stepper::pulse_phase_isr() { #endif #if ENABLED(MIXING_EXTRUDER) - if (step_needed.e) E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN); + if (step_needed.e) E_STEP_WRITE(mixer.get_stepper(), !STEP_STATE_E); #elif HAS_E0_STEP PULSE_STOP(E); #endif @@ -2638,7 +2638,7 @@ uint32_t Stepper::block_phase_isr() { la_delta_error -= advance_divisor; // Set the STEP pulse ON - E_STEP_WRITE(TERN(MIXING_EXTRUDER, mixer.get_next_stepper(), stepper_extruder), !INVERT_E_STEP_PIN); + E_STEP_WRITE(TERN(MIXING_EXTRUDER, mixer.get_next_stepper(), stepper_extruder), STEP_STATE_E); } TERN_(I2S_STEPPER_STREAM, i2s_push_sample()); @@ -2652,7 +2652,7 @@ uint32_t Stepper::block_phase_isr() { #endif // Set the STEP pulse OFF - E_STEP_WRITE(TERN(MIXING_EXTRUDER, mixer.get_stepper(), stepper_extruder), INVERT_E_STEP_PIN); + E_STEP_WRITE(TERN(MIXING_EXTRUDER, mixer.get_stepper(), stepper_extruder), !STEP_STATE_E); } } @@ -2906,7 +2906,7 @@ void Stepper::init() { #define AXIS_INIT(AXIS, PIN) \ _STEP_INIT(AXIS); \ - _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \ + _WRITE_STEP(AXIS, !_STEP_STATE(PIN)); \ _DISABLE_AXIS(AXIS) #define E_AXIS_INIT(NUM) AXIS_INIT(E## NUM, E) @@ -2915,7 +2915,7 @@ void Stepper::init() { #if HAS_X_STEP #if HAS_X2_STEPPER X2_STEP_INIT(); - X2_STEP_WRITE(INVERT_X_STEP_PIN); + X2_STEP_WRITE(!STEP_STATE_X); #endif AXIS_INIT(X, X); #endif @@ -2923,7 +2923,7 @@ void Stepper::init() { #if HAS_Y_STEP #if HAS_DUAL_Y_STEPPERS Y2_STEP_INIT(); - Y2_STEP_WRITE(INVERT_Y_STEP_PIN); + Y2_STEP_WRITE(!STEP_STATE_Y); #endif AXIS_INIT(Y, Y); #endif @@ -2931,15 +2931,15 @@ void Stepper::init() { #if HAS_Z_STEP #if NUM_Z_STEPPERS >= 2 Z2_STEP_INIT(); - Z2_STEP_WRITE(INVERT_Z_STEP_PIN); + Z2_STEP_WRITE(!STEP_STATE_Z); #endif #if NUM_Z_STEPPERS >= 3 Z3_STEP_INIT(); - Z3_STEP_WRITE(INVERT_Z_STEP_PIN); + Z3_STEP_WRITE(!STEP_STATE_Z); #endif #if NUM_Z_STEPPERS >= 4 Z4_STEP_INIT(); - Z4_STEP_WRITE(INVERT_Z_STEP_PIN); + Z4_STEP_WRITE(!STEP_STATE_Z); #endif AXIS_INIT(Z, Z); #endif @@ -3338,19 +3338,19 @@ void Stepper::report_positions() { #if DISABLED(DELTA) - #define BABYSTEP_AXIS(AXIS, INV, DIR) do{ \ - const uint8_t old_dir = _READ_DIR(AXIS); \ - _ENABLE_AXIS(AXIS); \ - DIR_WAIT_BEFORE(); \ - _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^DIR^INV); \ - DIR_WAIT_AFTER(); \ - _SAVE_START(); \ - _APPLY_STEP(AXIS, !_INVERT_STEP_PIN(AXIS), true); \ - _PULSE_WAIT(); \ - _APPLY_STEP(AXIS, _INVERT_STEP_PIN(AXIS), true); \ - EXTRA_DIR_WAIT_BEFORE(); \ - _APPLY_DIR(AXIS, old_dir); \ - EXTRA_DIR_WAIT_AFTER(); \ + #define BABYSTEP_AXIS(AXIS, INV, DIR) do{ \ + const uint8_t old_dir = _READ_DIR(AXIS); \ + _ENABLE_AXIS(AXIS); \ + DIR_WAIT_BEFORE(); \ + _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^DIR^INV); \ + DIR_WAIT_AFTER(); \ + _SAVE_START(); \ + _APPLY_STEP(AXIS, _STEP_STATE(AXIS), true); \ + _PULSE_WAIT(); \ + _APPLY_STEP(AXIS, !_STEP_STATE(AXIS), true); \ + EXTRA_DIR_WAIT_BEFORE(); \ + _APPLY_DIR(AXIS, old_dir); \ + EXTRA_DIR_WAIT_AFTER(); \ }while(0) #endif @@ -3365,11 +3365,11 @@ void Stepper::report_positions() { _APPLY_DIR(B, _INVERT_DIR(B)^DIR^INV^ALT); \ DIR_WAIT_AFTER(); \ _SAVE_START(); \ - _APPLY_STEP(A, !_INVERT_STEP_PIN(A), true); \ - _APPLY_STEP(B, !_INVERT_STEP_PIN(B), true); \ + _APPLY_STEP(A, _STEP_STATE(A), true); \ + _APPLY_STEP(B, _STEP_STATE(B), true); \ _PULSE_WAIT(); \ - _APPLY_STEP(A, _INVERT_STEP_PIN(A), true); \ - _APPLY_STEP(B, _INVERT_STEP_PIN(B), true); \ + _APPLY_STEP(A, !_STEP_STATE(A), true); \ + _APPLY_STEP(B, !_STEP_STATE(B), true); \ EXTRA_DIR_WAIT_BEFORE(); \ _APPLY_DIR(A, old_dir.a); _APPLY_DIR(B, old_dir.b); \ EXTRA_DIR_WAIT_AFTER(); \ @@ -3466,58 +3466,58 @@ void Stepper::report_positions() { _SAVE_START(); - X_STEP_WRITE(!INVERT_X_STEP_PIN); + X_STEP_WRITE(STEP_STATE_X); #ifdef Y_STEP_WRITE - Y_STEP_WRITE(!INVERT_Y_STEP_PIN); + Y_STEP_WRITE(STEP_STATE_Y); #endif #ifdef Z_STEP_WRITE - Z_STEP_WRITE(!INVERT_Z_STEP_PIN); + Z_STEP_WRITE(STEP_STATE_Z); #endif #ifdef I_STEP_WRITE - I_STEP_WRITE(!INVERT_I_STEP_PIN); + I_STEP_WRITE(STEP_STATE_I); #endif #ifdef J_STEP_WRITE - J_STEP_WRITE(!INVERT_J_STEP_PIN); + J_STEP_WRITE(STEP_STATE_J); #endif #ifdef K_STEP_WRITE - K_STEP_WRITE(!INVERT_K_STEP_PIN); + K_STEP_WRITE(STEP_STATE_K); #endif #ifdef U_STEP_WRITE - U_STEP_WRITE(!INVERT_U_STEP_PIN); + U_STEP_WRITE(STEP_STATE_U); #endif #ifdef V_STEP_WRITE - V_STEP_WRITE(!INVERT_V_STEP_PIN); + V_STEP_WRITE(STEP_STATE_V); #endif #ifdef W_STEP_WRITE - W_STEP_WRITE(!INVERT_W_STEP_PIN); + W_STEP_WRITE(STEP_STATE_W); #endif _PULSE_WAIT(); - X_STEP_WRITE(INVERT_X_STEP_PIN); + X_STEP_WRITE(!STEP_STATE_X); #ifdef Y_STEP_WRITE - Y_STEP_WRITE(INVERT_Y_STEP_PIN); + Y_STEP_WRITE(!STEP_STATE_Y); #endif #ifdef Z_STEP_WRITE - Z_STEP_WRITE(INVERT_Z_STEP_PIN); + Z_STEP_WRITE(!STEP_STATE_Z); #endif #ifdef I_STEP_WRITE - I_STEP_WRITE(INVERT_I_STEP_PIN); + I_STEP_WRITE(!STEP_STATE_I); #endif #ifdef J_STEP_WRITE - J_STEP_WRITE(INVERT_J_STEP_PIN); + J_STEP_WRITE(!STEP_STATE_J); #endif #ifdef K_STEP_WRITE - K_STEP_WRITE(INVERT_K_STEP_PIN); + K_STEP_WRITE(!STEP_STATE_K); #endif #ifdef U_STEP_WRITE - U_STEP_WRITE(INVERT_U_STEP_PIN); + U_STEP_WRITE(!STEP_STATE_U); #endif #ifdef V_STEP_WRITE - V_STEP_WRITE(INVERT_V_STEP_PIN); + V_STEP_WRITE(!STEP_STATE_V); #endif #ifdef W_STEP_WRITE - W_STEP_WRITE(INVERT_W_STEP_PIN); + W_STEP_WRITE(!STEP_STATE_W); #endif // Restore direction bits