|
@@ -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
|
|