1 Commits
Author SHA1 Message Date
rhetenor 16e45d2c11 wip: add flash info view 2026-08-29 15:39:28 +00:00
4 changed files with 39 additions and 60 deletions
+22 -43
View File
@@ -18,6 +18,7 @@ use creaturedex::drivers::tertiary_lcd::{
use creaturedex::navigation::inputs::Inputs; use creaturedex::navigation::inputs::Inputs;
use creaturedex::navigation::navigation::{self}; use creaturedex::navigation::navigation::{self};
use creaturedex::navigation::outputs::Outputs; use creaturedex::navigation::outputs::Outputs;
use creaturedex::network::wifi::setup_wifi;
use creaturedex::storage::cardstore::CardStore; use creaturedex::storage::cardstore::CardStore;
use creaturedex::storage::store::Store; use creaturedex::storage::store::Store;
use embassy_executor::Spawner; use embassy_executor::Spawner;
@@ -67,40 +68,32 @@ async fn main(spawner: Spawner) {
let timg0 = TimerGroup::new(peripherals.TIMG0); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0); esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
let (primary, mut secondaries) = retry( let (primary, mut secondaries) = spi_bus::DisplayPinConfiguration {
5, spi_peripheral: peripherals.SPI2,
spi_bus::DisplayPinConfiguration { sck: peripherals.GPIO36,
spi_peripheral: peripherals.SPI2, mosi: peripherals.GPIO35,
sck: peripherals.GPIO36, miso: peripherals.GPIO37,
mosi: peripherals.GPIO35, cs_primary: peripherals.GPIO11,
miso: peripherals.GPIO37, cs_secondary_1: peripherals.GPIO13,
cs_primary: peripherals.GPIO11, cs_secondary_2: peripherals.GPIO14,
cs_secondary_1: peripherals.GPIO13, cs_secondary_3: peripherals.GPIO21,
cs_secondary_2: peripherals.GPIO14, reset_primary: peripherals.GPIO10,
cs_secondary_3: peripherals.GPIO21, reset_secondary: peripherals.GPIO47,
reset_primary: peripherals.GPIO10, dc_pin: peripherals.GPIO12,
reset_secondary: peripherals.GPIO47, }
dc_pin: peripherals.GPIO12, .build();
},
spi_bus::DisplayPinConfiguration::build,
);
// Initialize the shared I2C bus using the refactored i2c_bus module. // Initialize the shared I2C bus using the refactored i2c_bus module.
let shared_i2c = { let shared_i2c = {
use alloc::boxed::Box; let config = I2cBusPinConfiguration {
let bus = retry(5, I2cBusPinConfiguration {
i2c_peripheral: peripherals.I2C0, i2c_peripheral: peripherals.I2C0,
scl: peripherals.GPIO18, scl: peripherals.GPIO18,
sda: peripherals.GPIO17, sda: peripherals.GPIO17,
}, I2cBusPinConfiguration::build); };
Box::leak(Box::new(bus)) config.build()
}; };
let mut lcd: TertiaryDisplay = retry( let mut lcd: TertiaryDisplay = TertiaryDisplayPinConfiguration { i2c: shared_i2c }.build();
5,
TertiaryDisplayPinConfiguration { i2c: shared_i2c },
TertiaryDisplayPinConfiguration::build,
);
lcd.load_charset(EXAMPLE).unwrap(); lcd.load_charset(EXAMPLE).unwrap();
let h = EXAMPLE[HEART]; let h = EXAMPLE[HEART];
let e = EXAMPLE[EMPTY]; let e = EXAMPLE[EMPTY];
@@ -114,7 +107,7 @@ async fn main(spawner: Spawner) {
} }
let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store"); let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store");
let cardstore = CardStore::new(store).expect("Could not initialize Card Store"); let card_store = CardStore::new(store).expect("Could not initialize Card Store");
let rtc = Rtc::new(peripherals.LPWR); let rtc = Rtc::new(peripherals.LPWR);
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await; //setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
@@ -155,9 +148,9 @@ async fn main(spawner: Spawner) {
log::info!("Setup complete, entering main loop"); log::info!("Setup complete, entering main loop");
spawner.spawn(navigation::run(inputs, outputs).expect("run task failed")); spawner.spawn(navigation::run(inputs, outputs).expect("run task failed"));
spawner.spawn( spawner.spawn(
background_tasks::nfc_scanner(nfc_driver, cardstore, rtc).expect("nfc scanner task failed"), background_tasks::nfc_scanner(nfc_driver, card_store, rtc)
.expect("nfc scanner task failed"),
); );
core::future::pending::<()>().await
} }
fn display_shit(oled: &mut SecondaryDisplay<'static>, text: &str) { fn display_shit(oled: &mut SecondaryDisplay<'static>, text: &str) {
@@ -169,17 +162,3 @@ fn display_shit(oled: &mut SecondaryDisplay<'static>, text: &str) {
.unwrap(); .unwrap();
oled.flush().unwrap(); oled.flush().unwrap();
} }
fn retry<T, U, F: FnMut(T) -> Result<U, T>>(repetitions: u32, input: T, mut action: F) -> U {
let mut initial_state = input;
for iteration in 0..repetitions {
log::debug!("Trying to initialize. Retries: {iteration}");
match action(initial_state) {
Ok(success) => return success,
Err(recovered_input) => initial_state = recovered_input,
}
}
panic!("Init failed after {repetitions} retries.")
}
+10 -10
View File
@@ -1,3 +1,4 @@
use alloc::boxed::Box;
use embedded_hal_bus::i2c::AtomicDevice; use embedded_hal_bus::i2c::AtomicDevice;
use embedded_hal_bus::util::AtomicCell; use embedded_hal_bus::util::AtomicCell;
use esp_hal::gpio::interconnect::PeripheralInput; use esp_hal::gpio::interconnect::PeripheralInput;
@@ -20,19 +21,18 @@ where
SCL: PeripheralOutput<'a> + PeripheralInput<'a>, SCL: PeripheralOutput<'a> + PeripheralInput<'a>,
SDA: PeripheralOutput<'a> + PeripheralInput<'a>, SDA: PeripheralOutput<'a> + PeripheralInput<'a>,
{ {
pub fn build(self) -> Result<AtomicCell<InnerI2cBus<'a>>, Self> { pub fn build(self) -> I2cBus<'a> {
let config = Config::default().with_frequency(esp_hal::time::Rate::from_khz(400)); let config = Config::default().with_frequency(esp_hal::time::Rate::from_khz(400));
match I2c::new(self.i2c_peripheral, config) { let i2c = match I2c::new(self.i2c_peripheral, config) {
Ok(bus) => { Ok(bus) => bus.with_sda(self.sda).with_scl(self.scl),
let i2c = bus.with_sda(self.sda).with_scl(self.scl);
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
Ok(AtomicCell::new(i2c))
}
Err(e) => { Err(e) => {
log::error!("Shared I2C bus initialization failed for GPIO17/GPIO18: {e:?}"); log::error!("Shared I2C bus initialization failed for GPIO17/GPIO18: {e:?}");
unimplemented!("Partial move makes it impossible to retry."); panic!("Shared I2C bus initialization failed");
// Err(self)
} }
} };
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
shared_i2c
} }
} }
+2 -2
View File
@@ -135,7 +135,7 @@ where
RES2: OutputPin + 'static, RES2: OutputPin + 'static,
DC: OutputPin + 'static, DC: OutputPin + 'static,
{ {
pub fn build(self) -> Result<(PrimaryDisplay<'static>, [SecondaryDisplay<'static>; 3]), Self> { pub fn build(self) -> (PrimaryDisplay<'static>, [SecondaryDisplay<'static>; 3]) {
let spi = Spi::new( let spi = Spi::new(
self.spi_peripheral, self.spi_peripheral,
SpiConfig::default() SpiConfig::default()
@@ -178,7 +178,7 @@ where
} }
.build(); .build();
Ok((primary, secondaries)) (primary, secondaries)
} }
} }
+5 -5
View File
@@ -15,20 +15,19 @@ pub struct TertiaryDisplayPinConfiguration<'a> {
} }
impl<'a> TertiaryDisplayPinConfiguration<'a> { impl<'a> TertiaryDisplayPinConfiguration<'a> {
pub fn build(self) -> Result<TertiaryDisplay<'a>, Self> { pub fn build(self) -> TertiaryDisplay<'a> {
let device = AtomicDevice::new(self.i2c); let device = AtomicDevice::new(self.i2c);
let mut lcd = CharacterDisplayPCF8574T::new(device, LcdDisplayType::Lcd16x2, Delay::new()); let mut lcd = CharacterDisplayPCF8574T::new(device, LcdDisplayType::Lcd16x2, Delay::new());
match lcd.init() { match lcd.init() {
Ok(()) => { Ok(()) => {
log::info!("I2C tertiary LCD initialized on PCF8574T at address 0x27"); log::info!("I2C tertiary LCD initialized on PCF8574T at address 0x27");
Ok(TertiaryDisplay { TertiaryDisplay {
display: lcd, display: lcd,
charset: create_custom_char_set!(), charset: create_custom_char_set!(),
}) }
} }
Err(e) => { Err(e) => {
log::error!("I2C tertiary LCD init failed on PCF8574T at address 0x27: {e}"); panic!("I2C tertiary LCD init failed on PCF8574T at address 0x27: {e}");
Err(self)
} }
} }
} }
@@ -408,3 +407,4 @@ pub const BOX: CharMap = [
]; ];
pub const EXAMPLE: CustomCharset = create_custom_char_set!(HEART, BOX, EMPTY); pub const EXAMPLE: CustomCharset = create_custom_char_set!(HEART, BOX, EMPTY);