wip refactor all hardware init in drivers
This commit is contained in:
+4
-4
@@ -10,9 +10,9 @@
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use creaturedex::card::decoder::split_nfc_hex;
|
use creaturedex::card::decoder::split_nfc_hex;
|
||||||
use creaturedex::card::model::Card;
|
use creaturedex::card::model::Card;
|
||||||
use creaturedex::display::secondary_oled::SecondaryDisplay;
|
use creaturedex::drivers::secondary_oled::SecondaryDisplay;
|
||||||
use creaturedex::display::shared_bus;
|
use creaturedex::drivers::spi_bus;
|
||||||
use creaturedex::display::tertiary_lcd::{TertiaryDisplay, init_tertiary_lcd, write_wrapped};
|
use creaturedex::drivers::tertiary_lcd::{TertiaryDisplay, init_tertiary_lcd, write_wrapped};
|
||||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||||
use creaturedex::navigation::inputs::Inputs;
|
use creaturedex::navigation::inputs::Inputs;
|
||||||
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
||||||
@@ -67,7 +67,7 @@ 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) = shared_bus::DisplayPinConfiguration {
|
let (primary, mut secondaries) = spi_bus::DisplayPinConfiguration {
|
||||||
spi_peripheral: peripherals.SPI2,
|
spi_peripheral: peripherals.SPI2,
|
||||||
sck: peripherals.GPIO36,
|
sck: peripherals.GPIO36,
|
||||||
mosi: peripherals.GPIO35,
|
mosi: peripherals.GPIO35,
|
||||||
|
|||||||
@@ -1,5 +1 @@
|
|||||||
pub mod primary_lcd;
|
|
||||||
pub mod secondary_oled;
|
|
||||||
pub mod shared_bus;
|
|
||||||
pub mod sprite;
|
pub mod sprite;
|
||||||
pub mod tertiary_lcd;
|
|
||||||
|
|||||||
@@ -1 +1,6 @@
|
|||||||
|
pub mod i2c_bus;
|
||||||
pub mod nfc_pn532;
|
pub mod nfc_pn532;
|
||||||
|
pub mod primary_lcd;
|
||||||
|
pub mod secondary_oled;
|
||||||
|
pub mod spi_bus;
|
||||||
|
pub mod tertiary_lcd;
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
use alloc::boxed::Box;
|
||||||
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
|
use esp_hal::gpio::interconnect::PeripheralInput;
|
||||||
|
use esp_hal::i2c::master::Config;
|
||||||
|
use esp_hal::{gpio::interconnect::PeripheralOutput, i2c::master::I2c};
|
||||||
|
|
||||||
|
type InnerI2cBus = esp_hal::i2c::master::I2c<'static, esp_hal::Blocking>;
|
||||||
|
pub type I2cBus = &'static AtomicCell<InnerI2cBus>;
|
||||||
|
|
||||||
|
pub struct I2cBusPinConfiguration<I2C, SCL, SDA> {
|
||||||
|
pub i2c_peripheral: I2C,
|
||||||
|
pub scl: SCL,
|
||||||
|
pub sda: SDA,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<I2C, SCL, SDA> I2cBusPinConfiguration<I2C, SCL, SDA>
|
||||||
|
where
|
||||||
|
I2C: esp_hal::i2c::master::Instance + 'static,
|
||||||
|
SCL: PeripheralOutput<'static> + PeripheralInput<'static>,
|
||||||
|
SDA: PeripheralOutput<'static> + PeripheralInput<'static>,
|
||||||
|
{
|
||||||
|
pub fn build(self) -> I2cBus {
|
||||||
|
let config = Config::default().with_frequency(esp_hal::time::Rate::from_khz(400));
|
||||||
|
let i2c = match I2c::new(self.i2c_peripheral, config) {
|
||||||
|
Ok(bus) => bus.with_sda(self.sda).with_scl(self.scl),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Shared I2C bus initialization failed for GPIO17/GPIO18: {e:?}");
|
||||||
|
panic!("Shared I2C bus initialization failed");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
|
||||||
|
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
|
||||||
|
|
||||||
|
shared_i2c
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ use esp_hal::delay::Delay;
|
|||||||
use esp_hal::gpio::Output;
|
use esp_hal::gpio::Output;
|
||||||
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
||||||
|
|
||||||
use crate::display::shared_bus::{DisplaySpiBus, SharedOutput};
|
use crate::drivers::spi_bus::{DisplaySpiBus, SharedOutput};
|
||||||
|
|
||||||
type GenericPrimaryDisplay<'a, BUS, DC, RES> =
|
type GenericPrimaryDisplay<'a, BUS, DC, RES> =
|
||||||
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
||||||
@@ -6,7 +6,7 @@ use embedded_hal_bus::util::AtomicCell;
|
|||||||
use esp_hal::delay::Delay;
|
use esp_hal::delay::Delay;
|
||||||
use esp_hal::gpio::Output;
|
use esp_hal::gpio::Output;
|
||||||
|
|
||||||
use crate::display::shared_bus::{DisplaySpiBus, SharedOutput, SharedReset};
|
use crate::drivers::spi_bus::{DisplaySpiBus, SharedOutput, SharedReset};
|
||||||
|
|
||||||
pub type GenericSecondaryDisplay<'a, BUS, RST, DC> =
|
pub type GenericSecondaryDisplay<'a, BUS, RST, DC> =
|
||||||
Ch1115<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RST, Size128x64>;
|
Ch1115<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RST, Size128x64>;
|
||||||
@@ -9,10 +9,10 @@ use esp_hal::spi::Mode;
|
|||||||
use esp_hal::spi::master::{Config as SpiConfig, Spi};
|
use esp_hal::spi::master::{Config as SpiConfig, Spi};
|
||||||
use esp_hal::time::Rate;
|
use esp_hal::time::Rate;
|
||||||
|
|
||||||
use crate::display::primary_lcd::PrimaryDisplay;
|
use crate::drivers::primary_lcd::PrimaryDisplay;
|
||||||
use crate::display::primary_lcd::PrimaryDisplayPinConfiguration;
|
use crate::drivers::primary_lcd::PrimaryDisplayPinConfiguration;
|
||||||
use crate::display::secondary_oled::SecondaryDisplay;
|
use crate::drivers::secondary_oled::SecondaryDisplay;
|
||||||
use crate::display::secondary_oled::SecondaryDisplayPinConfiguration;
|
use crate::drivers::secondary_oled::SecondaryDisplayPinConfiguration;
|
||||||
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use embassy_sync::blocking_mutex::Mutex as BlockingMutex;
|
use embassy_sync::blocking_mutex::Mutex as BlockingMutex;
|
||||||
@@ -3,7 +3,7 @@ use embedded_graphics::{
|
|||||||
pixelcolor::{Rgb565, RgbColor as _},
|
pixelcolor::{Rgb565, RgbColor as _},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::display::{
|
use crate::drivers::{
|
||||||
primary_lcd::PrimaryDisplay, secondary_oled::SecondaryDisplay, tertiary_lcd::TertiaryDisplay,
|
primary_lcd::PrimaryDisplay, secondary_oled::SecondaryDisplay, tertiary_lcd::TertiaryDisplay,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user