summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruvok2025-07-19 10:50:03 +0200
committeruvok2025-07-19 10:50:03 +0200
commit26a3a757f167b7de920ffe4f3563c40e88e9d3eb (patch)
tree52b38e1cf187a0a26061310cda07aac134386c27 /src
parentb5662a6e820845dad42147e0be18718a10f47581 (diff)
gpio: Re-attempt debouncing
Diffstat (limited to 'src')
-rw-r--r--src/gpio.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/gpio.cpp b/src/gpio.cpp
index a7927a8..84dc545 100644
--- a/src/gpio.cpp
+++ b/src/gpio.cpp
@@ -34,9 +34,10 @@ static unsigned long releasedTime = 0;
typedef struct
{
- uint32_t last_change;
+ // uint32_t last_change;
uint32_t last_level;
uint32_t pressed;
+ uint32_t released;
} InputInfo_t;
static volatile InputInfo_t inputs[NUM_DIGITAL_PINS];
@@ -107,22 +108,29 @@ static void gpio_loop(void *ctx)
const bool pressed = !received.state;
const uint8_t pin = received.pin;
LOG_F("(%u) Pin %u was %s\n", received.timestamp, pin, pressed ? "pressed" : "released");
+ LOG_F(" pressed: %u, released: %u\n", inputs[pin].pressed, inputs[pin].released);
}
}
}
-static ARDUINO_ISR_ATTR void gpio_pin_irq(void *arg)
+static ARDUINO_ISR_ATTR IRAM_ATTR void gpio_pin_irq(void *arg)
{
- uint8_t pin_no = (uint8_t)(ptrdiff_t)arg;
+ const uint8_t pin_no = (uint8_t)(ptrdiff_t)arg;
+ const int pinLevel = digitalRead(pin_no);
+
uint32_t now = millis();
+ if (!pinLevel)
+ {
+ inputs[pin_no].pressed = now;
+ return;
+ }
+ inputs[pin_no].released = now;
+
// Elecrow inputs - the selector - are very dirty...
// const bool is_dirty = now - inputs[pin_no].last_change < 50;
- // inputs[pin_no].last_change = now;
// if (is_dirty)
// return;
- int pinLevel = digitalRead(pin_no);
-
pin_notification_t send = {.timestamp = now, .pin = pin_no, .state = (pinLevel == HIGH)};
BaseType_t wakeup = false;
xQueueSendFromISR(gpio_task_stuff.queue_handle, &send, &wakeup);