Przeglądaj źródła

Use prior endstop pin-to-interrupt macros (#15771)

Giuliano Zaro 5 lat temu
rodzic
commit
35cd545106

+ 41
- 8
Marlin/src/HAL/HAL_AVR/endstop_interrupts.h Wyświetl plik

@@ -51,20 +51,53 @@ 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
+
54 55
   #define digitalPinHasPCICR(p)   (WITHIN(p, 10, 15) || WITHIN(p, 50, 53) || WITHIN(p, 62, 69))
55
-  #define moreDigitalPinToPCICR(p)    digitalPinToPCICR(WITHIN(p, 14, 15) ? 10 : p)
56
-  #define moreDigitalPinToPCICRbit(p) (WITHIN(p, 14, 15) ? 1 : digitalPinToPCICRbit(p))
57
-  #define moreDigitalPinToPCMSK(p)    (WITHIN(p, 14, 15) ? (&PCMSK1) : digitalPinToPCMSK(p))
58
-  #define moreDigitalPinToPCMSKbit(p) digitalPinToPCMSKbit(WITHIN(p, 14, 15) ? (p)+36 : p)
56
+
57
+  #undef  digitalPinToPCICR
58
+  #define digitalPinToPCICR(p)    (digitalPinHasPCICR(p) ? (&PCICR) : nullptr)
59
+
60
+  #undef  digitalPinToPCICRbit
61
+  #define digitalPinToPCICRbit(p) (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
62
+                                   WITHIN(p, 14, 15) ? 1 : \
63
+                                   WITHIN(p, 62, 69) ? 2 : \
64
+                                   0)
65
+  
66
+  #undef  digitalPinToPCMSK
67
+  #define digitalPinToPCMSK(p)    (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? (&PCMSK0) : \
68
+                                   WITHIN(p, 14, 15) ? (&PCMSK1) : \
69
+                                   WITHIN(p, 62, 69) ? (&PCMSK2) : \
70
+                                   nullptr)
71
+
72
+  #undef  digitalPinToPCMSKbit
73
+  #define digitalPinToPCMSKbit(p) (WITHIN(p, 10, 13) ? ((p) - 6) : \
74
+                                   (p) == 14 || (p) == 51 ? 2 : \
75
+                                   (p) == 15 || (p) == 52 ? 1 : \
76
+                                   (p) == 50 ? 3 : \
77
+                                   (p) == 53 ? 0 : \
78
+                                   WITHIN(p, 62, 69) ? ((p) - 62) : \
79
+                                   0)
80
+
81
+#elif defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324A__) || \
82
+      defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || \
83
+      defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || \
84
+      defined(__AVR_ATmega1284P__)
85
+
86
+  #define digitalPinHasPCICR(p)   WITHIN(p, 0, NUM_DIGITAL_PINS)
87
+
88
+#else
89
+
90
+  #error "Unsupported AVR variant!"
91
+
59 92
 #endif
60 93
 
61 94
 
62 95
 // Install Pin change interrupt for a pin. Can be called multiple times.
63 96
 void pciSetup(const int8_t pin) {
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
97
+  if (digitalPinToPCMSK(pin) != nullptr) {
98
+    SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin));  // enable pin
99
+    SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
100
+    SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
68 101
   }
69 102
 }
70 103
 

+ 5
- 4
buildroot/share/pin_interrupt_test/pin_interrupt_test.ino Wyświetl plik

@@ -2,16 +2,17 @@
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
-  #define moreDigitalPinToPCICR(p) digitalPinToPCICR(WITHIN(p, 14, 15) ? 10 : p)
6
-#else
7
-  #define moreDigitalPinToPCICR(p) digitalPinToPCICR(p)
5
+    #undef  digitalPinToPCICR
6
+    #define digitalPinToPCICR(p)    ( ((p) >= 10 && (p) <= 15) || \
7
+                                      ((p) >= 50 && (p) <= 53) || \
8
+                                      ((p) >= 62 && (p) <= 69) ? (&PCICR) : nullptr)
8 9
 #endif
9 10
 
10 11
 void setup() {
11 12
   Serial.begin(9600);
12 13
   Serial.println("PINs causing interrupts are:");
13 14
   for (int i = 2; i < NUM_DIGITAL_PINS; i++) {
14
-    if (moreDigitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
15
+    if (digitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
15 16
       for (int j = 0; j < NUM_ANALOG_INPUTS; j++) {
16 17
         if (analogInputToDigitalPin(j) == i) {
17 18
           Serial.print('A');

Ładowanie…
Anuluj
Zapisz