From 889da2e62ced19c0e7745206e0388f8a81c35785 Mon Sep 17 00:00:00 2001 From: ede1998 Date: Sun, 23 Aug 2026 10:54:21 +0200 Subject: [PATCH] prepare Outputs type --- src/bin/main.rs | 44 +++++++++++++++++++++--------------- src/card/model.rs | 12 +++++----- src/display/tertiary_lcd.rs | 2 ++ src/navigation.rs | 1 + src/navigation/navigation.rs | 9 ++++---- src/navigation/outputs.rs | 12 ++++++++++ src/navigation/state.rs | 6 ++--- src/views/menu_item.rs | 2 +- 8 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 src/navigation/outputs.rs diff --git a/src/bin/main.rs b/src/bin/main.rs index fa8a950..80f4141 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -11,10 +11,11 @@ use alloc::boxed::Box; use creaturedex::card::decoder::split_nfc_hex; use creaturedex::card::model::Card; use creaturedex::display::shared_bus::{DualSecondaryDisplay, init_dual_displays}; -use creaturedex::display::tertiary_lcd::{init_tertiary_lcd, write_wrapped}; +use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, init_tertiary_lcd, write_wrapped}; use creaturedex::drivers::nfc_pn532::NfcPn532Driver; use creaturedex::navigation::inputs::Inputs; use creaturedex::navigation::navigation::{self, CARD_DATA}; +use creaturedex::navigation::outputs::Outputs; use creaturedex::network::wifi::setup_wifi; use embassy_executor::Spawner; use embassy_time::Instant; @@ -65,7 +66,7 @@ async fn main(spawner: Spawner) { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0); - let (display, oled) = Box::leak(Box::new(init_dual_displays( + let (display, mut oled) = init_dual_displays( peripherals.SPI2, peripherals.GPIO36, // sck peripherals.GPIO35, // mosi @@ -75,18 +76,12 @@ async fn main(spawner: Spawner) { peripherals.GPIO10, // primary reset peripherals.GPIO47, // secondary reset peripherals.GPIO12, // shared dc - ))); + ); - let _secondary_oled_cs_2 = Output::new( - peripherals.GPIO14, - Level::High, - OutputConfig::default(), - ); - let _secondary_oled_cs_3 = Output::new( - peripherals.GPIO21, - Level::High, - OutputConfig::default(), - ); + let _secondary_oled_cs_2 = + Output::new(peripherals.GPIO14, Level::High, OutputConfig::default()); + let _secondary_oled_cs_3 = + Output::new(peripherals.GPIO21, Level::High, OutputConfig::default()); let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(400)); let i2c = match I2c::new(peripherals.I2C0, config) { @@ -101,10 +96,10 @@ async fn main(spawner: Spawner) { let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c))); log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)"); - let mut lcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c)); - if let Err(_) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") { + let mut lcd: TertiaryI2cLcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c)); + if let Err(e) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") { log::error!( - "Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses" + "Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses: {e}" ); } @@ -127,14 +122,27 @@ async fn main(spawner: Spawner) { ok: Input::new(peripherals.GPIO0, button_config), }; - display_shit(oled); + display_shit(&mut oled); + + let outputs = Outputs { + primary_display: display, + secondary_display_1: oled, + // secondary_display_2: todo!(), + // secondary_display_3: todo!(), + tertiary_display: lcd, + _led_a: (), + }; log::info!("Setup complete, entering main loop"); - spawner.spawn(navigation::run(inputs, display).expect("run task failed")); + spawner.spawn(navigation::run(inputs, outputs).expect("run task failed")); spawner.spawn(nfc_driver_task(nfc_driver).expect("nfc driver task failed")); } #[embassy_executor::task] +#[allow( + clippy::large_stack_frames, + reason = "ignoring this for now because it still works" +)] async fn nfc_driver_task( mut nfc_driver: NfcPn532Driver>>, ) { diff --git a/src/card/model.rs b/src/card/model.rs index 5747671..bb2ee96 100644 --- a/src/card/model.rs +++ b/src/card/model.rs @@ -48,9 +48,9 @@ impl Display for CardType { } pub type PrimaryColor = Rgb565; -impl Into for CardType { - fn into(self) -> PrimaryColor { - match self { +impl From for PrimaryColor { + fn from(val: CardType) -> Self { + match val { CardType::Default => Rgb888::new(0xD8, 0x68, 0x30).into(), CardType::Blueprint => Rgb888::new(0x6D, 0x81, 0xFF).into(), CardType::CYBER => Rgb888::new(0xFF, 0xFF, 0x04).into(), @@ -64,9 +64,9 @@ impl Into for CardType { } pub type Palette = [Rgb565; 16]; -impl Into for CardType { - fn into(self) -> Palette { - match self { +impl From for Palette { + fn from(val: CardType) -> Self { + match val { CardType::Default => [ Rgb888::new(31, 23, 35).into(), Rgb888::new(60, 47, 82).into(), diff --git a/src/display/tertiary_lcd.rs b/src/display/tertiary_lcd.rs index e066344..d3f10dc 100644 --- a/src/display/tertiary_lcd.rs +++ b/src/display/tertiary_lcd.rs @@ -1,9 +1,11 @@ use embedded_hal::i2c::I2c; +use embedded_hal_bus::i2c::AtomicDevice; use esp_hal::delay::Delay; use i2c_character_display::{CharacterDisplayPCF8574T, LcdDisplayType}; use log::error; pub type TertiaryLcd = CharacterDisplayPCF8574T; +pub type TertiaryI2cLcd<'a> = TertiaryLcd>>; pub fn init_tertiary_lcd(i2c: I2C) -> TertiaryLcd where diff --git a/src/navigation.rs b/src/navigation.rs index 6bee9cb..cbefd23 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -1,3 +1,4 @@ pub mod inputs; pub mod navigation; pub mod state; +pub mod outputs; diff --git a/src/navigation/navigation.rs b/src/navigation/navigation.rs index dd8fc34..d726cf2 100644 --- a/src/navigation/navigation.rs +++ b/src/navigation/navigation.rs @@ -1,7 +1,7 @@ use crate::card::model::Card; -use crate::display::shared_bus::DualPrimaryDisplay; use crate::navigation::inputs::ButtonAction; use crate::navigation::inputs::Inputs; +use crate::navigation::outputs::Outputs; use crate::navigation::state::NavigationState; use crate::views::view::View; @@ -33,15 +33,16 @@ pub trait Navigable { where D: DrawTarget + Send, D::Error: core::fmt::Debug; + // fn display(&self, outputs: &mut Outputs) -> impl core::future::Future + Send; fn handle_input(&self, input: Action) -> impl core::future::Future + Send; } #[embassy_executor::task] -pub async fn run(mut inputs: Inputs, display: &'static mut DualPrimaryDisplay<'static>) { +pub async fn run(mut inputs: Inputs, mut outputs: Outputs) { log::info!("starting navigation"); let mut state = NavigationState::new(); - state.screens.last().unwrap().display(display).await; + state.screens.last().unwrap().display(&mut outputs.primary_display).await; loop { let selection = select( @@ -87,7 +88,7 @@ pub async fn run(mut inputs: Inputs, display: &'static mut DualPrimaryDisplay<'s state.screens.push(new_state.view); if action != Action::Timer || new_state.redraw { - state.screens.last().unwrap().display(display).await; + state.screens.last().unwrap().display(&mut outputs.primary_display).await; } Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await; diff --git a/src/navigation/outputs.rs b/src/navigation/outputs.rs new file mode 100644 index 0000000..9a1683a --- /dev/null +++ b/src/navigation/outputs.rs @@ -0,0 +1,12 @@ +use crate::display::{shared_bus::{DualPrimaryDisplay, DualSecondaryDisplay}, tertiary_lcd::TertiaryI2cLcd}; + + + +pub struct Outputs { + pub primary_display: DualPrimaryDisplay<'static>, + pub secondary_display_1: DualSecondaryDisplay<'static>, + // pub secondary_display_2: DualSecondaryDisplay<'static>, + // pub secondary_display_3: DualSecondaryDisplay<'static>, + pub tertiary_display: TertiaryI2cLcd<'static>, + pub _led_a: (), +} \ No newline at end of file diff --git a/src/navigation/state.rs b/src/navigation/state.rs index 63ae293..a564a74 100644 --- a/src/navigation/state.rs +++ b/src/navigation/state.rs @@ -24,16 +24,16 @@ impl NavigationState { match &self.screens.len() { 0 => { log::info!("No screens to go back to"); - return self.screens.last().unwrap(); + self.screens.last().unwrap() } 1 => { log::info!("Only one screen on stack, cannot go back"); - return self.screens.last().unwrap(); + self.screens.last().unwrap() } _ => { log::info!("Going back to previous screen"); self.screens.pop(); - return self.screens.last().unwrap(); + self.screens.last().unwrap() } } } diff --git a/src/views/menu_item.rs b/src/views/menu_item.rs index 5802bb4..f97e8a9 100644 --- a/src/views/menu_item.rs +++ b/src/views/menu_item.rs @@ -7,7 +7,7 @@ use embedded_graphics::prelude::Point; use embedded_graphics::prelude::RgbColor; use embedded_graphics::text::Text; -pub fn show<'a, D>(display: &mut D, name: &str, position: i32, selected: i32) +pub fn show(display: &mut D, name: &str, position: i32, selected: i32) where D: DrawTarget, D::Error: core::fmt::Debug,