Triple oled #37
+16
-18
@@ -10,7 +10,7 @@
|
||||
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::shared_bus::{self, DualSecondaryDisplay};
|
||||
use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, init_tertiary_lcd, write_wrapped};
|
||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||
use creaturedex::navigation::inputs::Inputs;
|
||||
@@ -29,7 +29,7 @@ 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, Level, Output, OutputConfig, Pull};
|
||||
use esp_hal::gpio::{Input, InputConfig, Pull};
|
||||
use esp_hal::i2c::master::{Config as I2cConfig, I2c};
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use log::error;
|
||||
@@ -66,22 +66,20 @@ async fn main(spawner: Spawner) {
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
|
||||
|
||||
let (display, mut oled) = init_dual_displays(
|
||||
peripherals.SPI2,
|
||||
peripherals.GPIO36, // sck
|
||||
peripherals.GPIO35, // mosi
|
||||
peripherals.GPIO37, // miso
|
||||
peripherals.GPIO11, // primary cs
|
||||
peripherals.GPIO13, // oled cs
|
||||
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 (display, mut oled) = shared_bus::DisplayPinConfiguration {
|
||||
spi_peripheral: peripherals.SPI2,
|
||||
sck: peripherals.GPIO36,
|
||||
mosi: peripherals.GPIO35,
|
||||
miso: peripherals.GPIO37,
|
||||
cs_primary: peripherals.GPIO11,
|
||||
cs_secondary_1: peripherals.GPIO13,
|
||||
cs_secondary_2: peripherals.GPIO14,
|
||||
cs_secondary_3: peripherals.GPIO21,
|
||||
reset_primary: peripherals.GPIO10,
|
||||
reset_secondary: peripherals.GPIO47,
|
||||
dc_pin: peripherals.GPIO12,
|
||||
}
|
||||
.build();
|
||||
|
||||
let config = I2cConfig::default().with_frequency(esp_hal::time::Rate::from_khz(400));
|
||||
let i2c = match I2c::new(peripherals.I2C0, config) {
|
||||
|
||||
+60
-44
@@ -10,8 +10,8 @@ use esp_hal::spi::Mode;
|
||||
use esp_hal::spi::master::{Config as SpiConfig, Spi};
|
||||
use esp_hal::time::Rate;
|
||||
|
||||
use crate::display::secondary_oled::{SecondaryOledDisplay, init_secondary_oled_on_bus};
|
||||
use crate::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd_on_bus};
|
||||
use crate::display::secondary_oled::{SecondaryOledDisplay, init_secondary_oled_on_bus};
|
||||
|
||||
use core::cell::RefCell;
|
||||
use embassy_sync::blocking_mutex::Mutex as BlockingMutex;
|
||||
@@ -52,62 +52,78 @@ pub type DualPrimaryDisplay<'a> =
|
||||
pub type DualSecondaryDisplay<'a> =
|
||||
SecondaryOledDisplay<'a, DisplaySpiBus, SharedPin<'a, Output<'a>>, SharedPin<'a, Output<'a>>>;
|
||||
|
||||
pub fn init_dual_displays<SPI, SCK, MOSI, MISO, CS1, CS2, RES1, RES2, DC>(
|
||||
spi_peripheral: SPI,
|
||||
sck: SCK,
|
||||
mosi: MOSI,
|
||||
miso: MISO,
|
||||
cs_primary: CS1,
|
||||
cs_secondary: CS2,
|
||||
reset_primary: RES1,
|
||||
reset_secondary: RES2,
|
||||
dc_pin: DC,
|
||||
) -> (DualPrimaryDisplay<'static>, DualSecondaryDisplay<'static>)
|
||||
pub struct DisplayPinConfiguration<SPI, SCK, MOSI, MISO, CS0, CS1, CS2, CS3, RES1, RES2, DC> {
|
||||
pub spi_peripheral: SPI,
|
||||
pub sck: SCK,
|
||||
pub mosi: MOSI,
|
||||
pub miso: MISO,
|
||||
pub cs_primary: CS0,
|
||||
pub cs_secondary_1: CS1,
|
||||
pub cs_secondary_2: CS2,
|
||||
pub cs_secondary_3: CS3,
|
||||
pub reset_primary: RES1,
|
||||
pub reset_secondary: RES2,
|
||||
pub dc_pin: DC,
|
||||
}
|
||||
|
||||
impl<SPI, SCK, MOSI, MISO, CS0, CS1, CS2, CS3, RES1, RES2, DC>
|
||||
DisplayPinConfiguration<SPI, SCK, MOSI, MISO, CS0, CS1, CS2, CS3, RES1, RES2, DC>
|
||||
where
|
||||
SPI: esp_hal::spi::master::Instance + 'static,
|
||||
SCK: PeripheralOutput<'static>,
|
||||
MOSI: PeripheralOutput<'static>,
|
||||
MISO: PeripheralInput<'static>,
|
||||
CS0: OutputPin + 'static,
|
||||
CS1: OutputPin + 'static,
|
||||
CS2: OutputPin + 'static,
|
||||
CS3: OutputPin + 'static,
|
||||
RES1: OutputPin + 'static,
|
||||
RES2: OutputPin + 'static,
|
||||
DC: OutputPin + 'static,
|
||||
{
|
||||
let spi = Spi::new(
|
||||
spi_peripheral,
|
||||
SpiConfig::default()
|
||||
.with_frequency(Rate::from_khz(20_000))
|
||||
.with_mode(Mode::_0),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(sck)
|
||||
.with_mosi(mosi)
|
||||
.with_miso(miso);
|
||||
pub fn build(self) -> (DualPrimaryDisplay<'static>, DualSecondaryDisplay<'static>) {
|
||||
let spi = Spi::new(
|
||||
self.spi_peripheral,
|
||||
SpiConfig::default()
|
||||
.with_frequency(Rate::from_khz(20_000))
|
||||
.with_mode(Mode::_0),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(self.sck)
|
||||
.with_mosi(self.mosi)
|
||||
.with_miso(self.miso);
|
||||
|
||||
let bus_static: &'static AtomicCell<_> = Box::leak(Box::new(AtomicCell::new(spi)));
|
||||
let reset_primary_static =
|
||||
SharedPin::pre_wrap(Output::new(reset_primary, Level::High, OutputConfig::default()));
|
||||
let reset_secondary_static =
|
||||
SharedPin::pre_wrap(Output::new(reset_secondary, Level::High, OutputConfig::default()));
|
||||
let dc_static = SharedPin::pre_wrap(Output::new(dc_pin, Level::High, OutputConfig::default()));
|
||||
let mut delay = Delay::new();
|
||||
let bus_static: &'static AtomicCell<_> = Box::leak(Box::new(AtomicCell::new(spi)));
|
||||
let reset_primary_static = SharedPin::pre_wrap(Output::new(
|
||||
self.reset_primary,
|
||||
Level::High,
|
||||
OutputConfig::default(),
|
||||
));
|
||||
let reset_secondary_static = SharedPin::pre_wrap(Output::new(
|
||||
self.reset_secondary,
|
||||
Level::High,
|
||||
OutputConfig::default(),
|
||||
));
|
||||
let dc_static =
|
||||
SharedPin::pre_wrap(Output::new(self.dc_pin, Level::High, OutputConfig::default()));
|
||||
let mut delay = Delay::new();
|
||||
|
||||
let primary = init_primary_lcd_on_bus(
|
||||
bus_static,
|
||||
cs_primary,
|
||||
SharedPin::new(reset_primary_static),
|
||||
SharedPin::new(dc_static),
|
||||
&mut delay,
|
||||
);
|
||||
let primary = init_primary_lcd_on_bus(
|
||||
bus_static,
|
||||
self.cs_primary,
|
||||
SharedPin::new(reset_primary_static),
|
||||
SharedPin::new(dc_static),
|
||||
&mut delay,
|
||||
);
|
||||
|
||||
let secondary = init_secondary_oled_on_bus(
|
||||
bus_static,
|
||||
cs_secondary,
|
||||
SharedPin::new(reset_secondary_static),
|
||||
SharedPin::new(dc_static),
|
||||
&mut delay,
|
||||
);
|
||||
let secondary = init_secondary_oled_on_bus(
|
||||
bus_static,
|
||||
self.cs_secondary_1,
|
||||
SharedPin::new(reset_secondary_static),
|
||||
SharedPin::new(dc_static),
|
||||
&mut delay,
|
||||
);
|
||||
|
||||
(primary, secondary)
|
||||
(primary, secondary)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user