Skip to content

Commit 71b8d22

Browse files
thinkyheadvlsi
authored andcommitted
🔧 Refactor endstop state config (MarlinFirmware#25574)
1 parent 216a22c commit 71b8d22

File tree

14 files changed

+436
-615
lines changed

14 files changed

+436
-615
lines changed

‎Marlin/Configuration.h‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,26 +1101,29 @@
11011101
//#define ENDSTOPPULLDOWN_ZMIN_PROBE
11021102
#endif
11031103

1104-
// Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup).
1105-
#define X_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1106-
#define Y_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1107-
#define Z_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1108-
#define I_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1109-
#define J_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1110-
#define K_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1111-
#define U_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1112-
#define V_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1113-
#define W_MIN_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1114-
#define X_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1115-
#define Y_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1116-
#define Z_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1117-
#define I_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1118-
#define J_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1119-
#define K_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1120-
#define U_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1121-
#define V_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1122-
#define W_MAX_ENDSTOP_INVERTING false // Set to true to invert the logic of the endstop.
1123-
#define Z_MIN_PROBE_ENDSTOP_INVERTING false // Set to true to invert the logic of the probe.
1104+
/**
1105+
* Endstop "Hit" State
1106+
* Set to the state (HIGH or LOW) that applies to each endstop.
1107+
*/
1108+
#define X_MIN_ENDSTOP_HIT_STATE HIGH
1109+
#define X_MAX_ENDSTOP_HIT_STATE HIGH
1110+
#define Y_MIN_ENDSTOP_HIT_STATE HIGH
1111+
#define Y_MAX_ENDSTOP_HIT_STATE HIGH
1112+
#define Z_MIN_ENDSTOP_HIT_STATE HIGH
1113+
#define Z_MAX_ENDSTOP_HIT_STATE HIGH
1114+
#define I_MIN_ENDSTOP_HIT_STATE HIGH
1115+
#define I_MAX_ENDSTOP_HIT_STATE HIGH
1116+
#define J_MIN_ENDSTOP_HIT_STATE HIGH
1117+
#define J_MAX_ENDSTOP_HIT_STATE HIGH
1118+
#define K_MIN_ENDSTOP_HIT_STATE HIGH
1119+
#define K_MAX_ENDSTOP_HIT_STATE HIGH
1120+
#define U_MIN_ENDSTOP_HIT_STATE HIGH
1121+
#define U_MAX_ENDSTOP_HIT_STATE HIGH
1122+
#define V_MIN_ENDSTOP_HIT_STATE HIGH
1123+
#define V_MAX_ENDSTOP_HIT_STATE HIGH
1124+
#define W_MIN_ENDSTOP_HIT_STATE HIGH
1125+
#define W_MAX_ENDSTOP_HIT_STATE HIGH
1126+
#define Z_MIN_PROBE_ENDSTOP_HIT_STATE HIGH
11241127

11251128
// Enable this feature if all enabled endstop pins are interrupt-capable.
11261129
// This will remove the need to poll the interrupt pins, saving many CPU cycles.

‎Marlin/src/gcode/config/M43.cpp‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,17 @@ inline void servo_probe_test() {
139139
bool deploy_state = false, stow_state;
140140

141141
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
142-
142+
constexpr bool probe_hit_state = Z_MIN_ENDSTOP_HIT_STATE;
143143
#define PROBE_TEST_PIN Z_MIN_PIN
144-
constexpr bool probe_inverting = Z_MIN_ENDSTOP_INVERTING;
145-
146-
SERIAL_ECHOLNPGM(". Probe Z_MIN_PIN: ", PROBE_TEST_PIN);
147-
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
148-
144+
#define _PROBE_PREF "Z_MIN"
149145
#else
150-
146+
constexpr bool probe_hit_state = Z_MIN_PROBE_ENDSTOP_HIT_STATE;
151147
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
152-
constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
153-
154-
SERIAL_ECHOLNPGM(". Probe Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
155-
SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
156-
148+
#define _PROBE_PREF "Z_MIN_PROBE"
157149
#endif
158150

159-
serialprint_truefalse(probe_inverting);
151+
SERIAL_ECHOLNPGM(". Probe " _PROBE_PREF "_PIN: ", PROBE_TEST_PIN);
152+
serial_ternary(probe_hit_state, F(". " _PROBE_PREF "_ENDSTOP_HIT_STATE: "), F("HIGH"), F("LOW"));
160153
SERIAL_EOL();
161154

162155
SET_INPUT_PULLUP(PROBE_TEST_PIN);
@@ -173,11 +166,11 @@ inline void servo_probe_test() {
173166
SERIAL_ECHOLNPGM(". Check for BLTOUCH");
174167
bltouch._reset();
175168
bltouch._stow();
176-
if (probe_inverting == READ(PROBE_TEST_PIN)) {
169+
if (READ(PROBE_TEST_PIN) != probe_hit_state) {
177170
bltouch._set_SW_mode();
178-
if (probe_inverting != READ(PROBE_TEST_PIN)) {
171+
if (READ(PROBE_TEST_PIN) == probe_hit_state) {
179172
bltouch._deploy();
180-
if (probe_inverting == READ(PROBE_TEST_PIN)) {
173+
if (READ(PROBE_TEST_PIN) != probe_hit_state) {
181174
bltouch._stow();
182175
SERIAL_ECHOLNPGM("= BLTouch Classic 1.2, 1.3, Smart 1.0, 2.0, 2.2, 3.0, 3.1 detected.");
183176
// Check for a 3.1 by letting the user trigger it, later
@@ -195,31 +188,30 @@ inline void servo_probe_test() {
195188
if (!blt) {
196189
// DEPLOY and STOW 4 times and see if the signal follows
197190
// Then it is a mechanical switch
198-
uint8_t i = 0;
199191
SERIAL_ECHOLNPGM(". Deploy & stow 4 times");
200-
do {
192+
LOOP_L_N(i, 4) {
201193
servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
202194
safe_delay(500);
203195
deploy_state = READ(PROBE_TEST_PIN);
204196
servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
205197
safe_delay(500);
206198
stow_state = READ(PROBE_TEST_PIN);
207-
} while (++i < 4);
199+
}
208200

209-
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING: INVERTING setting probably backwards.");
201+
if (probe_hit_state == deploy_state) SERIAL_ECHOLNPGM("WARNING: " _PROBE_PREF "_ENDSTOP_HIT_STATE is probably wrong.");
210202

211203
if (deploy_state != stow_state) {
212204
SERIAL_ECHOLNPGM("= Mechanical Switch detected");
213205
if (deploy_state) {
214-
SERIAL_ECHOLNPGM(" DEPLOYED state: HIGH (logic 1)",
215-
" STOWED (triggered) state: LOW (logic 0)");
206+
SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)\n"
207+
". STOWED (triggered) state: LOW (logic 0)");
216208
}
217209
else {
218-
SERIAL_ECHOLNPGM(" DEPLOYED state: LOW (logic 0)",
219-
" STOWED (triggered) state: HIGH (logic 1)");
210+
SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)\n"
211+
". STOWED (triggered) state: HIGH (logic 1)");
220212
}
221213
#if ENABLED(BLTOUCH)
222-
SERIAL_ECHOLNPGM("FAIL: BLTOUCH enabled - Set up this device as a Servo Probe with INVERTING set to 'true'.");
214+
SERIAL_ECHOLNPGM("FAIL: Can't enable BLTOUCH. Check your settings.");
223215
#endif
224216
return;
225217
}

‎Marlin/src/inc/Conditionals_LCD.h‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@
779779
#if !HAS_Y_AXIS
780780
#undef ENDSTOPPULLUP_YMIN
781781
#undef ENDSTOPPULLUP_YMAX
782-
#undef Y_MIN_ENDSTOP_INVERTING
783-
#undef Y_MAX_ENDSTOP_INVERTING
782+
#undef Y_MIN_ENDSTOP_HIT_STATE
783+
#undef Y_MAX_ENDSTOP_HIT_STATE
784784
#undef Y2_DRIVER_TYPE
785785
#undef Y_ENABLE_ON
786786
#undef DISABLE_Y
@@ -796,8 +796,8 @@
796796
#if !HAS_Z_AXIS
797797
#undef ENDSTOPPULLUP_ZMIN
798798
#undef ENDSTOPPULLUP_ZMAX
799-
#undef Z_MIN_ENDSTOP_INVERTING
800-
#undef Z_MAX_ENDSTOP_INVERTING
799+
#undef Z_MIN_ENDSTOP_HIT_STATE
800+
#undef Z_MAX_ENDSTOP_HIT_STATE
801801
#undef Z2_DRIVER_TYPE
802802
#undef Z3_DRIVER_TYPE
803803
#undef Z4_DRIVER_TYPE
@@ -815,8 +815,8 @@
815815
#if !HAS_I_AXIS
816816
#undef ENDSTOPPULLUP_IMIN
817817
#undef ENDSTOPPULLUP_IMAX
818-
#undef I_MIN_ENDSTOP_INVERTING
819-
#undef I_MAX_ENDSTOP_INVERTING
818+
#undef I_MIN_ENDSTOP_HIT_STATE
819+
#undef I_MAX_ENDSTOP_HIT_STATE
820820
#undef I_ENABLE_ON
821821
#undef DISABLE_I
822822
#undef INVERT_I_DIR
@@ -831,8 +831,8 @@
831831
#if !HAS_J_AXIS
832832
#undef ENDSTOPPULLUP_JMIN
833833
#undef ENDSTOPPULLUP_JMAX
834-
#undef J_MIN_ENDSTOP_INVERTING
835-
#undef J_MAX_ENDSTOP_INVERTING
834+
#undef J_MIN_ENDSTOP_HIT_STATE
835+
#undef J_MAX_ENDSTOP_HIT_STATE
836836
#undef J_ENABLE_ON
837837
#undef DISABLE_J
838838
#undef INVERT_J_DIR
@@ -847,8 +847,8 @@
847847
#if !HAS_K_AXIS
848848
#undef ENDSTOPPULLUP_KMIN
849849
#undef ENDSTOPPULLUP_KMAX
850-
#undef K_MIN_ENDSTOP_INVERTING
851-
#undef K_MAX_ENDSTOP_INVERTING
850+
#undef K_MIN_ENDSTOP_HIT_STATE
851+
#undef K_MAX_ENDSTOP_HIT_STATE
852852
#undef K_ENABLE_ON
853853
#undef DISABLE_K
854854
#undef INVERT_K_DIR
@@ -863,8 +863,8 @@
863863
#if !HAS_U_AXIS
864864
#undef ENDSTOPPULLUP_UMIN
865865
#undef ENDSTOPPULLUP_UMAX
866-
#undef U_MIN_ENDSTOP_INVERTING
867-
#undef U_MAX_ENDSTOP_INVERTING
866+
#undef U_MIN_ENDSTOP_HIT_STATE
867+
#undef U_MAX_ENDSTOP_HIT_STATE
868868
#undef U_ENABLE_ON
869869
#undef DISABLE_U
870870
#undef INVERT_U_DIR
@@ -879,8 +879,8 @@
879879
#if !HAS_V_AXIS
880880
#undef ENDSTOPPULLUP_VMIN
881881
#undef ENDSTOPPULLUP_VMAX
882-
#undef V_MIN_ENDSTOP_INVERTING
883-
#undef V_MAX_ENDSTOP_INVERTING
882+
#undef V_MIN_ENDSTOP_HIT_STATE
883+
#undef V_MAX_ENDSTOP_HIT_STATE
884884
#undef V_ENABLE_ON
885885
#undef DISABLE_V
886886
#undef INVERT_V_DIR
@@ -895,8 +895,8 @@
895895
#if !HAS_W_AXIS
896896
#undef ENDSTOPPULLUP_WMIN
897897
#undef ENDSTOPPULLUP_WMAX
898-
#undef W_MIN_ENDSTOP_INVERTING
899-
#undef W_MAX_ENDSTOP_INVERTING
898+
#undef W_MIN_ENDSTOP_HIT_STATE
899+
#undef W_MAX_ENDSTOP_HIT_STATE
900900
#undef W_ENABLE_ON
901901
#undef DISABLE_W
902902
#undef INVERT_W_DIR
@@ -1055,10 +1055,8 @@
10551055
* The BLTouch Probe emulates a servo probe
10561056
* and uses "special" angles for its state.
10571057
*/
1058-
#if ENABLED(BLTOUCH)
1059-
#ifndef Z_PROBE_SERVO_NR
1060-
#define Z_PROBE_SERVO_NR 0
1061-
#endif
1058+
#if ENABLED(BLTOUCH) && !defined(Z_PROBE_SERVO_NR)
1059+
#define Z_PROBE_SERVO_NR 0
10621060
#endif
10631061

10641062
/**

0 commit comments

Comments
 (0)