diff --git a/firmware/firmware/src/main.rs b/firmware/firmware/src/main.rs index feae5da..47607b8 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::application::{Application, ApplicationBuilder, Displays}; +use foundation::channels::{ButtonEvent, ButtonEventReceiver}; use log::info; use midi::{UartMidiReader, UartMidiWriter}; use mipidsi::models::ST7789; 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/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/state.rs b/firmware/foundation/src/application.rs similarity index 99% rename from firmware/foundation/src/application/state.rs rename to firmware/foundation/src/application.rs index c4f3c28..d9b5d45 100644 --- a/firmware/foundation/src/application/state.rs +++ b/firmware/foundation/src/application.rs @@ -1,11 +1,11 @@ -use crate::application::channels::{ +use crate::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/application/mod.rs b/firmware/foundation/src/application/mod.rs deleted file mode 100644 index 43d14f6..0000000 --- a/firmware/foundation/src/application/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod channels; -pub mod state; -pub mod time; diff --git a/firmware/foundation/src/application/channels.rs b/firmware/foundation/src/channels.rs similarity index 89% rename from firmware/foundation/src/application/channels.rs rename to firmware/foundation/src/channels.rs index 594fd49..d4ae762 100644 --- a/firmware/foundation/src/application/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, diff --git a/firmware/foundation/src/lib.rs b/firmware/foundation/src/lib.rs index 6746f02..0a4d66b 100644 --- a/firmware/foundation/src/lib.rs +++ b/firmware/foundation/src/lib.rs @@ -8,10 +8,12 @@ mod generated { } pub mod application; +pub mod channels; 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/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/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/lib.rs b/firmware/simulator/src/lib.rs index cfc5767..c007e12 100644 --- a/firmware/simulator/src/lib.rs +++ b/firmware/simulator/src/lib.rs @@ -20,13 +20,12 @@ 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 log::{Level, info}; +use foundation::application::{Application, ApplicationBuilder, Displays}; +use foundation::channels::{ButtonEvent, ButtonEventReceiver, ButtonIdentifier}; +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}; diff --git a/firmware/simulator/src/storage.rs b/firmware/simulator/src/storage.rs index bc3c6c6..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), @@ -212,9 +213,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 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)]