Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2f80cf4aa
|
+14
-20
@@ -10,9 +10,8 @@
|
|||||||
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::drivers::secondary_oled::SecondaryDisplay;
|
use creaturedex::display::shared_bus::{self, DualSecondaryDisplay};
|
||||||
use creaturedex::drivers::spi_bus;
|
use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, 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 +66,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) = spi_bus::DisplayPinConfiguration {
|
let (display, mut oled) = shared_bus::DisplayPinConfiguration {
|
||||||
spi_peripheral: peripherals.SPI2,
|
spi_peripheral: peripherals.SPI2,
|
||||||
sck: peripherals.GPIO36,
|
sck: peripherals.GPIO36,
|
||||||
mosi: peripherals.GPIO35,
|
mosi: peripherals.GPIO35,
|
||||||
@@ -95,7 +94,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
|
let shared_i2c = Box::leak(Box::new(AtomicCell::new(i2c)));
|
||||||
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
|
log::info!("Shared I2C bus ready on GPIO17 (SDA) and GPIO18 (SCL)");
|
||||||
|
|
||||||
let mut lcd: TertiaryDisplay = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
|
let mut lcd: TertiaryI2cLcd = init_tertiary_lcd(AtomicDevice::new(shared_i2c));
|
||||||
if let Err(e) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
|
if let Err(e) = write_wrapped(&mut lcd, "Testing more than 16 chars what happens now?") {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses: {e}"
|
"Tertiary LCD startup text write failed over shared I2C bus; check the shared bus, wiring, and device responses: {e}"
|
||||||
@@ -121,20 +120,15 @@ async fn main(spawner: Spawner) {
|
|||||||
ok: Input::new(peripherals.GPIO0, button_config),
|
ok: Input::new(peripherals.GPIO0, button_config),
|
||||||
};
|
};
|
||||||
|
|
||||||
display_shit(&mut secondaries[0], "foo 1");
|
display_shit(&mut oled);
|
||||||
display_shit(&mut secondaries[1], "bar 1");
|
|
||||||
display_shit(&mut secondaries[2], "baz 1");
|
|
||||||
|
|
||||||
let outputs = {
|
let outputs = Outputs {
|
||||||
let [sec_1, sec_2, sec_3] = secondaries;
|
primary_display: display,
|
||||||
Outputs {
|
secondary_display_1: oled,
|
||||||
primary_display: primary,
|
// secondary_display_2: todo!(),
|
||||||
secondary_display_1: sec_1,
|
// secondary_display_3: todo!(),
|
||||||
secondary_display_2: sec_2,
|
tertiary_display: lcd,
|
||||||
secondary_display_3: sec_3,
|
_led_a: (),
|
||||||
tertiary_display: lcd,
|
|
||||||
_led_a: (),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("Setup complete, entering main loop");
|
log::info!("Setup complete, entering main loop");
|
||||||
@@ -179,11 +173,11 @@ async fn nfc_driver_task(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_shit(oled: &mut SecondaryDisplay<'static>, text: &str) {
|
fn display_shit(oled: &mut DualSecondaryDisplay<'static>) {
|
||||||
oled.clear().unwrap();
|
oled.clear().unwrap();
|
||||||
|
|
||||||
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
||||||
Text::new(text, Point::new(10, 20), text_style)
|
Text::new("Hello OLED", Point::new(10, 20), text_style)
|
||||||
.draw(oled)
|
.draw(oled)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
oled.flush().unwrap();
|
oled.flush().unwrap();
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
|
pub mod primary_lcd;
|
||||||
|
pub mod secondary_oled;
|
||||||
|
pub mod shared_bus;
|
||||||
pub mod sprite;
|
pub mod sprite;
|
||||||
|
pub mod tertiary_lcd;
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
use display_interface_spi::SPIInterface;
|
||||||
|
use embedded_graphics::draw_target::DrawTarget;
|
||||||
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
|
use embedded_graphics::prelude::RgbColor;
|
||||||
|
use embedded_hal::digital::OutputPin as EhOutputPin;
|
||||||
|
use embedded_hal_bus::spi::AtomicDevice;
|
||||||
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
|
use esp_hal::delay::Delay;
|
||||||
|
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
||||||
|
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
||||||
|
|
||||||
|
pub type PrimaryLcdDisplay<'a, BUS, DC, RES> =
|
||||||
|
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
||||||
|
|
||||||
|
pub fn init_primary_lcd_on_bus<'a, BUS, CS, RES, DC>(
|
||||||
|
spi_bus: &'a AtomicCell<BUS>,
|
||||||
|
cs: CS,
|
||||||
|
reset: RES,
|
||||||
|
dc: DC,
|
||||||
|
delay: &mut Delay,
|
||||||
|
) -> PrimaryLcdDisplay<'a, BUS, DC, RES>
|
||||||
|
where
|
||||||
|
BUS: embedded_hal::spi::SpiBus,
|
||||||
|
CS: OutputPin + 'static,
|
||||||
|
RES: EhOutputPin,
|
||||||
|
DC: EhOutputPin,
|
||||||
|
{
|
||||||
|
let cs_pin = Output::new(cs, Level::High, OutputConfig::default());
|
||||||
|
let spi_dev = AtomicDevice::new(spi_bus, cs_pin, *delay).unwrap();
|
||||||
|
let iface = SPIInterface::new(spi_dev, dc);
|
||||||
|
|
||||||
|
let mut display = Ili9341::new(
|
||||||
|
iface,
|
||||||
|
reset,
|
||||||
|
delay,
|
||||||
|
Orientation::Portrait,
|
||||||
|
DisplaySize240x320,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
display.clear(Rgb565::BLACK).unwrap();
|
||||||
|
display
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
use ch1115::{Ch1115, Size128x64};
|
||||||
|
use display_interface_spi::SPIInterface;
|
||||||
|
use embedded_hal::digital::OutputPin as EhOutputPin;
|
||||||
|
use embedded_hal_bus::spi::AtomicDevice;
|
||||||
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
|
use esp_hal::delay::Delay;
|
||||||
|
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
||||||
|
|
||||||
|
pub type SecondaryOledDisplay<'a, BUS, RST, DC> =
|
||||||
|
Ch1115<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RST, Size128x64>;
|
||||||
|
|
||||||
|
pub fn init_secondary_oled_on_bus<'a, BUS, CS, RES, DC>(
|
||||||
|
spi_bus: &'a AtomicCell<BUS>,
|
||||||
|
cs: CS,
|
||||||
|
res: RES,
|
||||||
|
dc: DC,
|
||||||
|
delay: &mut Delay,
|
||||||
|
) -> SecondaryOledDisplay<'a, BUS, RES, DC>
|
||||||
|
where
|
||||||
|
BUS: embedded_hal::spi::SpiBus,
|
||||||
|
CS: OutputPin + 'static,
|
||||||
|
RES: EhOutputPin,
|
||||||
|
DC: EhOutputPin,
|
||||||
|
{
|
||||||
|
let cs_pin = Output::new(cs, Level::High, OutputConfig::default());
|
||||||
|
let spi_dev = AtomicDevice::new(spi_bus, cs_pin, *delay).unwrap();
|
||||||
|
let interface = SPIInterface::new(spi_dev, dc);
|
||||||
|
|
||||||
|
let mut display = Ch1115::new(interface, res, Size128x64);
|
||||||
|
|
||||||
|
display.init(&mut Delay::new()).unwrap();
|
||||||
|
|
||||||
|
display
|
||||||
|
}
|
||||||
@@ -3,16 +3,15 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
|||||||
use embedded_hal::digital::ErrorType;
|
use embedded_hal::digital::ErrorType;
|
||||||
use embedded_hal::digital::OutputPin as EhOutputPin;
|
use embedded_hal::digital::OutputPin as EhOutputPin;
|
||||||
use embedded_hal_bus::util::AtomicCell;
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
|
use esp_hal::delay::Delay;
|
||||||
use esp_hal::gpio::interconnect::{PeripheralInput, PeripheralOutput};
|
use esp_hal::gpio::interconnect::{PeripheralInput, PeripheralOutput};
|
||||||
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
||||||
use esp_hal::spi::Mode;
|
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::drivers::primary_lcd::PrimaryDisplay;
|
use crate::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd_on_bus};
|
||||||
use crate::drivers::primary_lcd::PrimaryDisplayPinConfiguration;
|
use crate::display::secondary_oled::{SecondaryOledDisplay, init_secondary_oled_on_bus};
|
||||||
use crate::drivers::secondary_oled::SecondaryDisplay;
|
|
||||||
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;
|
||||||
@@ -102,9 +101,13 @@ impl<'a, P: EhOutputPin> EhOutputPin for SharedResetPin<'a, P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SharedOutput<'a> = SharedPin<'a, Output<'a>>;
|
type SharedOutput<'a> = SharedPin<'a, Output<'a>>;
|
||||||
pub type SharedReset<'a> = SharedResetPin<'a, Output<'a>>;
|
type SharedReset<'a> = SharedResetPin<'a, Output<'a>>;
|
||||||
pub type DisplaySpiBus = Spi<'static, esp_hal::Blocking>;
|
pub type DisplaySpiBus = Spi<'static, esp_hal::Blocking>;
|
||||||
|
pub type DualPrimaryDisplay<'a> =
|
||||||
|
PrimaryLcdDisplay<'a, DisplaySpiBus, SharedOutput<'a>, Output<'a>>;
|
||||||
|
pub type DualSecondaryDisplay<'a> =
|
||||||
|
SecondaryOledDisplay<'a, DisplaySpiBus, SharedReset<'a>, SharedOutput<'a>>;
|
||||||
|
|
||||||
pub struct DisplayPinConfiguration<SPI, SCK, MOSI, MISO, CS0, CS1, CS2, CS3, RES1, RES2, DC> {
|
pub struct DisplayPinConfiguration<SPI, SCK, MOSI, MISO, CS0, CS1, CS2, CS3, RES1, RES2, DC> {
|
||||||
pub spi_peripheral: SPI,
|
pub spi_peripheral: SPI,
|
||||||
@@ -135,7 +138,7 @@ where
|
|||||||
RES2: OutputPin + 'static,
|
RES2: OutputPin + 'static,
|
||||||
DC: OutputPin + 'static,
|
DC: OutputPin + 'static,
|
||||||
{
|
{
|
||||||
pub fn build(self) -> (PrimaryDisplay<'static>, [SecondaryDisplay<'static>; 3]) {
|
pub fn build(self) -> (DualPrimaryDisplay<'static>, DualSecondaryDisplay<'static>) {
|
||||||
let spi = Spi::new(
|
let spi = Spi::new(
|
||||||
self.spi_peripheral,
|
self.spi_peripheral,
|
||||||
SpiConfig::default()
|
SpiConfig::default()
|
||||||
@@ -148,6 +151,7 @@ where
|
|||||||
.with_miso(self.miso);
|
.with_miso(self.miso);
|
||||||
|
|
||||||
let bus_static: &'static AtomicCell<_> = Box::leak(Box::new(AtomicCell::new(spi)));
|
let bus_static: &'static AtomicCell<_> = Box::leak(Box::new(AtomicCell::new(spi)));
|
||||||
|
let reset_primary = Output::new(self.reset_primary, Level::High, OutputConfig::default());
|
||||||
let reset_secondary = SharedResetPin::new(
|
let reset_secondary = SharedResetPin::new(
|
||||||
Output::new(self.reset_secondary, Level::High, OutputConfig::default()),
|
Output::new(self.reset_secondary, Level::High, OutputConfig::default()),
|
||||||
false,
|
false,
|
||||||
@@ -157,31 +161,31 @@ where
|
|||||||
Level::High,
|
Level::High,
|
||||||
OutputConfig::default(),
|
OutputConfig::default(),
|
||||||
));
|
));
|
||||||
|
let mut delay = Delay::new();
|
||||||
|
|
||||||
let primary = PrimaryDisplayPinConfiguration {
|
let primary = init_primary_lcd_on_bus(
|
||||||
spi_bus: bus_static,
|
bus_static,
|
||||||
cs: low_active(self.cs_primary),
|
self.cs_primary,
|
||||||
reset: low_active(self.reset_primary),
|
reset_primary,
|
||||||
dc: dc.clone(),
|
dc.clone(),
|
||||||
}
|
&mut delay,
|
||||||
.build();
|
);
|
||||||
|
|
||||||
let secondaries = SecondaryDisplayPinConfiguration {
|
// TODO
|
||||||
spi_bus: bus_static,
|
// Build display
|
||||||
cs_pins: [
|
// Trigger reset
|
||||||
low_active(self.cs_secondary_1),
|
// disable init
|
||||||
low_active(self.cs_secondary_2),
|
// rest of init code
|
||||||
low_active(self.cs_secondary_3),
|
|
||||||
],
|
|
||||||
res: reset_secondary,
|
let secondary = init_secondary_oled_on_bus(
|
||||||
|
bus_static,
|
||||||
|
self.cs_secondary_1,
|
||||||
|
reset_secondary,
|
||||||
dc,
|
dc,
|
||||||
}
|
&mut delay,
|
||||||
.build();
|
);
|
||||||
|
|
||||||
(primary, secondaries)
|
(primary, secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn low_active<'a, CS: OutputPin + 'a>(pin: CS) -> Output<'a> {
|
|
||||||
Output::new(pin, Level::High, OutputConfig::default())
|
|
||||||
}
|
|
||||||
@@ -47,7 +47,10 @@ where
|
|||||||
let width = u32::try_from(end_x - start_x).unwrap();
|
let width = u32::try_from(end_x - start_x).unwrap();
|
||||||
let height = u32::try_from(end_y - start_y).unwrap();
|
let height = u32::try_from(end_y - start_y).unwrap();
|
||||||
|
|
||||||
let area = Rectangle::new(Point::new(start_x, start_y), Size::new(width, height));
|
let area = Rectangle::new(
|
||||||
|
Point::new(start_x.try_into().unwrap(), start_y.try_into().unwrap()),
|
||||||
|
Size::new(width, height),
|
||||||
|
);
|
||||||
|
|
||||||
let _ = ili9341.fill_solid(&area, color);
|
let _ = ili9341.fill_solid(&area, color);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ use esp_hal::delay::Delay;
|
|||||||
use i2c_character_display::{CharacterDisplayPCF8574T, LcdDisplayType};
|
use i2c_character_display::{CharacterDisplayPCF8574T, LcdDisplayType};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
type GenericTertiaryDisplay<I2C> = CharacterDisplayPCF8574T<I2C, Delay>;
|
pub type TertiaryLcd<I2C> = CharacterDisplayPCF8574T<I2C, Delay>;
|
||||||
pub type TertiaryDisplay<'a> =
|
pub type TertiaryI2cLcd<'a> = TertiaryLcd<AtomicDevice<'a, esp_hal::i2c::master::I2c<'a, esp_hal::Blocking>>>;
|
||||||
GenericTertiaryDisplay<AtomicDevice<'a, esp_hal::i2c::master::I2c<'a, esp_hal::Blocking>>>;
|
|
||||||
|
|
||||||
pub fn init_tertiary_lcd<I2C>(i2c: I2C) -> GenericTertiaryDisplay<I2C>
|
pub fn init_tertiary_lcd<I2C>(i2c: I2C) -> TertiaryLcd<I2C>
|
||||||
where
|
where
|
||||||
I2C: I2c,
|
I2C: I2c,
|
||||||
{
|
{
|
||||||
@@ -28,7 +27,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_line<I2C>(
|
pub fn write_line<I2C>(
|
||||||
lcd: &mut GenericTertiaryDisplay<I2C>,
|
lcd: &mut TertiaryLcd<I2C>,
|
||||||
line: u8,
|
line: u8,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Result<(), i2c_character_display::CharacterDisplayError<I2C>>
|
) -> Result<(), i2c_character_display::CharacterDisplayError<I2C>>
|
||||||
@@ -50,7 +49,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_wrapped<I2C>(
|
pub fn write_wrapped<I2C>(
|
||||||
lcd: &mut GenericTertiaryDisplay<I2C>,
|
lcd: &mut TertiaryLcd<I2C>,
|
||||||
text: &str,
|
text: &str,
|
||||||
) -> Result<(), i2c_character_display::CharacterDisplayError<I2C>>
|
) -> Result<(), i2c_character_display::CharacterDisplayError<I2C>>
|
||||||
where
|
where
|
||||||
@@ -1,6 +1 @@
|
|||||||
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;
|
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
use display_interface_spi::SPIInterface;
|
|
||||||
use embedded_graphics::draw_target::DrawTarget;
|
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
|
||||||
use embedded_graphics::prelude::RgbColor;
|
|
||||||
use embedded_hal_bus::spi::AtomicDevice;
|
|
||||||
use embedded_hal_bus::util::AtomicCell;
|
|
||||||
use esp_hal::delay::Delay;
|
|
||||||
use esp_hal::gpio::Output;
|
|
||||||
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
|
||||||
|
|
||||||
use crate::drivers::spi_bus::{DisplaySpiBus, SharedOutput};
|
|
||||||
|
|
||||||
type GenericPrimaryDisplay<'a, BUS, DC, RES> =
|
|
||||||
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
|
||||||
pub type PrimaryDisplay<'a> =
|
|
||||||
GenericPrimaryDisplay<'a, DisplaySpiBus, SharedOutput<'a>, Output<'a>>;
|
|
||||||
|
|
||||||
pub struct PrimaryDisplayPinConfiguration<'a> {
|
|
||||||
pub spi_bus: &'a AtomicCell<DisplaySpiBus>,
|
|
||||||
pub cs: Output<'a>,
|
|
||||||
pub reset: Output<'a>,
|
|
||||||
pub dc: SharedOutput<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> PrimaryDisplayPinConfiguration<'a> {
|
|
||||||
pub fn build(self) -> PrimaryDisplay<'a> {
|
|
||||||
let spi_dev = AtomicDevice::new(self.spi_bus, self.cs, Delay::new()).unwrap();
|
|
||||||
let iface = SPIInterface::new(spi_dev, self.dc);
|
|
||||||
|
|
||||||
let mut display = Ili9341::new(
|
|
||||||
iface,
|
|
||||||
self.reset,
|
|
||||||
&mut Delay::new(),
|
|
||||||
Orientation::Portrait,
|
|
||||||
DisplaySize240x320,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
display.clear(Rgb565::BLACK).unwrap();
|
|
||||||
display
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
use alloc::format;
|
|
||||||
use ch1115::{Ch1115, Size128x64};
|
|
||||||
use display_interface_spi::SPIInterface;
|
|
||||||
use embedded_hal_bus::spi::AtomicDevice;
|
|
||||||
use embedded_hal_bus::util::AtomicCell;
|
|
||||||
use esp_hal::delay::Delay;
|
|
||||||
use esp_hal::gpio::Output;
|
|
||||||
|
|
||||||
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>;
|
|
||||||
pub type SecondaryDisplay<'a> =
|
|
||||||
GenericSecondaryDisplay<'a, DisplaySpiBus, SharedReset<'a>, SharedOutput<'a>>;
|
|
||||||
|
|
||||||
pub struct SecondaryDisplayPinConfiguration<'a> {
|
|
||||||
pub spi_bus: &'a AtomicCell<DisplaySpiBus>,
|
|
||||||
pub cs_pins: [Output<'a>; 3],
|
|
||||||
pub res: SharedReset<'a>,
|
|
||||||
pub dc: SharedOutput<'a>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> SecondaryDisplayPinConfiguration<'a> {
|
|
||||||
pub fn build(self) -> [SecondaryDisplay<'a>; 3] {
|
|
||||||
let mut displays = self.cs_pins.map(|cs| {
|
|
||||||
let spi_dev = AtomicDevice::new(self.spi_bus, cs, Delay::new()).unwrap();
|
|
||||||
let interface = SPIInterface::new(spi_dev, self.dc.clone());
|
|
||||||
|
|
||||||
Ch1115::new(interface, self.res.clone(), Size128x64)
|
|
||||||
});
|
|
||||||
|
|
||||||
init_single_reset(&mut displays, self.res);
|
|
||||||
|
|
||||||
displays
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_single_reset<'a: 'b, 'b>(
|
|
||||||
displays: impl IntoIterator<Item = &'b mut SecondaryDisplay<'a>>,
|
|
||||||
shared_reset: SharedReset<'a>,
|
|
||||||
) {
|
|
||||||
let mut displays = displays.into_iter().peekable();
|
|
||||||
|
|
||||||
// Reset all secondaries via shared reset
|
|
||||||
let Some(any_display) = displays.peek_mut() else {
|
|
||||||
// no display to initialize
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
any_display.hard_reset(&mut Delay::new()).unwrap();
|
|
||||||
|
|
||||||
shared_reset.disable(true);
|
|
||||||
|
|
||||||
for (i, display) in displays.enumerate() {
|
|
||||||
display
|
|
||||||
.init(&mut Delay::new())
|
|
||||||
.map_err(|e| format!("Failed to init secondary display {}: {e:?}", i + 1))
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
pub mod inputs;
|
pub mod inputs;
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
pub mod outputs;
|
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
pub mod outputs;
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ use embedded_graphics::{
|
|||||||
pixelcolor::{Rgb565, RgbColor as _},
|
pixelcolor::{Rgb565, RgbColor as _},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::drivers::{
|
use crate::display::{
|
||||||
primary_lcd::PrimaryDisplay, secondary_oled::SecondaryDisplay, tertiary_lcd::TertiaryDisplay,
|
shared_bus::{DualPrimaryDisplay, DualSecondaryDisplay},
|
||||||
|
tertiary_lcd::TertiaryI2cLcd,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Outputs {
|
pub struct Outputs {
|
||||||
pub primary_display: PrimaryDisplay<'static>,
|
pub primary_display: DualPrimaryDisplay<'static>,
|
||||||
pub secondary_display_1: SecondaryDisplay<'static>,
|
pub secondary_display_1: DualSecondaryDisplay<'static>,
|
||||||
pub secondary_display_2: SecondaryDisplay<'static>,
|
// pub secondary_display_2: DualSecondaryDisplay<'static>,
|
||||||
pub secondary_display_3: SecondaryDisplay<'static>,
|
// pub secondary_display_3: DualSecondaryDisplay<'static>,
|
||||||
pub tertiary_display: TertiaryDisplay<'static>,
|
pub tertiary_display: TertiaryI2cLcd<'static>,
|
||||||
pub _led_a: (),
|
pub _led_a: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,7 @@ use embedded_graphics::prelude::RgbColor;
|
|||||||
use embedded_graphics_core::draw_target::DrawTarget;
|
use embedded_graphics_core::draw_target::DrawTarget;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
card::model::Card,
|
card::model::Card, navigation::{navigation::{Action, Navigable, NewState}, outputs::Outputs}, views::view::View,
|
||||||
navigation::{
|
|
||||||
navigation::{Action, Navigable, NewState},
|
|
||||||
outputs::Outputs,
|
|
||||||
},
|
|
||||||
views::view::View,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ pub struct MainMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Navigable for MainMenu {
|
impl Navigable for MainMenu {
|
||||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send
|
||||||
|
{
|
||||||
let display = &mut outputs.primary_display;
|
let display = &mut outputs.primary_display;
|
||||||
display.clear(Rgb565::BLACK).unwrap();
|
display.clear(Rgb565::BLACK).unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ pub struct ScanMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Navigable for ScanMenu {
|
impl Navigable for ScanMenu {
|
||||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send
|
||||||
|
{
|
||||||
let display = &mut outputs.primary_display;
|
let display = &mut outputs.primary_display;
|
||||||
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
||||||
display.clear(Rgb565::BLACK).unwrap();
|
display.clear(Rgb565::BLACK).unwrap();
|
||||||
|
|||||||
+3
-1
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
use crate::navigation::outputs::Outputs;
|
use crate::navigation::outputs::Outputs;
|
||||||
use crate::views::card_view::CardView;
|
use crate::views::card_view::CardView;
|
||||||
use crate::views::{
|
use crate::views::{
|
||||||
@@ -17,7 +18,8 @@ pub enum View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Navigable for View {
|
impl Navigable for View {
|
||||||
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send {
|
fn display(&self, outputs: &mut Outputs) -> impl core::future::Future<Output = ()> + Send
|
||||||
|
{
|
||||||
async move {
|
async move {
|
||||||
match self {
|
match self {
|
||||||
View::Main(main_menu) => main_menu.display(outputs).await,
|
View::Main(main_menu) => main_menu.display(outputs).await,
|
||||||
|
|||||||
Reference in New Issue
Block a user