From 6ab204216a02a61a524228d8a0d788ea71be3f91 Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:10:57 +0100 Subject: [PATCH 1/7] Remove unused imports --- firmware/simulator/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/firmware/simulator/src/lib.rs b/firmware/simulator/src/lib.rs index cfc5767..7d3415f 100644 --- a/firmware/simulator/src/lib.rs +++ b/firmware/simulator/src/lib.rs @@ -22,11 +22,10 @@ use embedded_graphics_web_simulator::{ }; use foundation::application::channels::{ButtonEvent, ButtonEventReceiver, ButtonIdentifier}; use foundation::application::state::{Application, ApplicationBuilder, Displays}; -use log::{Level, info}; +use log::info; use static_cell::StaticCell; use wasm_bindgen::JsCast; use wasm_bindgen::prelude::*; -use web_sys::js_sys::Date; use web_sys::js_sys::futures::spawn_local; use web_sys::{Document, Element, EventListener, HtmlButtonElement, Storage, window}; From 8c8a3359820cc4bb65c3efde2ec651cb896ef4b3 Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:11:27 +0100 Subject: [PATCH 2/7] Use imported name --- firmware/simulator/src/storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/simulator/src/storage.rs b/firmware/simulator/src/storage.rs index bc3c6c6..5f00643 100644 --- a/firmware/simulator/src/storage.rs +++ b/firmware/simulator/src/storage.rs @@ -212,9 +212,9 @@ impl Convertible for ButtonConfig { } } -impl Convertible for Preset { +impl Convertible for Preset { fn to(self) -> StoredPreset { - foundation::storage::state::StoredPreset { + StoredPreset { name: heapless::String::from_str(self.name.as_str()).unwrap(), buttons: heapless::Vec::from_iter( self.buttons From e697f78934cd2142f3b41f2194b81ce7b3642101 Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:16:58 +0100 Subject: [PATCH 3/7] Move time module --- firmware/firmware/src/time.rs | 2 +- firmware/foundation/src/application/mod.rs | 1 - firmware/foundation/src/application/state.rs | 2 +- firmware/foundation/src/lib.rs | 1 + firmware/foundation/src/{application => }/time.rs | 0 firmware/simulator/src/time.rs | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename firmware/foundation/src/{application => }/time.rs (100%) diff --git a/firmware/firmware/src/time.rs b/firmware/firmware/src/time.rs index c1c9444..e2bbfb9 100644 --- a/firmware/firmware/src/time.rs +++ b/firmware/firmware/src/time.rs @@ -1,4 +1,4 @@ -use foundation::application::time::TimeSource; +use foundation::time::TimeSource; #[derive(Default)] pub struct EmbassyTimeSource; diff --git a/firmware/foundation/src/application/mod.rs b/firmware/foundation/src/application/mod.rs index 43d14f6..9290e5e 100644 --- a/firmware/foundation/src/application/mod.rs +++ b/firmware/foundation/src/application/mod.rs @@ -1,3 +1,2 @@ pub mod channels; pub mod state; -pub mod time; diff --git a/firmware/foundation/src/application/state.rs b/firmware/foundation/src/application/state.rs index c4f3c28..6874a83 100644 --- a/firmware/foundation/src/application/state.rs +++ b/firmware/foundation/src/application/state.rs @@ -2,10 +2,10 @@ use crate::application::channels::{ ButtonEvent, ButtonEventReceiver, ButtonIdentifier, DisplayIdentifier, DisplayStateUpdateChannel, MidiOutChannel, StorageStateEvent, StorageStateUpdateChannel, }; -use crate::application::time::TimeSource; use crate::layout::DisplayLayout; use crate::midi::{MidiReader, MidiWriter}; use crate::storage::StorageManager; +use crate::time::TimeSource; use core::cell::RefCell; use embedded_graphics::draw_target::DrawTarget; use embedded_graphics::pixelcolor::Rgb565; diff --git a/firmware/foundation/src/lib.rs b/firmware/foundation/src/lib.rs index 6746f02..052be44 100644 --- a/firmware/foundation/src/lib.rs +++ b/firmware/foundation/src/lib.rs @@ -12,6 +12,7 @@ pub mod layout; pub mod midi; pub mod protocol; pub mod storage; +pub mod time; /// A trait for types that can be converted to and from another type `T` pub trait Convertible: Sized { diff --git a/firmware/foundation/src/application/time.rs b/firmware/foundation/src/time.rs similarity index 100% rename from firmware/foundation/src/application/time.rs rename to firmware/foundation/src/time.rs diff --git a/firmware/simulator/src/time.rs b/firmware/simulator/src/time.rs index 882a5dc..454efa1 100644 --- a/firmware/simulator/src/time.rs +++ b/firmware/simulator/src/time.rs @@ -1,4 +1,4 @@ -use foundation::application::time::TimeSource; +use foundation::time::TimeSource; use web_sys::js_sys::Date; #[derive(Default)] From 8b166d6faf27dcae7a93d4b9e4f4e29ac7cfdb01 Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:18:06 +0100 Subject: [PATCH 4/7] Move channels module --- firmware/firmware/src/main.rs | 2 +- firmware/foundation/src/application/mod.rs | 1 - firmware/foundation/src/application/state.rs | 2 +- firmware/foundation/src/{application => }/channels.rs | 0 firmware/foundation/src/lib.rs | 1 + firmware/simulator/src/lib.rs | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename firmware/foundation/src/{application => }/channels.rs (100%) diff --git a/firmware/firmware/src/main.rs b/firmware/firmware/src/main.rs index feae5da..cfeacad 100644 --- a/firmware/firmware/src/main.rs +++ b/firmware/firmware/src/main.rs @@ -46,8 +46,8 @@ use esp_hal::time::Rate; use esp_hal::timer::timg::TimerGroup; use esp_hal::uart::{Config as UartConfig, DataBits, Parity, StopBits, Uart, UartRx, UartTx}; use esp_hal::{Async, Blocking}; -use foundation::application::channels::{ButtonEvent, ButtonEventReceiver}; use foundation::application::state::{Application, ApplicationBuilder, Displays}; +use foundation::channels::{ButtonEvent, ButtonEventReceiver}; use log::info; use midi::{UartMidiReader, UartMidiWriter}; use mipidsi::models::ST7789; diff --git a/firmware/foundation/src/application/mod.rs b/firmware/foundation/src/application/mod.rs index 9290e5e..266c62a 100644 --- a/firmware/foundation/src/application/mod.rs +++ b/firmware/foundation/src/application/mod.rs @@ -1,2 +1 @@ -pub mod channels; pub mod state; diff --git a/firmware/foundation/src/application/state.rs b/firmware/foundation/src/application/state.rs index 6874a83..d9b5d45 100644 --- a/firmware/foundation/src/application/state.rs +++ b/firmware/foundation/src/application/state.rs @@ -1,4 +1,4 @@ -use crate::application::channels::{ +use crate::channels::{ ButtonEvent, ButtonEventReceiver, ButtonIdentifier, DisplayIdentifier, DisplayStateUpdateChannel, MidiOutChannel, StorageStateEvent, StorageStateUpdateChannel, }; diff --git a/firmware/foundation/src/application/channels.rs b/firmware/foundation/src/channels.rs similarity index 100% rename from firmware/foundation/src/application/channels.rs rename to firmware/foundation/src/channels.rs diff --git a/firmware/foundation/src/lib.rs b/firmware/foundation/src/lib.rs index 052be44..0a4d66b 100644 --- a/firmware/foundation/src/lib.rs +++ b/firmware/foundation/src/lib.rs @@ -8,6 +8,7 @@ mod generated { } pub mod application; +pub mod channels; pub mod layout; pub mod midi; pub mod protocol; diff --git a/firmware/simulator/src/lib.rs b/firmware/simulator/src/lib.rs index 7d3415f..529824f 100644 --- a/firmware/simulator/src/lib.rs +++ b/firmware/simulator/src/lib.rs @@ -20,8 +20,8 @@ use embedded_graphics::{ use embedded_graphics_web_simulator::{ display::WebSimulatorDisplay, output_settings::OutputSettingsBuilder, }; -use foundation::application::channels::{ButtonEvent, ButtonEventReceiver, ButtonIdentifier}; use foundation::application::state::{Application, ApplicationBuilder, Displays}; +use foundation::channels::{ButtonEvent, ButtonEventReceiver, ButtonIdentifier}; use log::info; use static_cell::StaticCell; use wasm_bindgen::JsCast; From a4e719b2dd80b57ca8e666532917ae7dfab6ab4e Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:20:04 +0100 Subject: [PATCH 5/7] Make some stuff crate-local --- firmware/foundation/src/channels.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/firmware/foundation/src/channels.rs b/firmware/foundation/src/channels.rs index 594fd49..d4ae762 100644 --- a/firmware/foundation/src/channels.rs +++ b/firmware/foundation/src/channels.rs @@ -50,16 +50,16 @@ impl AppChannel { } } -pub type MidiOutChannel = AppChannel; +pub(crate) type MidiOutChannel = AppChannel; -pub enum DisplayIdentifier { +pub(crate) enum DisplayIdentifier { Display1, Display2, Display3, Display4, } -pub struct DisplayStateUpdateMessage { +pub(crate) struct DisplayStateUpdateMessage { pub(crate) display_identifier: DisplayIdentifier, pub(crate) top_row_text: DisplayText, pub(crate) top_row_color: Colour, @@ -67,7 +67,7 @@ pub struct DisplayStateUpdateMessage { pub(crate) bottom_row_color: Colour, } -pub type DisplayStateUpdateChannel = AppChannel; +pub(crate) type DisplayStateUpdateChannel = AppChannel; #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum ButtonIdentifier { @@ -88,9 +88,9 @@ pub enum ButtonEvent { } #[cfg(target_arch = "wasm32")] -type Receiver<'a, T, const N: usize> = async_channel::Receiver; +pub type Receiver<'a, T, const N: usize> = async_channel::Receiver; #[cfg(not(target_arch = "wasm32"))] -type Receiver<'a, T, const N: usize> = embassy_sync::channel::Receiver< +pub type Receiver<'a, T, const N: usize> = embassy_sync::channel::Receiver< 'a, embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex, T, From f41ef8644b6778e004375e7d4fd7d2b2d839e036 Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:22:13 +0100 Subject: [PATCH 6/7] Move application module up --- firmware/firmware/src/main.rs | 2 +- .../foundation/src/{application/state.rs => application.rs} | 0 firmware/foundation/src/application/mod.rs | 1 - firmware/simulator/src/lib.rs | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) rename firmware/foundation/src/{application/state.rs => application.rs} (100%) delete mode 100644 firmware/foundation/src/application/mod.rs diff --git a/firmware/firmware/src/main.rs b/firmware/firmware/src/main.rs index cfeacad..47607b8 100644 --- a/firmware/firmware/src/main.rs +++ b/firmware/firmware/src/main.rs @@ -46,7 +46,7 @@ use esp_hal::time::Rate; use esp_hal::timer::timg::TimerGroup; use esp_hal::uart::{Config as UartConfig, DataBits, Parity, StopBits, Uart, UartRx, UartTx}; use esp_hal::{Async, Blocking}; -use foundation::application::state::{Application, ApplicationBuilder, Displays}; +use foundation::application::{Application, ApplicationBuilder, Displays}; use foundation::channels::{ButtonEvent, ButtonEventReceiver}; use log::info; use midi::{UartMidiReader, UartMidiWriter}; diff --git a/firmware/foundation/src/application/state.rs b/firmware/foundation/src/application.rs similarity index 100% rename from firmware/foundation/src/application/state.rs rename to firmware/foundation/src/application.rs diff --git a/firmware/foundation/src/application/mod.rs b/firmware/foundation/src/application/mod.rs deleted file mode 100644 index 266c62a..0000000 --- a/firmware/foundation/src/application/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod state; diff --git a/firmware/simulator/src/lib.rs b/firmware/simulator/src/lib.rs index 529824f..c007e12 100644 --- a/firmware/simulator/src/lib.rs +++ b/firmware/simulator/src/lib.rs @@ -20,7 +20,7 @@ use embedded_graphics::{ use embedded_graphics_web_simulator::{ display::WebSimulatorDisplay, output_settings::OutputSettingsBuilder, }; -use foundation::application::state::{Application, ApplicationBuilder, Displays}; +use foundation::application::{Application, ApplicationBuilder, Displays}; use foundation::channels::{ButtonEvent, ButtonEventReceiver, ButtonIdentifier}; use log::info; use static_cell::StaticCell; From 810e55c70d40c9c07db77da60f644a6ae62582aa Mon Sep 17 00:00:00 2001 From: issy Date: Fri, 1 May 2026 13:23:41 +0100 Subject: [PATCH 7/7] Move storage module up --- firmware/firmware/src/storage.rs | 5 +- .../src/{storage/state.rs => storage.rs} | 18 +++++++ firmware/foundation/src/storage/mod.rs | 22 --------- firmware/simulator/src/storage.rs | 49 ++++++++++--------- 4 files changed, 46 insertions(+), 48 deletions(-) rename firmware/foundation/src/{storage/state.rs => storage.rs} (84%) delete mode 100644 firmware/foundation/src/storage/mod.rs diff --git a/firmware/firmware/src/storage.rs b/firmware/firmware/src/storage.rs index 917aca1..1f07299 100644 --- a/firmware/firmware/src/storage.rs +++ b/firmware/firmware/src/storage.rs @@ -1,5 +1,6 @@ -use foundation::storage::state::Presets; -use foundation::storage::{StorageManager, StorageManagerLoadError, StorageManagerSaveError}; +use foundation::storage::{ + Presets, StorageManager, StorageManagerLoadError, StorageManagerSaveError, +}; #[derive(Default)] pub struct FakeStorageManager; diff --git a/firmware/foundation/src/storage/state.rs b/firmware/foundation/src/storage.rs similarity index 84% rename from firmware/foundation/src/storage/state.rs rename to firmware/foundation/src/storage.rs index 7d332a9..396b7a8 100644 --- a/firmware/foundation/src/storage/state.rs +++ b/firmware/foundation/src/storage.rs @@ -3,6 +3,24 @@ use crate::protocol::Colour; use heapless::{String, Vec}; use serde::{Deserialize, Serialize}; +#[derive(Debug)] +pub enum StorageManagerLoadError { + ErrorReadingFromStorage, + NoValueStored, + ErrorDeserializingData, +} + +#[derive(Debug)] +pub enum StorageManagerSaveError { + ErrorDeserializingData, + ErrorWritingToStorage, +} + +pub trait StorageManager { + fn load_presets(&self) -> Result; + fn save_presets(&mut self, presets: &Presets) -> Result<(), StorageManagerSaveError>; +} + pub const MAX_PRESETS: usize = 128; pub const MAX_STRING_LENGTH: usize = 16; pub const NUM_OF_BUTTONS: usize = 8; diff --git a/firmware/foundation/src/storage/mod.rs b/firmware/foundation/src/storage/mod.rs deleted file mode 100644 index 99e005c..0000000 --- a/firmware/foundation/src/storage/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use crate::storage::state::Presets; -use core::fmt::Debug; - -pub mod state; - -#[derive(Debug)] -pub enum StorageManagerLoadError { - ErrorReadingFromStorage, - NoValueStored, - ErrorDeserializingData, -} - -#[derive(Debug)] -pub enum StorageManagerSaveError { - ErrorDeserializingData, - ErrorWritingToStorage, -} - -pub trait StorageManager { - fn load_presets(&self) -> Result; - fn save_presets(&mut self, presets: &Presets) -> Result<(), StorageManagerSaveError>; -} diff --git a/firmware/simulator/src/storage.rs b/firmware/simulator/src/storage.rs index 5f00643..b7a292c 100644 --- a/firmware/simulator/src/storage.rs +++ b/firmware/simulator/src/storage.rs @@ -1,6 +1,7 @@ use foundation::Convertible; -use foundation::storage::state::{Presets, StoredPreset}; -use foundation::storage::{StorageManager, StorageManagerLoadError, StorageManagerSaveError}; +use foundation::storage::{ + Presets, StorageManager, StorageManagerLoadError, StorageManagerSaveError, StoredPreset, +}; use serde::{Deserialize, Serialize}; use std::str::FromStr; use std::vec::Vec; @@ -62,18 +63,18 @@ pub struct Preset { buttons: Vec, } -impl Convertible for ButtonType { - fn to(self) -> foundation::storage::state::ButtonType { +impl Convertible for ButtonType { + fn to(self) -> foundation::storage::ButtonType { match self { - ButtonType::Momentary => foundation::storage::state::ButtonType::Momentary, - ButtonType::Toggle => foundation::storage::state::ButtonType::Toggle, + ButtonType::Momentary => foundation::storage::ButtonType::Momentary, + ButtonType::Toggle => foundation::storage::ButtonType::Toggle, } } - fn from(value: foundation::storage::state::ButtonType) -> Self { + fn from(value: foundation::storage::ButtonType) -> Self { match value { - foundation::storage::state::ButtonType::Momentary => ButtonType::Momentary, - foundation::storage::state::ButtonType::Toggle => ButtonType::Toggle, + foundation::storage::ButtonType::Momentary => ButtonType::Momentary, + foundation::storage::ButtonType::Toggle => ButtonType::Toggle, } } } @@ -106,17 +107,17 @@ impl Convertible for Colour { } } -impl Convertible for MidiCommand { - fn to(self) -> foundation::storage::state::MidiCommand { +impl Convertible for MidiCommand { + fn to(self) -> foundation::storage::MidiCommand { match self { MidiCommand::ProgramChange { channel, program } => { - foundation::storage::state::MidiCommand::ProgramChange { channel, program } + foundation::storage::MidiCommand::ProgramChange { channel, program } } MidiCommand::ControllerChange { channel, controller, value, - } => foundation::storage::state::MidiCommand::ControllerChange { + } => foundation::storage::MidiCommand::ControllerChange { channel, controller, value, @@ -125,7 +126,7 @@ impl Convertible for MidiCommand { channel, note, velocity, - } => foundation::storage::state::MidiCommand::NoteOn { + } => foundation::storage::MidiCommand::NoteOn { channel, note, velocity, @@ -134,7 +135,7 @@ impl Convertible for MidiCommand { channel, note, velocity, - } => foundation::storage::state::MidiCommand::NoteOff { + } => foundation::storage::MidiCommand::NoteOff { channel, note, velocity, @@ -142,12 +143,12 @@ impl Convertible for MidiCommand { } } - fn from(value: foundation::storage::state::MidiCommand) -> Self { + fn from(value: foundation::storage::MidiCommand) -> Self { match value { - foundation::storage::state::MidiCommand::ProgramChange { channel, program } => { + foundation::storage::MidiCommand::ProgramChange { channel, program } => { MidiCommand::ProgramChange { channel, program } } - foundation::storage::state::MidiCommand::ControllerChange { + foundation::storage::MidiCommand::ControllerChange { channel, controller, value, @@ -156,7 +157,7 @@ impl Convertible for MidiCommand { controller, value, }, - foundation::storage::state::MidiCommand::NoteOn { + foundation::storage::MidiCommand::NoteOn { channel, note, velocity, @@ -165,7 +166,7 @@ impl Convertible for MidiCommand { note, velocity, }, - foundation::storage::state::MidiCommand::NoteOff { + foundation::storage::MidiCommand::NoteOff { channel, note, velocity, @@ -178,9 +179,9 @@ impl Convertible for MidiCommand { } } -impl Convertible for ButtonConfig { - fn to(self) -> foundation::storage::state::ButtonConfig { - foundation::storage::state::ButtonConfig { +impl Convertible for ButtonConfig { + fn to(self) -> foundation::storage::ButtonConfig { + foundation::storage::ButtonConfig { name: heapless::String::from_str(self.name.as_str()).unwrap(), button_type: self.button_type.to(), colour: self.colour.to(), @@ -193,7 +194,7 @@ impl Convertible for ButtonConfig { } } - fn from(value: foundation::storage::state::ButtonConfig) -> Self { + fn from(value: foundation::storage::ButtonConfig) -> Self { ButtonConfig { name: value.name.to_string(), button_type: Convertible::from(value.button_type),