From f94be3db2f2bb6c1b359744cb915683095e4ee80 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 26 Jul 2023 11:23:36 +1000 Subject: make event queue go faster --- src/drivers/gpios.cpp | 14 +++++++------- src/drivers/include/gpios.hpp | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/gpios.cpp b/src/drivers/gpios.cpp index 1d1f5281..f6293697 100644 --- a/src/drivers/gpios.cpp +++ b/src/drivers/gpios.cpp @@ -59,11 +59,8 @@ constexpr std::pair unpack(uint16_t ba) { } void interrupt_isr(void* arg) { - Gpios* instance = reinterpret_cast(arg); - auto listener = instance->listener(); - if (listener != nullptr) { - std::invoke(*listener); - } + SemaphoreHandle_t sem = reinterpret_cast(arg); + xSemaphoreGive(sem); } auto Gpios::Create() -> Gpios* { @@ -79,7 +76,7 @@ auto Gpios::Create() -> Gpios* { Gpios::Gpios() : ports_(pack(kPortADefault, kPortBDefault)), inputs_(0), - listener_(nullptr) { + read_pending_(xSemaphoreCreateBinary()) { gpio_config_t config{ .pin_bit_mask = static_cast(1) << GPIO_NUM_34, .mode = GPIO_MODE_INPUT, @@ -90,7 +87,6 @@ Gpios::Gpios() gpio_config(&config); gpio_install_isr_service(ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_SHARED | ESP_INTR_FLAG_IRAM); - gpio_isr_handler_add(GPIO_NUM_34, &interrupt_isr, this); } Gpios::~Gpios() { @@ -145,4 +141,8 @@ auto Gpios::Read() -> bool { return true; } +auto Gpios::InstallReadPendingISR() -> void { + gpio_isr_handler_add(GPIO_NUM_34, &interrupt_isr, read_pending_); +} + } // namespace drivers diff --git a/src/drivers/include/gpios.hpp b/src/drivers/include/gpios.hpp index da997843..5ac475bf 100644 --- a/src/drivers/include/gpios.hpp +++ b/src/drivers/include/gpios.hpp @@ -107,9 +107,8 @@ class Gpios : public IGpios { */ auto Read(void) -> bool; - auto listener() -> std::function* { return listener_; } - - auto set_listener(std::function* l) -> void { listener_ = l; } + auto InstallReadPendingISR() -> void; + auto IsReadPending() -> SemaphoreHandle_t { return read_pending_; } // Not copyable or movable. There should usually only ever be once instance // of this class, and that instance will likely have a static lifetime. @@ -122,7 +121,7 @@ class Gpios : public IGpios { std::atomic ports_; std::atomic inputs_; - std::function* listener_; + SemaphoreHandle_t read_pending_; }; } // namespace drivers -- cgit v1.2.3