My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

endstop_interrupts.h 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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_Z_MIN_PROBE_PIN
  98. #define MATCH_Z_MIN_PROBE_EILINE(P) MATCH_EILINE(P, Z_MIN_PROBE_PIN)
  99. #else
  100. #define MATCH_Z_MIN_PROBE_EILINE(P) false
  101. #endif
  102. #define AVAILABLE_EILINE(P) (PIN_TO_EILINE(P) != -1 \
  103. && !MATCH_X_MAX_EILINE(P) && !MATCH_X_MIN_EILINE(P) \
  104. && !MATCH_Y_MAX_EILINE(P) && !MATCH_Y_MIN_EILINE(P) \
  105. && !MATCH_Z_MAX_EILINE(P) && !MATCH_Z_MIN_EILINE(P) \
  106. && !MATCH_Z2_MAX_EILINE(P) && !MATCH_Z2_MIN_EILINE(P) \
  107. && !MATCH_Z3_MAX_EILINE(P) && !MATCH_Z3_MIN_EILINE(P) \
  108. && !MATCH_Z_MIN_PROBE_EILINE(P))
  109. // One ISR for all EXT-Interrupts
  110. void endstop_ISR(void) { endstops.update(); }
  111. void setup_endstop_interrupts(void) {
  112. #if HAS_X_MAX
  113. #if !AVAILABLE_EILINE(X_MAX_PIN)
  114. static_assert(false, "X_MAX_PIN has no EXTINT line available.");
  115. #endif
  116. attachInterrupt(X_MAX_PIN, endstop_ISR, CHANGE);
  117. #endif
  118. #if HAS_X_MIN
  119. #if !AVAILABLE_EILINE(X_MIN_PIN)
  120. static_assert(false, "X_MIN_PIN has no EXTINT line available.");
  121. #endif
  122. attachInterrupt(X_MIN_PIN, endstop_ISR, CHANGE);
  123. #endif
  124. #if HAS_Y_MAX
  125. #if !AVAILABLE_EILINE(Y_MAX_PIN)
  126. static_assert(false, "Y_MAX_PIN has no EXTINT line available.");
  127. #endif
  128. attachInterrupt(Y_MAX_PIN, endstop_ISR, CHANGE);
  129. #endif
  130. #if HAS_Y_MIN
  131. #if !AVAILABLE_EILINE(Y_MIN_PIN)
  132. static_assert(false, "Y_MIN_PIN has no EXTINT line available.");
  133. #endif
  134. attachInterrupt(Y_MIN_PIN, endstop_ISR, CHANGE);
  135. #endif
  136. #if HAS_Z_MAX
  137. #if !AVAILABLE_EILINE(Z_MAX_PIN)
  138. static_assert(false, "Z_MAX_PIN has no EXTINT line available.");
  139. #endif
  140. attachInterrupt(Z_MAX_PIN, endstop_ISR, CHANGE);
  141. #endif
  142. #if HAS_Z_MIN
  143. #if !AVAILABLE_EILINE(Z_MIN_PIN)
  144. static_assert(false, "Z_MIN_PIN has no EXTINT line available.");
  145. #endif
  146. attachInterrupt(Z_MIN_PIN, endstop_ISR, CHANGE);
  147. #endif
  148. #if HAS_Z2_MAX
  149. #if !AVAILABLE_EILINE(Z2_MAX_PIN)
  150. static_assert(false, "Z2_MAX_PIN has no EXTINT line available.");
  151. #endif
  152. attachInterrupt(Z2_MAX_PIN, endstop_ISR, CHANGE);
  153. #endif
  154. #if HAS_Z2_MIN
  155. #if !AVAILABLE_EILINE(Z2_MIN_PIN)
  156. static_assert(false, "Z2_MIN_PIN has no EXTINT line available.");
  157. #endif
  158. attachInterrupt(Z2_MIN_PIN, endstop_ISR, CHANGE);
  159. #endif
  160. #if HAS_Z3_MAX
  161. #if !AVAILABLE_EILINE(Z3_MAX_PIN)
  162. static_assert(false, "Z3_MAX_PIN has no EXTINT line available.");
  163. #endif
  164. attachInterrupt(Z3_MAX_PIN, endstop_ISR, CHANGE);
  165. #endif
  166. #if HAS_Z3_MIN
  167. #if !AVAILABLE_EILINE(Z3_MIN_PIN)
  168. static_assert(false, "Z3_MIN_PIN has no EXTINT line available.");
  169. #endif
  170. attachInterrupt(Z3_MIN_PIN, endstop_ISR, CHANGE);
  171. #endif
  172. #if HAS_Z_MIN_PROBE_PIN
  173. #if !AVAILABLE_EILINE(Z_MIN_PROBE_PIN)
  174. static_assert(false, "Z_MIN_PROBE_PIN has no EXTINT line available.");
  175. #endif
  176. attachInterrupt(Z_MIN_PROBE_PIN, endstop_ISR, CHANGE);
  177. #endif
  178. }