Skip to content

Commit d21e3f2

Browse files
committed
attachInterrupt(): check that the irq was not already detached
1 parent aa688fb commit d21e3f2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cores/arduino/Interrupts.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void detachInterrupt(PinName interruptNum) {
2929
void detachInterrupt(pin_size_t interruptNum) {
3030
if ((interruptNum < PINS_COUNT) && (digitalPinToInterruptObj(interruptNum) != NULL)) {
3131
delete digitalPinToInterruptObj(interruptNum);
32+
digitalPinToInterruptObj(interruptNum) = nullptr;
3233
}
3334
}
3435

@@ -57,7 +58,9 @@ void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinSta
5758
if (interruptNum >= PINS_COUNT) {
5859
return;
5960
}
60-
detachInterrupt(interruptNum);
61+
if (digitalPinToInterruptObj(interruptNum) != nullptr) {
62+
detachInterrupt(interruptNum);
63+
}
6164
mbed::InterruptIn* irq = new mbed::InterruptIn(digitalPinToPinName(interruptNum));
6265
if (mode == CHANGE) {
6366
irq->rise(mbed::callback(func, param));

0 commit comments

Comments
 (0)