diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-30 17:05:11 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-30 17:05:11 +1000 |
| commit | 0347555d5b2314e1be58261ef29fa13a76c039e6 (patch) | |
| tree | e38879c0dc8bbf0a58057d22b26f28c0a9b86e93 /src/system_fsm | |
| parent | 9763cc955c4f3b2c2af54b61c2c5ad77afef9603 (diff) | |
| download | tangara-fw-0347555d5b2314e1be58261ef29fa13a76c039e6.tar.gz | |
Start on converting gpio expander interupts to fsm events
Diffstat (limited to 'src/system_fsm')
| -rw-r--r-- | src/system_fsm/booting.cpp | 4 | ||||
| -rw-r--r-- | src/system_fsm/include/system_events.hpp | 19 | ||||
| -rw-r--r-- | src/system_fsm/include/system_fsm.hpp | 1 | ||||
| -rw-r--r-- | src/system_fsm/system_fsm.cpp | 38 |
4 files changed, 62 insertions, 0 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 1e1b2959..e7505f11 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -27,6 +27,10 @@ namespace states { static const char kTag[] = "BOOT"; +static std::function<void(void)> sGpiosCallback = []() { + events::EventQueue::GetInstance().DispatchFromISR(internal::GpioInterrupt{}); +}; + auto Booting::entry() -> void { ESP_LOGI(kTag, "beginning tangara boot"); ESP_LOGI(kTag, "installing early drivers"); diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp index ec202c69..0903cb77 100644 --- a/src/system_fsm/include/system_events.hpp +++ b/src/system_fsm/include/system_events.hpp @@ -47,6 +47,19 @@ struct StorageMounted : tinyfsm::Event { struct StorageError : tinyfsm::Event {}; +struct KeyUpChanged : tinyfsm::Event { + bool falling; +}; +struct KeyDownChanged : tinyfsm::Event { + bool falling; +}; +struct KeyLockChanged : tinyfsm::Event { + bool falling; +}; +struct HasPhonesChanged : tinyfsm::Event { + bool falling; +}; + namespace internal { /* @@ -55,6 +68,12 @@ namespace internal { */ struct ReadyToUnmount : tinyfsm::Event {}; +/* + * Sent when the actual unmount operation should be performed. Always dispatched + * by SysState in response to StoragePrepareToUnmount. + */ +struct GpioInterrupt : tinyfsm::Event {}; + } // namespace internal } // namespace system_fsm diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp index 037c0a0e..725f2f50 100644 --- a/src/system_fsm/include/system_fsm.hpp +++ b/src/system_fsm/include/system_fsm.hpp @@ -38,6 +38,7 @@ class SystemState : public tinyfsm::Fsm<SystemState> { void react(const tinyfsm::Event& ev) {} void react(const FatalError&); + void react(const internal::GpioInterrupt&); virtual void react(const DisplayReady&) {} virtual void react(const BootComplete&) {} diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp index c59c0908..dd5161ed 100644 --- a/src/system_fsm/system_fsm.cpp +++ b/src/system_fsm/system_fsm.cpp @@ -5,6 +5,8 @@ */ #include "system_fsm.hpp" +#include "audio_fsm.hpp" +#include "event_queue.hpp" #include "relative_wheel.hpp" #include "system_events.hpp" @@ -28,6 +30,42 @@ void SystemState::react(const FatalError& err) { } } +void SystemState::react(const internal::GpioInterrupt& ev) { + ESP_LOGI("sys", "gpios changed"); + bool prev_key_up = sGpioExpander->get_input(drivers::GpioExpander::KEY_UP); + bool prev_key_down = + sGpioExpander->get_input(drivers::GpioExpander::KEY_DOWN); + bool prev_key_lock = + sGpioExpander->get_input(drivers::GpioExpander::KEY_LOCK); + bool prev_has_headphones = + sGpioExpander->get_input(drivers::GpioExpander::PHONE_DETECT); + + sGpioExpander->Read(); + + bool key_up = sGpioExpander->get_input(drivers::GpioExpander::KEY_UP); + bool key_down = sGpioExpander->get_input(drivers::GpioExpander::KEY_DOWN); + bool key_lock = sGpioExpander->get_input(drivers::GpioExpander::KEY_LOCK); + bool has_headphones = + sGpioExpander->get_input(drivers::GpioExpander::PHONE_DETECT); + + if (key_up != prev_key_up) { + events::Dispatch<KeyUpChanged, audio::AudioState, ui::UiState>( + {.falling = prev_key_up}); + } + if (key_down != prev_key_down) { + events::Dispatch<KeyDownChanged, audio::AudioState, ui::UiState>( + {.falling = prev_key_down}); + } + if (key_lock != prev_key_lock) { + events::Dispatch<KeyLockChanged, SystemState, ui::UiState>( + {.falling = prev_key_lock}); + } + if (has_headphones != prev_has_headphones) { + events::Dispatch<HasPhonesChanged, audio::AudioState>( + {.falling = prev_has_headphones}); + } +} + } // namespace system_fsm FSM_INITIAL_STATE(system_fsm::SystemState, system_fsm::states::Booting) |
