From 2538a7c4d6148d8249f5418a76c58ec483343d2b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 29 Apr 2023 21:28:12 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Move=20DIR?= =?UTF-8?q?=20inverting=20to=20*=5FDIR=5FWRITE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/feature/bedlevel/bdl/bdl.cpp | 2 +- Marlin/src/module/planner.h | 2 +- Marlin/src/module/stepper.cpp | 66 +++--- Marlin/src/module/stepper.h | 2 +- Marlin/src/module/stepper/indirection.cpp | 2 +- Marlin/src/module/stepper/indirection.h | 265 ++++++++++++---------- 6 files changed, 186 insertions(+), 153 deletions(-) diff --git a/Marlin/src/feature/bedlevel/bdl/bdl.cpp b/Marlin/src/feature/bedlevel/bdl/bdl.cpp index 5ce5e894ca..064a8ffbd2 100644 --- a/Marlin/src/feature/bedlevel/bdl/bdl.cpp +++ b/Marlin/src/feature/bedlevel/bdl/bdl.cpp @@ -109,7 +109,7 @@ void BDS_Leveling::process() { #endif } else { - babystep.set_mm(Z_AXIS, 0); //if (old_cur_z <= cur_z) Z_DIR_WRITE(INVERT_DIR(Z, HIGH)); + babystep.set_mm(Z_AXIS, 0); //if (old_cur_z <= cur_z) Z_DIR_WRITE(HIGH); stepper.apply_directions(); } #endif diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 030c1b31db..e072e94dbd 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -246,7 +246,7 @@ typedef struct PlannerBlock { uint32_t acceleration_rate; // The acceleration rate used for acceleration calculation #endif - axis_bits_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) + axis_bits_t direction_bits; // Direction bits set for this block, where 1 is negative motion // Advance extrusion #if ENABLED(LIN_ADVANCE) diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index 9bb93597e2..8a4d801e76 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -477,6 +477,15 @@ xyze_int8_t Stepper::count_direction{0}; #define W_APPLY_STEP(v,Q) W_STEP_WRITE(v) #endif +#define E0_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(0) : REV_E_DIR(0); }while(0) +#define E1_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(1) : REV_E_DIR(1); }while(0) +#define E2_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(2) : REV_E_DIR(2); }while(0) +#define E3_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(3) : REV_E_DIR(3); }while(0) +#define E4_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(4) : REV_E_DIR(4); }while(0) +#define E5_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(5) : REV_E_DIR(5); }while(0) +#define E6_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(6) : REV_E_DIR(6); }while(0) +#define E7_APPLY_DIR(REV) do{ (REV) ? FWD_E_DIR(7) : REV_E_DIR(7); }while(0) + #if DISABLED(MIXING_EXTRUDER) #define E_APPLY_STEP(v,Q) E_STEP_WRITE(stepper_extruder, v) #endif @@ -592,14 +601,16 @@ void Stepper::disable_all_steppers() { TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled()); } -#define SET_STEP_DIR(A) \ - if (motor_direction(_AXIS(A))) { \ - A##_APPLY_DIR(INVERT_DIR(A, LOW), false); \ - count_direction[_AXIS(A)] = -1; \ - } \ - else { \ - A##_APPLY_DIR(INVERT_DIR(A, HIGH), false); \ - count_direction[_AXIS(A)] = 1; \ +// Set a single axis direction based on the last set flags. +// A direction bit of "1" indicates reverse or negative motion. +#define SET_STEP_DIR(A) \ + if (motor_direction(_AXIS(A))) { \ + A##_APPLY_DIR(LOW, false); \ + count_direction[_AXIS(A)] = -1; \ + } \ + else { \ + A##_APPLY_DIR(HIGH, false); \ + count_direction[_AXIS(A)] = 1; \ } /** @@ -2402,7 +2413,7 @@ hal_timer_t Stepper::block_phase_isr() { if (la_active) { const uint32_t la_step_rate = la_advance_steps > current_block->final_adv_steps ? current_block->la_advance_rate : 0; if (la_step_rate != step_rate) { - bool reverse_e = la_step_rate > step_rate; + const bool reverse_e = la_step_rate > step_rate; la_interval = calc_timer_interval((reverse_e ? la_step_rate - step_rate : step_rate - la_step_rate) >> current_block->la_scaling); if (reverse_e != motor_direction(E_AXIS)) { @@ -3163,21 +3174,6 @@ void Stepper::init() { sei(); #endif - // Init direction bits for first moves - set_directions(0 - NUM_AXIS_GANG( - | TERN0(INVERT_X_DIR, _BV(X_AXIS)), - | TERN0(INVERT_Y_DIR, _BV(Y_AXIS)), - | TERN0(INVERT_Z_DIR, _BV(Z_AXIS)), - | TERN0(INVERT_I_DIR, _BV(I_AXIS)), - | TERN0(INVERT_J_DIR, _BV(J_AXIS)), - | TERN0(INVERT_K_DIR, _BV(K_AXIS)), - | TERN0(INVERT_U_DIR, _BV(U_AXIS)), - | TERN0(INVERT_V_DIR, _BV(V_AXIS)), - | TERN0(INVERT_W_DIR, _BV(W_AXIS)) - ) - ); - #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM initialized = true; digipot_init(); @@ -3472,10 +3468,10 @@ void Stepper::report_positions() { #endif if (applyDir) { - TERN_(HAS_X_AXIS, X_DIR_WRITE(INVERT_DIR(X, TEST(command, FT_BIT_DIR_X)))); - TERN_(HAS_Y_AXIS, Y_DIR_WRITE(INVERT_DIR(Y, TEST(command, FT_BIT_DIR_Y)))); - TERN_(HAS_Z_AXIS, Z_DIR_WRITE(INVERT_DIR(Z, z_dir))); - TERN_(HAS_EXTRUDERS, E0_DIR_WRITE(INVERT_DIR(E0, TEST(command, FT_BIT_DIR_E)))); + TERN_(HAS_X_AXIS, X_DIR_WRITE(TEST(command, FT_BIT_DIR_X))); + TERN_(HAS_Y_AXIS, Y_DIR_WRITE(TEST(command, FT_BIT_DIR_Y))); + TERN_(HAS_Z_AXIS, Z_DIR_WRITE(z_dir)); + TERN_(HAS_EXTRUDERS, E0_DIR_WRITE(TEST(command, FT_BIT_DIR_E))); DIR_WAIT_AFTER(); } @@ -3632,7 +3628,7 @@ void Stepper::report_positions() { const uint8_t old_dir = _READ_DIR(AXIS); \ _ENABLE_AXIS(AXIS); \ DIR_WAIT_BEFORE(); \ - _APPLY_DIR(AXIS, INVERT_DIR(AXIS, (DIR)^(INV))); \ + _APPLY_DIR(AXIS, (DIR)^(INV)); \ DIR_WAIT_AFTER(); \ _SAVE_START(); \ _APPLY_STEP(AXIS, _STEP_STATE(AXIS), true); \ @@ -3651,8 +3647,8 @@ void Stepper::report_positions() { const xy_byte_t old_dir = { _READ_DIR(A), _READ_DIR(B) }; \ _ENABLE_AXIS(A); _ENABLE_AXIS(B); \ DIR_WAIT_BEFORE(); \ - _APPLY_DIR(A, INVERT_DIR(A, (DIR)^(INV))); \ - _APPLY_DIR(B, INVERT_DIR(B, (DIR)^(INV)^(ALT))); \ + _APPLY_DIR(A, (DIR)^(INV)); \ + _APPLY_DIR(B, (DIR)^(INV)^(ALT)); \ DIR_WAIT_AFTER(); \ _SAVE_START(); \ _APPLY_STEP(A, _STEP_STATE(A), true); \ @@ -3710,7 +3706,7 @@ void Stepper::report_positions() { #else // DELTA - const bool z_direction = direction ^ BABYSTEP_INVERT_Z; + const bool z_direction = TERN_(BABYSTEP_INVERT_Z, !) direction; NUM_AXIS_CODE( enable_axis(X_AXIS), enable_axis(Y_AXIS), enable_axis(Z_AXIS), @@ -3727,13 +3723,13 @@ void Stepper::report_positions() { ); #ifdef X_DIR_WRITE - X_DIR_WRITE(INVERT_DIR(X, z_direction)); + X_DIR_WRITE(z_direction); #endif #ifdef Y_DIR_WRITE - Y_DIR_WRITE(INVERT_DIR(Y, z_direction)); + Y_DIR_WRITE(z_direction); #endif #ifdef Z_DIR_WRITE - Z_DIR_WRITE(INVERT_DIR(Z, z_direction)); + Z_DIR_WRITE(z_direction); #endif DIR_WAIT_AFTER(); diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 7a591d2954..532db65dd9 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -522,7 +522,7 @@ class Stepper { // Quickly stop all steppers FORCE_INLINE static void quick_stop() { abort_current_block = true; } - // The direction of a single motor + // The direction of a single motor. A true result indicates reversed or negative motion. FORCE_INLINE static bool motor_direction(const AxisEnum axis) { return TEST(last_direction_bits, axis); } // The last movement direction was not null on the specified axis. Note that motor direction is not necessarily the same. diff --git a/Marlin/src/module/stepper/indirection.cpp b/Marlin/src/module/stepper/indirection.cpp index 427fd71cbe..0290d8135d 100644 --- a/Marlin/src/module/stepper/indirection.cpp +++ b/Marlin/src/module/stepper/indirection.cpp @@ -42,6 +42,6 @@ void reset_stepper_drivers() { } #if ENABLED(SOFTWARE_DRIVER_ENABLE) - // Flags to optimize XYZ Enabled state + // Flags to optimize axis enabled state xyz_bool_t axis_sw_enabled; // = { false, false, false } #endif diff --git a/Marlin/src/module/stepper/indirection.h b/Marlin/src/module/stepper/indirection.h index 1bbbccd842..7669853b2b 100644 --- a/Marlin/src/module/stepper/indirection.h +++ b/Marlin/src/module/stepper/indirection.h @@ -22,14 +22,51 @@ #pragma once /** - * stepper/indirection.h + * stepper/indirection.h - Stepper Indirection Macros * - * Stepper motor driver indirection to allow some stepper functions to - * be done via SPI/I2c instead of direct pin manipulation. + * Each axis in a machine may have between 1 and 4 stepper motors. + * Currently X and Y allow for 1 or 2 steppers. Z can have up to 4. + * Extruders usually have one E stepper per nozzle. + * + * XYZ Special Cases + * - Delta: 3 steppers contribute to X, Y, and Z. + * - SCARA: A and B steppers contribute to X and Y by angular transformation. + * - CoreXY: A and B steppers contribute to X and Y in combination. + * - CoreXZ: A and B steppers contribute to X and Z in combination. + * - CoreYZ: A and B steppers contribute to Y and Z in combination. + * + * E Special Cases + * - SINGLENOZZLE: All Extruders have a single nozzle so there is one heater and no XYZ offset. + * - Switching Extruder: One stepper is used for each pair of nozzles with a switching mechanism. + * - Duplication Mode: Two or more steppers move in sync when `extruder_duplication_enabled` is set. + * With MULTI_NOZZLE_DUPLICATION a `duplication_e_mask` is also used. + * - Průša MMU1: One stepper is used with a switching mechanism. Odd numbered E indexes are reversed. + * - Průša MMU2: One stepper is used with a switching mechanism. + * - E_DUAL_STEPPER_DRIVERS: Two steppers always move in sync, possibly with opposite DIR states. + * + * Direct Stepper Control + * Where "Q" represents X Y Z I J K U V W / X2 Y2 Z2 Z3 Z4 / E0 E1 E2 E3 E4 E5 E6 E7 + * Here each E index corresponds to a single E stepper driver. + * + * Q_ENABLE_INIT() Q_ENABLE_WRITE(S) Q_ENABLE_READ() + * Q_DIR_INIT() Q_DIR_WRITE(S) Q_DIR_READ() + * Q_STEP_INIT() Q_STEP_WRITE(S) Q_STEP_READ() + * + * Steppers may not have an enable state or may be enabled by other methods + * beyond a single pin (SOFTWARE_DRIVER_ENABLE) so these can be overriden: + * ENABLE_STEPPER_Q() DISABLE_STEPPER_Q() + * + * Axis Stepper Control (X Y Z I J K U V W) + * SOFTWARE_DRIVER_ENABLE gives all axes a status flag, so these macros will + * skip sending commands to steppers that are already in the desired state: + * ENABLE_AXIS_Q() DISABLE_AXIS_Q() + * + * E-Axis Stepper Control (0..n) + * For these macros the E index indicates a logical extruder (e.g., active_extruder). + * + * E_STEP_WRITE(E,V) FWD_E_DIR(E) REV_E_DIR(E) * - * Copyright (c) 2015 Dominik Wenger */ - #include "../../inc/MarlinConfig.h" #if HAS_TMC26X @@ -43,6 +80,8 @@ void restore_stepper_drivers(); // Called by powerManager.power_on() void reset_stepper_drivers(); // Called by settings.load / settings.reset +#define INVERT_DIR(AXIS, D) (TERN_(INVERT_## AXIS ##_DIR, !)(D)) + // X Stepper #ifndef X_ENABLE_INIT #define X_ENABLE_INIT() SET_OUTPUT(X_ENABLE_PIN) @@ -51,7 +90,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef X_DIR_INIT #define X_DIR_INIT() SET_OUTPUT(X_DIR_PIN) - #define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,STATE) + #define X_DIR_WRITE(STATE) WRITE(X_DIR_PIN,INVERT_DIR(X, STATE)) #define X_DIR_READ() bool(READ(X_DIR_PIN)) #endif #define X_STEP_INIT() SET_OUTPUT(X_STEP_PIN) @@ -69,7 +108,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Y_DIR_INIT #define Y_DIR_INIT() SET_OUTPUT(Y_DIR_PIN) - #define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,STATE) + #define Y_DIR_WRITE(STATE) WRITE(Y_DIR_PIN,INVERT_DIR(Y, STATE)) #define Y_DIR_READ() bool(READ(Y_DIR_PIN)) #endif #define Y_STEP_INIT() SET_OUTPUT(Y_STEP_PIN) @@ -88,7 +127,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Z_DIR_INIT #define Z_DIR_INIT() SET_OUTPUT(Z_DIR_PIN) - #define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,STATE) + #define Z_DIR_WRITE(STATE) WRITE(Z_DIR_PIN,INVERT_DIR(Z, STATE)) #define Z_DIR_READ() bool(READ(Z_DIR_PIN)) #endif #define Z_STEP_INIT() SET_OUTPUT(Z_STEP_PIN) @@ -107,7 +146,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef X2_DIR_INIT #define X2_DIR_INIT() SET_OUTPUT(X2_DIR_PIN) - #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,STATE) + #define X2_DIR_WRITE(STATE) WRITE(X2_DIR_PIN,INVERT_DIR(X2, STATE)) #define X2_DIR_READ() bool(READ(X2_DIR_PIN)) #endif #define X2_STEP_INIT() SET_OUTPUT(X2_STEP_PIN) @@ -126,7 +165,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Y2_DIR_INIT #define Y2_DIR_INIT() SET_OUTPUT(Y2_DIR_PIN) - #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,STATE) + #define Y2_DIR_WRITE(STATE) WRITE(Y2_DIR_PIN,INVERT_DIR(Y2, STATE)) #define Y2_DIR_READ() bool(READ(Y2_DIR_PIN)) #endif #define Y2_STEP_INIT() SET_OUTPUT(Y2_STEP_PIN) @@ -147,7 +186,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Z2_DIR_INIT #define Z2_DIR_INIT() SET_OUTPUT(Z2_DIR_PIN) - #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,STATE) + #define Z2_DIR_WRITE(STATE) WRITE(Z2_DIR_PIN,INVERT_DIR(Z2, STATE)) #define Z2_DIR_READ() bool(READ(Z2_DIR_PIN)) #endif #define Z2_STEP_INIT() SET_OUTPUT(Z2_STEP_PIN) @@ -168,7 +207,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Z3_DIR_INIT #define Z3_DIR_INIT() SET_OUTPUT(Z3_DIR_PIN) - #define Z3_DIR_WRITE(STATE) WRITE(Z3_DIR_PIN,STATE) + #define Z3_DIR_WRITE(STATE) WRITE(Z3_DIR_PIN,INVERT_DIR(Z3, STATE)) #define Z3_DIR_READ() bool(READ(Z3_DIR_PIN)) #endif #define Z3_STEP_INIT() SET_OUTPUT(Z3_STEP_PIN) @@ -189,7 +228,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef Z4_DIR_INIT #define Z4_DIR_INIT() SET_OUTPUT(Z4_DIR_PIN) - #define Z4_DIR_WRITE(STATE) WRITE(Z4_DIR_PIN,STATE) + #define Z4_DIR_WRITE(STATE) WRITE(Z4_DIR_PIN,INVERT_DIR(Z4, STATE)) #define Z4_DIR_READ() bool(READ(Z4_DIR_PIN)) #endif #define Z4_STEP_INIT() SET_OUTPUT(Z4_STEP_PIN) @@ -210,7 +249,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef I_DIR_INIT #define I_DIR_INIT() SET_OUTPUT(I_DIR_PIN) - #define I_DIR_WRITE(STATE) WRITE(I_DIR_PIN,STATE) + #define I_DIR_WRITE(STATE) WRITE(I_DIR_PIN,INVERT_DIR(I, STATE)) #define I_DIR_READ() bool(READ(I_DIR_PIN)) #endif #define I_STEP_INIT() SET_OUTPUT(I_STEP_PIN) @@ -229,7 +268,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef J_DIR_INIT #define J_DIR_INIT() SET_OUTPUT(J_DIR_PIN) - #define J_DIR_WRITE(STATE) WRITE(J_DIR_PIN,STATE) + #define J_DIR_WRITE(STATE) WRITE(J_DIR_PIN,INVERT_DIR(J, STATE)) #define J_DIR_READ() bool(READ(J_DIR_PIN)) #endif #define J_STEP_INIT() SET_OUTPUT(J_STEP_PIN) @@ -248,7 +287,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef K_DIR_INIT #define K_DIR_INIT() SET_OUTPUT(K_DIR_PIN) - #define K_DIR_WRITE(STATE) WRITE(K_DIR_PIN,STATE) + #define K_DIR_WRITE(STATE) WRITE(K_DIR_PIN,INVERT_DIR(K, STATE)) #define K_DIR_READ() bool(READ(K_DIR_PIN)) #endif #define K_STEP_INIT() SET_OUTPUT(K_STEP_PIN) @@ -267,7 +306,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef U_DIR_INIT #define U_DIR_INIT() SET_OUTPUT(U_DIR_PIN) - #define U_DIR_WRITE(STATE) WRITE(U_DIR_PIN,STATE) + #define U_DIR_WRITE(STATE) WRITE(U_DIR_PIN,INVERT_DIR(U, STATE)) #define U_DIR_READ() bool(READ(U_DIR_PIN)) #endif #define U_STEP_INIT() SET_OUTPUT(U_STEP_PIN) @@ -286,7 +325,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef V_DIR_INIT #define V_DIR_INIT() SET_OUTPUT(V_DIR_PIN) - #define V_DIR_WRITE(STATE) WRITE(V_DIR_PIN,STATE) + #define V_DIR_WRITE(STATE) WRITE(V_DIR_PIN,INVERT_DIR(V, STATE)) #define V_DIR_READ() bool(READ(V_DIR_PIN)) #endif #define V_STEP_INIT() SET_OUTPUT(V_STEP_PIN) @@ -305,7 +344,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef W_DIR_INIT #define W_DIR_INIT() SET_OUTPUT(W_DIR_PIN) - #define W_DIR_WRITE(STATE) WRITE(W_DIR_PIN,STATE) + #define W_DIR_WRITE(STATE) WRITE(W_DIR_PIN,INVERT_DIR(W, STATE)) #define W_DIR_READ() bool(READ(W_DIR_PIN)) #endif #define W_STEP_INIT() SET_OUTPUT(W_STEP_PIN) @@ -323,7 +362,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E0_DIR_INIT #define E0_DIR_INIT() SET_OUTPUT(E0_DIR_PIN) - #define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,STATE) + #define E0_DIR_WRITE(STATE) WRITE(E0_DIR_PIN,INVERT_DIR(E0, STATE)) #define E0_DIR_READ() bool(READ(E0_DIR_PIN)) #endif #define E0_STEP_INIT() SET_OUTPUT(E0_STEP_PIN) @@ -340,7 +379,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E1_DIR_INIT #define E1_DIR_INIT() SET_OUTPUT(E1_DIR_PIN) - #define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,STATE) + #define E1_DIR_WRITE(STATE) WRITE(E1_DIR_PIN,INVERT_DIR(E1, STATE)) #define E1_DIR_READ() bool(READ(E1_DIR_PIN)) #endif #define E1_STEP_INIT() SET_OUTPUT(E1_STEP_PIN) @@ -357,7 +396,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E2_DIR_INIT #define E2_DIR_INIT() SET_OUTPUT(E2_DIR_PIN) - #define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,STATE) + #define E2_DIR_WRITE(STATE) WRITE(E2_DIR_PIN,INVERT_DIR(E2, STATE)) #define E2_DIR_READ() bool(READ(E2_DIR_PIN)) #endif #define E2_STEP_INIT() SET_OUTPUT(E2_STEP_PIN) @@ -374,7 +413,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E3_DIR_INIT #define E3_DIR_INIT() SET_OUTPUT(E3_DIR_PIN) - #define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,STATE) + #define E3_DIR_WRITE(STATE) WRITE(E3_DIR_PIN,INVERT_DIR(E3, STATE)) #define E3_DIR_READ() bool(READ(E3_DIR_PIN)) #endif #define E3_STEP_INIT() SET_OUTPUT(E3_STEP_PIN) @@ -391,7 +430,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E4_DIR_INIT #define E4_DIR_INIT() SET_OUTPUT(E4_DIR_PIN) - #define E4_DIR_WRITE(STATE) WRITE(E4_DIR_PIN,STATE) + #define E4_DIR_WRITE(STATE) WRITE(E4_DIR_PIN,INVERT_DIR(E4, STATE)) #define E4_DIR_READ() bool(READ(E4_DIR_PIN)) #endif #define E4_STEP_INIT() SET_OUTPUT(E4_STEP_PIN) @@ -408,7 +447,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E5_DIR_INIT #define E5_DIR_INIT() SET_OUTPUT(E5_DIR_PIN) - #define E5_DIR_WRITE(STATE) WRITE(E5_DIR_PIN,STATE) + #define E5_DIR_WRITE(STATE) WRITE(E5_DIR_PIN,INVERT_DIR(E5, STATE)) #define E5_DIR_READ() bool(READ(E5_DIR_PIN)) #endif #define E5_STEP_INIT() SET_OUTPUT(E5_STEP_PIN) @@ -425,7 +464,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E6_DIR_INIT #define E6_DIR_INIT() SET_OUTPUT(E6_DIR_PIN) - #define E6_DIR_WRITE(STATE) WRITE(E6_DIR_PIN,STATE) + #define E6_DIR_WRITE(STATE) WRITE(E6_DIR_PIN,INVERT_DIR(E6, STATE)) #define E6_DIR_READ() bool(READ(E6_DIR_PIN)) #endif #define E6_STEP_INIT() SET_OUTPUT(E6_STEP_PIN) @@ -442,7 +481,7 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #ifndef E7_DIR_INIT #define E7_DIR_INIT() SET_OUTPUT(E7_DIR_PIN) - #define E7_DIR_WRITE(STATE) WRITE(E7_DIR_PIN,STATE) + #define E7_DIR_WRITE(STATE) WRITE(E7_DIR_PIN,INVERT_DIR(E7, STATE)) #define E7_DIR_READ() bool(READ(E7_DIR_PIN)) #endif #define E7_STEP_INIT() SET_OUTPUT(E7_STEP_PIN) @@ -451,8 +490,6 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #endif #define E7_STEP_READ() bool(READ(E7_STEP_PIN)) -#define INVERT_DIR(AXIS, D) (TERN_(INVERT_## AXIS ##_DIR, !)(D)) - /** * Extruder indirection for the single E axis */ @@ -460,91 +497,91 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #if EXTRUDERS > 7 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else if (E < 6) { E2_STEP_WRITE(V); } else { E3_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; \ - case 6: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; case 7: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; case 3: E1_DIR_WRITE(LOW ); break; \ + case 4: E2_DIR_WRITE(HIGH); break; case 5: E2_DIR_WRITE(LOW ); break; \ + case 6: E3_DIR_WRITE(HIGH); break; case 7: E3_DIR_WRITE(LOW ); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; \ - case 6: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; case 7: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; case 3: E1_DIR_WRITE(HIGH); break; \ + case 4: E2_DIR_WRITE(LOW ); break; case 5: E2_DIR_WRITE(HIGH); break; \ + case 6: E3_DIR_WRITE(LOW ); break; case 7: E3_DIR_WRITE(HIGH); break; \ } }while(0) #elif EXTRUDERS > 6 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else if (E < 6) { E2_STEP_WRITE(V); } else { E3_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; \ - case 6: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; case 3: E1_DIR_WRITE(LOW ); break; \ + case 4: E2_DIR_WRITE(HIGH); break; case 5: E2_DIR_WRITE(LOW ); break; \ + case 6: E3_DIR_WRITE(HIGH); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; \ - case 6: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); } }while(0) + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; case 3: E1_DIR_WRITE(HIGH); break; \ + case 4: E2_DIR_WRITE(LOW ); break; case 5: E2_DIR_WRITE(HIGH); break; \ + case 6: E3_DIR_WRITE(LOW ); } }while(0) #elif EXTRUDERS > 5 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; case 3: E1_DIR_WRITE(LOW ); break; \ + case 4: E2_DIR_WRITE(HIGH); break; case 5: E2_DIR_WRITE(LOW ); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 5: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; case 3: E1_DIR_WRITE(HIGH); break; \ + case 4: E2_DIR_WRITE(LOW ); break; case 5: E2_DIR_WRITE(HIGH); break; \ } }while(0) #elif EXTRUDERS > 4 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; case 3: E1_DIR_WRITE(LOW ); break; \ + case 4: E2_DIR_WRITE(HIGH); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 4: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; case 3: E1_DIR_WRITE(HIGH); break; \ + case 4: E2_DIR_WRITE(LOW ); break; \ } }while(0) #elif EXTRUDERS > 3 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; case 3: E1_DIR_WRITE(LOW ); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 3: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; case 3: E1_DIR_WRITE(HIGH); break; \ } }while(0) #elif EXTRUDERS > 2 #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0) #define FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E0_DIR_WRITE(LOW ); break; \ + case 2: E1_DIR_WRITE(HIGH); break; \ } }while(0) #define REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; \ - case 2: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E0_DIR_WRITE(HIGH); break; \ + case 2: E1_DIR_WRITE(LOW ); break; \ } }while(0) #else #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V) - #define FWD_E_DIR(E) do{ E0_DIR_WRITE(INVERT_DIR(E0, (E) ? LOW : HIGH)); }while(0) - #define REV_E_DIR(E) do{ E0_DIR_WRITE(INVERT_DIR(E0, (E) ? HIGH : LOW )); }while(0) + #define FWD_E_DIR(E) do{ E0_DIR_WRITE((E) ? LOW : HIGH); }while(0) + #define REV_E_DIR(E) do{ E0_DIR_WRITE((E) ? HIGH : LOW ); }while(0) #endif #elif HAS_PRUSA_MMU2 // One multiplexed stepper driver #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V) - #define FWD_E_DIR(E) E0_DIR_WRITE(INVERT_DIR(E0, HIGH)) - #define REV_E_DIR(E) E0_DIR_WRITE(INVERT_DIR(E0, LOW )) + #define FWD_E_DIR(E) E0_DIR_WRITE(HIGH) + #define REV_E_DIR(E) E0_DIR_WRITE(LOW ) #elif HAS_PRUSA_MMU1 // One multiplexed stepper driver, reversed on odd index #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V) - #define FWD_E_DIR(E) do{ E0_DIR_WRITE(INVERT_DIR(E0, TEST(E, 0) ? HIGH : LOW )); }while(0) - #define REV_E_DIR(E) do{ E0_DIR_WRITE(INVERT_DIR(E0, TEST(E, 0) ? LOW : HIGH)); }while(0) + #define FWD_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? HIGH : LOW ); }while(0) + #define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? LOW : HIGH); }while(0) #elif E_STEPPERS > 1 @@ -555,16 +592,16 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset case 4: E4_STEP_WRITE(V); break; case 5: E5_STEP_WRITE(V); break; case 6: E6_STEP_WRITE(V); break; case 7: E7_STEP_WRITE(V); break; \ } }while(0) #define _FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, HIGH)); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, HIGH)); break; \ - case 6: E6_DIR_WRITE(INVERT_DIR(E6, HIGH)); break; case 7: E7_DIR_WRITE(INVERT_DIR(E7, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; \ + case 2: E2_DIR_WRITE(HIGH); break; case 3: E3_DIR_WRITE(HIGH); break; \ + case 4: E4_DIR_WRITE(HIGH); break; case 5: E5_DIR_WRITE(HIGH); break; \ + case 6: E6_DIR_WRITE(HIGH); break; case 7: E7_DIR_WRITE(HIGH); break; \ } }while(0) #define _REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, LOW )); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, LOW )); break; \ - case 6: E6_DIR_WRITE(INVERT_DIR(E6, LOW )); break; case 7: E7_DIR_WRITE(INVERT_DIR(E7, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; \ + case 2: E2_DIR_WRITE(LOW ); break; case 3: E3_DIR_WRITE(LOW ); break; \ + case 4: E4_DIR_WRITE(LOW ); break; case 5: E5_DIR_WRITE(LOW ); break; \ + case 6: E6_DIR_WRITE(LOW ); break; case 7: E7_DIR_WRITE(LOW ); break; \ } }while(0) #elif E_STEPPERS > 6 @@ -574,16 +611,16 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset case 4: E4_STEP_WRITE(V); break; case 5: E5_STEP_WRITE(V); break; case 6: E6_STEP_WRITE(V); break; \ } }while(0) #define _FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, HIGH)); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, HIGH)); break; \ - case 6: E6_DIR_WRITE(INVERT_DIR(E6, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; \ + case 2: E2_DIR_WRITE(HIGH); break; case 3: E3_DIR_WRITE(HIGH); break; \ + case 4: E4_DIR_WRITE(HIGH); break; case 5: E5_DIR_WRITE(HIGH); break; \ + case 6: E6_DIR_WRITE(HIGH); break; \ } }while(0) #define _REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, LOW )); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, LOW )); break; \ - case 6: E6_DIR_WRITE(INVERT_DIR(E6, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; \ + case 2: E2_DIR_WRITE(LOW ); break; case 3: E3_DIR_WRITE(LOW ); break; \ + case 4: E4_DIR_WRITE(LOW ); break; case 5: E5_DIR_WRITE(LOW ); break; \ + case 6: E6_DIR_WRITE(LOW ); break; \ } }while(0) #elif E_STEPPERS > 5 @@ -593,14 +630,14 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset case 4: E4_STEP_WRITE(V); break; case 5: E5_STEP_WRITE(V); break; \ } }while(0) #define _FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, HIGH)); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; \ + case 2: E2_DIR_WRITE(HIGH); break; case 3: E3_DIR_WRITE(HIGH); break; \ + case 4: E4_DIR_WRITE(HIGH); break; case 5: E5_DIR_WRITE(HIGH); break; \ } }while(0) #define _REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, LOW )); break; case 5: E5_DIR_WRITE(INVERT_DIR(E5, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; \ + case 2: E2_DIR_WRITE(LOW ); break; case 3: E3_DIR_WRITE(LOW ); break; \ + case 4: E4_DIR_WRITE(LOW ); break; case 5: E5_DIR_WRITE(LOW ); break; \ } }while(0) #elif E_STEPPERS > 4 @@ -610,14 +647,14 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset case 4: E4_STEP_WRITE(V); break; \ } }while(0) #define _FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; \ + case 2: E2_DIR_WRITE(HIGH); break; case 3: E3_DIR_WRITE(HIGH); break; \ + case 4: E4_DIR_WRITE(HIGH); break; \ } }while(0) #define _REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ - case 4: E4_DIR_WRITE(INVERT_DIR(E4, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; \ + case 2: E2_DIR_WRITE(LOW ); break; case 3: E3_DIR_WRITE(LOW ); break; \ + case 4: E4_DIR_WRITE(LOW ); break; \ } }while(0) #elif E_STEPPERS > 3 @@ -626,25 +663,25 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); break; case 3: E3_STEP_WRITE(V); break; \ } }while(0) #define _FWD_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, HIGH)); break; \ + case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; \ + case 2: E2_DIR_WRITE(HIGH); break; case 3: E3_DIR_WRITE(HIGH); break; \ } }while(0) #define _REV_E_DIR(E) do{ switch (E) { \ - case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; \ - case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); break; case 3: E3_DIR_WRITE(INVERT_DIR(E3, LOW )); break; \ + case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; \ + case 2: E2_DIR_WRITE(LOW ); break; case 3: E3_DIR_WRITE(LOW ); break; \ } }while(0) #elif E_STEPPERS > 2 #define _E_STEP_WRITE(E,V) do{ switch (E) { case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); } }while(0) - #define _FWD_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); break; case 2: E2_DIR_WRITE(INVERT_DIR(E2, HIGH)); } }while(0) - #define _REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(INVERT_DIR(E0, LOW )); break; case 1: E1_DIR_WRITE(INVERT_DIR(E1, LOW )); break; case 2: E2_DIR_WRITE(INVERT_DIR(E2, LOW )); } }while(0) + #define _FWD_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(HIGH); break; case 1: E1_DIR_WRITE(HIGH); break; case 2: E2_DIR_WRITE(HIGH); } }while(0) + #define _REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(LOW ); break; case 1: E1_DIR_WRITE(LOW ); break; case 2: E2_DIR_WRITE(LOW ); } }while(0) #else #define _E_STEP_WRITE(E,V) do{ if (E == 0) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0) - #define _FWD_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(INVERT_DIR(E0, HIGH)); } else { E1_DIR_WRITE(INVERT_DIR(E1, HIGH)); } }while(0) - #define _REV_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(INVERT_DIR(E0, LOW )); } else { E1_DIR_WRITE(INVERT_DIR(E1, LOW )); } }while(0) + #define _FWD_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(HIGH); } else { E1_DIR_WRITE(HIGH); } }while(0) + #define _REV_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(LOW ); } else { E1_DIR_WRITE(LOW ); } }while(0) #endif #if HAS_DUPLICATION_MODE @@ -655,8 +692,8 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define DUPE(N,T,V) E##N##_##T##_WRITE(V); #endif - #define NDIR(N) DUPE(N,DIR,INVERT_DIR(E, HIGH)); - #define RDIR(N) DUPE(N,DIR,INVERT_DIR(E, LOW )); + #define NDIR(N) DUPE(N,DIR,HIGH); + #define RDIR(N) DUPE(N,DIR,LOW ); #define E_STEP_WRITE(E,V) do{ if (extruder_duplication_enabled) { REPEAT2(E_STEPPERS, DUPE, STEP, V); } else _E_STEP_WRITE(E,V); }while(0) #define FWD_E_DIR(E) do{ if (extruder_duplication_enabled) { REPEAT(E_STEPPERS, NDIR); } else _FWD_E_DIR(E); }while(0) @@ -672,13 +709,13 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #elif ENABLED(E_DUAL_STEPPER_DRIVERS) #define E_STEP_WRITE(E,V) do{ E0_STEP_WRITE(V); E1_STEP_WRITE(V); }while(0) - #define FWD_E_DIR(E) do{ constexpr bool d = INVERT_DIR(E0, HIGH); E0_DIR_WRITE(d); E1_DIR_WRITE(INVERT_DIR(E1_VS_E0, d)); }while(0) - #define REV_E_DIR(E) do{ constexpr bool d = INVERT_DIR(E0, LOW ); E0_DIR_WRITE(d); E1_DIR_WRITE(INVERT_DIR(E1_VS_E0, d)); }while(0) + #define FWD_E_DIR(E) do{ E0_DIR_WRITE(HIGH); E1_DIR_WRITE(INVERT_DIR(E1_VS_E0, HIGH)); }while(0) + #define REV_E_DIR(E) do{ E0_DIR_WRITE(LOW ); E1_DIR_WRITE(INVERT_DIR(E1_VS_E0, LOW )); }while(0) -#elif E_STEPPERS +#elif E_STEPPERS == 1 #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V) - #define FWD_E_DIR(E) E0_DIR_WRITE(INVERT_DIR(E0, HIGH)) - #define REV_E_DIR(E) E0_DIR_WRITE(INVERT_DIR(E0, LOW )) + #define FWD_E_DIR(E) E0_DIR_WRITE(HIGH) + #define REV_E_DIR(E) E0_DIR_WRITE(LOW ) #else #define E_STEP_WRITE(E,V) NOOP