Skip to content

Commit b0e8ff0

Browse files
committed
WInterrupts: optimized use of digitalPinToInterrupt()
1 parent e53a7a7 commit b0e8ff0

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

cores/arduino/WInterrupts.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
5757
uint32_t config;
5858
uint32_t pos;
5959

60-
if (digitalPinToInterrupt(pin) == NOT_AN_INTERRUPT)
61-
return;
62-
if (digitalPinToInterrupt(pin) == EXTERNAL_INT_NMI)
60+
EExt_Interrupts in = digitalPinToInterrupt(pin);
61+
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
6362
return;
6463

6564
if (!enabled) {
@@ -71,17 +70,17 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
7170
pinPeripheral(pin, PIO_EXTINT);
7271

7372
// Assign callback to interrupt
74-
callbacksInt[digitalPinToInterrupt(pin)] = callback;
73+
callbacksInt[in] = callback;
7574

7675
// Look for right CONFIG register to be addressed
77-
if (digitalPinToInterrupt(pin) > EXTERNAL_INT_7) {
76+
if (in > EXTERNAL_INT_7) {
7877
config = 1;
7978
} else {
8079
config = 0;
8180
}
8281

8382
// Configure the interrupt mode
84-
pos = ((digitalPinToInterrupt(pin) - (8 * config)) << 2);
83+
pos = (in - (8 * config)) << 2;
8584
switch (mode)
8685
{
8786
case LOW:
@@ -106,20 +105,19 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
106105
}
107106

108107
// Enable the interrupt
109-
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << digitalPinToInterrupt(pin));
108+
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
110109
}
111110

112111
/*
113112
* \brief Turns off the given interrupt.
114113
*/
115114
void detachInterrupt(uint32_t pin)
116115
{
117-
if (digitalPinToInterrupt(pin) == NOT_AN_INTERRUPT)
118-
return;
119-
if (digitalPinToInterrupt(pin) == EXTERNAL_INT_NMI)
116+
EExt_Interrupts in = digitalPinToInterrupt(pin);
117+
if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI)
120118
return;
121119

122-
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << digitalPinToInterrupt(pin));
120+
EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in);
123121
}
124122

125123
/*

0 commit comments

Comments
 (0)