From 2eb3fd53d7bf32cffb1569d6b2b0c1fbc5b9ed2c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 13 Mar 2024 17:07:03 +1100 Subject: Update the battery status when plugging/unplugging --- src/system_fsm/include/system_events.hpp | 1 - src/system_fsm/system_fsm.cpp | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/include/system_events.hpp b/src/system_fsm/include/system_events.hpp index 32394958..1be03f82 100644 --- a/src/system_fsm/include/system_events.hpp +++ b/src/system_fsm/include/system_events.hpp @@ -57,7 +57,6 @@ struct SamdUsbMscChanged : tinyfsm::Event { bool en; }; -struct ChargingStatusChanged : tinyfsm::Event {}; struct BatteryStateChanged : tinyfsm::Event { battery::Battery::BatteryState new_state; }; diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp index 977f4a6d..5a1ccf8c 100644 --- a/src/system_fsm/system_fsm.cpp +++ b/src/system_fsm/system_fsm.cpp @@ -84,10 +84,8 @@ void SystemState::react(const internal::SamdInterrupt&) { auto charge_status = samd.GetChargeStatus(); auto usb_status = samd.GetUsbStatus(); - if (charge_status != prev_charge_status) { - ChargingStatusChanged ev{}; - events::System().Dispatch(ev); - events::Ui().Dispatch(ev); + if (charge_status != prev_charge_status && sServices) { + sServices->battery().Update(); } if (usb_status != prev_usb_status) { ESP_LOGI(kTag, "usb status changed"); -- cgit v1.2.3 From 4cd3c187f92d8f5b73c2c985da308280c18465cf Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 20 Mar 2024 11:08:35 +1100 Subject: Add exact display size to nvs, since it can vary --- src/system_fsm/booting.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 41f46df2..14fed92e 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -62,8 +62,12 @@ auto Booting::entry() -> void { ESP_ERROR_CHECK(drivers::init_spi()); sServices->gpios(std::unique_ptr(drivers::Gpios::Create())); + // NVS is needed early so that we can correctly initialise the display. + sServices->nvs( + std::unique_ptr(drivers::NvsStorage::OpenSync())); + ESP_LOGI(kTag, "starting ui"); - if (!ui::UiState::InitBootSplash(sServices->gpios())) { + if (!ui::UiState::InitBootSplash(sServices->gpios(), sServices->nvs())) { events::System().Dispatch(FatalError{}); return; } @@ -74,8 +78,6 @@ auto Booting::entry() -> void { ESP_LOGI(kTag, "installing remaining drivers"); drivers::spiffs_mount(); sServices->samd(std::unique_ptr(drivers::Samd::Create())); - sServices->nvs( - std::unique_ptr(drivers::NvsStorage::OpenSync())); sServices->touchwheel( std::unique_ptr{drivers::TouchWheel::Create()}); sServices->haptics(std::make_unique()); -- cgit v1.2.3 From 46e67437717975c10c62775a3f40bec84ac4f44c Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 20 Mar 2024 11:15:33 +1100 Subject: version bump, plus prep for lock switch hack --- src/system_fsm/booting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 14fed92e..e911932c 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -102,7 +102,7 @@ auto Booting::entry() -> void { sServices->bluetooth().Enable(); } - sServices->nvs().LockPolarity(true); + sServices->nvs().LockPolarity(false); BootComplete ev{.services = sServices}; events::Audio().Dispatch(ev); -- cgit v1.2.3 From a05d93a1e26181237a76da5ce398c6b08497d591 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 20 Mar 2024 11:43:33 +1100 Subject: Start using the lock switch polarity bit in nvs --- src/system_fsm/booting.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index e911932c..eb931192 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -57,14 +57,19 @@ auto Booting::entry() -> void { sServices.reset(new ServiceLocator()); ESP_LOGI(kTag, "installing early drivers"); + // NVS is needed first because it contains information about what specific + // hardware configuration we're running on. + sServices->nvs( + std::unique_ptr(drivers::NvsStorage::OpenSync())); + + // HACK: fix up the switch polarity on newer dev units + sServices->nvs().LockPolarity(false); + // I2C and SPI are both always needed. We can't even power down or show an // error without these. ESP_ERROR_CHECK(drivers::init_spi()); - sServices->gpios(std::unique_ptr(drivers::Gpios::Create())); - - // NVS is needed early so that we can correctly initialise the display. - sServices->nvs( - std::unique_ptr(drivers::NvsStorage::OpenSync())); + sServices->gpios(std::unique_ptr( + drivers::Gpios::Create(sServices->nvs().LockPolarity()))); ESP_LOGI(kTag, "starting ui"); if (!ui::UiState::InitBootSplash(sServices->gpios(), sServices->nvs())) { @@ -102,8 +107,6 @@ auto Booting::entry() -> void { sServices->bluetooth().Enable(); } - sServices->nvs().LockPolarity(false); - BootComplete ev{.services = sServices}; events::Audio().Dispatch(ev); events::Ui().Dispatch(ev); -- cgit v1.2.3 From 21ae6a962623c9128fbb4a599cc50a2c616e9884 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 21 Mar 2024 09:15:44 +1100 Subject: comment out dev unit hack the nano code bug has received the hack, so now we don't need it applying by default anymore --- src/system_fsm/booting.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index eb931192..bd394428 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -63,7 +63,7 @@ auto Booting::entry() -> void { std::unique_ptr(drivers::NvsStorage::OpenSync())); // HACK: fix up the switch polarity on newer dev units - sServices->nvs().LockPolarity(false); + // sServices->nvs().LockPolarity(false); // I2C and SPI are both always needed. We can't even power down or show an // error without these. -- cgit v1.2.3 From dadac304dd930ddf4c5aebcc069c5d9f881b2b60 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 21 Mar 2024 11:51:48 +1100 Subject: Add very basic usb msc ui --- src/system_fsm/idle.cpp | 10 +++++++++- src/system_fsm/running.cpp | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/idle.cpp b/src/system_fsm/idle.cpp index b6bb2572..980f0c94 100644 --- a/src/system_fsm/idle.cpp +++ b/src/system_fsm/idle.cpp @@ -13,6 +13,7 @@ #include "audio_fsm.hpp" #include "event_queue.hpp" +#include "samd.hpp" #include "storage.hpp" #include "system_events.hpp" #include "system_fsm.hpp" @@ -40,7 +41,7 @@ void Idle::entry() { events::Audio().Dispatch(OnIdle{}); events::Ui().Dispatch(OnIdle{}); - sIdleTimeout = xTimerCreate("idle_timeout", kTicksBeforeSleep, false, NULL, + sIdleTimeout = xTimerCreate("idle_timeout", kTicksBeforeSleep, true, NULL, timer_callback); xTimerStart(sIdleTimeout, portMAX_DELAY); } @@ -63,6 +64,13 @@ void Idle::react(const internal::IdleTimeout& ev) { transit(); return; } + auto s = static_cast(sServices->samd().GetUsbStatus()); + ESP_LOGI(kTag, "usb status is %i", s); + if (sServices->samd().GetUsbStatus() != drivers::Samd::UsbStatus::kDetached) { + // Stay powered on if we're plugged in, in order to charge faster, sync + // files, flash updates, etc. + return; + } ESP_LOGI(kTag, "system shutting down"); // FIXME: It would be neater to just free a bunch of our pointers, deinit the diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index d1d02fab..d80809e6 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -41,7 +41,11 @@ void Running::entry() { sUnmountTimer = xTimerCreate("unmount_timeout", kTicksBeforeUnmount, false, NULL, timer_callback); } - mountStorage(); + // Only mount our storage immediately if we know it's not currently in use + // by the SAMD. + if (!sServices->samd().UsbMassStorage()) { + mountStorage(); + } } void Running::exit() { -- cgit v1.2.3 From d11eea7e0b93178824e804b5fd152e7793c4c277 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 21 Mar 2024 13:32:45 +1100 Subject: use charge status for staying on, not usb status usb status doesnt seem to be updating properly yet --- src/system_fsm/idle.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/idle.cpp b/src/system_fsm/idle.cpp index 980f0c94..e28864b3 100644 --- a/src/system_fsm/idle.cpp +++ b/src/system_fsm/idle.cpp @@ -64,9 +64,8 @@ void Idle::react(const internal::IdleTimeout& ev) { transit(); return; } - auto s = static_cast(sServices->samd().GetUsbStatus()); - ESP_LOGI(kTag, "usb status is %i", s); - if (sServices->samd().GetUsbStatus() != drivers::Samd::UsbStatus::kDetached) { + if (sServices->samd().GetChargeStatus() != + drivers::Samd::ChargeStatus::kDischarging) { // Stay powered on if we're plugged in, in order to charge faster, sync // files, flash updates, etc. return; -- cgit v1.2.3 From 175bfc4e3e9f7aa39e084d3f1625347f1d5711ec Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 25 Mar 2024 17:34:41 +1100 Subject: WIP rewrie audio pipeline+fsm guts for more reliability --- src/system_fsm/include/system_fsm.hpp | 4 ++-- src/system_fsm/running.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/system_fsm') diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp index cc60e43b..a129829e 100644 --- a/src/system_fsm/include/system_fsm.hpp +++ b/src/system_fsm/include/system_fsm.hpp @@ -63,7 +63,7 @@ class SystemState : public tinyfsm::Fsm { virtual void react(const SdDetectChanged&) {} virtual void react(const SamdUsbMscChanged&) {} virtual void react(const database::event::UpdateFinished&) {} - virtual void react(const audio::PlaybackStopped&) {} + virtual void react(const audio::PlaybackUpdate&) {} virtual void react(const internal::IdleTimeout&) {} virtual void react(const internal::UnmountTimeout&) {} @@ -101,7 +101,7 @@ class Running : public SystemState { void react(const KeyLockChanged&) override; void react(const SdDetectChanged&) override; - void react(const audio::PlaybackStopped&) override; + void react(const audio::PlaybackUpdate&) override; void react(const database::event::UpdateFinished&) override; void react(const SamdUsbMscChanged&) override; void react(const internal::UnmountTimeout&) override; diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index d80809e6..a6ab5d47 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -56,7 +56,7 @@ void Running::react(const KeyLockChanged& ev) { checkIdle(); } -void Running::react(const audio::PlaybackStopped& ev) { +void Running::react(const audio::PlaybackUpdate& ev) { checkIdle(); } -- cgit v1.2.3