summaryrefslogtreecommitdiff
path: root/src/system_fsm
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-11-24 07:18:14 +1100
committerjacqueline <me@jacqueline.id.au>2023-11-24 07:41:48 +1100
commit230721cd6271f3239b42e1d2471f8db15bebd712 (patch)
treecc27ec975261742dca8c9acf87b806f5933faae8 /src/system_fsm
parent2b095948b81cbde28ac84e7a572d472301a50af1 (diff)
downloadtangara-fw-230721cd6271f3239b42e1d2471f8db15bebd712.tar.gz
Periodically check int lines instead of relying on interrupts
Diffstat (limited to 'src/system_fsm')
-rw-r--r--src/system_fsm/booting.cpp6
-rw-r--r--src/system_fsm/include/system_fsm.hpp2
-rw-r--r--src/system_fsm/system_fsm.cpp10
3 files changed, 18 insertions, 0 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp
index e7080e9b..c9a0a2d2 100644
--- a/src/system_fsm/booting.cpp
+++ b/src/system_fsm/booting.cpp
@@ -51,6 +51,8 @@ static auto bt_event_cb(drivers::bluetooth::Event ev) -> void {
}
}
+static const TickType_t kInterruptCheckPeriod = pdMS_TO_TICKS(100);
+
auto Booting::entry() -> void {
ESP_LOGI(kTag, "beginning tangara boot");
sServices.reset(new ServiceLocator());
@@ -109,6 +111,10 @@ auto Booting::exit() -> void {
sAppConsole = new console::AppConsole();
sAppConsole->sServices = sServices;
sAppConsole->Launch();
+
+ TimerHandle_t timer = xTimerCreate("INTERRUPTS", kInterruptCheckPeriod, true,
+ NULL, check_interrupts_cb);
+ xTimerStart(timer, portMAX_DELAY);
}
auto Booting::react(const BootComplete& ev) -> void {
diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp
index c9803bef..cb733639 100644
--- a/src/system_fsm/include/system_fsm.hpp
+++ b/src/system_fsm/include/system_fsm.hpp
@@ -32,6 +32,8 @@
namespace system_fsm {
+void check_interrupts_cb(TimerHandle_t timer);
+
/*
* State machine for the overall system state. Responsible for managing
* peripherals, and bringing the rest of the system up and down.
diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp
index ca191324..9cca7eda 100644
--- a/src/system_fsm/system_fsm.cpp
+++ b/src/system_fsm/system_fsm.cpp
@@ -6,6 +6,7 @@
#include "system_fsm.hpp"
#include "audio_fsm.hpp"
+#include "driver/gpio.h"
#include "event_queue.hpp"
#include "gpios.hpp"
#include "relative_wheel.hpp"
@@ -23,6 +24,15 @@ std::unique_ptr<drivers::SdStorage> SystemState::sStorage;
console::AppConsole* SystemState::sAppConsole;
+void check_interrupts_cb(TimerHandle_t timer) {
+ if (!gpio_get_level(GPIO_NUM_34)) {
+ events::System().Dispatch(internal::GpioInterrupt{});
+ }
+ if (!gpio_get_level(GPIO_NUM_35)) {
+ events::System().Dispatch(internal::SamdInterrupt{});
+ }
+}
+
void SystemState::react(const FatalError& err) {
if (!is_in_state<states::Error>()) {
transit<states::Error>();