Triple oled #37
+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?") {
|
||||
|
||||
@@ -1,5 +1 @@
|
||||
pub mod primary_lcd;
|
||||
pub mod secondary_oled;
|
||||
pub mod shared_bus;
|
||||
pub mod sprite;
|
||||
pub mod tertiary_lcd;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
pub mod i2c_bus;
|
||||
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 ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
||||
|
||||
use crate::display::shared_bus::{DisplaySpiBus, SharedOutput};
|
||||
use crate::drivers::spi_bus::{DisplaySpiBus, SharedOutput};
|
||||
|
||||
type GenericPrimaryDisplay<'a, BUS, 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::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> =
|
||||
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::time::Rate;
|
||||
|
||||
use crate::display::primary_lcd::PrimaryDisplay;
|
||||
use crate::display::primary_lcd::PrimaryDisplayPinConfiguration;
|
||||
use crate::display::secondary_oled::SecondaryDisplay;
|
||||
use crate::display::secondary_oled::SecondaryDisplayPinConfiguration;
|
||||
use crate::drivers::primary_lcd::PrimaryDisplay;
|
||||
use crate::drivers::primary_lcd::PrimaryDisplayPinConfiguration;
|
||||
use crate::drivers::secondary_oled::SecondaryDisplay;
|
||||
use crate::drivers::secondary_oled::SecondaryDisplayPinConfiguration;
|
||||
|
||||
use core::cell::RefCell;
|
||||
use embassy_sync::blocking_mutex::Mutex as BlockingMutex;
|
||||
@@ -3,7 +3,7 @@ use embedded_graphics::{
|
||||
pixelcolor::{Rgb565, RgbColor as _},
|
||||
};
|
||||
|
||||
use crate::display::{
|
||||
use crate::drivers::{
|
||||
primary_lcd::PrimaryDisplay, secondary_oled::SecondaryDisplay, tertiary_lcd::TertiaryDisplay,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user