Skip to content

Commit

Permalink
🎨 Misc. fixes, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and Andy-Big committed Jul 14, 2023
1 parent 9f668e3 commit 642b122
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 263 deletions.
2 changes: 2 additions & 0 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ template <class L, class R> struct IF<true, L, R> { typedef L type; };

#define SECONDARY_AXIS_GANG(V...) GANG_N(SECONDARY_AXES, V)
#define SECONDARY_AXIS_CODE(V...) CODE_N(SECONDARY_AXES, V)
#define SECONDARY_AXIS_LIST(V...) LIST_N(SECONDARY_AXES, V)
#define SECONDARY_AXIS_ARGS(T) SECONDARY_AXIS_LIST(T i, T j, T k, T u, T v, T w)

#if HAS_ROTATIONAL_AXES
#define ROTATIONAL_AXIS_GANG(V...) GANG_N(ROTATIONAL_AXES, V)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/M666.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../../inc/MarlinConfig.h"

#if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
#if EITHER(DELTA, HAS_EXTRA_ENDSTOPS)

#include "../gcode.h"

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 665: M665(); break; // M665: Set Kinematics parameters
#endif

#if ENABLED(DELTA) || HAS_EXTRA_ENDSTOPS
#if EITHER(DELTA, HAS_EXTRA_ENDSTOPS)
case 666: M666(); break; // M666: Set delta or multiple endstop adjustment
#endif

Expand Down
148 changes: 44 additions & 104 deletions Marlin/src/module/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ void Endstops::update() {
#endif

// Macros to update / copy the live_state
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ_ENDSTOP(_ENDSTOP_PIN(AXIS, MINMAX)) == _ENDSTOP_HIT_STATE(AXIS, MINMAX)))
#define UPDATE_LIVE_STATE(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ_ENDSTOP(_ENDSTOP_PIN(AXIS, MINMAX)) == _ENDSTOP_HIT_STATE(AXIS, MINMAX)))
#define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))

