Browse Source

Patch es int tests for Arduino 1.8.10

Scott Lahteine 5 years ago
parent
commit
35b1149d96

+ 24
- 41
Marlin/src/HAL/HAL_AVR/endstop_interrupts.h View File

51
  * There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
51
  * There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
52
  */
52
  */
53
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
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
 #endif
59
 #endif
77
 
60
 
78
 
61
 
79
 // Install Pin change interrupt for a pin. Can be called multiple times.
62
 // Install Pin change interrupt for a pin. Can be called multiple times.
80
 void pciSetup(const int8_t pin) {
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
     #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
91
     #if (digitalPinToInterrupt(X_MAX_PIN) != NOT_AN_INTERRUPT)
109
       _ATTACH(X_MAX_PIN);
92
       _ATTACH(X_MAX_PIN);
110
     #else
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
       pciSetup(X_MAX_PIN);
95
       pciSetup(X_MAX_PIN);
113
     #endif
96
     #endif
114
   #endif
97
   #endif
116
     #if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
99
     #if (digitalPinToInterrupt(X_MIN_PIN) != NOT_AN_INTERRUPT)
117
       _ATTACH(X_MIN_PIN);
100
       _ATTACH(X_MIN_PIN);
118
     #else
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
       pciSetup(X_MIN_PIN);
103
       pciSetup(X_MIN_PIN);
121
     #endif
104
     #endif
122
   #endif
105
   #endif
124
     #if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
107
     #if (digitalPinToInterrupt(Y_MAX_PIN) != NOT_AN_INTERRUPT)
125
       _ATTACH(Y_MAX_PIN);
108
       _ATTACH(Y_MAX_PIN);
126
     #else
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
       pciSetup(Y_MAX_PIN);
111
       pciSetup(Y_MAX_PIN);
129
     #endif
112
     #endif
130
   #endif
113
   #endif
132
     #if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
115
     #if (digitalPinToInterrupt(Y_MIN_PIN) != NOT_AN_INTERRUPT)
133
       _ATTACH(Y_MIN_PIN);
116
       _ATTACH(Y_MIN_PIN);
134
     #else
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
       pciSetup(Y_MIN_PIN);
119
       pciSetup(Y_MIN_PIN);
137
     #endif
120
     #endif
138
   #endif
121
   #endif
140
     #if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
123
     #if (digitalPinToInterrupt(Z_MAX_PIN) != NOT_AN_INTERRUPT)
141
       _ATTACH(Z_MAX_PIN);
124
       _ATTACH(Z_MAX_PIN);
142
     #else
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
       pciSetup(Z_MAX_PIN);
127
       pciSetup(Z_MAX_PIN);
145
     #endif
128
     #endif
146
   #endif
129
   #endif
148
     #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
131
     #if (digitalPinToInterrupt(Z_MIN_PIN) != NOT_AN_INTERRUPT)
149
       _ATTACH(Z_MIN_PIN);
132
       _ATTACH(Z_MIN_PIN);
150
     #else
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
       pciSetup(Z_MIN_PIN);
135
       pciSetup(Z_MIN_PIN);
153
     #endif
136
     #endif
154
   #endif
137
   #endif
156
     #if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
139
     #if (digitalPinToInterrupt(X2_MAX_PIN) != NOT_AN_INTERRUPT)
157
       _ATTACH(X2_MAX_PIN);
140
       _ATTACH(X2_MAX_PIN);
158
     #else
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
       pciSetup(X2_MAX_PIN);
143
       pciSetup(X2_MAX_PIN);
161
     #endif
144
     #endif
162
   #endif
145
   #endif
164
     #if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
147
     #if (digitalPinToInterrupt(X2_MIN_PIN) != NOT_AN_INTERRUPT)
165
       _ATTACH(X2_MIN_PIN);
148
       _ATTACH(X2_MIN_PIN);
166
     #else
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
       pciSetup(X2_MIN_PIN);
151
       pciSetup(X2_MIN_PIN);
169
     #endif
152
     #endif
170
   #endif
153
   #endif
172
     #if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
155
     #if (digitalPinToInterrupt(Y2_MAX_PIN) != NOT_AN_INTERRUPT)
173
       _ATTACH(Y2_MAX_PIN);
156
       _ATTACH(Y2_MAX_PIN);
174
     #else
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
       pciSetup(Y2_MAX_PIN);
159
       pciSetup(Y2_MAX_PIN);
177
     #endif
160
     #endif
178
   #endif
161
   #endif
180
     #if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
163
     #if (digitalPinToInterrupt(Y2_MIN_PIN) != NOT_AN_INTERRUPT)
181
       _ATTACH(Y2_MIN_PIN);
164
       _ATTACH(Y2_MIN_PIN);
182
     #else
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
       pciSetup(Y2_MIN_PIN);
167
       pciSetup(Y2_MIN_PIN);
185
     #endif
168
     #endif
186
   #endif
169
   #endif
188
     #if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
171
     #if (digitalPinToInterrupt(Z2_MAX_PIN) != NOT_AN_INTERRUPT)
189
       _ATTACH(Z2_MAX_PIN);
172
       _ATTACH(Z2_MAX_PIN);
190
     #else
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
       pciSetup(Z2_MAX_PIN);
175
       pciSetup(Z2_MAX_PIN);
193
     #endif
176
     #endif
194
   #endif
177
   #endif
196
     #if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
179
     #if (digitalPinToInterrupt(Z2_MIN_PIN) != NOT_AN_INTERRUPT)
197
       _ATTACH(Z2_MIN_PIN);
180
       _ATTACH(Z2_MIN_PIN);
198
     #else
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
       pciSetup(Z2_MIN_PIN);
183
       pciSetup(Z2_MIN_PIN);
201
     #endif
184
     #endif
202
   #endif
185
   #endif
204
     #if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
187
     #if (digitalPinToInterrupt(Z3_MAX_PIN) != NOT_AN_INTERRUPT)
205
       _ATTACH(Z3_MAX_PIN);
188
       _ATTACH(Z3_MAX_PIN);
206
     #else
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
       pciSetup(Z3_MAX_PIN);
191
       pciSetup(Z3_MAX_PIN);
209
     #endif
192
     #endif
210
   #endif
193
   #endif
212
     #if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
195
     #if (digitalPinToInterrupt(Z3_MIN_PIN) != NOT_AN_INTERRUPT)
213
       _ATTACH(Z3_MIN_PIN);
196
       _ATTACH(Z3_MIN_PIN);
214
     #else
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
       pciSetup(Z3_MIN_PIN);
199
       pciSetup(Z3_MIN_PIN);
217
     #endif
200
     #endif
218
   #endif
201
   #endif
220
     #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
203
     #if (digitalPinToInterrupt(Z_MIN_PROBE_PIN) != NOT_AN_INTERRUPT)
221
       _ATTACH(Z_MIN_PROBE_PIN);
204
       _ATTACH(Z_MIN_PROBE_PIN);
222
     #else
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
       pciSetup(Z_MIN_PROBE_PIN);
207
       pciSetup(Z_MIN_PROBE_PIN);
225
     #endif
208
     #endif
226
   #endif
209
   #endif

+ 4
- 5
buildroot/share/pin_interrupt_test/pin_interrupt_test.ino View File

2
 // Compile with the same build settings you'd use for Marlin.
2
 // Compile with the same build settings you'd use for Marlin.
3
 
3
 
4
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
4
 #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)
9
 #endif
8
 #endif
10
 
9
 
11
 void setup() {
10
 void setup() {
12
   Serial.begin(9600);
11
   Serial.begin(9600);
13
   Serial.println("PINs causing interrupts are:");
12
   Serial.println("PINs causing interrupts are:");
14
   for (int i = 2; i < NUM_DIGITAL_PINS; i++) {
13
   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) {
16
       for (int j = 0; j < NUM_ANALOG_INPUTS; j++) {
15
       for (int j = 0; j < NUM_ANALOG_INPUTS; j++) {
17
         if (analogInputToDigitalPin(j) == i) {
16
         if (analogInputToDigitalPin(j) == i) {
18
           Serial.print('A');
17
           Serial.print('A');

Loading…
Cancel
Save