diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-07-26 11:23:36 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-07-26 11:23:36 +1000 |
| commit | f94be3db2f2bb6c1b359744cb915683095e4ee80 (patch) | |
| tree | 79d335db661720947c518a535bdde733fe669032 /src/drivers | |
| parent | d8194135bbaad97d1f3428a74c7fc54ba3f604ec (diff) | |
| download | tangara-fw-f94be3db2f2bb6c1b359744cb915683095e4ee80.tar.gz | |
make event queue go faster
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/gpios.cpp | 14 | ||||
| -rw-r--r-- | src/drivers/include/gpios.hpp | 7 |
2 files changed, 10 insertions, 11 deletions
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<uint8_t, uint8_t> unpack(uint16_t ba) { } void interrupt_isr(void* arg) { - Gpios* instance = reinterpret_cast<Gpios*>(arg); - auto listener = instance->listener(); - if (listener != nullptr) { - std::invoke(*listener); - } + SemaphoreHandle_t sem = reinterpret_cast<SemaphoreHandle_t>(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<uint64_t>(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<void(void)>* { return listener_; } - - auto set_listener(std::function<void(void)>* 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<uint16_t> ports_; std::atomic<uint16_t> inputs_; - std::function<void(void)>* listener_; + SemaphoreHandle_t read_pending_; }; } // namespace drivers |
