Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions firmware/firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions firmware/firmware/src/storage.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion firmware/firmware/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use foundation::application::time::TimeSource;
use foundation::time::TimeSource;

#[derive(Default)]
pub struct EmbassyTimeSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions firmware/foundation/src/application/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ impl<T, const N: usize> AppChannel<T, N> {
}
}

pub type MidiOutChannel = AppChannel<MidiPacket, 128>;
pub(crate) type MidiOutChannel = AppChannel<MidiPacket, 128>;

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,
pub(crate) bottom_row_text: DisplayText,
pub(crate) bottom_row_color: Colour,
}

pub type DisplayStateUpdateChannel = AppChannel<DisplayStateUpdateMessage, 16>;
pub(crate) type DisplayStateUpdateChannel = AppChannel<DisplayStateUpdateMessage, 16>;

#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum ButtonIdentifier {
Expand All @@ -88,9 +88,9 @@ pub enum ButtonEvent {
}

#[cfg(target_arch = "wasm32")]
type Receiver<'a, T, const N: usize> = async_channel::Receiver<T>;
pub type Receiver<'a, T, const N: usize> = async_channel::Receiver<T>;
#[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,
Expand Down
2 changes: 2 additions & 0 deletions firmware/foundation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: Sized {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Presets, StorageManagerLoadError>;
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;
Expand Down
22 changes: 0 additions & 22 deletions firmware/foundation/src/storage/mod.rs

This file was deleted.

7 changes: 3 additions & 4 deletions firmware/simulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
53 changes: 27 additions & 26 deletions firmware/simulator/src/storage.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -62,18 +63,18 @@ pub struct Preset {
buttons: Vec<ButtonConfig>,
}

impl Convertible<foundation::storage::state::ButtonType> for ButtonType {
fn to(self) -> foundation::storage::state::ButtonType {
impl Convertible<foundation::storage::ButtonType> 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,
}
}
}
Expand Down Expand Up @@ -106,17 +107,17 @@ impl Convertible<foundation::protocol::Colour> for Colour {
}
}

impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
fn to(self) -> foundation::storage::state::MidiCommand {
impl Convertible<foundation::storage::MidiCommand> 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,
Expand All @@ -125,7 +126,7 @@ impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
channel,
note,
velocity,
} => foundation::storage::state::MidiCommand::NoteOn {
} => foundation::storage::MidiCommand::NoteOn {
channel,
note,
velocity,
Expand All @@ -134,20 +135,20 @@ impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
channel,
note,
velocity,
} => foundation::storage::state::MidiCommand::NoteOff {
} => foundation::storage::MidiCommand::NoteOff {
channel,
note,
velocity,
},
}
}

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,
Expand All @@ -156,7 +157,7 @@ impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
controller,
value,
},
foundation::storage::state::MidiCommand::NoteOn {
foundation::storage::MidiCommand::NoteOn {
channel,
note,
velocity,
Expand All @@ -165,7 +166,7 @@ impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
note,
velocity,
},
foundation::storage::state::MidiCommand::NoteOff {
foundation::storage::MidiCommand::NoteOff {
channel,
note,
velocity,
Expand All @@ -178,9 +179,9 @@ impl Convertible<foundation::storage::state::MidiCommand> for MidiCommand {
}
}

impl Convertible<foundation::storage::state::ButtonConfig> for ButtonConfig {
fn to(self) -> foundation::storage::state::ButtonConfig {
foundation::storage::state::ButtonConfig {
impl Convertible<foundation::storage::ButtonConfig> 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(),
Expand All @@ -193,7 +194,7 @@ impl Convertible<foundation::storage::state::ButtonConfig> 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),
Expand All @@ -212,9 +213,9 @@ impl Convertible<foundation::storage::state::ButtonConfig> for ButtonConfig {
}
}

impl Convertible<foundation::storage::state::StoredPreset> for Preset {
impl Convertible<StoredPreset> 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
Expand Down
2 changes: 1 addition & 1 deletion firmware/simulator/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use foundation::application::time::TimeSource;
use foundation::time::TimeSource;
use web_sys::js_sys::Date;

#[derive(Default)]
Expand Down
Loading