My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

endstops.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * endstops.cpp - A singleton object to manage endstops
  24. */
  25. #include "endstops.h"
  26. #include "stepper.h"
  27. #include "../Marlin.h"
  28. #include "../sd/cardreader.h"
  29. #include "../module/temperature.h"
  30. #include "../lcd/ultralcd.h"
  31. // TEST_ENDSTOP: test the old and the current status of an endstop
  32. #define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits & old_endstop_bits, ENDSTOP))
  33. Endstops endstops;
  34. // public:
  35. bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
  36. volatile char Endstops::endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
  37. #if ENABLED(Z_DUAL_ENDSTOPS)
  38. uint16_t
  39. #else
  40. byte
  41. #endif
  42. Endstops::current_endstop_bits = 0,
  43. Endstops::old_endstop_bits = 0;
  44. #if HAS_BED_PROBE
  45. volatile bool Endstops::z_probe_enabled = false;
  46. #endif
  47. #if ENABLED(Z_DUAL_ENDSTOPS)
  48. float Endstops::z_endstop_adj;
  49. #endif
  50. /**
  51. * Class and Instance Methods
  52. */
  53. void Endstops::init() {
  54. #if HAS_X_MIN
  55. #if ENABLED(ENDSTOPPULLUP_XMIN)
  56. SET_INPUT_PULLUP(X_MIN_PIN);
  57. #else
  58. SET_INPUT(X_MIN_PIN);
  59. #endif
  60. #endif
  61. #if HAS_Y_MIN
  62. #if ENABLED(ENDSTOPPULLUP_YMIN)
  63. SET_INPUT_PULLUP(Y_MIN_PIN);
  64. #else
  65. SET_INPUT(Y_MIN_PIN);
  66. #endif
  67. #endif
  68. #if HAS_Z_MIN
  69. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  70. SET_INPUT_PULLUP(Z_MIN_PIN);
  71. #else
  72. SET_INPUT(Z_MIN_PIN);
  73. #endif
  74. #endif
  75. #if HAS_Z2_MIN
  76. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  77. SET_INPUT_PULLUP(Z2_MIN_PIN);
  78. #else
  79. SET_INPUT(Z2_MIN_PIN);
  80. #endif
  81. #endif
  82. #if HAS_X_MAX
  83. #if ENABLED(ENDSTOPPULLUP_XMAX)
  84. SET_INPUT_PULLUP(X_MAX_PIN);
  85. #else
  86. SET_INPUT(X_MAX_PIN);
  87. #endif
  88. #endif
  89. #if HAS_Y_MAX
  90. #if ENABLED(ENDSTOPPULLUP_YMAX)
  91. SET_INPUT_PULLUP(Y_MAX_PIN);
  92. #else
  93. SET_INPUT(Y_MAX_PIN);
  94. #endif
  95. #endif
  96. #if HAS_Z_MAX
  97. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  98. SET_INPUT_PULLUP(Z_MAX_PIN);
  99. #else
  100. SET_INPUT(Z_MAX_PIN);
  101. #endif
  102. #endif
  103. #if HAS_Z2_MAX
  104. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  105. SET_INPUT_PULLUP(Z2_MAX_PIN);
  106. #else
  107. SET_INPUT(Z2_MAX_PIN);
  108. #endif
  109. #endif
  110. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  111. #if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
  112. SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
  113. #else
  114. SET_INPUT(Z_MIN_PROBE_PIN);
  115. #endif
  116. #endif
  117. } // Endstops::init
  118. void Endstops::report_state() {
  119. if (endstop_hit_bits) {
  120. #if ENABLED(ULTRA_LCD)
  121. char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
  122. #define _SET_STOP_CHAR(A,C) (chr## A = C)
  123. #else
  124. #define _SET_STOP_CHAR(A,C) ;
  125. #endif
  126. #define _ENDSTOP_HIT_ECHO(A,C) do{ \
  127. SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", stepper.triggered_position_mm(A ##_AXIS)); \
  128. _SET_STOP_CHAR(A,C); }while(0)
  129. #define _ENDSTOP_HIT_TEST(A,C) \
  130. if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
  131. _ENDSTOP_HIT_ECHO(A,C)
  132. #define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
  133. #define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
  134. #define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')
  135. SERIAL_ECHO_START();
  136. SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
  137. ENDSTOP_HIT_TEST_X();
  138. ENDSTOP_HIT_TEST_Y();
  139. ENDSTOP_HIT_TEST_Z();
  140. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  141. #define P_AXIS Z_AXIS
  142. if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
  143. #endif
  144. SERIAL_EOL();
  145. #if ENABLED(ULTRA_LCD)
  146. lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
  147. #endif
  148. hit_on_purpose();
  149. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
  150. if (stepper.abort_on_endstop_hit) {
  151. card.sdprinting = false;
  152. card.closefile();
  153. quickstop_stepper();
  154. thermalManager.disable_all_heaters(); // switch off all heaters.
  155. }
  156. #endif
  157. }
  158. } // Endstops::report_state
  159. void Endstops::M119() {
  160. SERIAL_PROTOCOLLNPGM(MSG_M119_REPORT);
  161. #if HAS_X_MIN
  162. SERIAL_PROTOCOLPGM(MSG_X_MIN);
  163. SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  164. #endif
  165. #if HAS_X_MAX
  166. SERIAL_PROTOCOLPGM(MSG_X_MAX);
  167. SERIAL_PROTOCOLLN(((READ(X_MAX_PIN)^X_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  168. #endif
  169. #if HAS_Y_MIN
  170. SERIAL_PROTOCOLPGM(MSG_Y_MIN);
  171. SERIAL_PROTOCOLLN(((READ(Y_MIN_PIN)^Y_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  172. #endif
  173. #if HAS_Y_MAX
  174. SERIAL_PROTOCOLPGM(MSG_Y_MAX);
  175. SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  176. #endif
  177. #if HAS_Z_MIN
  178. SERIAL_PROTOCOLPGM(MSG_Z_MIN);
  179. SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  180. #endif
  181. #if HAS_Z2_MIN
  182. SERIAL_PROTOCOLPGM(MSG_Z2_MIN);
  183. SERIAL_PROTOCOLLN(((READ(Z2_MIN_PIN)^Z2_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  184. #endif
  185. #if HAS_Z_MAX
  186. SERIAL_PROTOCOLPGM(MSG_Z_MAX);
  187. SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  188. #endif
  189. #if HAS_Z2_MAX
  190. SERIAL_PROTOCOLPGM(MSG_Z2_MAX);
  191. SERIAL_PROTOCOLLN(((READ(Z2_MAX_PIN)^Z2_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  192. #endif
  193. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  194. SERIAL_PROTOCOLPGM(MSG_Z_PROBE);
  195. SERIAL_PROTOCOLLN(((READ(Z_MIN_PROBE_PIN)^Z_MIN_PROBE_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  196. #endif
  197. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  198. SERIAL_PROTOCOLPGM(MSG_FILAMENT_RUNOUT_SENSOR);
  199. SERIAL_PROTOCOLLN(((READ(FIL_RUNOUT_PIN)^FIL_RUNOUT_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  200. #endif
  201. } // Endstops::M119
  202. #if ENABLED(Z_DUAL_ENDSTOPS)
  203. // Pass the result of the endstop test
  204. void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) {
  205. byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
  206. if (z_test && stepper.current_block->steps[Z_AXIS] > 0) {
  207. SBI(endstop_hit_bits, Z_MIN);
  208. if (!stepper.performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
  209. stepper.kill_current_block();
  210. }
  211. }
  212. #endif
  213. // Check endstops - Called from ISR!
  214. void Endstops::update() {
  215. #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
  216. #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
  217. #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
  218. #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX))
  219. // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
  220. #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
  221. // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
  222. #define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
  223. #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
  224. UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
  225. if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
  226. _ENDSTOP_HIT(AXIS, MINMAX); \
  227. stepper.endstop_triggered(_AXIS(AXIS)); \
  228. } \
  229. } while(0)
  230. #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
  231. // If G38 command is active check Z_MIN_PROBE for ALL movement
  232. if (G38_move) {
  233. UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
  234. if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
  235. if (stepper.current_block->steps[_AXIS(X)] > 0) { _ENDSTOP_HIT(X, MIN); stepper.endstop_triggered(_AXIS(X)); }
  236. else if (stepper.current_block->steps[_AXIS(Y)] > 0) { _ENDSTOP_HIT(Y, MIN); stepper.endstop_triggered(_AXIS(Y)); }
  237. else if (stepper.current_block->steps[_AXIS(Z)] > 0) { _ENDSTOP_HIT(Z, MIN); stepper.endstop_triggered(_AXIS(Z)); }
  238. G38_endstop_hit = true;
  239. }
  240. }
  241. #endif
  242. /**
  243. * Define conditions for checking endstops
  244. */
  245. #if IS_CORE
  246. #define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
  247. #define D_(N) stepper.motor_direction(CORE_AXIS_##N)
  248. #endif
  249. #if CORE_IS_XY || CORE_IS_XZ
  250. /**
  251. * Head direction in -X axis for CoreXY and CoreXZ bots.
  252. *
  253. * If steps differ, both axes are moving.
  254. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
  255. * If DeltaA == DeltaB, the movement is only in the 1st axis (X)
  256. */
  257. #if ENABLED(COREXY) || ENABLED(COREXZ)
  258. #define X_CMP ==
  259. #else
  260. #define X_CMP !=
  261. #endif
  262. #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
  263. #define X_AXIS_HEAD X_HEAD
  264. #else
  265. #define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
  266. #define X_AXIS_HEAD X_AXIS
  267. #endif
  268. #if CORE_IS_XY || CORE_IS_YZ
  269. /**
  270. * Head direction in -Y axis for CoreXY / CoreYZ bots.
  271. *
  272. * If steps differ, both axes are moving
  273. * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
  274. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
  275. */
  276. #if ENABLED(COREYX) || ENABLED(COREYZ)
  277. #define Y_CMP ==
  278. #else
  279. #define Y_CMP !=
  280. #endif
  281. #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
  282. #define Y_AXIS_HEAD Y_HEAD
  283. #else
  284. #define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
  285. #define Y_AXIS_HEAD Y_AXIS
  286. #endif
  287. #if CORE_IS_XZ || CORE_IS_YZ
  288. /**
  289. * Head direction in -Z axis for CoreXZ or CoreYZ bots.
  290. *
  291. * If steps differ, both axes are moving
  292. * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
  293. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
  294. */
  295. #if ENABLED(COREZX) || ENABLED(COREZY)
  296. #define Z_CMP ==
  297. #else
  298. #define Z_CMP !=
  299. #endif
  300. #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
  301. #define Z_AXIS_HEAD Z_HEAD
  302. #else
  303. #define Z_MOVE_TEST stepper.current_block->steps[Z_AXIS] > 0
  304. #define Z_AXIS_HEAD Z_AXIS
  305. #endif
  306. // With Dual X, endstops are only checked in the homing direction for the active extruder
  307. #if ENABLED(DUAL_X_CARRIAGE)
  308. #define E0_ACTIVE stepper.current_block->active_extruder == 0
  309. #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
  310. #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
  311. #else
  312. #define X_MIN_TEST true
  313. #define X_MAX_TEST true
  314. #endif
  315. /**
  316. * Check and update endstops according to conditions
  317. */
  318. if (X_MOVE_TEST) {
  319. if (stepper.motor_direction(X_AXIS_HEAD)) {
  320. if (X_MIN_TEST) { // -direction
  321. #if HAS_X_MIN
  322. UPDATE_ENDSTOP(X, MIN);
  323. #endif
  324. }
  325. }
  326. else if (X_MAX_TEST) { // +direction
  327. #if HAS_X_MAX
  328. UPDATE_ENDSTOP(X, MAX);
  329. #endif
  330. }
  331. }
  332. if (Y_MOVE_TEST) {
  333. if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
  334. #if HAS_Y_MIN
  335. UPDATE_ENDSTOP(Y, MIN);
  336. #endif
  337. }
  338. else { // +direction
  339. #if HAS_Y_MAX
  340. UPDATE_ENDSTOP(Y, MAX);
  341. #endif
  342. }
  343. }
  344. if (Z_MOVE_TEST) {
  345. if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
  346. #if HAS_Z_MIN
  347. #if ENABLED(Z_DUAL_ENDSTOPS)
  348. UPDATE_ENDSTOP_BIT(Z, MIN);
  349. #if HAS_Z2_MIN
  350. UPDATE_ENDSTOP_BIT(Z2, MIN);
  351. #else
  352. COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
  353. #endif
  354. test_dual_z_endstops(Z_MIN, Z2_MIN);
  355. #else // !Z_DUAL_ENDSTOPS
  356. #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  357. if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
  358. #else
  359. UPDATE_ENDSTOP(Z, MIN);
  360. #endif
  361. #endif // !Z_DUAL_ENDSTOPS
  362. #endif // HAS_Z_MIN
  363. // When closing the gap check the enabled probe
  364. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  365. if (z_probe_enabled) {
  366. UPDATE_ENDSTOP(Z, MIN_PROBE);
  367. if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
  368. }
  369. #endif
  370. }
  371. else { // Z +direction. Gantry up, bed down.
  372. #if HAS_Z_MAX
  373. // Check both Z dual endstops
  374. #if ENABLED(Z_DUAL_ENDSTOPS)
  375. UPDATE_ENDSTOP_BIT(Z, MAX);
  376. #if HAS_Z2_MAX
  377. UPDATE_ENDSTOP_BIT(Z2, MAX);
  378. #else
  379. COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
  380. #endif
  381. test_dual_z_endstops(Z_MAX, Z2_MAX);
  382. // If this pin is not hijacked for the bed probe
  383. // then it belongs to the Z endstop
  384. #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
  385. UPDATE_ENDSTOP(Z, MAX);
  386. #endif // !Z_MIN_PROBE_PIN...
  387. #endif // Z_MAX_PIN
  388. }
  389. }
  390. old_endstop_bits = current_endstop_bits;
  391. } // Endstops::update()
  392. #if ENABLED(PINS_DEBUGGING)
  393. bool Endstops::monitor_flag = false;
  394. /**
  395. * monitors endstops & Z probe for changes
  396. *
  397. * If a change is detected then the LED is toggled and
  398. * a message is sent out the serial port
  399. *
  400. * Yes, we could miss a rapid back & forth change but
  401. * that won't matter because this is all manual.
  402. *
  403. */
  404. void Endstops::monitor() {
  405. static uint16_t old_endstop_bits_local = 0;
  406. static uint8_t local_LED_status = 0;
  407. uint16_t current_endstop_bits_local = 0;
  408. #if HAS_X_MIN
  409. if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN);
  410. #endif
  411. #if HAS_X_MAX
  412. if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX);
  413. #endif
  414. #if HAS_Y_MIN
  415. if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN);
  416. #endif
  417. #if HAS_Y_MAX
  418. if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX);
  419. #endif
  420. #if HAS_Z_MIN
  421. if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN);
  422. #endif
  423. #if HAS_Z_MAX
  424. if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX);
  425. #endif
  426. #if HAS_Z_MIN_PROBE_PIN
  427. if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE);
  428. #endif
  429. #if HAS_Z2_MIN
  430. if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN);
  431. #endif
  432. #if HAS_Z2_MAX
  433. if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX);
  434. #endif
  435. uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local;
  436. if (endstop_change) {
  437. #if HAS_X_MIN
  438. if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
  439. #endif
  440. #if HAS_X_MAX
  441. if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
  442. #endif
  443. #if HAS_Y_MIN
  444. if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
  445. #endif
  446. #if HAS_Y_MAX
  447. if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
  448. #endif
  449. #if HAS_Z_MIN
  450. if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
  451. #endif
  452. #if HAS_Z_MAX
  453. if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
  454. #endif
  455. #if HAS_Z_MIN_PROBE_PIN
  456. if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
  457. #endif
  458. #if HAS_Z2_MIN
  459. if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
  460. #endif
  461. #if HAS_Z2_MAX
  462. if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
  463. #endif
  464. SERIAL_PROTOCOLPGM("\n\n");
  465. analogWrite(LED_PIN, local_LED_status);
  466. local_LED_status ^= 255;
  467. old_endstop_bits_local = current_endstop_bits_local;
  468. }
  469. }
  470. #endif // PINS_DEBUGGING