#if ENABLED(G38_PROBE_TARGET)
// For G38 moves check the probe's pin for ALL movement
if (G38_move) UPDATE_ENDSTOP_BIT(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
if (G38_move) UPDATE_LIVE_STATE(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
#endif

// With Dual X, endstops are only checked in the homing direction for the active extruder
Expand Down Expand Up @@ -556,67 +556,67 @@ void Endstops::update() {
* Check and update endstops
*/
#if HAS_X_MIN && !X_SPI_SENSORLESS
UPDATE_ENDSTOP_BIT(X, MIN);
UPDATE_LIVE_STATE(X, MIN);
#if ENABLED(X_DUAL_ENDSTOPS)
#if HAS_X2_MIN
UPDATE_ENDSTOP_BIT(X2, MIN);
UPDATE_LIVE_STATE(X2, MIN);
#else
COPY_LIVE_STATE(X_MIN, X2_MIN);
#endif
#endif
#endif

#if HAS_X_MAX && !X_SPI_SENSORLESS
UPDATE_ENDSTOP_BIT(X, MAX);
UPDATE_LIVE_STATE(X, MAX);
#if ENABLED(X_DUAL_ENDSTOPS)
#if HAS_X2_MAX
UPDATE_ENDSTOP_BIT(X2, MAX);
UPDATE_LIVE_STATE(X2, MAX);
#else
COPY_LIVE_STATE(X_MAX, X2_MAX);
#endif
#endif
#endif

#if HAS_Y_MIN && !Y_SPI_SENSORLESS
UPDATE_ENDSTOP_BIT(Y, MIN);
UPDATE_LIVE_STATE(Y, MIN);
#if ENABLED(Y_DUAL_ENDSTOPS)
#if HAS_Y2_MIN
UPDATE_ENDSTOP_BIT(Y2, MIN);
UPDATE_LIVE_STATE(Y2, MIN);
#else
COPY_LIVE_STATE(Y_MIN, Y2_MIN);
#endif
#endif
#endif

#if HAS_Y_MAX && !Y_SPI_SENSORLESS
UPDATE_ENDSTOP_BIT(Y, MAX);
UPDATE_LIVE_STATE(Y, MAX);
#if ENABLED(Y_DUAL_ENDSTOPS)
#if HAS_Y2_MAX
UPDATE_ENDSTOP_BIT(Y2, MAX);
UPDATE_LIVE_STATE(Y2, MAX);
#else
COPY_LIVE_STATE(Y_MAX, Y2_MAX);
#endif
#endif
#endif

#if HAS_Z_MIN && NONE(Z_SPI_SENSORLESS, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
UPDATE_ENDSTOP_BIT(Z, MIN);
UPDATE_LIVE_STATE(Z, MIN);
#if ENABLED(Z_MULTI_ENDSTOPS)
#if HAS_Z2_MIN
UPDATE_ENDSTOP_BIT(Z2, MIN);
UPDATE_LIVE_STATE(Z2, MIN);
#else
COPY_LIVE_STATE(Z_MIN, Z2_MIN);
#endif
#if NUM_Z_STEPPERS >= 3
#if HAS_Z3_MIN
UPDATE_ENDSTOP_BIT(Z3, MIN);
UPDATE_LIVE_STATE(Z3, MIN);
#else
COPY_LIVE_STATE(Z_MIN, Z3_MIN);
#endif
#endif
#if NUM_Z_STEPPERS >= 4
#if HAS_Z4_MIN
UPDATE_ENDSTOP_BIT(Z4, MIN);
UPDATE_LIVE_STATE(Z4, MIN);
#else
COPY_LIVE_STATE(Z_MIN, Z4_MIN);
#endif
Expand All @@ -627,189 +627,129 @@ void Endstops::update() {
#if HAS_BED_PROBE
// When closing the gap check the enabled probe
if (probe_switch_activated())
UPDATE_ENDSTOP_BIT(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
UPDATE_LIVE_STATE(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
#endif

#if HAS_Z_MAX && !Z_SPI_SENSORLESS
// Check both Z dual endstops
#if ENABLED(Z_MULTI_ENDSTOPS)
UPDATE_ENDSTOP_BIT(Z, MAX);
UPDATE_LIVE_STATE(Z, MAX);
#if HAS_Z2_MAX
UPDATE_ENDSTOP_BIT(Z2, MAX);
UPDATE_LIVE_STATE(Z2, MAX);
#else
COPY_LIVE_STATE(Z_MAX, Z2_MAX);
#endif
#if NUM_Z_STEPPERS >= 3
#if HAS_Z3_MAX
UPDATE_ENDSTOP_BIT(Z3, MAX);
UPDATE_LIVE_STATE(Z3, MAX);
#else
COPY_LIVE_STATE(Z_MAX, Z3_MAX);
#endif
#endif
#if NUM_Z_STEPPERS >= 4
#if HAS_Z4_MAX
UPDATE_ENDSTOP_BIT(Z4, MAX);
UPDATE_LIVE_STATE(Z4, MAX);
#else
COPY_LIVE_STATE(Z_MAX, Z4_MAX);
#endif
#endif
#elif TERN1(USES_Z_MIN_PROBE_PIN, Z_MAX_PIN != Z_MIN_PROBE_PIN)
// If this pin isn't the bed probe it's the Z endstop
UPDATE_ENDSTOP_BIT(Z, MAX);
UPDATE_LIVE_STATE(Z, MAX);
#endif
#endif

#if HAS_I_MIN && !I_SPI_SENSORLESS
#if ENABLED(I_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(I, MIN);
#if HAS_I2_MIN
UPDATE_ENDSTOP_BIT(I2, MAX);
#else
COPY_LIVE_STATE(I_MIN, I2_MIN);
#endif
UPDATE_LIVE_STATE(I, MIN);
#else
UPDATE_ENDSTOP_BIT(I, MIN);
UPDATE_LIVE_STATE(I, MIN);
#endif
#endif

#if HAS_I_MAX && !I_SPI_SENSORLESS
#if ENABLED(I_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(I, MAX);
#if HAS_I2_MAX
UPDATE_ENDSTOP_BIT(I2, MAX);
#else
COPY_LIVE_STATE(I_MAX, I2_MAX);
#endif
UPDATE_LIVE_STATE(I, MAX);
#else
UPDATE_ENDSTOP_BIT(I, MAX);
UPDATE_LIVE_STATE(I, MAX);
#endif
#endif

#if HAS_J_MIN && !J_SPI_SENSORLESS
#if ENABLED(J_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(J, MIN);
#if HAS_J2_MIN
UPDATE_ENDSTOP_BIT(J2, MIN);
#else
COPY_LIVE_STATE(J_MIN, J2_MIN);
#endif
UPDATE_LIVE_STATE(J, MIN);
#else
UPDATE_ENDSTOP_BIT(J, MIN);
UPDATE_LIVE_STATE(J, MIN);
#endif
#endif

#if HAS_J_MAX && !J_SPI_SENSORLESS
#if ENABLED(J_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(J, MAX);
#if HAS_J2_MAX
UPDATE_ENDSTOP_BIT(J2, MAX);
#else
COPY_LIVE_STATE(J_MAX, J2_MAX);
#endif
UPDATE_LIVE_STATE(J, MAX);
#else
UPDATE_ENDSTOP_BIT(J, MAX);
UPDATE_LIVE_STATE(J, MAX);
#endif
#endif

#if HAS_K_MIN && !K_SPI_SENSORLESS
#if ENABLED(K_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(K, MIN);
#if HAS_K2_MIN
UPDATE_ENDSTOP_BIT(K2, MIN);
#else
COPY_LIVE_STATE(K_MIN, K2_MIN);
#endif
UPDATE_LIVE_STATE(K, MIN);
#else
UPDATE_ENDSTOP_BIT(K, MIN);
UPDATE_LIVE_STATE(K, MIN);
#endif
#endif

#if HAS_K_MAX && !K_SPI_SENSORLESS
#if ENABLED(K_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(K, MAX);
#if HAS_K2_MAX
UPDATE_ENDSTOP_BIT(K2, MAX);
#else
COPY_LIVE_STATE(K_MAX, K2_MAX);
#endif
UPDATE_LIVE_STATE(K, MAX);
#else
UPDATE_ENDSTOP_BIT(K, MAX);
UPDATE_LIVE_STATE(K, MAX);
#endif
#endif

#if HAS_U_MIN && !U_SPI_SENSORLESS
#if ENABLED(U_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(U, MIN);
#if HAS_U2_MIN
UPDATE_ENDSTOP_BIT(U2, MIN);
#else
COPY_LIVE_STATE(U_MIN, U2_MIN);
#endif
UPDATE_LIVE_STATE(U, MIN);
#else
UPDATE_ENDSTOP_BIT(U, MIN);
UPDATE_LIVE_STATE(U, MIN);
#endif
#endif

#if HAS_U_MAX && !U_SPI_SENSORLESS
#if ENABLED(U_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(U, MAX);
#if HAS_U2_MAX
UPDATE_ENDSTOP_BIT(U2, MAX);
#else
COPY_LIVE_STATE(U_MAX, U2_MAX);
#endif
UPDATE_LIVE_STATE(U, MAX);
#else
UPDATE_ENDSTOP_BIT(U, MAX);
UPDATE_LIVE_STATE(U, MAX);
#endif
#endif

#if HAS_V_MIN && !V_SPI_SENSORLESS
#if ENABLED(V_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(V, MIN);
#if HAS_V2_MIN
UPDATE_ENDSTOP_BIT(V2, MIN);
#else
COPY_LIVE_STATE(V_MIN, V2_MIN);
#endif
UPDATE_LIVE_STATE(V, MIN);
#else
UPDATE_ENDSTOP_BIT(V, MIN);
UPDATE_LIVE_STATE(V, MIN);
#endif
#endif
#if HAS_V_MAX && !V_SPI_SENSORLESS
#if ENABLED(O_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(V, MAX);
#if HAS_V2_MAX
UPDATE_ENDSTOP_BIT(V2, MAX);
#else
COPY_LIVE_STATE(V_MAX, V2_MAX);
#endif
UPDATE_LIVE_STATE(V, MAX);
#else
UPDATE_ENDSTOP_BIT(V, MAX);
UPDATE_LIVE_STATE(V, MAX);
#endif
#endif

#if HAS_W_MIN && !W_SPI_SENSORLESS
#if ENABLED(W_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(W, MIN);
#if HAS_W2_MIN
UPDATE_ENDSTOP_BIT(W2, MIN);
#else
COPY_LIVE_STATE(W_MIN, W2_MIN);
#endif
UPDATE_LIVE_STATE(W, MIN);
#else
UPDATE_ENDSTOP_BIT(W, MIN);
UPDATE_LIVE_STATE(W, MIN);
#endif
#endif
#if HAS_W_MAX && !W_SPI_SENSORLESS
#if ENABLED(W_DUAL_ENDSTOPS)
UPDATE_ENDSTOP_BIT(W, MAX);
#if HAS_W2_MAX
UPDATE_ENDSTOP_BIT(W2, MAX);
#else
COPY_LIVE_STATE(W_MAX, W2_MAX);
#endif
UPDATE_LIVE_STATE(W, MAX);
#else
UPDATE_ENDSTOP_BIT(W, MAX);
UPDATE_LIVE_STATE(W, MAX);
#endif
#endif

Expand Down
Loading

0 comments on commit 642b122

Please sign in to comment.