refactor all hardware init in drivers
This commit is contained in:
+14
-18
@@ -7,13 +7,13 @@
|
||||
)]
|
||||
#![deny(clippy::large_stack_frames)]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use creaturedex::card::decoder::split_nfc_hex;
|
||||
use creaturedex::card::model::Card;
|
||||
use creaturedex::display::secondary_oled::SecondaryDisplay;
|
||||
use creaturedex::display::shared_bus;
|
||||
use creaturedex::display::tertiary_lcd::{TertiaryDisplay, init_tertiary_lcd, write_wrapped};
|
||||
use creaturedex::drivers::i2c_bus::I2cBusPinConfiguration;
|
||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||
use creaturedex::drivers::secondary_oled::SecondaryDisplay;
|
||||
use creaturedex::drivers::spi_bus;
|
||||
use creaturedex::drivers::tertiary_lcd::{TertiaryDisplay, init_tertiary_lcd, write_wrapped};
|
||||
use creaturedex::navigation::inputs::Inputs;
|
||||
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
||||
use creaturedex::navigation::outputs::Outputs;
|
||||
@@ -27,11 +27,10 @@ use embedded_graphics::{
|
||||
text::Text,
|
||||
};
|
||||
use embedded_hal_bus::i2c::AtomicDevice;
|
||||
use embedded_hal_bus::util::AtomicCell;
|
||||
use esp_hal::Blocking;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::gpio::{Input, InputConfig, Pull};
|
||||
use esp_hal::i2c::master::{Config as I2cConfig, I2c};
|
||||
use esp_hal::i2c::master::I2c;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use log::error;
|
||||
|
||||
@@ -67,7 +66,7 @@ async fn main(spawner: Spawner) {
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
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,
|
||||
sck: peripherals.GPIO36,
|
||||
mosi: peripherals.GPIO35,
|
||||
@@ -82,18 +81,15 @@ async fn main(spawner: Spawner) {
|
||||
}
|
||||
.build();
|
||||
|
||||
let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(400));
|
||||
let i2c = match I2c::new(peripherals.I2C0, config) {
|
||||
Ok(bus) => bus
|
||||
.with_sda(peripherals.GPIO17)
|
||||
.with_scl(peripherals.GPIO18),
|
||||
Err(e) => {
|
||||
log::error!("Shared I2C bus initialization failed for GPIO17/GPIO18: {e:?}");
|
||||
panic!("Shared I2C bus initialization failed");
|
||||
}
|
||||
// Initialize the shared I2C bus using the refactored i2c_bus module.
|
||||
let shared_i2c = {
|
||||
let config = I2cBusPinConfiguration {
|
||||
i2c_peripheral: peripherals.I2C0,
|
||||
scl: peripherals.GPIO18,
|
||||
sda: peripherals.GPIO17,
|
||||
};
|
||||
config.build()
|
||||
};
|
||||
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: TertiaryDisplay = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
|
||||
if let Err(e) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
|
||||
|
||||
Reference in New Issue
Block a user