ソースを参照

Patch es int tests for Arduino 1.8.10

Scott Lahteine 4年前
コミット
35b1149d96

+ 24
- 41
Marlin/src/HAL/HAL_AVR/endstop_interrupts.h ファイルの表示

@@ -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,7 +91,7 @@ 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
@@ -116,7 +99,7 @@ void setup_endstop_interrupts() {
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
@@ -124,7 +107,7 @@ void setup_endstop_interrupts() {
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
@@ -132,7 +115,7 @@ void setup_endstop_interrupts() {
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
@@ -140,7 +123,7 @@ void setup_endstop_interrupts() {
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
@@ -148,7 +131,7 @@ void setup_endstop_interrupts() {
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
@@ -156,7 +139,7 @@ void setup_endstop_interrupts() {
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
@@ -164,7 +147,7 @@ void setup_endstop_interrupts() {
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
@@ -172,7 +155,7 @@ void setup_endstop_interrupts() {
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
@@ -180,7 +163,7 @@ void setup_endstop_interrupts() {
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
@@ -188,7 +171,7 @@ void setup_endstop_interrupts() {
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
@@ -196,7 +179,7 @@ void setup_endstop_interrupts() {
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
@@ -204,7 +187,7 @@ void setup_endstop_interrupts() {
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
@@ -212,7 +195,7 @@ void setup_endstop_interrupts() {
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
@@ -220,7 +203,7 @@ void setup_endstop_interrupts() {
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

+ 4
- 5
buildroot/share/pin_interrupt_test/pin_interrupt_test.ino ファイルの表示

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

読み込み中…
キャンセル
保存