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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  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 "../sd/cardreader.h"
  28. #include "temperature.h"
  29. #include "../lcd/marlinui.h"
  30. #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
  31. #include HAL_PATH(../HAL, endstop_interrupts.h)
  32. #endif
  33. #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
  34. #include "printcounter.h" // for print_job_timer
  35. #endif
  36. #if ENABLED(BLTOUCH)
  37. #include "../feature/bltouch.h"
  38. #endif
  39. #if ENABLED(JOYSTICK)
  40. #include "../feature/joystick.h"
  41. #endif
  42. #if HAS_BED_PROBE
  43. #include "probe.h"
  44. #endif
  45. Endstops endstops;
  46. // private:
  47. bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
  48. volatile Endstops::endstop_mask_t Endstops::hit_state;
  49. Endstops::endstop_mask_t Endstops::live_state = 0;
  50. #if ENDSTOP_NOISE_THRESHOLD
  51. Endstops::endstop_mask_t Endstops::validated_live_state;
  52. uint8_t Endstops::endstop_poll_count;
  53. #endif
  54. #if HAS_BED_PROBE
  55. volatile bool Endstops::z_probe_enabled = false;
  56. #endif
  57. // Initialized by settings.load()
  58. #if ENABLED(X_DUAL_ENDSTOPS)
  59. float Endstops::x2_endstop_adj;
  60. #endif
  61. #if ENABLED(Y_DUAL_ENDSTOPS)
  62. float Endstops::y2_endstop_adj;
  63. #endif
  64. #if ENABLED(Z_MULTI_ENDSTOPS)
  65. float Endstops::z2_endstop_adj;
  66. #if NUM_Z_STEPPERS >= 3
  67. float Endstops::z3_endstop_adj;
  68. #if NUM_Z_STEPPERS >= 4
  69. float Endstops::z4_endstop_adj;
  70. #endif
  71. #endif
  72. #endif
  73. #if ENABLED(SPI_ENDSTOPS)
  74. Endstops::tmc_spi_homing_t Endstops::tmc_spi_homing; // = 0
  75. #endif
  76. #if ENABLED(IMPROVE_HOMING_RELIABILITY)
  77. millis_t sg_guard_period; // = 0
  78. #endif
  79. /**
  80. * Class and Instance Methods
  81. */
  82. void Endstops::init() {
  83. #if HAS_X_MIN
  84. #if ENABLED(ENDSTOPPULLUP_XMIN)
  85. SET_INPUT_PULLUP(X_MIN_PIN);
  86. #elif ENABLED(ENDSTOPPULLDOWN_XMIN)
  87. SET_INPUT_PULLDOWN(X_MIN_PIN);
  88. #else
  89. SET_INPUT(X_MIN_PIN);
  90. #endif
  91. #endif
  92. #if HAS_X2_MIN
  93. #if ENABLED(ENDSTOPPULLUP_XMIN)
  94. SET_INPUT_PULLUP(X2_MIN_PIN);
  95. #elif ENABLED(ENDSTOPPULLDOWN_XMIN)
  96. SET_INPUT_PULLDOWN(X2_MIN_PIN);
  97. #else
  98. SET_INPUT(X2_MIN_PIN);
  99. #endif
  100. #endif
  101. #if HAS_Y_MIN
  102. #if ENABLED(ENDSTOPPULLUP_YMIN)
  103. SET_INPUT_PULLUP(Y_MIN_PIN);
  104. #elif ENABLED(ENDSTOPPULLDOWN_YMIN)
  105. SET_INPUT_PULLDOWN(Y_MIN_PIN);
  106. #else
  107. SET_INPUT(Y_MIN_PIN);
  108. #endif
  109. #endif
  110. #if HAS_Y2_MIN
  111. #if ENABLED(ENDSTOPPULLUP_YMIN)
  112. SET_INPUT_PULLUP(Y2_MIN_PIN);
  113. #elif ENABLED(ENDSTOPPULLDOWN_YMIN)
  114. SET_INPUT_PULLDOWN(Y2_MIN_PIN);
  115. #else
  116. SET_INPUT(Y2_MIN_PIN);
  117. #endif
  118. #endif
  119. #if HAS_Z_MIN
  120. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  121. SET_INPUT_PULLUP(Z_MIN_PIN);
  122. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  123. SET_INPUT_PULLDOWN(Z_MIN_PIN);
  124. #else
  125. SET_INPUT(Z_MIN_PIN);
  126. #endif
  127. #endif
  128. #if HAS_Z2_MIN
  129. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  130. SET_INPUT_PULLUP(Z2_MIN_PIN);
  131. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  132. SET_INPUT_PULLDOWN(Z2_MIN_PIN);
  133. #else
  134. SET_INPUT(Z2_MIN_PIN);
  135. #endif
  136. #endif
  137. #if HAS_Z3_MIN
  138. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  139. SET_INPUT_PULLUP(Z3_MIN_PIN);
  140. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  141. SET_INPUT_PULLDOWN(Z3_MIN_PIN);
  142. #else
  143. SET_INPUT(Z3_MIN_PIN);
  144. #endif
  145. #endif
  146. #if HAS_Z4_MIN
  147. #if ENABLED(ENDSTOPPULLUP_ZMIN)
  148. SET_INPUT_PULLUP(Z4_MIN_PIN);
  149. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
  150. SET_INPUT_PULLDOWN(Z4_MIN_PIN);
  151. #else
  152. SET_INPUT(Z4_MIN_PIN);
  153. #endif
  154. #endif
  155. #if HAS_X_MAX
  156. #if ENABLED(ENDSTOPPULLUP_XMAX)
  157. SET_INPUT_PULLUP(X_MAX_PIN);
  158. #elif ENABLED(ENDSTOPPULLDOWN_XMAX)
  159. SET_INPUT_PULLDOWN(X_MAX_PIN);
  160. #else
  161. SET_INPUT(X_MAX_PIN);
  162. #endif
  163. #endif
  164. #if HAS_X2_MAX
  165. #if ENABLED(ENDSTOPPULLUP_XMAX)
  166. SET_INPUT_PULLUP(X2_MAX_PIN);
  167. #elif ENABLED(ENDSTOPPULLDOWN_XMAX)
  168. SET_INPUT_PULLDOWN(X2_MAX_PIN);
  169. #else
  170. SET_INPUT(X2_MAX_PIN);
  171. #endif
  172. #endif
  173. #if HAS_Y_MAX
  174. #if ENABLED(ENDSTOPPULLUP_YMAX)
  175. SET_INPUT_PULLUP(Y_MAX_PIN);
  176. #elif ENABLED(ENDSTOPPULLDOWN_YMAX)
  177. SET_INPUT_PULLDOWN(Y_MAX_PIN);
  178. #else
  179. SET_INPUT(Y_MAX_PIN);
  180. #endif
  181. #endif
  182. #if HAS_Y2_MAX
  183. #if ENABLED(ENDSTOPPULLUP_YMAX)
  184. SET_INPUT_PULLUP(Y2_MAX_PIN);
  185. #elif ENABLED(ENDSTOPPULLDOWN_YMAX)
  186. SET_INPUT_PULLDOWN(Y2_MAX_PIN);
  187. #else
  188. SET_INPUT(Y2_MAX_PIN);
  189. #endif
  190. #endif
  191. #if HAS_Z_MAX
  192. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  193. SET_INPUT_PULLUP(Z_MAX_PIN);
  194. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  195. SET_INPUT_PULLDOWN(Z_MAX_PIN);
  196. #else
  197. SET_INPUT(Z_MAX_PIN);
  198. #endif
  199. #endif
  200. #if HAS_Z2_MAX
  201. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  202. SET_INPUT_PULLUP(Z2_MAX_PIN);
  203. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  204. SET_INPUT_PULLDOWN(Z2_MAX_PIN);
  205. #else
  206. SET_INPUT(Z2_MAX_PIN);
  207. #endif
  208. #endif
  209. #if HAS_Z3_MAX
  210. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  211. SET_INPUT_PULLUP(Z3_MAX_PIN);
  212. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  213. SET_INPUT_PULLDOWN(Z3_MAX_PIN);
  214. #else
  215. SET_INPUT(Z3_MAX_PIN);
  216. #endif
  217. #endif
  218. #if HAS_Z4_MAX
  219. #if ENABLED(ENDSTOPPULLUP_ZMAX)
  220. SET_INPUT_PULLUP(Z4_MAX_PIN);
  221. #elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
  222. SET_INPUT_PULLDOWN(Z4_MAX_PIN);
  223. #else
  224. SET_INPUT(Z4_MAX_PIN);
  225. #endif
  226. #endif
  227. #if HAS_I_MIN
  228. #if ENABLED(ENDSTOPPULLUP_IMIN)
  229. SET_INPUT_PULLUP(I_MIN_PIN);
  230. #elif ENABLED(ENDSTOPPULLDOWN_IMIN)
  231. SET_INPUT_PULLDOWN(I_MIN_PIN);
  232. #else
  233. SET_INPUT(I_MIN_PIN);
  234. #endif
  235. #endif
  236. #if HAS_I_MAX
  237. #if ENABLED(ENDSTOPPULLUP_IMAX)
  238. SET_INPUT_PULLUP(I_MAX_PIN);
  239. #elif ENABLED(ENDSTOPPULLDOWN_IMAX)
  240. SET_INPUT_PULLDOWN(I_MAX_PIN);
  241. #else
  242. SET_INPUT(I_MAX_PIN);
  243. #endif
  244. #endif
  245. #if HAS_J_MIN
  246. #if ENABLED(ENDSTOPPULLUP_JMIN)
  247. SET_INPUT_PULLUP(J_MIN_PIN);
  248. #elif ENABLED(ENDSTOPPULLDOWN_IMIN)
  249. SET_INPUT_PULLDOWN(J_MIN_PIN);
  250. #else
  251. SET_INPUT(J_MIN_PIN);
  252. #endif
  253. #endif
  254. #if HAS_J_MAX
  255. #if ENABLED(ENDSTOPPULLUP_JMAX)
  256. SET_INPUT_PULLUP(J_MAX_PIN);
  257. #elif ENABLED(ENDSTOPPULLDOWN_JMAX)
  258. SET_INPUT_PULLDOWN(J_MAX_PIN);
  259. #else
  260. SET_INPUT(J_MAX_PIN);
  261. #endif
  262. #endif
  263. #if HAS_K_MIN
  264. #if ENABLED(ENDSTOPPULLUP_KMIN)
  265. SET_INPUT_PULLUP(K_MIN_PIN);
  266. #elif ENABLED(ENDSTOPPULLDOWN_KMIN)
  267. SET_INPUT_PULLDOWN(K_MIN_PIN);
  268. #else
  269. SET_INPUT(K_MIN_PIN);
  270. #endif
  271. #endif
  272. #if HAS_K_MAX
  273. #if ENABLED(ENDSTOPPULLUP_KMAX)
  274. SET_INPUT_PULLUP(K_MAX_PIN);
  275. #elif ENABLED(ENDSTOPPULLDOWN_KMIN)
  276. SET_INPUT_PULLDOWN(K_MAX_PIN);
  277. #else
  278. SET_INPUT(K_MAX_PIN);
  279. #endif
  280. #endif
  281. #if HAS_U_MIN
  282. #if ENABLED(ENDSTOPPULLUP_UMIN)
  283. SET_INPUT_PULLUP(U_MIN_PIN);
  284. #elif ENABLED(ENDSTOPPULLDOWN_UMIN)
  285. SET_INPUT_PULLDOWN(U_MIN_PIN);
  286. #else
  287. SET_INPUT(U_MIN_PIN);
  288. #endif
  289. #endif
  290. #if HAS_U_MAX
  291. #if ENABLED(ENDSTOPPULLUP_UMAX)
  292. SET_INPUT_PULLUP(U_MAX_PIN);
  293. #elif ENABLED(ENDSTOPPULLDOWN_UMIN)
  294. SET_INPUT_PULLDOWN(U_MAX_PIN);
  295. #else
  296. SET_INPUT(U_MAX_PIN);
  297. #endif
  298. #endif
  299. #if HAS_V_MIN
  300. #if ENABLED(ENDSTOPPULLUP_VMIN)
  301. SET_INPUT_PULLUP(V_MIN_PIN);
  302. #elif ENABLED(ENDSTOPPULLDOWN_VMIN)
  303. SET_INPUT_PULLDOWN(V_MIN_PIN);
  304. #else
  305. SET_INPUT(V_MIN_PIN);
  306. #endif
  307. #endif
  308. #if HAS_V_MAX
  309. #if ENABLED(ENDSTOPPULLUP_VMAX)
  310. SET_INPUT_PULLUP(V_MAX_PIN);
  311. #elif ENABLED(ENDSTOPPULLDOWN_VMIN)
  312. SET_INPUT_PULLDOWN(V_MAX_PIN);
  313. #else
  314. SET_INPUT(V_MAX_PIN);
  315. #endif
  316. #endif
  317. #if HAS_W_MIN
  318. #if ENABLED(ENDSTOPPULLUP_WMIN)
  319. SET_INPUT_PULLUP(W_MIN_PIN);
  320. #elif ENABLED(ENDSTOPPULLDOWN_WMIN)
  321. SET_INPUT_PULLDOWN(W_MIN_PIN);
  322. #else
  323. SET_INPUT(W_MIN_PIN);
  324. #endif
  325. #endif
  326. #if HAS_W_MAX
  327. #if ENABLED(ENDSTOPPULLUP_WMAX)
  328. SET_INPUT_PULLUP(W_MAX_PIN);
  329. #elif ENABLED(ENDSTOPPULLDOWN_WMIN)
  330. SET_INPUT_PULLDOWN(W_MAX_PIN);
  331. #else
  332. SET_INPUT(W_MAX_PIN);
  333. #endif
  334. #endif
  335. #if PIN_EXISTS(CALIBRATION)
  336. #if ENABLED(CALIBRATION_PIN_PULLUP)
  337. SET_INPUT_PULLUP(CALIBRATION_PIN);
  338. #elif ENABLED(CALIBRATION_PIN_PULLDOWN)
  339. SET_INPUT_PULLDOWN(CALIBRATION_PIN);
  340. #else
  341. SET_INPUT(CALIBRATION_PIN);
  342. #endif
  343. #endif
  344. #if USES_Z_MIN_PROBE_PIN
  345. #if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
  346. SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
  347. #elif ENABLED(ENDSTOPPULLDOWN_ZMIN_PROBE)
  348. SET_INPUT_PULLDOWN(Z_MIN_PROBE_PIN);
  349. #else
  350. SET_INPUT(Z_MIN_PROBE_PIN);
  351. #endif
  352. #endif
  353. #if ENABLED(PROBE_ACTIVATION_SWITCH)
  354. SET_INPUT(PROBE_ACTIVATION_SWITCH_PIN);
  355. #endif
  356. TERN_(PROBE_TARE, probe.tare());
  357. TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());
  358. // Enable endstops
  359. enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
  360. } // Endstops::init
  361. // Called at ~1kHz from Temperature ISR: Poll endstop state if required
  362. void Endstops::poll() {
  363. TERN_(PINS_DEBUGGING, run_monitor()); // Report changes in endstop status
  364. #if DISABLED(ENDSTOP_INTERRUPTS_FEATURE)
  365. update();
  366. #elif ENDSTOP_NOISE_THRESHOLD
  367. if (endstop_poll_count) update();
  368. #endif
  369. }
  370. void Endstops::enable_globally(const bool onoff) {
  371. enabled_globally = enabled = onoff;
  372. resync();
  373. }
  374. // Enable / disable endstop checking
  375. void Endstops::enable(const bool onoff) {
  376. enabled = onoff;
  377. resync();
  378. }
  379. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  380. void Endstops::not_homing() {
  381. enabled = enabled_globally;
  382. }
  383. #if ENABLED(VALIDATE_HOMING_ENDSTOPS)
  384. // If the last move failed to trigger an endstop, call kill
  385. void Endstops::validate_homing_move() {
  386. if (trigger_state()) hit_on_purpose();
  387. else kill(GET_TEXT_F(MSG_KILL_HOMING_FAILED));
  388. }
  389. #endif
  390. // Enable / disable endstop z-probe checking
  391. #if HAS_BED_PROBE
  392. void Endstops::enable_z_probe(const bool onoff) {
  393. z_probe_enabled = onoff;
  394. #if PIN_EXISTS(PROBE_ENABLE)
  395. WRITE(PROBE_ENABLE_PIN, onoff);
  396. #endif
  397. resync();
  398. }
  399. #endif
  400. // Get the stable endstop states when enabled
  401. void Endstops::resync() {
  402. if (!abort_enabled()) return; // If endstops/probes are disabled the loop below can hang
  403. // Wait for Temperature ISR to run at least once (runs at 1kHz)
  404. TERN(ENDSTOP_INTERRUPTS_FEATURE, update(), safe_delay(2));
  405. while (TERN0(ENDSTOP_NOISE_THRESHOLD, endstop_poll_count)) safe_delay(1);
  406. }
  407. #if ENABLED(PINS_DEBUGGING)
  408. void Endstops::run_monitor() {
  409. if (!monitor_flag) return;
  410. static uint8_t monitor_count = 16; // offset this check from the others
  411. monitor_count += _BV(1); // 15 Hz
  412. monitor_count &= 0x7F;
  413. if (!monitor_count) monitor(); // report changes in endstop status
  414. }
  415. #endif
  416. void Endstops::event_handler() {
  417. static endstop_mask_t prev_hit_state; // = 0
  418. if (hit_state == prev_hit_state) return;
  419. prev_hit_state = hit_state;
  420. if (hit_state) {
  421. #if HAS_STATUS_MESSAGE
  422. char NUM_AXIS_LIST(chrX = ' ', chrY = ' ', chrZ = ' ', chrI = ' ', chrJ = ' ', chrK = ' ', chrU = ' ', chrV = ' ', chrW = ' '),
  423. chrP = ' ';
  424. #define _SET_STOP_CHAR(A,C) (chr## A = C)
  425. #else
  426. #define _SET_STOP_CHAR(A,C) NOOP
  427. #endif
  428. #define _ENDSTOP_HIT_ECHO(A,C) do{ \
  429. SERIAL_ECHOPGM(" " STRINGIFY(A) ":", planner.triggered_position_mm(_AXIS(A))); _SET_STOP_CHAR(A,C); }while(0)
  430. #define _ENDSTOP_HIT_TEST(A,C) \
  431. if (TERN0(HAS_##A##_MIN, TEST(hit_state, A##_MIN)) || TERN0(HAS_##A##_MAX, TEST(hit_state, A##_MAX))) \
  432. _ENDSTOP_HIT_ECHO(A,C)
  433. #define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
  434. #define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
  435. #define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')
  436. #define ENDSTOP_HIT_TEST_I() _ENDSTOP_HIT_TEST(I,'I')
  437. #define ENDSTOP_HIT_TEST_J() _ENDSTOP_HIT_TEST(J,'J')
  438. #define ENDSTOP_HIT_TEST_K() _ENDSTOP_HIT_TEST(K,'K')
  439. #define ENDSTOP_HIT_TEST_U() _ENDSTOP_HIT_TEST(U,'U')
  440. #define ENDSTOP_HIT_TEST_V() _ENDSTOP_HIT_TEST(V,'V')
  441. #define ENDSTOP_HIT_TEST_W() _ENDSTOP_HIT_TEST(W,'W')
  442. SERIAL_ECHO_START();
  443. SERIAL_ECHOPGM(STR_ENDSTOPS_HIT);
  444. NUM_AXIS_CODE(
  445. ENDSTOP_HIT_TEST_X(),
  446. ENDSTOP_HIT_TEST_Y(),
  447. ENDSTOP_HIT_TEST_Z(),
  448. _ENDSTOP_HIT_TEST(I,'I'),
  449. _ENDSTOP_HIT_TEST(J,'J'),
  450. _ENDSTOP_HIT_TEST(K,'K'),
  451. _ENDSTOP_HIT_TEST(U,'U'),
  452. _ENDSTOP_HIT_TEST(V,'V'),
  453. _ENDSTOP_HIT_TEST(W,'W')
  454. );
  455. #if USES_Z_MIN_PROBE_PIN
  456. #define P_AXIS Z_AXIS
  457. if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
  458. #endif
  459. SERIAL_EOL();
  460. TERN_(HAS_STATUS_MESSAGE,
  461. ui.status_printf(0,
  462. F(S_FMT GANG_N_1(NUM_AXES, " %c") " %c"),
  463. GET_TEXT(MSG_LCD_ENDSTOPS),
  464. NUM_AXIS_LIST(chrX, chrY, chrZ, chrI, chrJ, chrK, chrU, chrV, chrW), chrP
  465. )
  466. );
  467. #if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
  468. if (planner.abort_on_endstop_hit) {
  469. card.abortFilePrintNow();
  470. quickstop_stepper();
  471. thermalManager.disable_all_heaters();
  472. print_job_timer.stop();
  473. }
  474. #endif
  475. }
  476. }
  477. #pragma GCC diagnostic push
  478. #if GCC_VERSION <= 50000
  479. #pragma GCC diagnostic ignored "-Wunused-function"
  480. #endif
  481. static void print_es_state(const bool is_hit, FSTR_P const flabel=nullptr) {
  482. if (flabel) SERIAL_ECHOF(flabel);
  483. SERIAL_ECHOPGM(": ");
  484. SERIAL_ECHOLNF(is_hit ? F(STR_ENDSTOP_HIT) : F(STR_ENDSTOP_OPEN));
  485. }
  486. #pragma GCC diagnostic pop
  487. void __O2 Endstops::report_states() {
  488. TERN_(BLTOUCH, bltouch._set_SW_mode());
  489. SERIAL_ECHOLNPGM(STR_M119_REPORT);
  490. #define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, F(STR_##S))
  491. #if HAS_X_MIN
  492. ES_REPORT(X_MIN);
  493. #endif
  494. #if HAS_X2_MIN
  495. ES_REPORT(X2_MIN);
  496. #endif
  497. #if HAS_X_MAX
  498. ES_REPORT(X_MAX);
  499. #endif
  500. #if HAS_X2_MAX
  501. ES_REPORT(X2_MAX);
  502. #endif
  503. #if HAS_Y_MIN
  504. ES_REPORT(Y_MIN);
  505. #endif
  506. #if HAS_Y2_MIN
  507. ES_REPORT(Y2_MIN);
  508. #endif
  509. #if HAS_Y_MAX
  510. ES_REPORT(Y_MAX);
  511. #endif
  512. #if HAS_Y2_MAX
  513. ES_REPORT(Y2_MAX);
  514. #endif
  515. #if HAS_Z_MIN
  516. ES_REPORT(Z_MIN);
  517. #endif
  518. #if HAS_Z2_MIN
  519. ES_REPORT(Z2_MIN);
  520. #endif
  521. #if HAS_Z3_MIN
  522. ES_REPORT(Z3_MIN);
  523. #endif
  524. #if HAS_Z4_MIN
  525. ES_REPORT(Z4_MIN);
  526. #endif
  527. #if HAS_Z_MAX
  528. ES_REPORT(Z_MAX);
  529. #endif
  530. #if HAS_Z2_MAX
  531. ES_REPORT(Z2_MAX);
  532. #endif
  533. #if HAS_Z3_MAX
  534. ES_REPORT(Z3_MAX);
  535. #endif
  536. #if HAS_Z4_MAX
  537. ES_REPORT(Z4_MAX);
  538. #endif
  539. #if HAS_I_MIN
  540. ES_REPORT(I_MIN);
  541. #endif
  542. #if HAS_I_MAX
  543. ES_REPORT(I_MAX);
  544. #endif
  545. #if HAS_J_MIN
  546. ES_REPORT(J_MIN);
  547. #endif
  548. #if HAS_J_MAX
  549. ES_REPORT(J_MAX);
  550. #endif
  551. #if HAS_K_MIN
  552. ES_REPORT(K_MIN);
  553. #endif
  554. #if HAS_K_MAX
  555. ES_REPORT(K_MAX);
  556. #endif
  557. #if HAS_U_MIN
  558. ES_REPORT(U_MIN);
  559. #endif
  560. #if HAS_U_MAX
  561. ES_REPORT(U_MAX);
  562. #endif
  563. #if HAS_V_MIN
  564. ES_REPORT(V_MIN);
  565. #endif
  566. #if HAS_V_MAX
  567. ES_REPORT(V_MAX);
  568. #endif
  569. #if HAS_W_MIN
  570. ES_REPORT(W_MIN);
  571. #endif
  572. #if HAS_W_MAX
  573. ES_REPORT(W_MAX);
  574. #endif
  575. #if ENABLED(PROBE_ACTIVATION_SWITCH)
  576. print_es_state(probe_switch_activated(), F(STR_PROBE_EN));
  577. #endif
  578. #if USES_Z_MIN_PROBE_PIN
  579. print_es_state(PROBE_TRIGGERED(), F(STR_Z_PROBE));
  580. #endif
  581. #if MULTI_FILAMENT_SENSOR
  582. #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break;
  583. LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
  584. pin_t pin;
  585. uint8_t state;
  586. switch (i) {
  587. default: continue;
  588. REPEAT_1(NUM_RUNOUT_SENSORS, _CASE_RUNOUT)
  589. }
  590. SERIAL_ECHOPGM(STR_FILAMENT);
  591. if (i > 1) SERIAL_CHAR(' ', '0' + i);
  592. print_es_state(extDigitalRead(pin) != state);
  593. }
  594. #undef _CASE_RUNOUT
  595. #elif HAS_FILAMENT_SENSOR
  596. print_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE, F(STR_FILAMENT));
  597. #endif
  598. TERN_(BLTOUCH, bltouch._reset_SW_mode());
  599. TERN_(JOYSTICK_DEBUG, joystick.report());
  600. } // Endstops::report_states
  601. #if HAS_DELTA_SENSORLESS_PROBING
  602. #define __ENDSTOP(AXIS, ...) AXIS ##_MAX
  603. #define _ENDSTOP_PIN(AXIS, ...) AXIS ##_MAX_PIN
  604. #define _ENDSTOP_INVERTING(AXIS, ...) AXIS ##_MAX_ENDSTOP_INVERTING
  605. #else
  606. #define __ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
  607. #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
  608. #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
  609. #endif
  610. #define _ENDSTOP(AXIS, MINMAX) __ENDSTOP(AXIS, MINMAX)
  611. /**
  612. * Called from interrupt context by the Endstop ISR or Stepper ISR!
  613. * Read endstops to get their current states, register hits for all
  614. * axes moving in the direction of their endstops, and abort moves.
  615. */
  616. void Endstops::update() {
  617. #if !ENDSTOP_NOISE_THRESHOLD // If not debouncing...
  618. if (!abort_enabled()) return; // ...and not enabled, exit.
  619. #endif
  620. // Macros to update / copy the live_state
  621. #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
  622. #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
  623. #if ENABLED(G38_PROBE_TARGET) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
  624. #define HAS_G38_PROBE 1
  625. // For G38 moves check the probe's pin for ALL movement
  626. if (G38_move) UPDATE_ENDSTOP_BIT(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
  627. #endif
  628. // With Dual X, endstops are only checked in the homing direction for the active extruder
  629. #define X_MIN_TEST() TERN1(DUAL_X_CARRIAGE, TERN0(X_HOME_TO_MIN, stepper.last_moved_extruder == 0) || TERN0(X2_HOME_TO_MIN, stepper.last_moved_extruder != 0))
  630. #define X_MAX_TEST() TERN1(DUAL_X_CARRIAGE, TERN0(X_HOME_TO_MAX, stepper.last_moved_extruder == 0) || TERN0(X2_HOME_TO_MAX, stepper.last_moved_extruder != 0))
  631. // Use HEAD for core axes, AXIS for others
  632. #if ANY(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
  633. #define X_AXIS_HEAD X_HEAD
  634. #else
  635. #define X_AXIS_HEAD X_AXIS
  636. #endif
  637. #if ANY(CORE_IS_XY, CORE_IS_YZ, MARKFORGED_XY, MARKFORGED_YX)
  638. #define Y_AXIS_HEAD Y_HEAD
  639. #else
  640. #define Y_AXIS_HEAD Y_AXIS
  641. #endif
  642. #if CORE_IS_XZ || CORE_IS_YZ
  643. #define Z_AXIS_HEAD Z_HEAD
  644. #else
  645. #define Z_AXIS_HEAD Z_AXIS
  646. #endif
  647. #define I_AXIS_HEAD I_AXIS
  648. #define J_AXIS_HEAD J_AXIS
  649. #define K_AXIS_HEAD K_AXIS
  650. #define U_AXIS_HEAD U_AXIS
  651. #define V_AXIS_HEAD V_AXIS
  652. #define W_AXIS_HEAD W_AXIS
  653. /**
  654. * Check and update endstops
  655. */
  656. #if HAS_X_MIN && !X_SPI_SENSORLESS
  657. UPDATE_ENDSTOP_BIT(X, MIN);
  658. #if ENABLED(X_DUAL_ENDSTOPS)
  659. #if HAS_X2_MIN
  660. UPDATE_ENDSTOP_BIT(X2, MIN);
  661. #else
  662. COPY_LIVE_STATE(X_MIN, X2_MIN);
  663. #endif
  664. #endif
  665. #endif
  666. #if HAS_X_MAX && !X_SPI_SENSORLESS
  667. UPDATE_ENDSTOP_BIT(X, MAX);
  668. #if ENABLED(X_DUAL_ENDSTOPS)
  669. #if HAS_X2_MAX
  670. UPDATE_ENDSTOP_BIT(X2, MAX);
  671. #else
  672. COPY_LIVE_STATE(X_MAX, X2_MAX);
  673. #endif
  674. #endif
  675. #endif
  676. #if HAS_Y_MIN && !Y_SPI_SENSORLESS
  677. UPDATE_ENDSTOP_BIT(Y, MIN);
  678. #if ENABLED(Y_DUAL_ENDSTOPS)
  679. #if HAS_Y2_MIN
  680. UPDATE_ENDSTOP_BIT(Y2, MIN);
  681. #else
  682. COPY_LIVE_STATE(Y_MIN, Y2_MIN);
  683. #endif
  684. #endif
  685. #endif
  686. #if HAS_Y_MAX && !Y_SPI_SENSORLESS
  687. UPDATE_ENDSTOP_BIT(Y, MAX);
  688. #if ENABLED(Y_DUAL_ENDSTOPS)
  689. #if HAS_Y2_MAX
  690. UPDATE_ENDSTOP_BIT(Y2, MAX);
  691. #else
  692. COPY_LIVE_STATE(Y_MAX, Y2_MAX);
  693. #endif
  694. #endif
  695. #endif
  696. #if HAS_Z_MIN && NONE(Z_SPI_SENSORLESS, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
  697. UPDATE_ENDSTOP_BIT(Z, MIN);
  698. #if ENABLED(Z_MULTI_ENDSTOPS)
  699. #if HAS_Z2_MIN
  700. UPDATE_ENDSTOP_BIT(Z2, MIN);
  701. #else
  702. COPY_LIVE_STATE(Z_MIN, Z2_MIN);
  703. #endif
  704. #if NUM_Z_STEPPERS >= 3
  705. #if HAS_Z3_MIN
  706. UPDATE_ENDSTOP_BIT(Z3, MIN);
  707. #else
  708. COPY_LIVE_STATE(Z_MIN, Z3_MIN);
  709. #endif
  710. #endif
  711. #if NUM_Z_STEPPERS >= 4
  712. #if HAS_Z4_MIN
  713. UPDATE_ENDSTOP_BIT(Z4, MIN);
  714. #else
  715. COPY_LIVE_STATE(Z_MIN, Z4_MIN);
  716. #endif
  717. #endif
  718. #endif
  719. #endif
  720. #if HAS_BED_PROBE
  721. // When closing the gap check the enabled probe
  722. if (probe_switch_activated())
  723. UPDATE_ENDSTOP_BIT(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN));
  724. #endif
  725. #if HAS_Z_MAX && !Z_SPI_SENSORLESS
  726. // Check both Z dual endstops
  727. #if ENABLED(Z_MULTI_ENDSTOPS)
  728. UPDATE_ENDSTOP_BIT(Z, MAX);
  729. #if HAS_Z2_MAX
  730. UPDATE_ENDSTOP_BIT(Z2, MAX);
  731. #else
  732. COPY_LIVE_STATE(Z_MAX, Z2_MAX);
  733. #endif
  734. #if NUM_Z_STEPPERS >= 3
  735. #if HAS_Z3_MAX
  736. UPDATE_ENDSTOP_BIT(Z3, MAX);
  737. #else
  738. COPY_LIVE_STATE(Z_MAX, Z3_MAX);
  739. #endif
  740. #endif
  741. #if NUM_Z_STEPPERS >= 4
  742. #if HAS_Z4_MAX
  743. UPDATE_ENDSTOP_BIT(Z4, MAX);
  744. #else
  745. COPY_LIVE_STATE(Z_MAX, Z4_MAX);
  746. #endif
  747. #endif
  748. #elif TERN1(USES_Z_MIN_PROBE_PIN, Z_MAX_PIN != Z_MIN_PROBE_PIN)
  749. // If this pin isn't the bed probe it's the Z endstop
  750. UPDATE_ENDSTOP_BIT(Z, MAX);
  751. #endif
  752. #endif
  753. #if HAS_I_MIN && !I_SPI_SENSORLESS
  754. #if ENABLED(I_DUAL_ENDSTOPS)
  755. UPDATE_ENDSTOP_BIT(I, MIN);
  756. #if HAS_I2_MIN
  757. UPDATE_ENDSTOP_BIT(I2, MAX);
  758. #else
  759. COPY_LIVE_STATE(I_MIN, I2_MIN);
  760. #endif
  761. #else
  762. UPDATE_ENDSTOP_BIT(I, MIN);
  763. #endif
  764. #endif
  765. #if HAS_I_MAX && !I_SPI_SENSORLESS
  766. #if ENABLED(I_DUAL_ENDSTOPS)
  767. UPDATE_ENDSTOP_BIT(I, MAX);
  768. #if HAS_I2_MAX
  769. UPDATE_ENDSTOP_BIT(I2, MAX);
  770. #else
  771. COPY_LIVE_STATE(I_MAX, I2_MAX);
  772. #endif
  773. #else
  774. UPDATE_ENDSTOP_BIT(I, MAX);
  775. #endif
  776. #endif
  777. #if HAS_J_MIN && !J_SPI_SENSORLESS
  778. #if ENABLED(J_DUAL_ENDSTOPS)
  779. UPDATE_ENDSTOP_BIT(J, MIN);
  780. #if HAS_J2_MIN
  781. UPDATE_ENDSTOP_BIT(J2, MIN);
  782. #else
  783. COPY_LIVE_STATE(J_MIN, J2_MIN);
  784. #endif
  785. #else
  786. UPDATE_ENDSTOP_BIT(J, MIN);
  787. #endif
  788. #endif
  789. #if HAS_J_MAX && !J_SPI_SENSORLESS
  790. #if ENABLED(J_DUAL_ENDSTOPS)
  791. UPDATE_ENDSTOP_BIT(J, MAX);
  792. #if HAS_J2_MAX
  793. UPDATE_ENDSTOP_BIT(J2, MAX);
  794. #else
  795. COPY_LIVE_STATE(J_MAX, J2_MAX);
  796. #endif
  797. #else
  798. UPDATE_ENDSTOP_BIT(J, MAX);
  799. #endif
  800. #endif
  801. #if HAS_K_MIN && !K_SPI_SENSORLESS
  802. #if ENABLED(K_DUAL_ENDSTOPS)
  803. UPDATE_ENDSTOP_BIT(K, MIN);
  804. #if HAS_K2_MIN
  805. UPDATE_ENDSTOP_BIT(K2, MIN);
  806. #else
  807. COPY_LIVE_STATE(K_MIN, K2_MIN);
  808. #endif
  809. #else
  810. UPDATE_ENDSTOP_BIT(K, MIN);
  811. #endif
  812. #endif
  813. #if HAS_K_MAX && !K_SPI_SENSORLESS
  814. #if ENABLED(K_DUAL_ENDSTOPS)
  815. UPDATE_ENDSTOP_BIT(K, MAX);
  816. #if HAS_K2_MAX
  817. UPDATE_ENDSTOP_BIT(K2, MAX);
  818. #else
  819. COPY_LIVE_STATE(K_MAX, K2_MAX);
  820. #endif
  821. #else
  822. UPDATE_ENDSTOP_BIT(K, MAX);
  823. #endif
  824. #endif
  825. #if HAS_U_MIN && !U_SPI_SENSORLESS
  826. #if ENABLED(U_DUAL_ENDSTOPS)
  827. UPDATE_ENDSTOP_BIT(U, MIN);
  828. #if HAS_U2_MIN
  829. UPDATE_ENDSTOP_BIT(U2, MIN);
  830. #else
  831. COPY_LIVE_STATE(U_MIN, U2_MIN);
  832. #endif
  833. #else
  834. UPDATE_ENDSTOP_BIT(U, MIN);
  835. #endif
  836. #endif
  837. #if HAS_U_MAX && !U_SPI_SENSORLESS
  838. #if ENABLED(U_DUAL_ENDSTOPS)
  839. UPDATE_ENDSTOP_BIT(U, MAX);
  840. #if HAS_U2_MAX
  841. UPDATE_ENDSTOP_BIT(U2, MAX);
  842. #else
  843. COPY_LIVE_STATE(U_MAX, U2_MAX);
  844. #endif
  845. #else
  846. UPDATE_ENDSTOP_BIT(U, MAX);
  847. #endif
  848. #endif
  849. #if HAS_V_MIN && !V_SPI_SENSORLESS
  850. #if ENABLED(V_DUAL_ENDSTOPS)
  851. UPDATE_ENDSTOP_BIT(V, MIN);
  852. #if HAS_V2_MIN
  853. UPDATE_ENDSTOP_BIT(V2, MIN);
  854. #else
  855. COPY_LIVE_STATE(V_MIN, V2_MIN);
  856. #endif
  857. #else
  858. UPDATE_ENDSTOP_BIT(V, MIN);
  859. #endif
  860. #endif
  861. #if HAS_V_MAX && !V_SPI_SENSORLESS
  862. #if ENABLED(O_DUAL_ENDSTOPS)
  863. UPDATE_ENDSTOP_BIT(V, MAX);
  864. #if HAS_V2_MAX
  865. UPDATE_ENDSTOP_BIT(V2, MAX);
  866. #else
  867. COPY_LIVE_STATE(V_MAX, V2_MAX);
  868. #endif
  869. #else
  870. UPDATE_ENDSTOP_BIT(V, MAX);
  871. #endif
  872. #endif
  873. #if HAS_W_MIN && !W_SPI_SENSORLESS
  874. #if ENABLED(W_DUAL_ENDSTOPS)
  875. UPDATE_ENDSTOP_BIT(W, MIN);
  876. #if HAS_W2_MIN
  877. UPDATE_ENDSTOP_BIT(W2, MIN);
  878. #else
  879. COPY_LIVE_STATE(W_MIN, W2_MIN);
  880. #endif
  881. #else
  882. UPDATE_ENDSTOP_BIT(W, MIN);
  883. #endif
  884. #endif
  885. #if HAS_W_MAX && !W_SPI_SENSORLESS
  886. #if ENABLED(W_DUAL_ENDSTOPS)
  887. UPDATE_ENDSTOP_BIT(W, MAX);
  888. #if HAS_W2_MAX
  889. UPDATE_ENDSTOP_BIT(W2, MAX);
  890. #else
  891. COPY_LIVE_STATE(W_MAX, W2_MAX);
  892. #endif
  893. #else
  894. UPDATE_ENDSTOP_BIT(W, MAX);
  895. #endif
  896. #endif
  897. #if ENDSTOP_NOISE_THRESHOLD
  898. /**
  899. * Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
  900. * that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
  901. * of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
  902. * also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
  903. * 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
  904. * reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
  905. * still exist. The only way to reduce them further is to increase the number of samples.
  906. * To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
  907. */
  908. static endstop_mask_t old_live_state;
  909. if (old_live_state != live_state) {
  910. endstop_poll_count = ENDSTOP_NOISE_THRESHOLD;
  911. old_live_state = live_state;
  912. }
  913. else if (endstop_poll_count && !--endstop_poll_count)
  914. validated_live_state = live_state;
  915. if (!abort_enabled()) return;
  916. #endif
  917. // Test the current status of an endstop
  918. #define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
  919. // Record endstop was hit
  920. #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
  921. // Call the endstop triggered routine for single endstops
  922. #define PROCESS_ENDSTOP(AXIS, MINMAX) do { \
  923. if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
  924. _ENDSTOP_HIT(AXIS, MINMAX); \
  925. planner.endstop_triggered(_AXIS(AXIS)); \
  926. } \
  927. }while(0)
  928. // Core Sensorless Homing needs to test an Extra Pin
  929. #define CORE_DIAG(QQ,A,MM) (CORE_IS_##QQ && A##_SENSORLESS && !A##_SPI_SENSORLESS && HAS_##A##_##MM)
  930. #define PROCESS_CORE_ENDSTOP(A1,M1,A2,M2) do { \
  931. if (TEST_ENDSTOP(_ENDSTOP(A1,M1))) { \
  932. _ENDSTOP_HIT(A2,M2); \
  933. planner.endstop_triggered(_AXIS(A2)); \
  934. } \
  935. }while(0)
  936. // Call the endstop triggered routine for dual endstops
  937. #define PROCESS_DUAL_ENDSTOP(A, MINMAX) do { \
  938. const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1); \
  939. if (dual_hit) { \
  940. _ENDSTOP_HIT(A, MINMAX); \
  941. /* if not performing home or if both endstops were triggered during homing... */ \
  942. if (!stepper.separate_multi_axis || dual_hit == 0b11) \
  943. planner.endstop_triggered(_AXIS(A)); \
  944. } \
  945. }while(0)
  946. #define PROCESS_TRIPLE_ENDSTOP(A, MINMAX) do { \
  947. const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2); \
  948. if (triple_hit) { \
  949. _ENDSTOP_HIT(A, MINMAX); \
  950. /* if not performing home or if both endstops were triggered during homing... */ \
  951. if (!stepper.separate_multi_axis || triple_hit == 0b111) \
  952. planner.endstop_triggered(_AXIS(A)); \
  953. } \
  954. }while(0)
  955. #define PROCESS_QUAD_ENDSTOP(A, MINMAX) do { \
  956. 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); \
  957. if (quad_hit) { \
  958. _ENDSTOP_HIT(A, MINMAX); \
  959. /* if not performing home or if both endstops were triggered during homing... */ \
  960. if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
  961. planner.endstop_triggered(_AXIS(A)); \
  962. } \
  963. }while(0)
  964. #if ENABLED(X_DUAL_ENDSTOPS)
  965. #define PROCESS_ENDSTOP_X(MINMAX) PROCESS_DUAL_ENDSTOP(X, MINMAX)
  966. #else
  967. #define PROCESS_ENDSTOP_X(MINMAX) if (X_##MINMAX##_TEST()) PROCESS_ENDSTOP(X, MINMAX)
  968. #endif
  969. #if ENABLED(Y_DUAL_ENDSTOPS)
  970. #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_DUAL_ENDSTOP(Y, MINMAX)
  971. #else
  972. #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_ENDSTOP(Y, MINMAX)
  973. #endif
  974. #if DISABLED(Z_MULTI_ENDSTOPS)
  975. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_ENDSTOP(Z, MINMAX)
  976. #elif NUM_Z_STEPPERS == 4
  977. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_QUAD_ENDSTOP(Z, MINMAX)
  978. #elif NUM_Z_STEPPERS == 3
  979. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_TRIPLE_ENDSTOP(Z, MINMAX)
  980. #else
  981. #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_DUAL_ENDSTOP(Z, MINMAX)
  982. #endif
  983. #if HAS_G38_PROBE // TODO (DerAndere): Add support for HAS_I_AXIS
  984. #define _G38_OPEN_STATE TERN(G38_PROBE_AWAY, (G38_move >= 4), LOW)
  985. // For G38 moves check the probe's pin for ALL movement
  986. if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, TERN(USES_Z_MIN_PROBE_PIN, MIN_PROBE, MIN))) != _G38_OPEN_STATE) {
  987. if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, TERN(X_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(X_AXIS); }
  988. #if HAS_Y_AXIS
  989. else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, TERN(Y_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Y_AXIS); }
  990. #endif
  991. #if HAS_Z_AXIS
  992. else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, TERN(Z_HOME_TO_MIN, MIN, MAX)); planner.endstop_triggered(Z_AXIS); }
  993. #endif
  994. G38_did_trigger = true;
  995. }
  996. #endif
  997. // Signal, after validation, if an endstop limit is pressed or not
  998. if (stepper.axis_is_moving(X_AXIS)) {
  999. if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
  1000. #if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_TO_MIN)
  1001. PROCESS_ENDSTOP_X(MIN);
  1002. #if CORE_DIAG(XY, Y, MIN)
  1003. PROCESS_CORE_ENDSTOP(Y,MIN,X,MIN);
  1004. #elif CORE_DIAG(XY, Y, MAX)
  1005. PROCESS_CORE_ENDSTOP(Y,MAX,X,MIN);
  1006. #elif CORE_DIAG(XZ, Z, MIN)
  1007. PROCESS_CORE_ENDSTOP(Z,MIN,X,MIN);
  1008. #elif CORE_DIAG(XZ, Z, MAX)
  1009. PROCESS_CORE_ENDSTOP(Z,MAX,X,MIN);
  1010. #endif
  1011. #endif
  1012. }
  1013. else { // +direction
  1014. #if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_TO_MAX)
  1015. PROCESS_ENDSTOP_X(MAX);
  1016. #if CORE_DIAG(XY, Y, MIN)
  1017. PROCESS_CORE_ENDSTOP(Y,MIN,X,MAX);
  1018. #elif CORE_DIAG(XY, Y, MAX)
  1019. PROCESS_CORE_ENDSTOP(Y,MAX,X,MAX);
  1020. #elif CORE_DIAG(XZ, Z, MIN)
  1021. PROCESS_CORE_ENDSTOP(Z,MIN,X,MAX);
  1022. #elif CORE_DIAG(XZ, Z, MAX)
  1023. PROCESS_CORE_ENDSTOP(Z,MAX,X,MAX);
  1024. #endif
  1025. #endif
  1026. }
  1027. }
  1028. #if HAS_Y_AXIS
  1029. if (stepper.axis_is_moving(Y_AXIS)) {
  1030. if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
  1031. #if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_TO_MIN)
  1032. PROCESS_ENDSTOP_Y(MIN);
  1033. #if CORE_DIAG(XY, X, MIN)
  1034. PROCESS_CORE_ENDSTOP(X,MIN,Y,MIN);
  1035. #elif CORE_DIAG(XY, X, MAX)
  1036. PROCESS_CORE_ENDSTOP(X,MAX,Y,MIN);
  1037. #elif CORE_DIAG(YZ, Z, MIN)
  1038. PROCESS_CORE_ENDSTOP(Z,MIN,Y,MIN);
  1039. #elif CORE_DIAG(YZ, Z, MAX)
  1040. PROCESS_CORE_ENDSTOP(Z,MAX,Y,MIN);
  1041. #endif
  1042. #endif
  1043. }
  1044. else { // +direction
  1045. #if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_TO_MAX)
  1046. PROCESS_ENDSTOP_Y(MAX);
  1047. #if CORE_DIAG(XY, X, MIN)
  1048. PROCESS_CORE_ENDSTOP(X,MIN,Y,MAX);
  1049. #elif CORE_DIAG(XY, X, MAX)
  1050. PROCESS_CORE_ENDSTOP(X,MAX,Y,MAX);
  1051. #elif CORE_DIAG(YZ, Z, MIN)
  1052. PROCESS_CORE_ENDSTOP(Z,MIN,Y,MAX);
  1053. #elif CORE_DIAG(YZ, Z, MAX)
  1054. PROCESS_CORE_ENDSTOP(Z,MAX,Y,MAX);
  1055. #endif
  1056. #endif
  1057. }
  1058. }
  1059. #endif
  1060. #if HAS_Z_AXIS
  1061. if (stepper.axis_is_moving(Z_AXIS)) {
  1062. if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
  1063. #if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_TO_MIN)
  1064. if ( TERN1(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, z_probe_enabled)
  1065. && TERN1(USES_Z_MIN_PROBE_PIN, !z_probe_enabled)
  1066. ) PROCESS_ENDSTOP_Z(MIN);
  1067. #if CORE_DIAG(XZ, X, MIN)
  1068. PROCESS_CORE_ENDSTOP(X,MIN,Z,MIN);
  1069. #elif CORE_DIAG(XZ, X, MAX)
  1070. PROCESS_CORE_ENDSTOP(X,MAX,Z,MIN);
  1071. #elif CORE_DIAG(YZ, Y, MIN)
  1072. PROCESS_CORE_ENDSTOP(Y,MIN,Z,MIN);
  1073. #elif CORE_DIAG(YZ, Y, MAX)
  1074. PROCESS_CORE_ENDSTOP(Y,MAX,Z,MIN);
  1075. #endif
  1076. #endif
  1077. // When closing the gap check the enabled probe
  1078. #if USES_Z_MIN_PROBE_PIN
  1079. if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE);
  1080. #endif
  1081. }
  1082. else { // Z +direction. Gantry up, bed down.
  1083. #if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_TO_MAX)
  1084. #if ENABLED(Z_MULTI_ENDSTOPS)
  1085. PROCESS_ENDSTOP_Z(MAX);
  1086. #elif TERN1(USES_Z_MIN_PROBE_PIN, Z_MAX_PIN != Z_MIN_PROBE_PIN) // No probe or probe is Z_MIN || Probe is not Z_MAX
  1087. PROCESS_ENDSTOP(Z, MAX);
  1088. #endif
  1089. #if CORE_DIAG(XZ, X, MIN)
  1090. PROCESS_CORE_ENDSTOP(X,MIN,Z,MAX);
  1091. #elif CORE_DIAG(XZ, X, MAX)
  1092. PROCESS_CORE_ENDSTOP(X,MAX,Z,MAX);
  1093. #elif CORE_DIAG(YZ, Y, MIN)
  1094. PROCESS_CORE_ENDSTOP(Y,MIN,Z,MAX);
  1095. #elif CORE_DIAG(YZ, Y, MAX)
  1096. PROCESS_CORE_ENDSTOP(Y,MAX,Z,MAX);
  1097. #endif
  1098. #endif
  1099. }
  1100. }
  1101. #endif
  1102. #if HAS_I_AXIS
  1103. if (stepper.axis_is_moving(I_AXIS)) {
  1104. if (stepper.motor_direction(I_AXIS_HEAD)) { // -direction
  1105. #if HAS_I_MIN || (I_SPI_SENSORLESS && I_HOME_TO_MIN)
  1106. PROCESS_ENDSTOP(I, MIN);
  1107. #endif
  1108. }
  1109. else { // +direction
  1110. #if HAS_I_MAX || (I_SPI_SENSORLESS && I_HOME_TO_MAX)
  1111. PROCESS_ENDSTOP(I, MAX);
  1112. #endif
  1113. }
  1114. }
  1115. #endif
  1116. #if HAS_J_AXIS
  1117. if (stepper.axis_is_moving(J_AXIS)) {
  1118. if (stepper.motor_direction(J_AXIS_HEAD)) { // -direction
  1119. #if HAS_J_MIN || (J_SPI_SENSORLESS && J_HOME_TO_MIN)
  1120. PROCESS_ENDSTOP(J, MIN);
  1121. #endif
  1122. }
  1123. else { // +direction
  1124. #if HAS_J_MAX || (J_SPI_SENSORLESS && J_HOME_TO_MAX)
  1125. PROCESS_ENDSTOP(J, MAX);
  1126. #endif
  1127. }
  1128. }
  1129. #endif
  1130. #if HAS_K_AXIS
  1131. if (stepper.axis_is_moving(K_AXIS)) {
  1132. if (stepper.motor_direction(K_AXIS_HEAD)) { // -direction
  1133. #if HAS_K_MIN || (K_SPI_SENSORLESS && K_HOME_TO_MIN)
  1134. PROCESS_ENDSTOP(K, MIN);
  1135. #endif
  1136. }
  1137. else { // +direction
  1138. #if HAS_K_MAX || (K_SPI_SENSORLESS && K_HOME_TO_MAX)
  1139. PROCESS_ENDSTOP(K, MAX);
  1140. #endif
  1141. }
  1142. }
  1143. #endif
  1144. #if HAS_U_AXIS
  1145. if (stepper.axis_is_moving(U_AXIS)) {
  1146. if (stepper.motor_direction(U_AXIS_HEAD)) { // -direction
  1147. #if HAS_U_MIN || (U_SPI_SENSORLESS && U_HOME_TO_MIN)
  1148. PROCESS_ENDSTOP(U, MIN);
  1149. #endif
  1150. }
  1151. else { // +direction
  1152. #if HAS_U_MAX || (U_SPI_SENSORLESS && U_HOME_TO_MAX)
  1153. PROCESS_ENDSTOP(U, MAX);
  1154. #endif
  1155. }
  1156. }
  1157. #endif
  1158. #if HAS_V_AXIS
  1159. if (stepper.axis_is_moving(V_AXIS)) {
  1160. if (stepper.motor_direction(V_AXIS_HEAD)) { // -direction
  1161. #if HAS_V_MIN || (V_SPI_SENSORLESS && V_HOME_TO_MIN)
  1162. PROCESS_ENDSTOP(V, MIN);
  1163. #endif
  1164. }
  1165. else { // +direction
  1166. #if HAS_V_MAX || (V_SPI_SENSORLESS && V_HOME_TO_MAX)
  1167. PROCESS_ENDSTOP(V, MAX);
  1168. #endif
  1169. }
  1170. }
  1171. #endif
  1172. #if HAS_W_AXIS
  1173. if (stepper.axis_is_moving(W_AXIS)) {
  1174. if (stepper.motor_direction(W_AXIS_HEAD)) { // -direction
  1175. #if HAS_W_MIN || (W_SPI_SENSORLESS && W_HOME_TO_MIN)
  1176. PROCESS_ENDSTOP(W, MIN);
  1177. #endif
  1178. }
  1179. else { // +direction
  1180. #if HAS_W_MAX || (W_SPI_SENSORLESS && W_HOME_TO_MAX)
  1181. PROCESS_ENDSTOP(W, MAX);
  1182. #endif
  1183. }
  1184. }
  1185. #endif
  1186. } // Endstops::update()
  1187. #if ENABLED(SPI_ENDSTOPS)
  1188. // Called from idle() to read Trinamic stall states
  1189. bool Endstops::tmc_spi_homing_check() {
  1190. bool hit = false;
  1191. #if X_SPI_SENSORLESS
  1192. if (tmc_spi_homing.x && (stepperX.test_stall_status()
  1193. #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && Y_SPI_SENSORLESS
  1194. || stepperY.test_stall_status()
  1195. #elif CORE_IS_XZ && Z_SPI_SENSORLESS
  1196. || stepperZ.test_stall_status()
  1197. #endif
  1198. )) {
  1199. SBI(live_state, X_ENDSTOP);
  1200. hit = true;
  1201. }
  1202. #endif
  1203. #if Y_SPI_SENSORLESS
  1204. if (tmc_spi_homing.y && (stepperY.test_stall_status()
  1205. #if ANY(CORE_IS_XY, MARKFORGED_XY, MARKFORGED_YX) && X_SPI_SENSORLESS
  1206. || stepperX.test_stall_status()
  1207. #elif CORE_IS_YZ && Z_SPI_SENSORLESS
  1208. || stepperZ.test_stall_status()
  1209. #endif
  1210. )) {
  1211. SBI(live_state, Y_ENDSTOP);
  1212. hit = true;
  1213. }
  1214. #endif
  1215. #if Z_SPI_SENSORLESS
  1216. if (tmc_spi_homing.z && (stepperZ.test_stall_status()
  1217. #if CORE_IS_XZ && X_SPI_SENSORLESS
  1218. || stepperX.test_stall_status()
  1219. #elif CORE_IS_YZ && Y_SPI_SENSORLESS
  1220. || stepperY.test_stall_status()
  1221. #endif
  1222. )) {
  1223. SBI(live_state, Z_ENDSTOP);
  1224. hit = true;
  1225. }
  1226. #endif
  1227. #if I_SPI_SENSORLESS
  1228. if (tmc_spi_homing.i && stepperI.test_stall_status()) {
  1229. SBI(live_state, I_ENDSTOP);
  1230. hit = true;
  1231. }
  1232. #endif
  1233. #if J_SPI_SENSORLESS
  1234. if (tmc_spi_homing.j && stepperJ.test_stall_status()) {
  1235. SBI(live_state, J_ENDSTOP);
  1236. hit = true;
  1237. }
  1238. #endif
  1239. #if K_SPI_SENSORLESS
  1240. if (tmc_spi_homing.k && stepperK.test_stall_status()) {
  1241. SBI(live_state, K_ENDSTOP);
  1242. hit = true;
  1243. }
  1244. #endif
  1245. #if U_SPI_SENSORLESS
  1246. if (tmc_spi_homing.u && stepperU.test_stall_status()) {
  1247. SBI(live_state, U_ENDSTOP);
  1248. hit = true;
  1249. }
  1250. #endif
  1251. #if V_SPI_SENSORLESS
  1252. if (tmc_spi_homing.v && stepperV.test_stall_status()) {
  1253. SBI(live_state, V_ENDSTOP);
  1254. hit = true;
  1255. }
  1256. #endif
  1257. #if W_SPI_SENSORLESS
  1258. if (tmc_spi_homing.w && stepperW.test_stall_status()) {
  1259. SBI(live_state, W_ENDSTOP);
  1260. hit = true;
  1261. }
  1262. #endif
  1263. if (TERN0(ENDSTOP_INTERRUPTS_FEATURE, hit)) update();
  1264. return hit;
  1265. }
  1266. void Endstops::clear_endstop_state() {
  1267. TERN_(X_SPI_SENSORLESS, CBI(live_state, X_ENDSTOP));
  1268. TERN_(Y_SPI_SENSORLESS, CBI(live_state, Y_ENDSTOP));
  1269. TERN_(Z_SPI_SENSORLESS, CBI(live_state, Z_ENDSTOP));
  1270. TERN_(I_SPI_SENSORLESS, CBI(live_state, I_ENDSTOP));
  1271. TERN_(J_SPI_SENSORLESS, CBI(live_state, J_ENDSTOP));
  1272. TERN_(K_SPI_SENSORLESS, CBI(live_state, K_ENDSTOP));
  1273. TERN_(U_SPI_SENSORLESS, CBI(live_state, U_ENDSTOP));
  1274. TERN_(V_SPI_SENSORLESS, CBI(live_state, V_ENDSTOP));
  1275. TERN_(W_SPI_SENSORLESS, CBI(live_state, W_ENDSTOP));
  1276. }
  1277. #endif // SPI_ENDSTOPS
  1278. #if ENABLED(PINS_DEBUGGING)
  1279. bool Endstops::monitor_flag = false;
  1280. /**
  1281. * Monitor Endstops and Z Probe for changes
  1282. *
  1283. * If a change is detected then the LED is toggled and
  1284. * a message is sent out the serial port.
  1285. *
  1286. * Yes, we could miss a rapid back & forth change but
  1287. * that won't matter because this is all manual.
  1288. */
  1289. void Endstops::monitor() {
  1290. static uint16_t old_live_state_local = 0;
  1291. static uint8_t local_LED_status = 0;
  1292. uint16_t live_state_local = 0;
  1293. #define ES_GET_STATE(S) if (READ(S##_PIN)) SBI(live_state_local, S)
  1294. #if HAS_X_MIN
  1295. ES_GET_STATE(X_MIN);
  1296. #endif
  1297. #if HAS_X_MAX
  1298. ES_GET_STATE(X_MAX);
  1299. #endif
  1300. #if HAS_Y_MIN
  1301. ES_GET_STATE(Y_MIN);
  1302. #endif
  1303. #if HAS_Y_MAX
  1304. ES_GET_STATE(Y_MAX);
  1305. #endif
  1306. #if HAS_Z_MIN
  1307. ES_GET_STATE(Z_MIN);
  1308. #endif
  1309. #if HAS_Z_MAX
  1310. ES_GET_STATE(Z_MAX);
  1311. #endif
  1312. #if HAS_Z_MIN_PROBE_PIN
  1313. ES_GET_STATE(Z_MIN_PROBE);
  1314. #endif
  1315. #if HAS_X2_MIN
  1316. ES_GET_STATE(X2_MIN);
  1317. #endif
  1318. #if HAS_X2_MAX
  1319. ES_GET_STATE(X2_MAX);
  1320. #endif
  1321. #if HAS_Y2_MIN
  1322. ES_GET_STATE(Y2_MIN);
  1323. #endif
  1324. #if HAS_Y2_MAX
  1325. ES_GET_STATE(Y2_MAX);
  1326. #endif
  1327. #if HAS_Z2_MIN
  1328. ES_GET_STATE(Z2_MIN);
  1329. #endif
  1330. #if HAS_Z2_MAX
  1331. ES_GET_STATE(Z2_MAX);
  1332. #endif
  1333. #if HAS_Z3_MIN
  1334. ES_GET_STATE(Z3_MIN);
  1335. #endif
  1336. #if HAS_Z3_MAX
  1337. ES_GET_STATE(Z3_MAX);
  1338. #endif
  1339. #if HAS_Z4_MIN
  1340. ES_GET_STATE(Z4_MIN);
  1341. #endif
  1342. #if HAS_Z4_MAX
  1343. ES_GET_STATE(Z4_MAX);
  1344. #endif
  1345. #if HAS_I_MAX
  1346. ES_GET_STATE(I_MAX);
  1347. #endif
  1348. #if HAS_I_MIN
  1349. ES_GET_STATE(I_MIN);
  1350. #endif
  1351. #if HAS_J_MAX
  1352. ES_GET_STATE(J_MAX);
  1353. #endif
  1354. #if HAS_J_MIN
  1355. ES_GET_STATE(J_MIN);
  1356. #endif
  1357. #if HAS_K_MAX
  1358. ES_GET_STATE(K_MAX);
  1359. #endif
  1360. #if HAS_K_MIN
  1361. ES_GET_STATE(K_MIN);
  1362. #endif
  1363. #if HAS_U_MAX
  1364. ES_GET_STATE(U_MAX);
  1365. #endif
  1366. #if HAS_U_MIN
  1367. ES_GET_STATE(U_MIN);
  1368. #endif
  1369. #if HAS_V_MAX
  1370. ES_GET_STATE(V_MAX);
  1371. #endif
  1372. #if HAS_V_MIN
  1373. ES_GET_STATE(V_MIN);
  1374. #endif
  1375. #if HAS_W_MAX
  1376. ES_GET_STATE(W_MAX);
  1377. #endif
  1378. #if HAS_W_MIN
  1379. ES_GET_STATE(W_MIN);
  1380. #endif
  1381. uint16_t endstop_change = live_state_local ^ old_live_state_local;
  1382. #define ES_REPORT_CHANGE(S) if (TEST(endstop_change, S)) SERIAL_ECHOPGM(" " STRINGIFY(S) ":", TEST(live_state_local, S))
  1383. if (endstop_change) {
  1384. #if HAS_X_MIN
  1385. ES_REPORT_CHANGE(X_MIN);
  1386. #endif
  1387. #if HAS_X_MAX
  1388. ES_REPORT_CHANGE(X_MAX);
  1389. #endif
  1390. #if HAS_Y_MIN
  1391. ES_REPORT_CHANGE(Y_MIN);
  1392. #endif
  1393. #if HAS_Y_MAX
  1394. ES_REPORT_CHANGE(Y_MAX);
  1395. #endif
  1396. #if HAS_Z_MIN
  1397. ES_REPORT_CHANGE(Z_MIN);
  1398. #endif
  1399. #if HAS_Z_MAX
  1400. ES_REPORT_CHANGE(Z_MAX);
  1401. #endif
  1402. #if HAS_Z_MIN_PROBE_PIN
  1403. ES_REPORT_CHANGE(Z_MIN_PROBE);
  1404. #endif
  1405. #if HAS_X2_MIN
  1406. ES_REPORT_CHANGE(X2_MIN);
  1407. #endif
  1408. #if HAS_X2_MAX
  1409. ES_REPORT_CHANGE(X2_MAX);
  1410. #endif
  1411. #if HAS_Y2_MIN
  1412. ES_REPORT_CHANGE(Y2_MIN);
  1413. #endif
  1414. #if HAS_Y2_MAX
  1415. ES_REPORT_CHANGE(Y2_MAX);
  1416. #endif
  1417. #if HAS_Z2_MIN
  1418. ES_REPORT_CHANGE(Z2_MIN);
  1419. #endif
  1420. #if HAS_Z2_MAX
  1421. ES_REPORT_CHANGE(Z2_MAX);
  1422. #endif
  1423. #if HAS_Z3_MIN
  1424. ES_REPORT_CHANGE(Z3_MIN);
  1425. #endif
  1426. #if HAS_Z3_MAX
  1427. ES_REPORT_CHANGE(Z3_MAX);
  1428. #endif
  1429. #if HAS_Z4_MIN
  1430. ES_REPORT_CHANGE(Z4_MIN);
  1431. #endif
  1432. #if HAS_Z4_MAX
  1433. ES_REPORT_CHANGE(Z4_MAX);
  1434. #endif
  1435. #if HAS_I_MIN
  1436. ES_REPORT_CHANGE(I_MIN);
  1437. #endif
  1438. #if HAS_I_MAX
  1439. ES_REPORT_CHANGE(I_MAX);
  1440. #endif
  1441. #if HAS_J_MIN
  1442. ES_REPORT_CHANGE(J_MIN);
  1443. #endif
  1444. #if HAS_J_MAX
  1445. ES_REPORT_CHANGE(J_MAX);
  1446. #endif
  1447. #if HAS_K_MIN
  1448. ES_REPORT_CHANGE(K_MIN);
  1449. #endif
  1450. #if HAS_K_MAX
  1451. ES_REPORT_CHANGE(K_MAX);
  1452. #endif
  1453. #if HAS_U_MIN
  1454. ES_REPORT_CHANGE(U_MIN);
  1455. #endif
  1456. #if HAS_U_MAX
  1457. ES_REPORT_CHANGE(U_MAX);
  1458. #endif
  1459. #if HAS_V_MIN
  1460. ES_REPORT_CHANGE(V_MIN);
  1461. #endif
  1462. #if HAS_V_MAX
  1463. ES_REPORT_CHANGE(V_MAX);
  1464. #endif
  1465. #if HAS_W_MIN
  1466. ES_REPORT_CHANGE(W_MIN);
  1467. #endif
  1468. #if HAS_W_MAX
  1469. ES_REPORT_CHANGE(W_MAX);
  1470. #endif
  1471. SERIAL_ECHOLNPGM("\n");
  1472. hal.set_pwm_duty(pin_t(LED_PIN), local_LED_status);
  1473. local_LED_status ^= 255;
  1474. old_live_state_local = live_state_local;
  1475. }
  1476. }
  1477. #endif // PINS_DEBUGGING