From 230721cd6271f3239b42e1d2471f8db15bebd712 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 24 Nov 2023 07:18:14 +1100 Subject: Periodically check int lines instead of relying on interrupts --- src/drivers/gpios.cpp | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'src/drivers/gpios.cpp') diff --git a/src/drivers/gpios.cpp b/src/drivers/gpios.cpp index dc737710..e5560665 100644 --- a/src/drivers/gpios.cpp +++ b/src/drivers/gpios.cpp @@ -6,12 +6,13 @@ #include "gpios.hpp" -#include - #include +#include "assert.h" #include "driver/gpio.h" #include "esp_attr.h" +#include "esp_err.h" +#include "esp_intr_alloc.h" #include "hal/gpio_types.h" #include "i2c.hpp" @@ -60,12 +61,7 @@ constexpr std::pair unpack(uint16_t ba) { return std::pair((uint8_t)ba, (uint8_t)(ba >> 8)); } -SemaphoreHandle_t Gpios::sReadPending; - -IRAM_ATTR static void interrupt_isr(void* arg) { - SemaphoreHandle_t sem = reinterpret_cast(arg); - xSemaphoreGive(sem); -} +static constexpr gpio_num_t kIntPin = GPIO_NUM_34; auto Gpios::Create() -> Gpios* { Gpios* instance = new Gpios(); @@ -78,22 +74,10 @@ auto Gpios::Create() -> Gpios* { } Gpios::Gpios() : ports_(pack(kPortADefault, kPortBDefault)), inputs_(0) { - gpio_config_t config{ - .pin_bit_mask = static_cast(1) << GPIO_NUM_34, - .mode = GPIO_MODE_INPUT, - .pull_up_en = GPIO_PULLUP_ENABLE, - .pull_down_en = GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTR_NEGEDGE, - }; - gpio_config(&config); - gpio_install_isr_service(ESP_INTR_FLAG_LEVEL1); - gpio_isr_handler_add(GPIO_NUM_34, &interrupt_isr, sReadPending); + gpio_set_direction(kIntPin, GPIO_MODE_INPUT); } -Gpios::~Gpios() { - gpio_isr_handler_remove(GPIO_NUM_34); - gpio_uninstall_isr_service(); -} +Gpios::~Gpios() {} auto Gpios::WriteBuffered(Pin pin, bool value) -> void { if (value) { @@ -142,9 +126,4 @@ auto Gpios::Read() -> bool { return true; } -auto Gpios::CreateReadPending() -> SemaphoreHandle_t { - sReadPending = xSemaphoreCreateBinary(); - return sReadPending; -} - } // namespace drivers -- cgit v1.2.3