My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

endstops.cpp 29KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://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 "../MarlinCore.h"
  28. #include "../sd/cardreader.h"
  29. #include "temperature.h"
  30. #include "../lcd/ultralcd.h"
  31. #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
  32. #include HAL_PATH(../HAL, endstop_interrupts.h)
  33. #endif
  34. #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
  35. #include "printcounter.h" // for print_job_timer
  36. #endif
  37. #if ENABLED(BLTOUCH)
  38. #include "../feature/bltouch.h"
  39. #endif
  40. #if ENABLED(JOYSTICK)
  41. #include "../feature/joystick.h"
  42. #endif
  43. Endstops endstops;
  44. // private:
  45. bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
  46. volatile uint8_t Endstops::hit_state;
  47. Endstops::esbits_t Endstops::live_state = 0;
  48. #if ENDSTOP_NOISE_THRESHOLD
  49. Endstops::esbits_t Endstops::validated_live_state;
  50. uint8_t Endstops::endstop_poll_count;
  51. #endif
  52. #if HAS_BED_PROBE
  53. volatile bool Endstops::z_probe_enabled = false;
  54. #endif
  55. // Initialized by settings.load()
  56. #if ENABLED(X_DUAL_ENDSTOPS)
  57. float Endstops::x2_endstop_adj;
  58. #endif
  59. #if ENABLED(Y_DUAL_ENDSTOPS)
  60. float Endstops::y2_endstop_adj;
  61. #endif
  62. #if ENABLED(Z_MULTI_ENDSTOPS)
  63. float Endstops::z2_endstop_adj;
  64. #if NUM_Z_STEPPER_DRIVERS >= 3
  65. float Endstops::z3_endstop_adj;
  66. #if NUM_Z_STEPPER_DRIVERS >= 4
  67. float Endstops::z4_endstop_adj;
  68. #endif
  69. #endif
  70. #endif
  71. #if ENABLED(SPI_ENDSTOPS)
  72. Endstops::tmc_spi_homing_t Endstops::tmc_spi_homing; // = 0
  73. #endif
  74. #if ENABLED(IMPROVE_HOMING_RELIABILITY)
  75. millis_t sg_guard_period; // = 0
  76. #endif
  77. /**
  78. * Class and Instance Methods
  79. */
  80. void Endstops::init() {
  81. #if HAS_X_MIN
  82. #if ENABLED(ENDSTOPPULLUP_XMIN)
  83. SET_INPUT_PULLUP(X_MIN_PIN);
  84. #elif ENABLED(ENDSTOPPULLDOWN_XMIN)
  85. SET_INPUT_PULLDOWN(X_MIN_PIN);
  86. #else
  87. SET_INPUT(X_MIN_PIN);
  88. #endif
  89. #endif
  90. #if HAS_X2_MIN
  91. #if ENABLED(ENDSTOPPULLUP_XMIN)
  92. SET_INPUT_PULLUP(X2_MIN_PIN);
  93. #elif ENABLED(ENDSTOPPULLDOWN_XMIN)
  94. SET_INPUT_PULLDOWN(X2_MIN_PIN);
  95. #else
  96. SET_INPUT(X2_MIN_PIN);
  97. #endif
  98. #endif
  99. #if HAS_Y_MIN
  100. #if ENABLED(ENDSTOPPULLUP_YMIN)
  101. SET_INPUT_PULLUP(Y_MIN_PIN);
  102. #elif ENABLED(ENDSTOPPULLDOWN_YMIN)
  103. SET_INPUT_PULLDOWN(Y_MIN_PIN);
  104. #else
  105. SET_INPUT(Y_MIN_PIN);
  106. #endif
  107. #endif
  108. #if HAS_Y2_MIN
  109. #if ENABLED(ENDSTOPPULLUP_YMIN)
  110. SET_INPUT_PULLUP(Y2_MIN_PIN);
  111. #elif ENABLED(ENDSTOPPULLDOWN_YMIN)
  112. SET_INPUT_PULLDOWN(Y2_MIN_PIN);
  113. #else
  114. SET_INPUT(Y2_MIN_PIN);
  115. #endif
  116. #endif
  117. #if HAS_Z_MIN
  118. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  119. SET_INPUT_PULLUP(Z_MIN_PIN);
  120. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  121. SET_INPUT_PULLDOWN(Z_MIN_PIN);
  122. #else
  123. SET_INPUT(Z_MIN_PIN);
  124. #endif
  125. #endif
  126. #if HAS_Z2_MIN
  127. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  128. SET_INPUT_PULLUP(Z2_MIN_PIN);
  129. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  130. SET_INPUT_PULLDOWN(Z2_MIN_PIN);
  131. #else
  132. SET_INPUT(Z2_MIN_PIN);
  133. #endif
  134. #endif
  135. #if HAS_Z3_MIN
  136. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  137. SET_INPUT_PULLUP(Z3_MIN_PIN);
  138. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  139. SET_INPUT_PULLDOWN(Z3_MIN_PIN);
  140. #else
  141. SET_INPUT(Z3_MIN_PIN);
  142. #endif
  143. #endif
  144. #if HAS_Z4_MIN
  145. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  146. SET_INPUT_PULLUP(Z4_MIN_PIN);
  147. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  148. SET_INPUT_PULLDOWN(Z4_MIN_PIN);
  149. #else
  150. SET_INPUT(Z4_MIN_PIN);
  151. #endif
  152. #endif
  153. #if HAS_X_MAX
  154. #if ENABLED(ENDSTOPPULLUP_XMAX)
  155. SET_INPUT_PULLUP(X_MAX_PIN);
  156. #elif ENABLED(ENDSTOPPULLDOWN_XMAX)
  157. SET_INPUT_PULLDOWN(X_MAX_PIN);
  158. #else
  159. SET_INPUT(X_MAX_PIN);
  160. #endif
  161. #endif
  162. #if HAS_X2_MAX
  163. #if ENABLED(ENDSTOPPULLUP_XMAX)
  164. SET_INPUT_PULLUP(X2_MAX_PIN);
  165. #elif ENABLED(ENDSTOPPULLDOWN_XMAX)
  166. SET_INPUT_PULLDOWN(X2_MAX_PIN);
  167. #else
  168. SET_INPUT(X2_MAX_PIN);
  169. #endif
  170. #endif
  171. #if HAS_Y_MAX
  172. #if ENABLED(ENDSTOPPULLUP_YMAX)
  173. SET_INPUT_PULLUP(Y_MAX_PIN);
  174. #elif ENABLED(ENDSTOPPULLDOWN_YMAX)
  175. SET_INPUT_PULLDOWN(Y_MAX_PIN);
  176. #else
  177. SET_INPUT(Y_MAX_PIN);
  178. #endif
  179. #endif
  180. #if HAS_Y2_MAX
  181. #if ENABLED(ENDSTOPPULLUP_YMAX)
  182. SET_INPUT_PULLUP(Y2_MAX_PIN);
  183. #elif ENABLED(ENDSTOPPULLDOWN_YMAX)
  184. SET_INPUT_PULLDOWN(Y2_MAX_PIN);
  185. #else
  186. SET_INPUT(Y2_MAX_PIN);
  187. #endif
  188. #endif
  189. #if HAS_Z_MAX
  190. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  191. SET_INPUT_PULLUP(Z_MAX_PIN);
  192. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  193. SET_INPUT_PULLDOWN(Z_MAX_PIN);
  194. #else
  195. SET_INPUT(Z_MAX_PIN);
  196. #endif
  197. #endif
  198. #if HAS_Z2_MAX
  199. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  200. SET_INPUT_PULLUP(Z2_MAX_PIN);
  201. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  202. SET_INPUT_PULLDOWN(Z2_MAX_PIN);
  203. #else
  204. SET_INPUT(Z2_MAX_PIN);
  205. #endif
  206. #endif
  207. #if HAS_Z3_MAX
  208. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  209. SET_INPUT_PULLUP(Z3_MAX_PIN);
  210. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  211. SET_INPUT_PULLDOWN(Z3_MAX_PIN);
  212. #else
  213. SET_INPUT(Z3_MAX_PIN);
  214. #endif
  215. #endif
  216. #if HAS_Z4_MAX
  217. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  218. SET_INPUT_PULLUP(Z4_MAX_PIN);
  219. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  220. SET_INPUT_PULLDOWN(Z4_MAX_PIN);
  221. #else
  222. SET_INPUT(Z4_MAX_PIN);
  223. #endif
  224. #endif
  225. #if PIN_EXISTS(CALIBRATION)
  226. #if ENABLED(CALIBRATION_PIN_PULLUP)
  227. SET_INPUT_PULLUP(CALIBRATION_PIN);
  228. #elif ENABLED(CALIBRATION_PIN_PULLDOWN)
  229. SET_INPUT_PULLDOWN(CALIBRATION_PIN);
  230. #else
  231. SET_INPUT(CALIBRATION_PIN);
  232. #endif
  233. #endif
  234. #if HAS_CUSTOM_PROBE_PIN
  235. #if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
  236. SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
  237. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN_PROBE)
  238. SET_INPUT_PULLDOWN(Z_MIN_PROBE_PIN);
  239. #else
  240. SET_INPUT(Z_MIN_PROBE_PIN);
  241. #endif
  242. #endif
  243. TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());
  244. // Enable endstops
  245. enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
  246. } // Endstops::init
  247. // Called at ~1KHz from Temperature ISR: Poll endstop state if required
  248. void Endstops::poll() {
  249. TERN_(PINS_DEBUGGING, run_monitor()); // Report changes in endstop status
  250. #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE)
  251. update();
  252. #elif ENDSTOP_NOISE_THRESHOLD
  253. if (endstop_poll_count) update();
  254. #endif
  255. }
  256. void Endstops::enable_globally(const bool onoff) {
  257. enabled_globally = enabled = onoff;
  258. resync();
  259. }
  260. // Enable / disable endstop checking
  261. void Endstops::enable(const bool onoff) {
  262. enabled = onoff;
  263. resync();
  264. }
  265. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  266. void Endstops::not_homing() {
  267. enabled = enabled_globally;
  268. }
  269. #if ENABLED(VALIDATE_HOMING_ENDSTOPS)
  270. // If the last move failed to trigger an endstop, call kill
  271. void Endstops::validate_homing_move() {
  272. if (trigger_state()) hit_on_purpose();
  273. else kill(GET_TEXT(MSG_KILL_HOMING_FAILED));
  274. }
  275. #endif
  276. // Enable / disable endstop z-probe checking
  277. #if HAS_BED_PROBE
  278. void Endstops::enable_z_probe(const bool onoff) {
  279. z_probe_enabled = onoff;
  280. resync();
  281. }
  282. #endif
  283. // Get the stable endstop states when enabled
  284. void Endstops::resync() {
  285. if (!abort_enabled()) return; // If endstops/probes are disabled the loop below can hang
  286. // Wait for Temperature ISR to run at least once (runs at 1KHz)
  287. TERN(ENDSTOP_INTERRUPTS_FEATURE, update(), safe_delay(2));
  288. while (TERN0(ENDSTOP_NOISE_THRESHOLD, endstop_poll_count)) safe_delay(1);
  289. }
  290. #if ENABLED(PINS_DEBUGGING)
  291. void Endstops::run_monitor() {
  292. if (!monitor_flag) return;
  293. static uint8_t monitor_count = 16; // offset this check from the others
  294. monitor_count += _BV(1); // 15 Hz
  295. monitor_count &= 0x7F;
  296. if (!monitor_count) monitor(); // report changes in endstop status
  297. }
  298. #endif
  299. void Endstops::event_handler() {
  300. static uint8_t prev_hit_state; // = 0
  301. if (hit_state == prev_hit_state) return;
  302. prev_hit_state = hit_state;
  303. if (hit_state) {
  304. #if HAS_SPI_LCD
  305. char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
  306. #define _SET_STOP_CHAR(A,C) (chr## A = C)
  307. #else
  308. #define _SET_STOP_CHAR(A,C) ;
  309. #endif
  310. #define _ENDSTOP_HIT_ECHO(A,C) do{ \
  311. SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", planner.triggered_position_mm(_AXIS(A))); \
  312. _SET_STOP_CHAR(A,C); }while(0)
  313. #define _ENDSTOP_HIT_TEST(A,C) \
  314. if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \
  315. _ENDSTOP_HIT_ECHO(A,C)
  316. #define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
  317. #define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
  318. #define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')
  319. SERIAL_ECHO_START();
  320. SERIAL_ECHOPGM(STR_ENDSTOPS_HIT);
  321. ENDSTOP_HIT_TEST_X();
  322. ENDSTOP_HIT_TEST_Y();
  323. ENDSTOP_HIT_TEST_Z();
  324. #if HAS_CUSTOM_PROBE_PIN
  325. #define P_AXIS Z_AXIS
  326. if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
  327. #endif
  328. SERIAL_EOL();
  329. TERN_(HAS_SPI_LCD, ui.status_printf_P(0, PSTR(S_FMT " %c %c %c %c"), GET_TEXT(MSG_LCD_ENDSTOPS), chrX, chrY, chrZ, chrP));
  330. #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
  331. if (planner.abort_on_endstop_hit) {
  332. card.endFilePrint();
  333. quickstop_stepper();
  334. thermalManager.disable_all_heaters();
  335. print_job_timer.stop();
  336. }
  337. #endif
  338. }
  339. }
  340. static void print_es_state(const bool is_hit, PGM_P const label=nullptr) {
  341. if (label) serialprintPGM(label);
  342. SERIAL_ECHOPGM(": ");
  343. serialprintPGM(is_hit ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN));
  344. SERIAL_EOL();
  345. }
  346. void _O2 Endstops::report_states() {
  347. TERN_(BLTOUCH, bltouch._set_SW_mode());
  348. SERIAL_ECHOLNPGM(STR_M119_REPORT);
  349. #define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, PSTR(STR_##S))
  350. #if HAS_X_MIN
  351. ES_REPORT(X_MIN);
  352. #endif
  353. #if HAS_X2_MIN
  354. ES_REPORT(X2_MIN);
  355. #endif
  356. #if HAS_X_MAX
  357. ES_REPORT(X_MAX);
  358. #endif
  359. #if HAS_X2_MAX
  360. ES_REPORT(X2_MAX);
  361. #endif
  362. #if HAS_Y_MIN
  363. ES_REPORT(Y_MIN);
  364. #endif
  365. #if HAS_Y2_MIN
  366. ES_REPORT(Y2_MIN);
  367. #endif
  368. #if HAS_Y_MAX
  369. ES_REPORT(Y_MAX);
  370. #endif
  371. #if HAS_Y2_MAX
  372. ES_REPORT(Y2_MAX);
  373. #endif
  374. #if HAS_Z_MIN
  375. ES_REPORT(Z_MIN);
  376. #endif
  377. #if HAS_Z2_MIN
  378. ES_REPORT(Z2_MIN);
  379. #endif
  380. #if HAS_Z3_MIN
  381. ES_REPORT(Z3_MIN);
  382. #endif
  383. #if HAS_Z4_MIN
  384. ES_REPORT(Z4_MIN);
  385. #endif
  386. #if HAS_Z_MAX
  387. ES_REPORT(Z_MAX);
  388. #endif
  389. #if HAS_Z2_MAX
  390. ES_REPORT(Z2_MAX);
  391. #endif
  392. #if HAS_Z3_MAX
  393. ES_REPORT(Z3_MAX);
  394. #endif
  395. #if HAS_Z4_MAX
  396. ES_REPORT(Z4_MAX);
  397. #endif
  398. #if HAS_CUSTOM_PROBE_PIN
  399. print_es_state(READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING, PSTR(STR_Z_PROBE));
  400. #endif
  401. #if HAS_FILAMENT_SENSOR
  402. #if NUM_RUNOUT_SENSORS == 1
  403. print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
  404. #else
  405. #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
  406. LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
  407. pin_t pin;
  408. switch (i) {
  409. default: continue;
  410. REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT)
  411. }
  412. SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR);
  413. if (i > 1) SERIAL_CHAR(' ', '0' + i);
  414. print_es_state(extDigitalRead(pin) != FIL_RUNOUT_STATE);
  415. }
  416. #undef _CASE_RUNOUT
  417. #endif
  418. #endif
  419. TERN_(BLTOUCH, bltouch._reset_SW_mode());
  420. TERN_(JOYSTICK_DEBUG, joystick.report());
  421. } // Endstops::report_states
  422. // The following routines are called from an ISR context. It could be the temperature ISR, the
  423. // endstop ISR or the Stepper ISR.
  424. #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
  425. #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
  426. #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
  427. // Check endstops - Could be called from Temperature ISR!
  428. void Endstops::update() {
  429. #if !ENDSTOP_NOISE_THRESHOLD
  430. if (!abort_enabled()) return;
  431. #endif
  432. #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
  433. #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
  434. #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
  435. // If G38 command is active check Z_MIN_PROBE for ALL movement
  436. if (G38_move) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
  437. #endif
  438. // With Dual X, endstops are only checked in the homing direction for the active extruder
  439. #if ENABLED(DUAL_X_CARRIAGE)
  440. #define E0_ACTIVE stepper.movement_extruder() == 0
  441. #define X_MIN_TEST() ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
  442. #define X_MAX_TEST() ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
  443. #else
  444. #define X_MIN_TEST() true
  445. #define X_MAX_TEST() true
  446. #endif
  447. // Use HEAD for core axes, AXIS for others
  448. #if ANY(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
  449. #define X_AXIS_HEAD X_HEAD
  450. #else
  451. #define X_AXIS_HEAD X_AXIS
  452. #endif
  453. #if ANY(CORE_IS_XY, CORE_IS_YZ, MARKFORGED_XY)
  454. #define Y_AXIS_HEAD Y_HEAD
  455. #else
  456. #define Y_AXIS_HEAD Y_AXIS
  457. #endif
  458. #if CORE_IS_XZ || CORE_IS_YZ
  459. #define Z_AXIS_HEAD Z_HEAD
  460. #else
  461. #define Z_AXIS_HEAD Z_AXIS
  462. #endif
  463. /**
  464. * Check and update endstops
  465. */
  466. #if HAS_X_MIN && !X_SPI_SENSORLESS
  467. UPDATE_ENDSTOP_BIT(X, MIN);
  468. #if ENABLED(X_DUAL_ENDSTOPS)
  469. #if HAS_X2_MIN
  470. UPDATE_ENDSTOP_BIT(X2, MIN);
  471. #else
  472. COPY_LIVE_STATE(X_MIN, X2_MIN);
  473. #endif
  474. #endif
  475. #endif
  476. #if HAS_X_MAX && !X_SPI_SENSORLESS
  477. UPDATE_ENDSTOP_BIT(X, MAX);
  478. #if ENABLED(X_DUAL_ENDSTOPS)
  479. #if HAS_X2_MAX
  480. UPDATE_ENDSTOP_BIT(X2, MAX);
  481. #else
  482. COPY_LIVE_STATE(X_MAX, X2_MAX);
  483. #endif
  484. #endif
  485. #endif
  486. #if HAS_Y_MIN && !Y_SPI_SENSORLESS
  487. UPDATE_ENDSTOP_BIT(Y, MIN);
  488. #if ENABLED(Y_DUAL_ENDSTOPS)
  489. #if HAS_Y2_MIN
  490. UPDATE_ENDSTOP_BIT(Y2, MIN);
  491. #else
  492. COPY_LIVE_STATE(Y_MIN, Y2_MIN);
  493. #endif
  494. #endif
  495. #endif
  496. #if HAS_Y_MAX && !Y_SPI_SENSORLESS
  497. UPDATE_ENDSTOP_BIT(Y, MAX);
  498. #if ENABLED(Y_DUAL_ENDSTOPS)
  499. #if HAS_Y2_MAX
  500. UPDATE_ENDSTOP_BIT(Y2, MAX);
  501. #else
  502. COPY_LIVE_STATE(Y_MAX, Y2_MAX);
  503. #endif
  504. #endif
  505. #endif
  506. #if HAS_Z_MIN && !Z_SPI_SENSORLESS
  507. UPDATE_ENDSTOP_BIT(Z, MIN);
  508. #if ENABLED(Z_MULTI_ENDSTOPS)
  509. #if HAS_Z2_MIN
  510. UPDATE_ENDSTOP_BIT(Z2, MIN);
  511. #else
  512. COPY_LIVE_STATE(Z_MIN, Z2_MIN);
  513. #endif
  514. #if NUM_Z_STEPPER_DRIVERS >= 3
  515. #if HAS_Z3_MIN
  516. UPDATE_ENDSTOP_BIT(Z3, MIN);
  517. #else
  518. COPY_LIVE_STATE(Z_MIN, Z3_MIN);
  519. #endif
  520. #endif
  521. #if NUM_Z_STEPPER_DRIVERS >= 4
  522. #if HAS_Z4_MIN
  523. UPDATE_ENDSTOP_BIT(Z4, MIN);
  524. #else
  525. COPY_LIVE_STATE(Z_MIN, Z4_MIN);
  526. #endif
  527. #endif
  528. #endif
  529. #endif
  530. // When closing the gap check the enabled probe
  531. #if HAS_CUSTOM_PROBE_PIN
  532. UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
  533. #endif
  534. #if HAS_Z_MAX && !Z_SPI_SENSORLESS
  535. // Check both Z dual endstops
  536. #if ENABLED(Z_MULTI_ENDSTOPS)
  537. UPDATE_ENDSTOP_BIT(Z, MAX);
  538. #if HAS_Z2_MAX
  539. UPDATE_ENDSTOP_BIT(Z2, MAX);
  540. #else
  541. COPY_LIVE_STATE(Z_MAX, Z2_MAX);
  542. #endif
  543. #if NUM_Z_STEPPER_DRIVERS >= 3
  544. #if HAS_Z3_MAX
  545. UPDATE_ENDSTOP_BIT(Z3, MAX);
  546. #else
  547. COPY_LIVE_STATE(Z_MAX, Z3_MAX);
  548. #endif
  549. #endif
  550. #if NUM_Z_STEPPER_DRIVERS >= 4
  551. #if HAS_Z4_MAX
  552. UPDATE_ENDSTOP_BIT(Z4, MAX);
  553. #else
  554. COPY_LIVE_STATE(Z_MAX, Z4_MAX);
  555. #endif
  556. #endif
  557. #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN
  558. // If this pin isn't the bed probe it's the Z endstop
  559. UPDATE_ENDSTOP_BIT(Z, MAX);
  560. #endif
  561. #endif
  562. #if ENDSTOP_NOISE_THRESHOLD
  563. /**
  564. * Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
  565. * that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
  566. * of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
  567. * also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
  568. * 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
  569. * reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
  570. * still exist. The only way to reduce them further is to increase the number of samples.
  571. * To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
  572. */
  573. static esbits_t old_live_state;
  574. if (old_live_state != live_state) {
  575. endstop_poll_count = ENDSTOP_NOISE_THRESHOLD;
  576. old_live_state = live_state;
  577. }
  578. else if (endstop_poll_count && !--endstop_poll_count)
  579. validated_live_state = live_state;
  580. if (!abort_enabled()) return;
  581. #endif
  582. // Test the current status of an endstop
  583. #define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
  584. // Record endstop was hit
  585. #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
  586. // Call the endstop triggered routine for single endstops
  587. #define PROCESS_ENDSTOP(AXIS, MINMAX) do { \
  588. if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
  589. _ENDSTOP_HIT(AXIS, MINMAX); \
  590. planner.endstop_triggered(_AXIS(AXIS)); \
  591. } \
  592. }while(0)
  593. // Core Sensorless Homing needs to test an Extra Pin
  594. #define CORE_DIAG(QQ,A,MM) (CORE_IS_##QQ && A##_SENSORLESS && !A##_SPI_SENSORLESS && HAS_##A##_##MM)
  595. #define PROCESS_CORE_ENDSTOP(A1,M1,A2,M2) do { \
  596. if (TEST_ENDSTOP(_ENDSTOP(A1,M1))) { \
  597. _ENDSTOP_HIT(A2,M2); \
  598. planner.endstop_triggered(_AXIS(A2)); \
  599. } \
  600. }while(0)
  601. // Call the endstop triggered routine for dual endstops
  602. #define PROCESS_DUAL_ENDSTOP(A, MINMAX) do { \
  603. const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1); \
  604. if (dual_hit) { \
  605. _ENDSTOP_HIT(A, MINMAX); \
  606. /* if not performing home or if both endstops were trigged during homing... */ \
  607. if (!stepper.separate_multi_axis || dual_hit == 0b11) \
  608. planner.endstop_triggered(_AXIS(A)); \
  609. } \
  610. }while(0)
  611. #define PROCESS_TRIPLE_ENDSTOP(A, MINMAX) do { \
  612. const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2); \
  613. if (triple_hit) { \
  614. _ENDSTOP_HIT(A, MINMAX); \
  615. /* if not performing home or if both endstops were trigged during homing... */ \
  616. if (!stepper.separate_multi_axis || triple_hit == 0b111) \
  617. planner.endstop_triggered(_AXIS(A)); \
  618. } \
  619. }while(0)
  620. #define PROCESS_QUAD_ENDSTOP(A, MINMAX) do { \
  621. const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(A##4, MINMAX)) << 3); \
  622. if (quad_hit) { \
  623. _ENDSTOP_HIT(A, MINMAX); \
  624. /* if not performing home or if both endstops were trigged during homing... */ \
  625. if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
  626. planner.endstop_triggered(_AXIS(A)); \
  627. } \
  628. }while(0)
  629. #if ENABLED(X_DUAL_ENDSTOPS)
  630. #define PROCESS_ENDSTOP_X(MINMAX) PROCESS_DUAL_ENDSTOP(X, MINMAX)
  631. #else
  632. #define PROCESS_ENDSTOP_X(MINMAX) if (X_##MINMAX##_TEST()) PROCESS_ENDSTOP(X, MINMAX)
  633. #endif
  634. #if ENABLED(Y_DUAL_ENDSTOPS)
  635. #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_DUAL_ENDSTOP(Y, MINMAX)
  636. #else
  637. #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_ENDSTOP(Y, MINMAX)
  638. #endif
  639. #if DISABLED(Z_MULTI_ENDSTOPS)
  640. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_ENDSTOP(Z, MINMAX)
  641. #elif NUM_Z_STEPPER_DRIVERS == 4
  642. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_QUAD_ENDSTOP(Z, MINMAX)
  643. #elif NUM_Z_STEPPER_DRIVERS == 3
  644. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_TRIPLE_ENDSTOP(Z, MINMAX)
  645. #else
  646. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_DUAL_ENDSTOP(Z, MINMAX)
  647. #endif
  648. #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
  649. #if ENABLED(G38_PROBE_AWAY)
  650. #define _G38_OPEN_STATE (G38_move >= 4)
  651. #else
  652. #define _G38_OPEN_STATE LOW
  653. #endif
  654. // If G38 command is active check Z_MIN_PROBE for ALL movement
  655. if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE)) != _G38_OPEN_STATE) {
  656. if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(X_AXIS); }
  657. else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(Y_AXIS); }
  658. else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(Z_AXIS); }
  659. G38_did_trigger = true;
  660. }
  661. #endif
  662. // Signal, after validation, if an endstop limit is pressed or not
  663. if (stepper.axis_is_moving(X_AXIS)) {
  664. if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
  665. #if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
  666. PROCESS_ENDSTOP_X(MIN);
  667. #if CORE_DIAG(XY, Y, MIN)
  668. PROCESS_CORE_ENDSTOP(Y,MIN,X,MIN);
  669. #elif CORE_DIAG(XY, Y, MAX)
  670. PROCESS_CORE_ENDSTOP(Y,MAX,X,MIN);
  671. #elif CORE_DIAG(XZ, Z, MIN)
  672. PROCESS_CORE_ENDSTOP(Z,MIN,X,MIN);
  673. #elif CORE_DIAG(XZ, Z, MAX)
  674. PROCESS_CORE_ENDSTOP(Z,MAX,X,MIN);
  675. #endif
  676. #endif
  677. }
  678. else { // +direction
  679. #if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
  680. PROCESS_ENDSTOP_X(MAX);
  681. #if CORE_DIAG(XY, Y, MIN)
  682. PROCESS_CORE_ENDSTOP(Y,MIN,X,MAX);
  683. #elif CORE_DIAG(XY, Y, MAX)
  684. PROCESS_CORE_ENDSTOP(Y,MAX,X,MAX);
  685. #elif CORE_DIAG(XZ, Z, MIN)
  686. PROCESS_CORE_ENDSTOP(Z,MIN,X,MAX);
  687. #elif CORE_DIAG(XZ, Z, MAX)
  688. PROCESS_CORE_ENDSTOP(Z,MAX,X,MAX);
  689. #endif
  690. #endif
  691. }
  692. }
  693. if (stepper.axis_is_moving(Y_AXIS)) {
  694. if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
  695. #if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
  696. PROCESS_ENDSTOP_Y(MIN);
  697. #if CORE_DIAG(XY, X, MIN)
  698. PROCESS_CORE_ENDSTOP(X,MIN,Y,MIN);
  699. #elif CORE_DIAG(XY, X, MAX)
  700. PROCESS_CORE_ENDSTOP(X,MAX,Y,MIN);
  701. #elif CORE_DIAG(YZ, Z, MIN)
  702. PROCESS_CORE_ENDSTOP(Z,MIN,Y,MIN);
  703. #elif CORE_DIAG(YZ, Z, MAX)
  704. PROCESS_CORE_ENDSTOP(Z,MAX,Y,MIN);
  705. #endif
  706. #endif
  707. }
  708. else { // +direction
  709. #if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
  710. PROCESS_ENDSTOP_Y(MAX);
  711. #if CORE_DIAG(XY, X, MIN)
  712. PROCESS_CORE_ENDSTOP(X,MIN,Y,MAX);
  713. #elif CORE_DIAG(XY, X, MAX)
  714. PROCESS_CORE_ENDSTOP(X,MAX,Y,MAX);
  715. #elif CORE_DIAG(YZ, Z, MIN)
  716. PROCESS_CORE_ENDSTOP(Z,MIN,Y,MAX);
  717. #elif CORE_DIAG(YZ, Z, MAX)
  718. PROCESS_CORE_ENDSTOP(Z,MAX,Y,MAX);
  719. #endif
  720. #endif
  721. }
  722. }
  723. if (stepper.axis_is_moving(Z_AXIS)) {
  724. if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
  725. #if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
  726. if ( TERN1(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, z_probe_enabled)
  727. && TERN1(HAS_CUSTOM_PROBE_PIN, !z_probe_enabled)
  728. ) PROCESS_ENDSTOP_Z(MIN);
  729. #if CORE_DIAG(XZ, X, MIN)
  730. PROCESS_CORE_ENDSTOP(X,MIN,Z,MIN);
  731. #elif CORE_DIAG(XZ, X, MAX)
  732. PROCESS_CORE_ENDSTOP(X,MAX,Z,MIN);
  733. #elif CORE_DIAG(YZ, Y, MIN)
  734. PROCESS_CORE_ENDSTOP(Y,MIN,Z,MIN);
  735. #elif CORE_DIAG(YZ, Y, MAX)
  736. PROCESS_CORE_ENDSTOP(Y,MAX,Z,MIN);
  737. #endif
  738. #endif
  739. // When closing the gap check the enabled probe
  740. #if HAS_CUSTOM_PROBE_PIN
  741. if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE);
  742. #endif
  743. }
  744. else { // Z +direction. Gantry up, bed down.
  745. #if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
  746. #if ENABLED(Z_MULTI_ENDSTOPS)
  747. PROCESS_ENDSTOP_Z(MAX);
  748. #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN // No probe or probe is Z_MIN || Probe is not Z_MAX
  749. PROCESS_ENDSTOP(Z, MAX);
  750. #endif
  751. #if CORE_DIAG(XZ, X, MIN)
  752. PROCESS_CORE_ENDSTOP(X,MIN,Z,MAX);
  753. #elif CORE_DIAG(XZ, X, MAX)
  754. PROCESS_CORE_ENDSTOP(X,MAX,Z,MAX);
  755. #elif CORE_DIAG(YZ, Y, MIN)
  756. PROCESS_CORE_ENDSTOP(Y,MIN,Z,MAX);
  757. #elif CORE_DIAG(YZ, Y, MAX)
  758. PROCESS_CORE_ENDSTOP(Y,MAX,Z,MAX);
  759. #endif
  760. #endif
  761. }
  762. }
  763. } // Endstops::update()
  764. #if ENABLED(SPI_ENDSTOPS)
  765. bool Endstops::tmc_spi_homing_check() {
  766. bool hit = false;
  767. #if X_SPI_SENSORLESS
  768. if (tmc_spi_homing.x && (stepperX.test_stall_status()
  769. #if ANY(CORE_IS_XY, MARKFORGED_XY) && Y_SPI_SENSORLESS
  770. || stepperY.test_stall_status()
  771. #elif CORE_IS_XZ && Z_SPI_SENSORLESS
  772. || stepperZ.test_stall_status()
  773. #endif
  774. )) {
  775. SBI(live_state, X_ENDSTOP);
  776. hit = true;
  777. }
  778. #endif
  779. #if Y_SPI_SENSORLESS
  780. if (tmc_spi_homing.y && (stepperY.test_stall_status()
  781. #if ANY(CORE_IS_XY, MARKFORGED_XY) && X_SPI_SENSORLESS
  782. || stepperX.test_stall_status()
  783. #elif CORE_IS_YZ && Z_SPI_SENSORLESS
  784. || stepperZ.test_stall_status()
  785. #endif
  786. )) {
  787. SBI(live_state, Y_ENDSTOP);
  788. hit = true;
  789. }
  790. #endif
  791. #if Z_SPI_SENSORLESS
  792. if (tmc_spi_homing.z && (stepperZ.test_stall_status()
  793. #if CORE_IS_XZ && X_SPI_SENSORLESS
  794. || stepperX.test_stall_status()
  795. #elif CORE_IS_YZ && Y_SPI_SENSORLESS
  796. || stepperY.test_stall_status()
  797. #endif
  798. )) {
  799. SBI(live_state, Z_ENDSTOP);
  800. hit = true;
  801. }
  802. #endif
  803. return hit;
  804. }
  805. void Endstops::clear_endstop_state() {
  806. TERN_(X_SPI_SENSORLESS, CBI(live_state, X_ENDSTOP));
  807. TERN_(Y_SPI_SENSORLESS, CBI(live_state, Y_ENDSTOP));
  808. TERN_(Z_SPI_SENSORLESS, CBI(live_state, Z_ENDSTOP));
  809. }
  810. #endif // SPI_ENDSTOPS
  811. #if ENABLED(PINS_DEBUGGING)
  812. bool Endstops::monitor_flag = false;
  813. /**
  814. * Monitor Endstops and Z Probe for changes
  815. *
  816. * If a change is detected then the LED is toggled and
  817. * a message is sent out the serial port.
  818. *
  819. * Yes, we could miss a rapid back & forth change but
  820. * that won't matter because this is all manual.
  821. */
  822. void Endstops::monitor() {
  823. static uint16_t old_live_state_local = 0;
  824. static uint8_t local_LED_status = 0;
  825. uint16_t live_state_local = 0;
  826. #define ES_GET_STATE(S) if (READ(S##_PIN)) SBI(live_state_local, S)
  827. #if HAS_X_MIN
  828. ES_GET_STATE(X_MIN);
  829. #endif
  830. #if HAS_X_MAX
  831. ES_GET_STATE(X_MAX);
  832. #endif
  833. #if HAS_Y_MIN
  834. ES_GET_STATE(Y_MIN);
  835. #endif
  836. #if HAS_Y_MAX
  837. ES_GET_STATE(Y_MAX);
  838. #endif
  839. #if HAS_Z_MIN
  840. ES_GET_STATE(Z_MIN);
  841. #endif
  842. #if HAS_Z_MAX
  843. ES_GET_STATE(Z_MAX);
  844. #endif
  845. #if HAS_Z_MIN_PROBE_PIN
  846. ES_GET_STATE(Z_MIN_PROBE);
  847. #endif
  848. #if HAS_X2_MIN
  849. ES_GET_STATE(X2_MIN);
  850. #endif
  851. #if HAS_X2_MAX
  852. ES_GET_STATE(X2_MAX);
  853. #endif
  854. #if HAS_Y2_MIN
  855. ES_GET_STATE(Y2_MIN);
  856. #endif
  857. #if HAS_Y2_MAX
  858. ES_GET_STATE(Y2_MAX);
  859. #endif
  860. #if HAS_Z2_MIN
  861. ES_GET_STATE(Z2_MIN);
  862. #endif
  863. #if HAS_Z2_MAX
  864. ES_GET_STATE(Z2_MAX);
  865. #endif
  866. #if HAS_Z3_MIN
  867. ES_GET_STATE(Z3_MIN);
  868. #endif
  869. #if HAS_Z3_MAX
  870. ES_GET_STATE(Z3_MAX);
  871. #endif
  872. #if HAS_Z4_MIN
  873. ES_GET_STATE(Z4_MIN);
  874. #endif
  875. #if HAS_Z4_MAX
  876. ES_GET_STATE(Z4_MAX);
  877. #endif
  878. uint16_t endstop_change = live_state_local ^ old_live_state_local;
  879. #define ES_REPORT_CHANGE(S) if (TEST(endstop_change, S)) SERIAL_ECHOPAIR(" " STRINGIFY(S) ":", TEST(live_state_local, S))
  880. if (endstop_change) {
  881. #if HAS_X_MIN
  882. ES_REPORT_CHANGE(X_MIN);
  883. #endif
  884. #if HAS_X_MAX
  885. ES_REPORT_CHANGE(X_MAX);
  886. #endif
  887. #if HAS_Y_MIN
  888. ES_REPORT_CHANGE(Y_MIN);
  889. #endif
  890. #if HAS_Y_MAX
  891. ES_REPORT_CHANGE(Y_MAX);
  892. #endif
  893. #if HAS_Z_MIN
  894. ES_REPORT_CHANGE(Z_MIN);
  895. #endif
  896. #if HAS_Z_MAX
  897. ES_REPORT_CHANGE(Z_MAX);
  898. #endif
  899. #if HAS_Z_MIN_PROBE_PIN
  900. ES_REPORT_CHANGE(Z_MIN_PROBE);
  901. #endif
  902. #if HAS_X2_MIN
  903. ES_REPORT_CHANGE(X2_MIN);
  904. #endif
  905. #if HAS_X2_MAX
  906. ES_REPORT_CHANGE(X2_MAX);
  907. #endif
  908. #if HAS_Y2_MIN
  909. ES_REPORT_CHANGE(Y2_MIN);
  910. #endif
  911. #if HAS_Y2_MAX
  912. ES_REPORT_CHANGE(Y2_MAX);
  913. #endif
  914. #if HAS_Z2_MIN
  915. ES_REPORT_CHANGE(Z2_MIN);
  916. #endif
  917. #if HAS_Z2_MAX
  918. ES_REPORT_CHANGE(Z2_MAX);
  919. #endif
  920. #if HAS_Z3_MIN
  921. ES_REPORT_CHANGE(Z3_MIN);
  922. #endif
  923. #if HAS_Z3_MAX
  924. ES_REPORT_CHANGE(Z3_MAX);
  925. #endif
  926. #if HAS_Z4_MIN
  927. ES_REPORT_CHANGE(Z4_MIN);
  928. #endif
  929. #if HAS_Z4_MAX
  930. ES_REPORT_CHANGE(Z4_MAX);
  931. #endif
  932. SERIAL_ECHOLNPGM("\n");
  933. analogWrite(pin_t(LED_PIN), local_LED_status);
  934. local_LED_status ^= 255;
  935. old_live_state_local = live_state_local;
  936. }
  937. }
  938. #endif // PINS_DEBUGGING