Browse Source

Macrofy attachInterrupt

Scott Lahteine 4 years ago
parent
commit
a06010e08a

+ 20
- 49
Marlin/src/HAL/HAL_AVR/endstop_interrupts.h View File

@@ -102,153 +102,124 @@ void pciSetup(const int8_t pin) {
102 102
   ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
103 103
 #endif
104 104
 
105
-void setup_endstop_interrupts( void ) {
106
-
105
+void setup_endstop_interrupts(void) {
106
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
107 107
   #if HAS_X_MAX
108
-    #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT) // if pin has an external interrupt
109
-      attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
108
+    #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
109
+      _ATTACH(X_MAX_PIN);
110 110
     #else
111
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
112
-      static_assert(digitalPinToPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable"); // if pin has no pin change interrupt - error
113
-      pciSetup(X_MAX_PIN);                                                            // assign it
111
+      static_assert(digitalPinToPCICR(X_MAX_PIN), "X_MAX_PIN is not interrupt-capable");
112
+      pciSetup(X_MAX_PIN);
114 113
     #endif
115 114
   #endif
116
-
117 115
   #if HAS_X_MIN
118 116
     #if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
119
-      attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
117
+      _ATTACH(X_MIN_PIN);
120 118
     #else
121
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
122 119
       static_assert(digitalPinToPCICR(X_MIN_PIN), "X_MIN_PIN is not interrupt-capable");
123 120
       pciSetup(X_MIN_PIN);
124 121
     #endif
125 122
   #endif
126
-
127 123
   #if HAS_Y_MAX
128 124
     #if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
129
-      attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
125
+      _ATTACH(Y_MAX_PIN);
130 126
     #else
131
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
132 127
       static_assert(digitalPinToPCICR(Y_MAX_PIN), "Y_MAX_PIN is not interrupt-capable");
133 128
       pciSetup(Y_MAX_PIN);
134 129
     #endif
135 130
   #endif
136
-
137 131
   #if HAS_Y_MIN
138 132
     #if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
139
-      attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
133
+      _ATTACH(Y_MIN_PIN);
140 134
     #else
141
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
142 135
       static_assert(digitalPinToPCICR(Y_MIN_PIN), "Y_MIN_PIN is not interrupt-capable");
143 136
       pciSetup(Y_MIN_PIN);
144 137
     #endif
145 138
   #endif
146
-
147 139
   #if HAS_Z_MAX
148 140
     #if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
149
-      attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
141
+      _ATTACH(Z_MAX_PIN);
150 142
     #else
151
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
152 143
       static_assert(digitalPinToPCICR(Z_MAX_PIN), "Z_MAX_PIN is not interrupt-capable");
153 144
       pciSetup(Z_MAX_PIN);
154 145
     #endif
155 146
   #endif
156
-
157 147
   #if HAS_Z_MIN
158 148
     #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
159
-      attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
149
+      _ATTACH(Z_MIN_PIN);
160 150
     #else
161
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
162 151
       static_assert(digitalPinToPCICR(Z_MIN_PIN), "Z_MIN_PIN is not interrupt-capable");
163 152
       pciSetup(Z_MIN_PIN);
164 153
     #endif
165 154
   #endif
166
-
167 155
   #if HAS_X2_MAX
168 156
     #if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
169
-      attachInterrupt(digitalPinToInterrupt(X2_MAX_PIN), endstop_ISR, CHANGE);
157
+      _ATTACH(X2_MAX_PIN);
170 158
     #else
171
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
172 159
       static_assert(digitalPinToPCICR(X2_MAX_PIN), "X2_MAX_PIN is not interrupt-capable");
173 160
       pciSetup(X2_MAX_PIN);
174 161
     #endif
175 162
   #endif
176
-
177 163
   #if HAS_X2_MIN
178 164
     #if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
179
-      attachInterrupt(digitalPinToInterrupt(X2_MIN_PIN), endstop_ISR, CHANGE);
165
+      _ATTACH(X2_MIN_PIN);
180 166
     #else
181
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
182 167
       static_assert(digitalPinToPCICR(X2_MIN_PIN), "X2_MIN_PIN is not interrupt-capable");
183 168
       pciSetup(X2_MIN_PIN);
184 169
     #endif
185 170
   #endif
186
-
187 171
   #if HAS_Y2_MAX
188 172
     #if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
189
-      attachInterrupt(digitalPinToInterrupt(Y2_MAX_PIN), endstop_ISR, CHANGE);
173
+      _ATTACH(Y2_MAX_PIN);
190 174
     #else
191
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
192 175
       static_assert(digitalPinToPCICR(Y2_MAX_PIN), "Y2_MAX_PIN is not interrupt-capable");
193 176
       pciSetup(Y2_MAX_PIN);
194 177
     #endif
195 178
   #endif
196
-
197 179
   #if HAS_Y2_MIN
198 180
     #if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
199
-      attachInterrupt(digitalPinToInterrupt(Y2_MIN_PIN), endstop_ISR, CHANGE);
181
+      _ATTACH(Y2_MIN_PIN);
200 182
     #else
201
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
202 183
       static_assert(digitalPinToPCICR(Y2_MIN_PIN), "Y2_MIN_PIN is not interrupt-capable");
203 184
       pciSetup(Y2_MIN_PIN);
204 185
     #endif
205 186
   #endif
206
-
207 187
   #if HAS_Z2_MAX
208 188
     #if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
209
-      attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
189
+      _ATTACH(Z2_MAX_PIN);
210 190
     #else
211
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
212 191
       static_assert(digitalPinToPCICR(Z2_MAX_PIN), "Z2_MAX_PIN is not interrupt-capable");
213 192
       pciSetup(Z2_MAX_PIN);
214 193
     #endif
215 194
   #endif
216
-
217 195
   #if HAS_Z2_MIN
218 196
     #if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
219
-      attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
197
+      _ATTACH(Z2_MIN_PIN);
220 198
     #else
221
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
222 199
       static_assert(digitalPinToPCICR(Z2_MIN_PIN), "Z2_MIN_PIN is not interrupt-capable");
223 200
       pciSetup(Z2_MIN_PIN);
224 201
     #endif
225 202
   #endif
226
-
227 203
   #if HAS_Z3_MAX
228 204
     #if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
229
-      attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
205
+      _ATTACH(Z3_MAX_PIN);
230 206
     #else
231
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
232 207
       static_assert(digitalPinToPCICR(Z3_MAX_PIN), "Z3_MAX_PIN is not interrupt-capable");
233 208
       pciSetup(Z3_MAX_PIN);
234 209
     #endif
235 210
   #endif
236
-
237 211
   #if HAS_Z3_MIN
238 212
     #if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
239
-      attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
213
+      _ATTACH(Z3_MIN_PIN);
240 214
     #else
241
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
242 215
       static_assert(digitalPinToPCICR(Z3_MIN_PIN), "Z3_MIN_PIN is not interrupt-capable");
243 216
       pciSetup(Z3_MIN_PIN);
244 217
     #endif
245 218
   #endif
246
-
247 219
   #if HAS_Z_MIN_PROBE_PIN
248 220
     #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
249
-      attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
221
+      _ATTACH(Z_MIN_PROBE_PIN);
250 222
     #else
251
-      // Not all used endstop/probe -pins can raise interrupts. Please deactivate ENDSTOP_INTERRUPTS or change the pin configuration!
252 223
       static_assert(digitalPinToPCICR(Z_MIN_PROBE_PIN), "Z_MIN_PROBE_PIN is not interrupt-capable");
253 224
       pciSetup(Z_MIN_PROBE_PIN);
254 225
     #endif

+ 12
- 11
Marlin/src/HAL/HAL_DUE/endstop_interrupts.h View File

@@ -46,37 +46,38 @@ void endstop_ISR(void) { endstops.update(); }
46 46
  */
47 47
 
48 48
 void setup_endstop_interrupts(void) {
49
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
49 50
   #if HAS_X_MAX
50
-    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
51
+    _ATTACH(X_MAX_PIN);
51 52
   #endif
52 53
   #if HAS_X_MIN
53
-    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
54
+    _ATTACH(X_MIN_PIN);
54 55
   #endif
55 56
   #if HAS_Y_MAX
56
-    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
57
+    _ATTACH(Y_MAX_PIN);
57 58
   #endif
58 59
   #if HAS_Y_MIN
59
-    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
60
+    _ATTACH(Y_MIN_PIN);
60 61
   #endif
61 62
   #if HAS_Z_MAX
62
-    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
63
+    _ATTACH(Z_MAX_PIN);
63 64
   #endif
64 65
   #if HAS_Z_MIN
65
-     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
66
+     _ATTACH(Z_MIN_PIN);
66 67
   #endif
67 68
   #if HAS_Z2_MAX
68
-    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
69
+    _ATTACH(Z2_MAX_PIN);
69 70
   #endif
70 71
   #if HAS_Z2_MIN
71
-    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
72
+    _ATTACH(Z2_MIN_PIN);
72 73
   #endif
73 74
   #if HAS_Z3_MAX
74
-    attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
75
+    _ATTACH(Z3_MAX_PIN);
75 76
   #endif
76 77
   #if HAS_Z3_MIN
77
-    attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
78
+    _ATTACH(Z3_MIN_PIN);
78 79
   #endif
79 80
   #if HAS_Z_MIN_PROBE_PIN
80
-    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
81
+    _ATTACH(Z_MIN_PROBE_PIN);
81 82
   #endif
82 83
 }

+ 12
- 11
Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h View File

@@ -41,37 +41,38 @@
41 41
 void ICACHE_RAM_ATTR endstop_ISR(void) { endstops.update(); }
42 42
 
43 43
 void setup_endstop_interrupts(void) {
44
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
44 45
   #if HAS_X_MAX
45
-    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
46
+    _ATTACH(X_MAX_PIN);
46 47
   #endif
47 48
   #if HAS_X_MIN
48
-    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
49
+    _ATTACH(X_MIN_PIN);
49 50
   #endif
50 51
   #if HAS_Y_MAX
51
-    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
52
+    _ATTACH(Y_MAX_PIN);
52 53
   #endif
53 54
   #if HAS_Y_MIN
54
-    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
55
+    _ATTACH(Y_MIN_PIN);
55 56
   #endif
56 57
   #if HAS_Z_MAX
57
-    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
58
+    _ATTACH(Z_MAX_PIN);
58 59
   #endif
59 60
   #if HAS_Z_MIN
60
-     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
61
+     _ATTACH(Z_MIN_PIN);
61 62
   #endif
62 63
   #if HAS_Z2_MAX
63
-    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
64
+    _ATTACH(Z2_MAX_PIN);
64 65
   #endif
65 66
   #if HAS_Z2_MIN
66
-    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
67
+    _ATTACH(Z2_MIN_PIN);
67 68
   #endif
68 69
   #if HAS_Z3_MAX
69
-    attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
70
+    _ATTACH(Z3_MAX_PIN);
70 71
   #endif
71 72
   #if HAS_Z3_MIN
72
-    attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
73
+    _ATTACH(Z3_MIN_PIN);
73 74
   #endif
74 75
   #if HAS_Z_MIN_PROBE_PIN
75
-    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
76
+    _ATTACH(Z_MIN_PROBE_PIN);
76 77
   #endif
77 78
 }

+ 23
- 22
Marlin/src/HAL/HAL_LPC1768/endstop_interrupts.h View File

@@ -41,70 +41,71 @@
41 41
 void endstop_ISR(void) { endstops.update(); }
42 42
 
43 43
 void setup_endstop_interrupts(void) {
44
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
44 45
   #if HAS_X_MAX
45 46
     #if !LPC1768_PIN_INTERRUPT_M(X_MAX_PIN)
46
-      #error "X_MAX_PIN is not an INTERRUPT capable pin."
47
+      #error "X_MAX_PIN is not INTERRUPT-capable."
47 48
     #endif
48
-    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
49
+    _ATTACH(X_MAX_PIN);
49 50
   #endif
50 51
   #if HAS_X_MIN
51 52
     #if !LPC1768_PIN_INTERRUPT_M(X_MIN_PIN)
52
-      #error "X_MIN_PIN is not an INTERRUPT capable pin."
53
+      #error "X_MIN_PIN is not INTERRUPT-capable."
53 54
     #endif
54
-    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
55
+    _ATTACH(X_MIN_PIN);
55 56
   #endif
56 57
   #if HAS_Y_MAX
57 58
     #if !LPC1768_PIN_INTERRUPT_M(Y_MAX_PIN)
58
-      #error "Y_MAX_PIN is not an INTERRUPT capable pin."
59
+      #error "Y_MAX_PIN is not INTERRUPT-capable."
59 60
     #endif
60
-    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
61
+    _ATTACH(Y_MAX_PIN);
61 62
   #endif
62 63
   #if HAS_Y_MIN
63 64
     #if !LPC1768_PIN_INTERRUPT_M(Y_MIN_PIN)
64
-      #error "Y_MIN_PIN is not an INTERRUPT capable pin."
65
+      #error "Y_MIN_PIN is not INTERRUPT-capable."
65 66
     #endif
66
-    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
67
+    _ATTACH(Y_MIN_PIN);
67 68
   #endif
68 69
   #if HAS_Z_MAX
69 70
     #if !LPC1768_PIN_INTERRUPT_M(Z_MAX_PIN)
70
-      #error "Z_MAX_PIN is not an INTERRUPT capable pin."
71
+      #error "Z_MAX_PIN is not INTERRUPT-capable."
71 72
     #endif
72
-    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
73
+    _ATTACH(Z_MAX_PIN);
73 74
   #endif
74 75
   #if HAS_Z_MIN
75 76
     #if !LPC1768_PIN_INTERRUPT_M(Z_MIN_PIN)
76
-      #error "Z_MIN_PIN is not an INTERRUPT capable pin."
77
+      #error "Z_MIN_PIN is not INTERRUPT-capable."
77 78
     #endif
78
-     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
79
+     _ATTACH(Z_MIN_PIN);
79 80
   #endif
80 81
   #if HAS_Z2_MAX
81 82
     #if !LPC1768_PIN_INTERRUPT_M(Z2_MAX_PIN)
82
-      #error "Z2_MAX_PIN is not an INTERRUPT capable pin."
83
+      #error "Z2_MAX_PIN is not INTERRUPT-capable."
83 84
     #endif
84
-    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
85
+    _ATTACH(Z2_MAX_PIN);
85 86
   #endif
86 87
   #if HAS_Z2_MIN
87 88
     #if !LPC1768_PIN_INTERRUPT_M(Z2_MIN_PIN)
88
-      #error "Z2_MIN_PIN is not an INTERRUPT capable pin."
89
+      #error "Z2_MIN_PIN is not INTERRUPT-capable."
89 90
     #endif
90
-    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
91
+    _ATTACH(Z2_MIN_PIN);
91 92
   #endif
92 93
   #if HAS_Z3_MAX
93 94
     #if !LPC1768_PIN_INTERRUPT_M(Z3_MIN_PIN)
94
-      #error "Z3_MIN_PIN is not an INTERRUPT capable pin."
95
+      #error "Z3_MIN_PIN is not INTERRUPT-capable."
95 96
     #endif
96
-    attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
97
+    _ATTACH(Z3_MAX_PIN);
97 98
   #endif
98 99
   #if HAS_Z3_MIN
99 100
     #if !LPC1768_PIN_INTERRUPT_M(Z3_MIN_PIN)
100
-      #error "Z3_MIN_PIN is not an INTERRUPT capable pin."
101
+      #error "Z3_MIN_PIN is not INTERRUPT-capable."
101 102
     #endif
102
-    attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
103
+    _ATTACH(Z3_MIN_PIN);
103 104
   #endif
104 105
   #if HAS_Z_MIN_PROBE_PIN
105 106
     #if !LPC1768_PIN_INTERRUPT_M(Z_MIN_PROBE_PIN)
106
-      #error "Z_MIN_PROBE_PIN is not an INTERRUPT capable pin."
107
+      #error "Z_MIN_PROBE_PIN is not INTERRUPT-capable."
107 108
     #endif
108
-    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
109
+    _ATTACH(Z_MIN_PROBE_PIN);
109 110
   #endif
110 111
 }

+ 11
- 19
Marlin/src/HAL/HAL_TEENSY31_32/endstop_interrupts.h View File

@@ -45,41 +45,33 @@ void endstop_ISR(void) { endstops.update(); }
45 45
  *  On Due, all pins support external interrupt capability.
46 46
  */
47 47
 
48
-void setup_endstop_interrupts( void ) {
49
-
48
+void setup_endstop_interrupts(void) {
49
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
50 50
   #if HAS_X_MAX
51
-    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
51
+    _ATTACH(X_MAX_PIN);
52 52
   #endif
53
-
54 53
   #if HAS_X_MIN
55
-    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
54
+    _ATTACH(X_MIN_PIN);
56 55
   #endif
57
-
58 56
   #if HAS_Y_MAX
59
-    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
57
+    _ATTACH(Y_MAX_PIN);
60 58
   #endif
61
-
62 59
   #if HAS_Y_MIN
63
-    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
60
+    _ATTACH(Y_MIN_PIN);
64 61
   #endif
65
-
66 62
   #if HAS_Z_MAX
67
-    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
63
+    _ATTACH(Z_MAX_PIN);
68 64
   #endif
69
-
70 65
   #if HAS_Z_MIN
71
-     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
66
+     _ATTACH(Z_MIN_PIN);
72 67
   #endif
73
-
74 68
   #if HAS_Z2_MAX
75
-    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
69
+    _ATTACH(Z2_MAX_PIN);
76 70
   #endif
77
-
78 71
   #if HAS_Z2_MIN
79
-    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
72
+    _ATTACH(Z2_MIN_PIN);
80 73
   #endif
81
-
82 74
   #if HAS_Z_MIN_PROBE_PIN
83
-    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
75
+    _ATTACH(Z_MIN_PROBE_PIN);
84 76
   #endif
85 77
 }

+ 13
- 12
Marlin/src/HAL/HAL_TEENSY35_36/endstop_interrupts.h View File

@@ -44,38 +44,39 @@ void endstop_ISR(void) { endstops.update(); }
44 44
  * Endstop interrupts for Due based targets.
45 45
  * On Due, all pins support external interrupt capability.
46 46
  */
47
-void setup_endstop_interrupts( void ) {
47
+void setup_endstop_interrupts(void) {
48
+  #define _ATTACH(P) attachInterrupt(digitalPinToInterrupt(P), endstop_ISR, CHANGE)
48 49
   #if HAS_X_MAX
49
-    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE); // assign it
50
+    _ATTACH(X_MAX_PIN);
50 51
   #endif
51 52
   #if HAS_X_MIN
52
-    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
53
+    _ATTACH(X_MIN_PIN);
53 54
   #endif
54 55
   #if HAS_Y_MAX
55
-    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
56
+    _ATTACH(Y_MAX_PIN);
56 57
   #endif
57 58
   #if HAS_Y_MIN
58
-    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
59
+    _ATTACH(Y_MIN_PIN);
59 60
   #endif
60 61
   #if HAS_Z_MAX
61
-    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
62
+    _ATTACH(Z_MAX_PIN);
62 63
   #endif
63 64
   #if HAS_Z_MIN
64
-     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
65
+     _ATTACH(Z_MIN_PIN);
65 66
   #endif
66 67
   #if HAS_Z2_MAX
67
-    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
68
+    _ATTACH(Z2_MAX_PIN);
68 69
   #endif
69 70
   #if HAS_Z2_MIN
70
-    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
71
+    _ATTACH(Z2_MIN_PIN);
71 72
   #endif
72 73
   #if HAS_Z3_MAX
73
-    attachInterrupt(digitalPinToInterrupt(Z3_MAX_PIN), endstop_ISR, CHANGE);
74
+    _ATTACH(Z3_MAX_PIN);
74 75
   #endif
75 76
   #if HAS_Z3_MIN
76
-    attachInterrupt(digitalPinToInterrupt(Z3_MIN_PIN), endstop_ISR, CHANGE);
77
+    _ATTACH(Z3_MIN_PIN);
77 78
   #endif
78 79
   #if HAS_Z_MIN_PROBE_PIN
79
-    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
80
+    _ATTACH(Z_MIN_PROBE_PIN);
80 81
   #endif
81 82
 }

Loading…
Cancel
Save