1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-26 13:25:54 +00:00

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

This commit is contained in:
Giuliano Zaro 2019-11-04 22:24:41 +01:00 committed by Scott Lahteine
parent 1fe0646d25
commit 35cd545106
2 changed files with 46 additions and 12 deletions

View File

@ -51,20 +51,53 @@ void endstop_ISR() { endstops.update(); }
* There are more PCI-enabled processor pins on Port J, but they are not connected to Arduino MEGA.
*/
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
#define digitalPinHasPCICR(p) (WITHIN(p, 10, 15) || WITHIN(p, 50, 53) || WITHIN(p, 62, 69))
#define moreDigitalPinToPCICR(p) digitalPinToPCICR(WITHIN(p, 14, 15) ? 10 : p)
#define moreDigitalPinToPCICRbit(p) (WITHIN(p, 14, 15) ? 1 : digitalPinToPCICRbit(p))
#define moreDigitalPinToPCMSK(p) (WITHIN(p, 14, 15) ? (&PCMSK1) : digitalPinToPCMSK(p))
#define moreDigitalPinToPCMSKbit(p) digitalPinToPCMSKbit(WITHIN(p, 14, 15) ? (p)+36 : p)
#undef digitalPinToPCICR
#define digitalPinToPCICR(p) (digitalPinHasPCICR(p) ? (&PCICR) : nullptr)
#undef digitalPinToPCICRbit
#define digitalPinToPCICRbit(p) (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
WITHIN(p, 14, 15) ? 1 : \
WITHIN(p, 62, 69) ? 2 : \
0)
#undef digitalPinToPCMSK
#define digitalPinToPCMSK(p) (WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? (&PCMSK0) : \
WITHIN(p, 14, 15) ? (&PCMSK1) : \
WITHIN(p, 62, 69) ? (&PCMSK2) : \
nullptr)
#undef digitalPinToPCMSKbit
#define digitalPinToPCMSKbit(p) (WITHIN(p, 10, 13) ? ((p) - 6) : \
(p) == 14 || (p) == 51 ? 2 : \
(p) == 15 || (p) == 52 ? 1 : \
(p) == 50 ? 3 : \
(p) == 53 ? 0 : \
WITHIN(p, 62, 69) ? ((p) - 62) : \
0)
#elif defined(__AVR_ATmega164A__) || defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324A__) || \
defined(__AVR_ATmega324P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega324PB__) || \
defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || \
defined(__AVR_ATmega1284P__)
#define digitalPinHasPCICR(p) WITHIN(p, 0, NUM_DIGITAL_PINS)
#else
#error "Unsupported AVR variant!"
#endif
// Install Pin change interrupt for a pin. Can be called multiple times.
void pciSetup(const int8_t pin) {
if (moreDigitalPinToPCMSK(pin) != nullptr) {
SBI(*moreDigitalPinToPCMSK(pin), moreDigitalPinToPCMSKbit(pin)); // enable pin
SBI(PCIFR, moreDigitalPinToPCICRbit(pin)); // clear any outstanding interrupt
SBI(PCICR, moreDigitalPinToPCICRbit(pin)); // enable interrupt for the group
if (digitalPinToPCMSK(pin) != nullptr) {
SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
}
}

View File

@ -2,16 +2,17 @@
// Compile with the same build settings you'd use for Marlin.
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
#define moreDigitalPinToPCICR(p) digitalPinToPCICR(WITHIN(p, 14, 15) ? 10 : p)
#else
#define moreDigitalPinToPCICR(p) digitalPinToPCICR(p)
#undef digitalPinToPCICR
#define digitalPinToPCICR(p) ( ((p) >= 10 && (p) <= 15) || \
((p) >= 50 && (p) <= 53) || \
((p) >= 62 && (p) <= 69) ? (&PCICR) : nullptr)
#endif
void setup() {
Serial.begin(9600);
Serial.println("PINs causing interrupts are:");
for (int i = 2; i < NUM_DIGITAL_PINS; i++) {
if (moreDigitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
if (digitalPinToPCICR(i) || (int)digitalPinToInterrupt(i) != -1) {
for (int j = 0; j < NUM_ANALOG_INPUTS; j++) {
if (analogInputToDigitalPin(j) == i) {
Serial.print('A');