My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

endstop_interrupts.h 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /**
  2. * Marlin 3D Printer Firmware
  3. *
  4. * Copyright (c) 2019 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 <http://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. #if HAS_X_MAX
  124. #if !AVAILABLE_EILINE(X_MAX_PIN)
  125. #error "X_MAX_PIN has no EXTINT line available."
  126. #endif
  127. attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
  128. #endif
  129. #if HAS_X_MIN
  130. #if !AVAILABLE_EILINE(X_MIN_PIN)
  131. #error "X_MIN_PIN has no EXTINT line available."
  132. #endif
  133. attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
  134. #endif
  135. #if HAS_Y_MAX
  136. #if !AVAILABLE_EILINE(Y_MAX_PIN)
  137. #error "Y_MAX_PIN has no EXTINT line available."
  138. #endif
  139. attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
  140. #endif
  141. #if HAS_Y_MIN
  142. #if !AVAILABLE_EILINE(Y_MIN_PIN)
  143. #error "Y_MIN_PIN has no EXTINT line available."
  144. #endif
  145. attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
  146. #endif
  147. #if HAS_Z_MAX
  148. #if !AVAILABLE_EILINE(Z_MAX_PIN)
  149. #error "Z_MAX_PIN has no EXTINT line available."
  150. #endif
  151. attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
  152. #endif
  153. #if HAS_Z_MIN
  154. #if !AVAILABLE_EILINE(Z_MIN_PIN)
  155. #error "Z_MIN_PIN has no EXTINT line available."
  156. #endif
  157. attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
  158. #endif
  159. #if HAS_Z2_MAX
  160. #if !AVAILABLE_EILINE(Z2_MAX_PIN)
  161. #error "Z2_MAX_PIN has no EXTINT line available."
  162. #endif
  163. attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
  164. #endif
  165. #if HAS_Z2_MIN
  166. #if !AVAILABLE_EILINE(Z2_MIN_PIN)
  167. #error "Z2_MIN_PIN has no EXTINT line available."
  168. #endif
  169. attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
  170. #endif
  171. #if HAS_Z3_MAX
  172. #if !AVAILABLE_EILINE(Z3_MAX_PIN)
  173. #error "Z3_MAX_PIN has no EXTINT line available."
  174. #endif
  175. attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
  176. #endif
  177. #if HAS_Z3_MIN
  178. #if !AVAILABLE_EILINE(Z3_MIN_PIN)
  179. #error "Z3_MIN_PIN has no EXTINT line available."
  180. #endif
  181. attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
  182. #endif
  183. #if HAS_Z4_MAX
  184. #if !AVAILABLE_EILINE(Z4_MAX_PIN)
  185. #error "Z4_MAX_PIN has no EXTINT line available."
  186. #endif
  187. attachInterrupt(Z4_MAX_PIN, endstop_ISR, CHANGE);
  188. #endif
  189. #if HAS_Z4_MIN
  190. #if !AVAILABLE_EILINE(Z4_MIN_PIN)
  191. #error "Z4_MIN_PIN has no EXTINT line available."
  192. #endif
  193. attachInterrupt(Z4_MIN_PIN, endstop_ISR, CHANGE);
  194. #endif
  195. #if HAS_Z_MIN_PROBE_PIN
  196. #if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
  197. #error "Z_MIN_PROBE_PIN has no EXTINT line available."
  198. #endif
  199. attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
  200. #endif
  201. }