Skip to content

Commit 17753b5

Browse files
committed
Restore original pull after attachInterrupt
Fixes arduino#253
1 parent 93e56ff commit 17753b5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: cores/arduino/Interrupts.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ void attachInterrupt(PinName interruptNum, voidFuncPtr func, PinStatus mode) {
5353
attachInterruptParam(interruptNum, (voidFuncPtrParam)func, mode, NULL);
5454
}
5555

56+
uint8_t _pinMode[NUM_DIGITAL_PINS];
57+
5658
void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinStatus mode, void* param) {
5759
if (interruptNum >= PINS_COUNT) {
5860
return;
@@ -77,6 +79,11 @@ void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinSta
7779
} else {
7880
pinMode(interruptNum, INPUT);
7981
}
82+
} else {
83+
// Restore the original pull
84+
if (_pinMode[interruptNum] != OUTPUT) {
85+
pinMode(interruptNum, _pinMode[interruptNum]);
86+
}
8087
}
8188
}
8289

Diff for: cores/arduino/wiring_digital.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ void pinMode(PinName pin, PinMode mode)
4949
}
5050
}
5151

52+
extern uint8_t _pinMode[];
53+
5254
void pinMode(pin_size_t pin, PinMode mode)
5355
{
5456
mbed::DigitalInOut* gpio = digitalPinToGpio(pin);
@@ -57,6 +59,8 @@ void pinMode(pin_size_t pin, PinMode mode)
5759
digitalPinToGpio(pin) = gpio;
5860
}
5961

62+
_pinMode[pin] = mode;
63+
6064
switch (mode) {
6165
case INPUT:
6266
gpio->input();

0 commit comments

Comments
 (0)