From 8db72d027e8189130e6f03244abe337cbfd6dcf4 Mon Sep 17 00:00:00 2001 From: Orel <37673727+0r31@users.noreply.github.com> Date: Sat, 21 Nov 2020 23:27:06 +0100 Subject: [PATCH] Skip unnecessary (costly) SW Stepper Enable (#20218) Co-authored-by: Jason Smith Co-authored-by: Scott Lahteine --- Marlin/src/module/stepper/indirection.cpp | 5 ++++ Marlin/src/module/stepper/indirection.h | 28 +++++++++++++++-------- buildroot/tests/NUCLEO_F767ZI-tests | 2 +- buildroot/tests/esp32-tests | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Marlin/src/module/stepper/indirection.cpp b/Marlin/src/module/stepper/indirection.cpp index 6f9ac9ba0a..6297d83366 100644 --- a/Marlin/src/module/stepper/indirection.cpp +++ b/Marlin/src/module/stepper/indirection.cpp @@ -43,3 +43,8 @@ void reset_stepper_drivers() { TERN_(HAS_L64XX, L64xxManager.init_to_defaults()); TERN_(HAS_TRINAMIC_CONFIG, reset_trinamic_drivers()); } + +#if ENABLED(SOFTWARE_DRIVER_ENABLE) + // Flags to optimize XYZ 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 dfdd63b05b..04cebc216f 100644 --- a/Marlin/src/module/stepper/indirection.h +++ b/Marlin/src/module/stepper/indirection.h @@ -843,22 +843,32 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset // // Axis steppers enable / disable macros // +#if ENABLED(SOFTWARE_DRIVER_ENABLE) + // Avoid expensive calls to enable / disable steppers + extern xyz_bool_t axis_sw_enabled; + #define SHOULD_ENABLE(N) !axis_sw_enabled.N + #define SHOULD_DISABLE(N) axis_sw_enabled.N + #define AFTER_CHANGE(N,TF) axis_sw_enabled.N = TF +#else + #define SHOULD_ENABLE(N) true + #define SHOULD_DISABLE(N) true + #define AFTER_CHANGE(N,TF) NOOP +#endif + +#define ENABLE_AXIS_X() if (SHOULD_ENABLE(x)) { ENABLE_STEPPER_X(); ENABLE_STEPPER_X2(); AFTER_CHANGE(x, true); } +#define DISABLE_AXIS_X() if (SHOULD_DISABLE(x)) { DISABLE_STEPPER_X(); DISABLE_STEPPER_X2(); AFTER_CHANGE(x, false); FORGET_AXIS(X_AXIS); } +#define ENABLE_AXIS_Y() if (SHOULD_ENABLE(y)) { ENABLE_STEPPER_Y(); ENABLE_STEPPER_Y2(); AFTER_CHANGE(y, true); } +#define DISABLE_AXIS_Y() if (SHOULD_DISABLE(y)) { DISABLE_STEPPER_Y(); DISABLE_STEPPER_Y2(); AFTER_CHANGE(y, false); FORGET_AXIS(Y_AXIS); } +#define ENABLE_AXIS_Z() if (SHOULD_ENABLE(z)) { ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); AFTER_CHANGE(z, true); } +#define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); AFTER_CHANGE(z, false); FORGET_AXIS(Z_AXIS); Z_RESET(); } + #define FORGET_AXIS(A) TERN(HOME_AFTER_DEACTIVATE, set_axis_never_homed(A), CBI(axis_known_position, A)) -#define ENABLE_AXIS_X() do{ ENABLE_STEPPER_X(); ENABLE_STEPPER_X2(); }while(0) -#define DISABLE_AXIS_X() do{ DISABLE_STEPPER_X(); DISABLE_STEPPER_X2(); FORGET_AXIS(X_AXIS); }while(0) - -#define ENABLE_AXIS_Y() do{ ENABLE_STEPPER_Y(); ENABLE_STEPPER_Y2(); }while(0) -#define DISABLE_AXIS_Y() do{ DISABLE_STEPPER_Y(); DISABLE_STEPPER_Y2(); FORGET_AXIS(Y_AXIS); }while(0) - -#define ENABLE_AXIS_Z() do{ ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); }while(0) - #ifdef Z_AFTER_DEACTIVATE #define Z_RESET() do{ current_position.z = Z_AFTER_DEACTIVATE; sync_plan_position(); }while(0) #else #define Z_RESET() #endif -#define DISABLE_AXIS_Z() do{ DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); FORGET_AXIS(Z_AXIS); Z_RESET(); }while(0) // // Extruder steppers enable / disable macros diff --git a/buildroot/tests/NUCLEO_F767ZI-tests b/buildroot/tests/NUCLEO_F767ZI-tests index 1a2e7c8362..bd5ca86970 100644 --- a/buildroot/tests/NUCLEO_F767ZI-tests +++ b/buildroot/tests/NUCLEO_F767ZI-tests @@ -12,7 +12,7 @@ set -e restore_configs opt_set MOTHERBOARD BOARD_NUCLEO_F767ZI opt_set SERIAL_PORT -1 -opt_enable BLTOUCH Z_SAFE_HOMING SPEAKER +opt_enable BLTOUCH Z_SAFE_HOMING SPEAKER SOFTWARE_DRIVER_ENABLE opt_set X_DRIVER_TYPE TMC2209 opt_set Y_DRIVER_TYPE TMC2208 exec_test $1 $2 "Mixed timer usage" "$3" diff --git a/buildroot/tests/esp32-tests b/buildroot/tests/esp32-tests index 283d02f7e0..310eea298e 100755 --- a/buildroot/tests/esp32-tests +++ b/buildroot/tests/esp32-tests @@ -34,7 +34,7 @@ opt_set X_SLAVE_ADDRESS 0 opt_set Y_SLAVE_ADDRESS 1 opt_set Z_SLAVE_ADDRESS 2 opt_set E0_SLAVE_ADDRESS 3 -opt_enable HOTEND_IDLE_TIMEOUT +opt_enable HOTEND_IDLE_TIMEOUT SOFTWARE_DRIVER_ENABLE exec_test $1 $2 "ESP32, TMC HW Serial, Hotend Idle" "$3" # cleanup