From 769051aa76c90baff86e88c6872f9f2f0e9b1629 Mon Sep 17 00:00:00 2001 From: rmlearney-digicatapult <39194639+rmlearney-digicatapult@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:03:09 +0100 Subject: [PATCH 1/2] Set default pinMode for CHANGE IRQ Use switch/case statement to set pinMode to cover CHANGE (and other future interrupt types) as just INPUT --- cores/arduino/Interrupts.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index a5770b70..c0c3900b 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -69,10 +69,20 @@ void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinSta digitalPinToInterruptObj(interruptNum) = irq; // Give a default pullup for the pin, since calling InterruptIn with PinMode is impossible if (digitalPinToGpio(interruptNum) == NULL) { - pinMode(interruptNum, mode == FALLING ? INPUT_PULLUP : INPUT_PULLDOWN); + switch(mode){ + case FALLING: + pinMode(interruptNum, INPUT_PULLUP); + break; + case RISING: + pinMode(interruptNum, INPUT_PULLDOWN); + break; + default: + pinMode(interruptNum, INPUT); + break; + } } } void attachInterrupt(pin_size_t interruptNum, voidFuncPtr func, PinStatus mode) { attachInterruptParam(interruptNum, (voidFuncPtrParam)func, mode, NULL); -} \ No newline at end of file +} From 35f67d971f6b6ab1d9607981668477005123e975 Mon Sep 17 00:00:00 2001 From: rmlearney-digicatapult <39194639+rmlearney-digicatapult@users.noreply.github.com> Date: Thu, 18 Jun 2020 22:07:48 +0100 Subject: [PATCH 2/2] Set default pinMode on CHANGE Use same nested if/else style to set default pinMode to INPUT for all non-RISING/FALLING IRQs --- cores/arduino/Interrupts.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cores/arduino/Interrupts.cpp b/cores/arduino/Interrupts.cpp index c0c3900b..f00b391f 100644 --- a/cores/arduino/Interrupts.cpp +++ b/cores/arduino/Interrupts.cpp @@ -69,16 +69,12 @@ void attachInterruptParam(pin_size_t interruptNum, voidFuncPtrParam func, PinSta digitalPinToInterruptObj(interruptNum) = irq; // Give a default pullup for the pin, since calling InterruptIn with PinMode is impossible if (digitalPinToGpio(interruptNum) == NULL) { - switch(mode){ - case FALLING: - pinMode(interruptNum, INPUT_PULLUP); - break; - case RISING: - pinMode(interruptNum, INPUT_PULLDOWN); - break; - default: - pinMode(interruptNum, INPUT); - break; + if (mode == FALLING) { + pinMode(interruptNum, INPUT_PULLUP); + } else if (mode == RISING) { + pinMode(interruptNum, INPUT_PULLDOWN); + } else { + pinMode(interruptNum, INPUT); } } }