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.

endstop_interrupts.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  5. * SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #pragma once
  22. /**
  23. * Endstop interrupts for ATMEL SAMD51 based targets.
  24. *
  25. * On SAMD51, all pins support external interrupt capability.
  26. * Any pin can be used for external interrupts, but there are some restrictions.
  27. * At most 16 different external interrupts can be used at one time.
  28. * Further, you can’t just pick any 16 pins to use. This is because every pin on the SAMD51
  29. * connects to what is called an EXTINT line, and only one pin per EXTINT line can be used for external
  30. * interrupts at a time
  31. */
  32. /**
  33. * Endstop Interrupts
  34. *
  35. * Without endstop interrupts the endstop pins must be polled continually in
  36. * the temperature-ISR via endstops.update(), most of the time finding no change.
  37. * With this feature endstops.update() is called only when we know that at
  38. * least one endstop has changed state, saving valuable CPU cycles.
  39. *
  40. * This feature only works when all used endstop pins can generate an 'external interrupt'.
  41. *
  42. * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
  43. * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
  44. */
  45. #include "../../module/endstops.h"
  46. #define MATCH_EILINE(P1,P2) (P1 != P2 && PIN_TO_EILINE(P1) == PIN_TO_EILINE(P2))
  47. #if HAS_X_MAX
  48. #define MATCH_X_MAX_EILINE(P) MATCH_EILINE(P, X_MAX_PIN)
  49. #else
  50. #define MATCH_X_MAX_EILINE(P) false
  51. #endif
  52. #if HAS_X_MIN
  53. #define MATCH_X_MIN_EILINE(P) MATCH_EILINE(P, X_MIN_PIN)
  54. #else
  55. #define MATCH_X_MIN_EILINE(P) false
  56. #endif
  57. #if HAS_Y_MAX
  58. #define MATCH_Y_MAX_EILINE(P) MATCH_EILINE(P, Y_MAX_PIN)
  59. #else
  60. #define MATCH_Y_MAX_EILINE(P) false
  61. #endif
  62. #if HAS_Y_MIN
  63. #define MATCH_Y_MIN_EILINE(P) MATCH_EILINE(P, Y_MIN_PIN)
  64. #else
  65. #define MATCH_Y_MIN_EILINE(P) false
  66. #endif
  67. #if HAS_Z_MAX
  68. #define MATCH_Z_MAX_EILINE(P) MATCH_EILINE(P, Z_MAX_PIN)
  69. #else
  70. #define MATCH_Z_MAX_EILINE(P) false
  71. #endif
  72. #if HAS_Z_MIN
  73. #define MATCH_Z_MIN_EILINE(P) MATCH_EILINE(P, Z_MIN_PIN)
  74. #else
  75. #define MATCH_Z_MIN_EILINE(P) false
  76. #endif
  77. #if HAS_Z2_MAX
  78. #define MATCH_Z2_MAX_EILINE(P) MATCH_EILINE(P, Z2_MAX_PIN)
  79. #else
  80. #define MATCH_Z2_MAX_EILINE(P) false
  81. #endif
  82. #if HAS_Z2_MIN
  83. #define MATCH_Z2_MIN_EILINE(P) MATCH_EILINE(P, Z2_MIN_PIN)
  84. #else
  85. #define MATCH_Z2_MIN_EILINE(P) false
  86. #endif
  87. #if HAS_Z3_MAX
  88. #define MATCH_Z3_MAX_EILINE(P) MATCH_EILINE(P, Z3_MAX_PIN)
  89. #else
  90. #define MATCH_Z3_MAX_EILINE(P) false
  91. #endif
  92. #if HAS_Z3_MIN
  93. #define MATCH_Z3_MIN_EILINE(P) MATCH_EILINE(P, Z3_MIN_PIN)
  94. #else
  95. #define MATCH_Z3_MIN_EILINE(P) false
  96. #endif
  97. #if HAS_Z4_MAX
  98. #define MATCH_Z4_MAX_EILINE(P) MATCH_EILINE(P, Z4_MAX_PIN)
  99. #else
  100. #define MATCH_Z4_MAX_EILINE(P) false
  101. #endif
  102. #if HAS_Z4_MIN
  103. #define MATCH_Z4_MIN_EILINE(P) MATCH_EILINE(P, Z4_MIN_PIN)
  104. #else
  105. #define MATCH_Z4_MIN_EILINE(P) false
  106. #endif
  107. #if HAS_Z_MIN_PROBE_PIN
  108. #define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
  109. #else
  110. #define MATCH_Z_MIN_PROBE_EILINE(P) false
  111. #endif
  112. #define AVAILABLE_EILINE(P) (PIN_TO_EILINE(P) != -1 \
  113. && !MATCH_X_MAX_EILINE(P) && !MATCH_X_MIN_EILINE(P) \
  114. && !MATCH_Y_MAX_EILINE(P) && !MATCH_Y_MIN_EILINE(P) \
  115. && !MATCH_Z_MAX_EILINE(P) && !MATCH_Z_MIN_EILINE(P) \
  116. && !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
  117. && !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
  118. && !MATCH_Z4_MAX_EILINE(P) && !MATCH_Z4_MIN_EILINE(P) \
  119. && !MATCH_Z_MIN_PROBE_EILINE(P))
  120. // One ISR for all EXT-Interrupts
  121. void endstop_ISR() { endstops.update(); }
  122. void setup_endstop_interrupts() {
  123. #define _ATTACH(P) attachInterrupt(P, endstop_ISR, CHANGE)
  124. #if HAS_X_MAX
  125. #if !AVAILABLE_EILINE(X_MAX_PIN)
  126. #error "X_MAX_PIN has no EXTINT line available."
  127. #endif
  128. _ATTACH(X_MAX_PIN);
  129. #endif
  130. #if HAS_X_MIN
  131. #if !AVAILABLE_EILINE(X_MIN_PIN)
  132. #error "X_MIN_PIN has no EXTINT line available."
  133. #endif
  134. _ATTACH(X_MIN_PIN);
  135. #endif
  136. #if HAS_Y_MAX
  137. #if !AVAILABLE_EILINE(Y_MAX_PIN)
  138. #error "Y_MAX_PIN has no EXTINT line available."
  139. #endif
  140. _ATTACH(Y_MAX_PIN);
  141. #endif
  142. #if HAS_Y_MIN
  143. #if !AVAILABLE_EILINE(Y_MIN_PIN)
  144. #error "Y_MIN_PIN has no EXTINT line available."
  145. #endif
  146. _ATTACH(Y_MIN_PIN);
  147. #endif
  148. #if HAS_Z_MAX
  149. #if !AVAILABLE_EILINE(Z_MAX_PIN)
  150. #error "Z_MAX_PIN has no EXTINT line available."
  151. #endif
  152. _ATTACH(Z_MAX_PIN);
  153. #endif
  154. #if HAS_Z_MIN
  155. #if !AVAILABLE_EILINE(Z_MIN_PIN)
  156. #error "Z_MIN_PIN has no EXTINT line available."
  157. #endif
  158. _ATTACH(Z_MIN_PIN);
  159. #endif
  160. #if HAS_Z2_MAX
  161. #if !AVAILABLE_EILINE(Z2_MAX_PIN)
  162. #error "Z2_MAX_PIN has no EXTINT line available."
  163. #endif
  164. _ATTACH(Z2_MAX_PIN);
  165. #endif
  166. #if HAS_Z2_MIN
  167. #if !AVAILABLE_EILINE(Z2_MIN_PIN)
  168. #error "Z2_MIN_PIN has no EXTINT line available."
  169. #endif
  170. _ATTACH(Z2_MIN_PIN);
  171. #endif
  172. #if HAS_Z3_MAX
  173. #if !AVAILABLE_EILINE(Z3_MAX_PIN)
  174. #error "Z3_MAX_PIN has no EXTINT line available."
  175. #endif
  176. _ATTACH(Z3_MAX_PIN);
  177. #endif
  178. #if HAS_Z3_MIN
  179. #if !AVAILABLE_EILINE(Z3_MIN_PIN)
  180. #error "Z3_MIN_PIN has no EXTINT line available."
  181. #endif
  182. _ATTACH(Z3_MIN_PIN);
  183. #endif
  184. #if HAS_Z4_MAX
  185. #if !AVAILABLE_EILINE(Z4_MAX_PIN)
  186. #error "Z4_MAX_PIN has no EXTINT line available."
  187. #endif
  188. _ATTACH(Z4_MAX_PIN);
  189. #endif
  190. #if HAS_Z4_MIN
  191. #if !AVAILABLE_EILINE(Z4_MIN_PIN)
  192. #error "Z4_MIN_PIN has no EXTINT line available."
  193. #endif
  194. _ATTACH(Z4_MIN_PIN);
  195. #endif
  196. #if HAS_Z_MIN_PROBE_PIN
  197. #if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
  198. #error "Z_MIN_PROBE_PIN has no EXTINT line available."
  199. #endif
  200. _ATTACH(Z_MIN_PROBE_PIN);
  201. #endif
  202. }