Skip to content

Commit

Permalink
Express as if
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Nov 21, 2020
1 parent fce43ac commit ad039ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
7 changes: 2 additions & 5 deletions Marlin/src/module/stepper/indirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ void reset_stepper_drivers() {
TERN_(HAS_TRINAMIC_CONFIG, reset_trinamic_drivers());
}


/**
* Enable state for each axis
*/
#if ENABLED(SOFTWARE_DRIVER_ENABLE)
xyz_bool_t axis_sw_enabled = {false, false, false};
// Flags to optimize XYZ Enabled state
xyz_bool_t axis_sw_enabled; // = { false, false, false }
#endif
37 changes: 18 additions & 19 deletions Marlin/src/module/stepper/indirection.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,26 +843,32 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
//
// Axis steppers enable / disable macros
//
#define FORGET_AXIS(A) TERN(HOME_AFTER_DEACTIVATE, set_axis_never_homed(A), CBI(axis_known_position, A))

// Break out of a loop if axis is already in the correct state. To be used only with ENABLE/DISABLE_AXIS macros
#define CHECK_AXIS_SW_ENABLED(N) TERN(SOFTWARE_DRIVER_ENABLE, if(axis_sw_enabled[N##_AXIS]) break; else axis_sw_enabled[N##_AXIS] = true, NOOP)
#define CHECK_AXIS_SW_DISABLED(N) TERN(SOFTWARE_DRIVER_ENABLE, if(!axis_sw_enabled[N##_AXIS]) break; else axis_sw_enabled[N##_AXIS] = false, NOOP)

#define ENABLE_AXIS_X() do{ CHECK_AXIS_SW_ENABLED(X); ENABLE_STEPPER_X(); ENABLE_STEPPER_X2(); }while(0)
#define DISABLE_AXIS_X() do{ CHECK_AXIS_SW_DISABLED(X); DISABLE_STEPPER_X(); DISABLE_STEPPER_X2(); FORGET_AXIS(X_AXIS); }while(0)
#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_Y() do{ CHECK_AXIS_SW_ENABLED(Y); ENABLE_STEPPER_Y(); ENABLE_STEPPER_Y2(); }while(0)
#define DISABLE_AXIS_Y() do{ CHECK_AXIS_SW_DISABLED(Y); DISABLE_STEPPER_Y(); DISABLE_STEPPER_Y2(); FORGET_AXIS(Y_AXIS); }while(0)
#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 ENABLE_AXIS_Z() do{ CHECK_AXIS_SW_ENABLED(Z); ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); }while(0)
#define FORGET_AXIS(A) TERN(HOME_AFTER_DEACTIVATE, set_axis_never_homed(A), CBI(axis_known_position, A))

#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{ CHECK_AXIS_SW_DISABLED(Z); 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
Expand Down Expand Up @@ -997,10 +1003,3 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
#define DISABLE_AXIS_E7() NOOP
#endif
#endif

/**
* Enable state for each axis
*/
#if ENABLED(SOFTWARE_DRIVER_ENABLE)
extern xyz_bool_t axis_sw_enabled;
#endif

0 comments on commit ad039ed

Please sign in to comment.