summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruvok2025-07-18 20:29:13 +0200
committeruvok2025-07-18 20:29:13 +0200
commit7f4bd7d961679d4fe5b0bc6e6255968e65352111 (patch)
tree79200f2370902943ae5ebf9cbecd576f8df50a1e /src
parentbbf5b27ec18c8d65d515c01b36c2c9cef3c4272b (diff)
Pin deboncing
Diffstat (limited to 'src')
-rw-r--r--src/gpio.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/gpio.cpp b/src/gpio.cpp
index f3f600f..e76368a 100644
--- a/src/gpio.cpp
+++ b/src/gpio.cpp
@@ -24,6 +24,15 @@ typedef uint32_t pin_notification_t;
static unsigned long pressedTime = 0;
static unsigned long releasedTime = 0;
+typedef struct
+{
+ uint32_t last_change;
+ uint32_t last_level;
+ uint32_t pressed;
+} InputInfo_t;
+
+static volatile InputInfo_t inputs[NUM_DIGITAL_PINS];
+
static struct
{
@@ -50,6 +59,7 @@ void de::uvok::badge::gpio_init(void)
pinMode(p, GPIO_MODE_INPUT);
// simply use pin number as arg
attachInterruptArg(p, gpio_pin_irq, (void *)(ptrdiff_t)p, CHANGE);
+ inputs[p].last_level = digitalRead(p);
}
#endif
}
@@ -97,6 +107,13 @@ static void gpio_loop(void *ctx)
static ARDUINO_ISR_ATTR void gpio_pin_irq(void *arg)
{
uint8_t pin_no = (uint8_t)(ptrdiff_t)arg;
+ uint32_t now = millis();
+ // Elecrow inputs - the selector - are very dirty...
+ const bool is_dirty = now - inputs[pin_no].last_change < 100;
+ inputs[pin_no].last_change = now;
+ if (is_dirty)
+ return;
+
int pinLevel = digitalRead(pin_no);
pin_notification_t send = (pinLevel << 8) | (pin_no);