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 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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 "Marlin.h"
  26. #include "cardreader.h"
  27. #include "endstops.h"
  28. #include "temperature.h"
  29. #include "stepper.h"
  30. #include "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(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || 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. /**
  48. * Class and Instance Methods
  49. */
  50. void Endstops::init() {
  51. #if HAS_X_MIN
  52. #if ENABLED(ENDSTOPPULLUP_XMIN)
  53. SET_INPUT_PULLUP(X_MIN_PIN);
  54. #else
  55. SET_INPUT(X_MIN_PIN);
  56. #endif
  57. #endif
  58. #if HAS_X2_MIN
  59. #if ENABLED(ENDSTOPPULLUP_XMIN)
  60. SET_INPUT_PULLUP(X2_MIN_PIN);
  61. #else
  62. SET_INPUT(X2_MIN_PIN);
  63. #endif
  64. #endif
  65. #if HAS_Y_MIN
  66. #if ENABLED(ENDSTOPPULLUP_YMIN)
  67. SET_INPUT_PULLUP(Y_MIN_PIN);
  68. #else
  69. SET_INPUT(Y_MIN_PIN);
  70. #endif
  71. #endif
  72. #if HAS_Y2_MIN
  73. #if ENABLED(ENDSTOPPULLUP_YMIN)
  74. SET_INPUT_PULLUP(Y2_MIN_PIN);
  75. #else
  76. SET_INPUT(Y2_MIN_PIN);
  77. #endif
  78. #endif
  79. #if HAS_Z_MIN
  80. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  81. SET_INPUT_PULLUP(Z_MIN_PIN);
  82. #else
  83. SET_INPUT(Z_MIN_PIN);
  84. #endif
  85. #endif
  86. #if HAS_Z2_MIN
  87. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  88. SET_INPUT_PULLUP(Z2_MIN_PIN);
  89. #else
  90. SET_INPUT(Z2_MIN_PIN);
  91. #endif
  92. #endif
  93. #if HAS_X_MAX
  94. #if ENABLED(ENDSTOPPULLUP_XMAX)
  95. SET_INPUT_PULLUP(X_MAX_PIN);
  96. #else
  97. SET_INPUT(X_MAX_PIN);
  98. #endif
  99. #endif
  100. #if HAS_X2_MAX
  101. #if ENABLED(ENDSTOPPULLUP_XMAX)
  102. SET_INPUT_PULLUP(X2_MAX_PIN);
  103. #else
  104. SET_INPUT(X2_MAX_PIN);
  105. #endif
  106. #endif
  107. #if HAS_Y_MAX
  108. #if ENABLED(ENDSTOPPULLUP_YMAX)
  109. SET_INPUT_PULLUP(Y_MAX_PIN);
  110. #else
  111. SET_INPUT(Y_MAX_PIN);
  112. #endif
  113. #endif
  114. #if HAS_Y2_MAX
  115. #if ENABLED(ENDSTOPPULLUP_YMAX)
  116. SET_INPUT_PULLUP(Y2_MAX_PIN);
  117. #else
  118. SET_INPUT(Y2_MAX_PIN);
  119. #endif
  120. #endif
  121. #if HAS_Z_MAX
  122. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  123. SET_INPUT_PULLUP(Z_MAX_PIN);
  124. #else
  125. SET_INPUT(Z_MAX_PIN);
  126. #endif
  127. #endif
  128. #if HAS_Z2_MAX
  129. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  130. SET_INPUT_PULLUP(Z2_MAX_PIN);
  131. #else
  132. SET_INPUT(Z2_MAX_PIN);
  133. #endif
  134. #endif
  135. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  136. #if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
  137. SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
  138. #else
  139. SET_INPUT(Z_MIN_PROBE_PIN);
  140. #endif
  141. #endif
  142. } // Endstops::init
  143. void Endstops::report_state() {
  144. if (endstop_hit_bits) {
  145. #if ENABLED(ULTRA_LCD)
  146. char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
  147. #define _SET_STOP_CHAR(A,C) (chr## A = C)
  148. #else
  149. #define _SET_STOP_CHAR(A,C) ;
  150. #endif
  151. #define _ENDSTOP_HIT_ECHO(A,C) do{ \
  152. SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", stepper.triggered_position_mm(A ##_AXIS)); \
  153. _SET_STOP_CHAR(A,C); }while(0)
  154. #define _ENDSTOP_HIT_TEST(A,C) \
  155. if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
  156. _ENDSTOP_HIT_ECHO(A,C)
  157. #define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
  158. #define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
  159. #define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')
  160. SERIAL_ECHO_START();
  161. SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
  162. ENDSTOP_HIT_TEST_X();
  163. ENDSTOP_HIT_TEST_Y();
  164. ENDSTOP_HIT_TEST_Z();
  165. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  166. #define P_AXIS Z_AXIS
  167. if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
  168. #endif
  169. SERIAL_EOL();
  170. #if ENABLED(ULTRA_LCD)
  171. lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
  172. #endif
  173. hit_on_purpose();
  174. #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
  175. if (stepper.abort_on_endstop_hit) {
  176. card.sdprinting = false;
  177. card.closefile();
  178. quickstop_stepper();
  179. thermalManager.disable_all_heaters(); // switch off all heaters.
  180. }
  181. #endif
  182. }
  183. } // Endstops::report_state
  184. void Endstops::M119() {
  185. SERIAL_PROTOCOLLNPGM(MSG_M119_REPORT);
  186. #define ES_REPORT(AXIS) do{ \
  187. SERIAL_PROTOCOLPGM(MSG_##AXIS); \
  188. SERIAL_PROTOCOLLN(((READ(AXIS##_PIN)^AXIS##_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN)); \
  189. }while(0)
  190. #if HAS_X_MIN
  191. ES_REPORT(X_MIN);
  192. #endif
  193. #if HAS_X2_MIN
  194. ES_REPORT(X2_MIN);
  195. #endif
  196. #if HAS_X_MAX
  197. ES_REPORT(X_MAX);
  198. #endif
  199. #if HAS_X2_MAX
  200. ES_REPORT(X2_MAX);
  201. #endif
  202. #if HAS_Y_MIN
  203. ES_REPORT(Y_MIN);
  204. #endif
  205. #if HAS_Y2_MIN
  206. ES_REPORT(Y2_MIN);
  207. #endif
  208. #if HAS_Y_MAX
  209. ES_REPORT(Y_MAX);
  210. #endif
  211. #if HAS_Y2_MAX
  212. ES_REPORT(Y2_MAX);
  213. #endif
  214. #if HAS_Z_MIN
  215. ES_REPORT(Z_MIN);
  216. #endif
  217. #if HAS_Z2_MIN
  218. ES_REPORT(Z2_MIN);
  219. #endif
  220. #if HAS_Z_MAX
  221. ES_REPORT(Z_MAX);
  222. #endif
  223. #if HAS_Z2_MAX
  224. ES_REPORT(Z2_MAX);
  225. #endif
  226. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  227. SERIAL_PROTOCOLPGM(MSG_Z_PROBE);
  228. SERIAL_PROTOCOLLN(((READ(Z_MIN_PROBE_PIN)^Z_MIN_PROBE_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  229. #endif
  230. #if ENABLED(FILAMENT_RUNOUT_SENSOR)
  231. SERIAL_PROTOCOLPGM(MSG_FILAMENT_RUNOUT_SENSOR);
  232. SERIAL_PROTOCOLLN(((READ(FIL_RUNOUT_PIN)^FIL_RUNOUT_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
  233. #endif
  234. } // Endstops::M119
  235. #if ENABLED(X_DUAL_ENDSTOPS)
  236. void Endstops::test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2) {
  237. byte x_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for X, bit 1 for X2
  238. if (x_test && stepper.current_block->steps[X_AXIS] > 0) {
  239. SBI(endstop_hit_bits, X_MIN);
  240. if (!stepper.performing_homing || (x_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
  241. stepper.kill_current_block();
  242. }
  243. }
  244. #endif
  245. #if ENABLED(Y_DUAL_ENDSTOPS)
  246. void Endstops::test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2) {
  247. byte y_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Y, bit 1 for Y2
  248. if (y_test && stepper.current_block->steps[Y_AXIS] > 0) {
  249. SBI(endstop_hit_bits, Y_MIN);
  250. if (!stepper.performing_homing || (y_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
  251. stepper.kill_current_block();
  252. }
  253. }
  254. #endif
  255. #if ENABLED(Z_DUAL_ENDSTOPS)
  256. void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) {
  257. byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
  258. if (z_test && stepper.current_block->steps[Z_AXIS] > 0) {
  259. SBI(endstop_hit_bits, Z_MIN);
  260. if (!stepper.performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
  261. stepper.kill_current_block();
  262. }
  263. }
  264. #endif
  265. // Check endstops - Called from ISR!
  266. void Endstops::update() {
  267. #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
  268. #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
  269. #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
  270. #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX))
  271. // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
  272. #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
  273. // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
  274. #define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
  275. #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
  276. UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
  277. if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
  278. _ENDSTOP_HIT(AXIS, MINMAX); \
  279. stepper.endstop_triggered(_AXIS(AXIS)); \
  280. } \
  281. }while(0)
  282. #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
  283. // If G38 command is active check Z_MIN_PROBE for ALL movement
  284. if (G38_move) {
  285. UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
  286. if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
  287. if (stepper.current_block->steps[_AXIS(X)] > 0) { _ENDSTOP_HIT(X, MIN); stepper.endstop_triggered(_AXIS(X)); }
  288. else if (stepper.current_block->steps[_AXIS(Y)] > 0) { _ENDSTOP_HIT(Y, MIN); stepper.endstop_triggered(_AXIS(Y)); }
  289. else if (stepper.current_block->steps[_AXIS(Z)] > 0) { _ENDSTOP_HIT(Z, MIN); stepper.endstop_triggered(_AXIS(Z)); }
  290. G38_endstop_hit = true;
  291. }
  292. }
  293. #endif
  294. /**
  295. * Define conditions for checking endstops
  296. */
  297. #if IS_CORE
  298. #define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
  299. #define D_(N) stepper.motor_direction(CORE_AXIS_##N)
  300. #endif
  301. #if CORE_IS_XY || CORE_IS_XZ
  302. /**
  303. * Head direction in -X axis for CoreXY and CoreXZ bots.
  304. *
  305. * If steps differ, both axes are moving.
  306. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
  307. * If DeltaA == DeltaB, the movement is only in the 1st axis (X)
  308. */
  309. #if ENABLED(COREXY) || ENABLED(COREXZ)
  310. #define X_CMP ==
  311. #else
  312. #define X_CMP !=
  313. #endif
  314. #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
  315. #define X_AXIS_HEAD X_HEAD
  316. #else
  317. #define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
  318. #define X_AXIS_HEAD X_AXIS
  319. #endif
  320. #if CORE_IS_XY || CORE_IS_YZ
  321. /**
  322. * Head direction in -Y axis for CoreXY / CoreYZ bots.
  323. *
  324. * If steps differ, both axes are moving
  325. * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
  326. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
  327. */
  328. #if ENABLED(COREYX) || ENABLED(COREYZ)
  329. #define Y_CMP ==
  330. #else
  331. #define Y_CMP !=
  332. #endif
  333. #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
  334. #define Y_AXIS_HEAD Y_HEAD
  335. #else
  336. #define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
  337. #define Y_AXIS_HEAD Y_AXIS
  338. #endif
  339. #if CORE_IS_XZ || CORE_IS_YZ
  340. /**
  341. * Head direction in -Z axis for CoreXZ or CoreYZ bots.
  342. *
  343. * If steps differ, both axes are moving
  344. * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
  345. * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
  346. */
  347. #if ENABLED(COREZX) || ENABLED(COREZY)
  348. #define Z_CMP ==
  349. #else
  350. #define Z_CMP !=
  351. #endif
  352. #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
  353. #define Z_AXIS_HEAD Z_HEAD
  354. #else
  355. #define Z_MOVE_TEST stepper.current_block->steps[Z_AXIS] > 0
  356. #define Z_AXIS_HEAD Z_AXIS
  357. #endif
  358. // With Dual X, endstops are only checked in the homing direction for the active extruder
  359. #if ENABLED(DUAL_X_CARRIAGE)
  360. #define E0_ACTIVE stepper.current_block->active_extruder == 0
  361. #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
  362. #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
  363. #else
  364. #define X_MIN_TEST true
  365. #define X_MAX_TEST true
  366. #endif
  367. /**
  368. * Check and update endstops according to conditions
  369. */
  370. if (X_MOVE_TEST) {
  371. if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
  372. #if HAS_X_MIN
  373. #if ENABLED(X_DUAL_ENDSTOPS)
  374. UPDATE_ENDSTOP_BIT(X, MIN);
  375. #if HAS_X2_MIN
  376. UPDATE_ENDSTOP_BIT(X2, MIN);
  377. #else
  378. COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
  379. #endif
  380. test_dual_x_endstops(X_MIN, X2_MIN);
  381. #else
  382. if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
  383. #endif
  384. #endif
  385. }
  386. else { // +direction
  387. #if HAS_X_MAX
  388. #if ENABLED(X_DUAL_ENDSTOPS)
  389. UPDATE_ENDSTOP_BIT(X, MAX);
  390. #if HAS_X2_MAX
  391. UPDATE_ENDSTOP_BIT(X2, MAX);
  392. #else
  393. COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
  394. #endif
  395. test_dual_x_endstops(X_MAX, X2_MAX);
  396. #else
  397. if (X_MIN_TEST) UPDATE_ENDSTOP(X, MAX);
  398. #endif
  399. #endif
  400. }
  401. }
  402. if (Y_MOVE_TEST) {
  403. if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
  404. #if HAS_Y_MIN
  405. #if ENABLED(Y_DUAL_ENDSTOPS)
  406. UPDATE_ENDSTOP_BIT(Y, MIN);
  407. #if HAS_Y2_MIN
  408. UPDATE_ENDSTOP_BIT(Y2, MIN);
  409. #else
  410. COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
  411. #endif
  412. test_dual_y_endstops(Y_MIN, Y2_MIN);
  413. #else
  414. UPDATE_ENDSTOP(Y, MIN);
  415. #endif
  416. #endif
  417. }
  418. else { // +direction
  419. #if HAS_Y_MAX
  420. #if ENABLED(Y_DUAL_ENDSTOPS)
  421. UPDATE_ENDSTOP_BIT(Y, MAX);
  422. #if HAS_Y2_MAX
  423. UPDATE_ENDSTOP_BIT(Y2, MAX);
  424. #else
  425. COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
  426. #endif
  427. test_dual_y_endstops(Y_MAX, Y2_MAX);
  428. #else
  429. UPDATE_ENDSTOP(Y, MAX);
  430. #endif
  431. #endif
  432. }
  433. }
  434. if (Z_MOVE_TEST) {
  435. if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
  436. #if HAS_Z_MIN
  437. #if ENABLED(Z_DUAL_ENDSTOPS)
  438. UPDATE_ENDSTOP_BIT(Z, MIN);
  439. #if HAS_Z2_MIN
  440. UPDATE_ENDSTOP_BIT(Z2, MIN);
  441. #else
  442. COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
  443. #endif
  444. test_dual_z_endstops(Z_MIN, Z2_MIN);
  445. #else
  446. #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  447. if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
  448. #else
  449. UPDATE_ENDSTOP(Z, MIN);
  450. #endif
  451. #endif
  452. #endif
  453. // When closing the gap check the enabled probe
  454. #if ENABLED(Z_MIN_PROBE_ENDSTOP)
  455. if (z_probe_enabled) {
  456. UPDATE_ENDSTOP(Z, MIN_PROBE);
  457. if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
  458. }
  459. #endif
  460. }
  461. else { // Z +direction. Gantry up, bed down.
  462. #if HAS_Z_MAX
  463. // Check both Z dual endstops
  464. #if ENABLED(Z_DUAL_ENDSTOPS)
  465. UPDATE_ENDSTOP_BIT(Z, MAX);
  466. #if HAS_Z2_MAX
  467. UPDATE_ENDSTOP_BIT(Z2, MAX);
  468. #else
  469. COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
  470. #endif
  471. test_dual_z_endstops(Z_MAX, Z2_MAX);
  472. // If this pin is not hijacked for the bed probe
  473. // then it belongs to the Z endstop
  474. #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
  475. UPDATE_ENDSTOP(Z, MAX);
  476. #endif
  477. #endif
  478. }
  479. }
  480. old_endstop_bits = current_endstop_bits;
  481. } // Endstops::update()