Skip to content

Commit 35b1149

Browse files
committed
Patch es int tests for Arduino 1.8.10
1 parent c80eda0 commit 35b1149

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

Marlin/src/HAL/HAL_AVR/endstop_interrupts.h

+24-41
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,20 @@ void endstop_ISR() { endstops.update(); }
5151
* There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
5252
*/
5353
#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)
7659
#endif
7760

7861

7962
// Install Pin change interrupt for a pin. Can be called multiple times.
8063
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
8568
}
8669
}
8770

@@ -108,119 +91,119 @@ void setup_endstop_interrupts() {
10891
#if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
10992
_ATTACH(X_MAX_PIN);
11093
#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");
11295
pciSetup(X_MAX_PIN);
11396
#endif
11497
#endif
11598
#if HAS_X_MIN
11699
#if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
117100
_ATTACH(X_MIN_PIN);
118101
#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");
120103
pciSetup(X_MIN_PIN);
121104
#endif
122105
#endif
123106
#if HAS_Y_MAX
124107
#if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
125108
_ATTACH(Y_MAX_PIN);
126109
#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");
128111
pciSetup(Y_MAX_PIN);
129112
#endif
130113
#endif
131114
#if HAS_Y_MIN
132115
#if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
133116
_ATTACH(Y_MIN_PIN);
134117
#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");
136119
pciSetup(Y_MIN_PIN);
137120
#endif
138121
#endif
139122
#if HAS_Z_MAX
140123
#if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
141124
_ATTACH(Z_MAX_PIN);
142125
#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");
144127
pciSetup(Z_MAX_PIN);
145128
#endif
146129
#endif
147130
#if HAS_Z_MIN
148131
#if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
149132
_ATTACH(Z_MIN_PIN);
150133
#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");
152135
pciSetup(Z_MIN_PIN);
153136
#endif
154137
#endif
155138
#if HAS_X2_MAX
156139
#if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
157140
_ATTACH(X2_MAX_PIN);
158141
#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");
160143
pciSetup(X2_MAX_PIN);
161144
#endif
162145
#endif
163146
#if HAS_X2_MIN
164147
#if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
165148
_ATTACH(X2_MIN_PIN);
166149
#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");
168151
pciSetup(X2_MIN_PIN);
169152
#endif
170153
#endif
171154
#if HAS_Y2_MAX
172155
#if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
173156
_ATTACH(Y2_MAX_PIN);
174157
#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");
176159
pciSetup(Y2_MAX_PIN);
177160
#endif
178161
#endif
179162
#if HAS_Y2_MIN
180163
#if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
181164
_ATTACH(Y2_MIN_PIN);
182165
#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");
184167
pciSetup(Y2_MIN_PIN);
185168
#endif
186169
#endif
187170
#if HAS_Z2_MAX
188171
#if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
189172
_ATTACH(Z2_MAX_PIN);
190173
#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");
192175
pciSetup(Z2_MAX_PIN);
193176
#endif
194177
#endif
195178
#if HAS_Z2_MIN
196179
#if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
197180
_ATTACH(Z2_MIN_PIN);
198181
#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");
200183
pciSetup(Z2_MIN_PIN);
201184
#endif
202185
#endif
203186
#if HAS_Z3_MAX
204187
#if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
205188
_ATTACH(Z3_MAX_PIN);
206189
#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");
208191
pciSetup(Z3_MAX_PIN);
209192
#endif
210193
#endif
211194
#if HAS_Z3_MIN
212195
#if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
213196
_ATTACH(Z3_MIN_PIN);
214197
#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");
216199
pciSetup(Z3_MIN_PIN);
217200
#endif
218201
#endif
219202
#if HAS_Z_MIN_PROBE_PIN
220203
#if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
221204
_ATTACH(Z_MIN_PROBE_PIN);
222205
#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");
224207
pciSetup(Z_MIN_PROBE_PIN);
225208
#endif
226209
#endif

buildroot/share/pin_interrupt_test/pin_interrupt_test.ino

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
// Compile with the same build settings you'd use for Marlin.
33

44
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
5-
#undef digitalPinToPCICR
6-
#define digitalPinToPCICR(p) ( ((p) >= 10 && (p) <= 15) || \
7-
((p) >= 50 && (p) <= 53) || \
8-
((p) >= 62 && (p) <= 69) ? &PCICR : nullptr)
5+
#define moreDigitalPinToPCICR(p) digitalPinToPCICR(WITHIN(p, 13, 14) ? 10 : p)
6+
#else
7+
#define moreDigitalPinToPCICR(p) digitalPinToPCICR(p)
98
#endif
109

1110
void setup() {
1211
Serial.begin(9600);
1312
Serial.println("PINs causing interrupts are:");
1413
for (int i = 2; i < NUM_DIGITAL_PINS; i++) {
15-
if (digitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
14+
if (moreDigitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
1615
for (int j = 0; j < NUM_ANALOG_INPUTS; j++) {
1716
if (analogInputToDigitalPin(j) == i) {
1817
Serial.print('A');

0 commit comments

Comments
 (0)