@@ -51,37 +51,20 @@ void endstop_ISR() { endstops.update(); }
51
51
* There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
52
52
*/
53
53
#if defined(ARDUINO_AVR_MEGA2560 ) || defined(ARDUINO_AVR_MEGA )
54
- #undef digitalPinToPCICR
55
- #define digitalPinToPCICR (p ) ( WITHIN(p, 10, 15) || \
56
- WITHIN(p, 50, 53) || \
57
- WITHIN(p, 62, 69) ? &PCICR : nullptr )
58
- #undef digitalPinToPCICRbit
59
- #define digitalPinToPCICRbit (p ) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
60
- WITHIN(p, 14, 15) ? 1 : \
61
- WITHIN(p, 62, 69) ? 2 : \
62
- 0 )
63
- #undef digitalPinToPCMSK
64
- #define digitalPinToPCMSK (p ) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
65
- WITHIN(p, 14, 15) ? &PCMSK1 : \
66
- WITHIN(p, 62, 69) ? &PCMSK2 : \
67
- nullptr )
68
- #undef digitalPinToPCMSKbit
69
- #define digitalPinToPCMSKbit (p ) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
70
- (p) == 14 || (p) == 51 ? 2 : \
71
- (p) == 15 || (p) == 52 ? 1 : \
72
- (p) == 50 ? 3 : \
73
- (p) == 53 ? 0 : \
74
- WITHIN(p, 62, 69) ? ((p) - 62) : \
75
- 0 )
54
+ #define digitalPinHasPCICR (p ) (WITHIN(p, 10, 15) || WITHIN(p, 50, 53) || WITHIN(p, 62, 69))
55
+ #define moreDigitalPinToPCICR (p ) digitalPinToPCICR(WITHIN(p, 13, 14) ? 10 : p)
56
+ #define moreDigitalPinToPCICRbit (p ) digitalPinToPCICRbit(p == 13 ? 10 : p == 14 ? 15 : p)
57
+ #define moreDigitalPinToPCMSK (p ) digitalPinToPCMSK( p == 13 ? 10 : p == 14 ? 15 : p)
58
+ #define moreDigitalPinToPCMSKbit (p ) digitalPinToPCMSKbit(p == 13 ? 10 : p == 14 ? 51 : p)
76
59
#endif
77
60
78
61
79
62
// Install Pin change interrupt for a pin. Can be called multiple times.
80
63
void pciSetup (const int8_t pin ) {
81
- if (digitalPinToPCMSK (pin ) != nullptr ) {
82
- SBI (* digitalPinToPCMSK (pin ), digitalPinToPCMSKbit (pin )); // enable pin
83
- SBI (PCIFR , digitalPinToPCICRbit (pin )); // clear any outstanding interrupt
84
- SBI (PCICR , digitalPinToPCICRbit (pin )); // enable interrupt for the group
64
+ if (moreDigitalPinToPCMSK (pin ) != nullptr ) {
65
+ SBI (* moreDigitalPinToPCMSK (pin ), moreDigitalPinToPCMSKbit (pin )); // enable pin
66
+ SBI (PCIFR , moreDigitalPinToPCICRbit (pin )); // clear any outstanding interrupt
67
+ SBI (PCICR , moreDigitalPinToPCICRbit (pin )); // enable interrupt for the group
85
68
}
86
69
}
87
70
@@ -108,119 +91,119 @@ void setup_endstop_interrupts() {
108
91
#if (digitalPinToInterrupt (X_MAX_PIN ) != NOT_AN_INTERRUPT )
109
92
_ATTACH (X_MAX_PIN );
110
93
#else
111
- static_assert (digitalPinToPCICR (X_MAX_PIN ), "X_MAX_PIN is not interrupt-capable" );
94
+ static_assert (digitalPinHasPCICR (X_MAX_PIN ), "X_MAX_PIN is not interrupt-capable" );
112
95
pciSetup (X_MAX_PIN );
113
96
#endif
114
97
#endif
115
98
#if HAS_X_MIN
116
99
#if (digitalPinToInterrupt (X_MIN_PIN ) != NOT_AN_INTERRUPT )
117
100
_ATTACH (X_MIN_PIN );
118
101
#else
119
- static_assert (digitalPinToPCICR (X_MIN_PIN ), "X_MIN_PIN is not interrupt-capable" );
102
+ static_assert (digitalPinHasPCICR (X_MIN_PIN ), "X_MIN_PIN is not interrupt-capable" );
120
103
pciSetup (X_MIN_PIN );
121
104
#endif
122
105
#endif
123
106
#if HAS_Y_MAX
124
107
#if (digitalPinToInterrupt (Y_MAX_PIN ) != NOT_AN_INTERRUPT )
125
108
_ATTACH (Y_MAX_PIN );
126
109
#else
127
- static_assert (digitalPinToPCICR (Y_MAX_PIN ), "Y_MAX_PIN is not interrupt-capable" );
110
+ static_assert (digitalPinHasPCICR (Y_MAX_PIN ), "Y_MAX_PIN is not interrupt-capable" );
128
111
pciSetup (Y_MAX_PIN );
129
112
#endif
130
113
#endif
131
114
#if HAS_Y_MIN
132
115
#if (digitalPinToInterrupt (Y_MIN_PIN ) != NOT_AN_INTERRUPT )
133
116
_ATTACH (Y_MIN_PIN );
134
117
#else
135
- static_assert (digitalPinToPCICR (Y_MIN_PIN ), "Y_MIN_PIN is not interrupt-capable" );
118
+ static_assert (digitalPinHasPCICR (Y_MIN_PIN ), "Y_MIN_PIN is not interrupt-capable" );
136
119
pciSetup (Y_MIN_PIN );
137
120
#endif
138
121
#endif
139
122
#if HAS_Z_MAX
140
123
#if (digitalPinToInterrupt (Z_MAX_PIN ) != NOT_AN_INTERRUPT )
141
124
_ATTACH (Z_MAX_PIN );
142
125
#else
143
- static_assert (digitalPinToPCICR (Z_MAX_PIN ), "Z_MAX_PIN is not interrupt-capable" );
126
+ static_assert (digitalPinHasPCICR (Z_MAX_PIN ), "Z_MAX_PIN is not interrupt-capable" );
144
127
pciSetup (Z_MAX_PIN );
145
128
#endif
146
129
#endif
147
130
#if HAS_Z_MIN
148
131
#if (digitalPinToInterrupt (Z_MIN_PIN ) != NOT_AN_INTERRUPT )
149
132
_ATTACH (Z_MIN_PIN );
150
133
#else
151
- static_assert (digitalPinToPCICR (Z_MIN_PIN ), "Z_MIN_PIN is not interrupt-capable" );
134
+ static_assert (digitalPinHasPCICR (Z_MIN_PIN ), "Z_MIN_PIN is not interrupt-capable" );
152
135
pciSetup (Z_MIN_PIN );
153
136
#endif
154
137
#endif
155
138
#if HAS_X2_MAX
156
139
#if (digitalPinToInterrupt (X2_MAX_PIN ) != NOT_AN_INTERRUPT )
157
140
_ATTACH (X2_MAX_PIN );
158
141
#else
159
- static_assert (digitalPinToPCICR (X2_MAX_PIN ), "X2_MAX_PIN is not interrupt-capable" );
142
+ static_assert (digitalPinHasPCICR (X2_MAX_PIN ), "X2_MAX_PIN is not interrupt-capable" );
160
143
pciSetup (X2_MAX_PIN );
161
144
#endif
162
145
#endif
163
146
#if HAS_X2_MIN
164
147
#if (digitalPinToInterrupt (X2_MIN_PIN ) != NOT_AN_INTERRUPT )
165
148
_ATTACH (X2_MIN_PIN );
166
149
#else
167
- static_assert (digitalPinToPCICR (X2_MIN_PIN ), "X2_MIN_PIN is not interrupt-capable" );
150
+ static_assert (digitalPinHasPCICR (X2_MIN_PIN ), "X2_MIN_PIN is not interrupt-capable" );
168
151
pciSetup (X2_MIN_PIN );
169
152
#endif
170
153
#endif
171
154
#if HAS_Y2_MAX
172
155
#if (digitalPinToInterrupt (Y2_MAX_PIN ) != NOT_AN_INTERRUPT )
173
156
_ATTACH (Y2_MAX_PIN );
174
157
#else
175
- static_assert (digitalPinToPCICR (Y2_MAX_PIN ), "Y2_MAX_PIN is not interrupt-capable" );
158
+ static_assert (digitalPinHasPCICR (Y2_MAX_PIN ), "Y2_MAX_PIN is not interrupt-capable" );
176
159
pciSetup (Y2_MAX_PIN );
177
160
#endif
178
161
#endif
179
162
#if HAS_Y2_MIN
180
163
#if (digitalPinToInterrupt (Y2_MIN_PIN ) != NOT_AN_INTERRUPT )
181
164
_ATTACH (Y2_MIN_PIN );
182
165
#else
183
- static_assert (digitalPinToPCICR (Y2_MIN_PIN ), "Y2_MIN_PIN is not interrupt-capable" );
166
+ static_assert (digitalPinHasPCICR (Y2_MIN_PIN ), "Y2_MIN_PIN is not interrupt-capable" );
184
167
pciSetup (Y2_MIN_PIN );
185
168
#endif
186
169
#endif
187
170
#if HAS_Z2_MAX
188
171
#if (digitalPinToInterrupt (Z2_MAX_PIN ) != NOT_AN_INTERRUPT )
189
172
_ATTACH (Z2_MAX_PIN );
190
173
#else
191
- static_assert (digitalPinToPCICR (Z2_MAX_PIN ), "Z2_MAX_PIN is not interrupt-capable" );
174
+ static_assert (digitalPinHasPCICR (Z2_MAX_PIN ), "Z2_MAX_PIN is not interrupt-capable" );
192
175
pciSetup (Z2_MAX_PIN );
193
176
#endif
194
177
#endif
195
178
#if HAS_Z2_MIN
196
179
#if (digitalPinToInterrupt (Z2_MIN_PIN ) != NOT_AN_INTERRUPT )
197
180
_ATTACH (Z2_MIN_PIN );
198
181
#else
199
- static_assert (digitalPinToPCICR (Z2_MIN_PIN ), "Z2_MIN_PIN is not interrupt-capable" );
182
+ static_assert (digitalPinHasPCICR (Z2_MIN_PIN ), "Z2_MIN_PIN is not interrupt-capable" );
200
183
pciSetup (Z2_MIN_PIN );
201
184
#endif
202
185
#endif
203
186
#if HAS_Z3_MAX
204
187
#if (digitalPinToInterrupt (Z3_MAX_PIN ) != NOT_AN_INTERRUPT )
205
188
_ATTACH (Z3_MAX_PIN );
206
189
#else
207
- static_assert (digitalPinToPCICR (Z3_MAX_PIN ), "Z3_MAX_PIN is not interrupt-capable" );
190
+ static_assert (digitalPinHasPCICR (Z3_MAX_PIN ), "Z3_MAX_PIN is not interrupt-capable" );
208
191
pciSetup (Z3_MAX_PIN );
209
192
#endif
210
193
#endif
211
194
#if HAS_Z3_MIN
212
195
#if (digitalPinToInterrupt (Z3_MIN_PIN ) != NOT_AN_INTERRUPT )
213
196
_ATTACH (Z3_MIN_PIN );
214
197
#else
215
- static_assert (digitalPinToPCICR (Z3_MIN_PIN ), "Z3_MIN_PIN is not interrupt-capable" );
198
+ static_assert (digitalPinHasPCICR (Z3_MIN_PIN ), "Z3_MIN_PIN is not interrupt-capable" );
216
199
pciSetup (Z3_MIN_PIN );
217
200
#endif
218
201
#endif
219
202
#if HAS_Z_MIN_PROBE_PIN
220
203
#if (digitalPinToInterrupt (Z_MIN_PROBE_PIN ) != NOT_AN_INTERRUPT )
221
204
_ATTACH (Z_MIN_PROBE_PIN );
222
205
#else
223
- static_assert (digitalPinToPCICR (Z_MIN_PROBE_PIN ), "Z_MIN_PROBE_PIN is not interrupt-capable" );
206
+ static_assert (digitalPinHasPCICR (Z_MIN_PROBE_PIN ), "Z_MIN_PROBE_PIN is not interrupt-capable" );
224
207
pciSetup (Z_MIN_PROBE_PIN );
225
208
#endif
226
209
#endif
0 commit comments