Skip to content

Commit 9405f1a

Browse files
cmagliemattairtech
authored andcommitted
WInterrupts: optimized use of digitalPinToInterrupt()
1 parent 03aa3ce commit 9405f1a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

cores/arduino/WInterrupts.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
6060
// Assign pin to EIC
6161
if (pinPeripheral(pin, PIO_EXTINT) != RET_STATUS_OK)
6262
return;
63-
if (digitalPinToInterrupt(pin) == EXTERNAL_INT_NMI)
63+
64+
EExt_Interrupts in = digitalPinToInterrupt(pin);
65+
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
6466
return;
6567

6668
if (!enabled) {
@@ -69,17 +71,17 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
6971
}
7072

7173
// Assign callback to interrupt
72-
callbacksInt[digitalPinToInterrupt(pin)] = callback;
74+
callbacksInt[in] = callback;
7375

7476
// Look for right CONFIG register to be addressed
75-
if (digitalPinToInterrupt(pin) > EXTERNAL_INT_7) {
77+
if (in > EXTERNAL_INT_7) {
7678
config = 1;
7779
} else {
7880
config = 0;
7981
}
8082

8183
// Configure the interrupt mode
82-
pos = ((digitalPinToInterrupt(pin) - (8 * config)) << 2);
84+
pos = (in - (8 * config)) << 2;
8385
switch (mode)
8486
{
8587
case LOW:
@@ -104,20 +106,19 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
104106
}
105107

106108
// Enable the interrupt
107-
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << digitalPinToInterrupt(pin));
109+
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
108110
}
109111

110112
/*
111113
* \brief Turns off the given interrupt.
112114
*/
113115
void detachInterrupt(uint32_t pin)
114116
{
115-
if (digitalPinToInterrupt(pin) == NOT_AN_INTERRUPT)
116-
return;
117-
if (digitalPinToInterrupt(pin) == EXTERNAL_INT_NMI)
117+
EExt_Interrupts in = digitalPinToInterrupt(pin);
118+
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
118119
return;
119120

120-
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << digitalPinToInterrupt(pin));
121+
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);
121122
}
122123

123124
/*

0 commit comments

Comments
 (0)