Triple oled #37
+16
-10
@@ -10,7 +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::display::shared_bus::{self, DualSecondaryDisplay};
|
use creaturedex::display::secondary_oled::DualSecondaryDisplay;
|
||||||
|
use creaturedex::display::shared_bus;
|
||||||
use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, init_tertiary_lcd, write_wrapped};
|
use creaturedex::display::tertiary_lcd::{TertiaryI2cLcd, 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;
|
||||||
@@ -66,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 (display, mut oled) = shared_bus::DisplayPinConfiguration {
|
let (primary, mut secondaries) = shared_bus::DisplayPinConfiguration {
|
||||||
spi_peripheral: peripherals.SPI2,
|
spi_peripheral: peripherals.SPI2,
|
||||||
sck: peripherals.GPIO36,
|
sck: peripherals.GPIO36,
|
||||||
mosi: peripherals.GPIO35,
|
mosi: peripherals.GPIO35,
|
||||||
@@ -120,15 +121,20 @@ async fn main(spawner: Spawner) {
|
|||||||
ok: Input::new(peripherals.GPIO0, button_config),
|
ok: Input::new(peripherals.GPIO0, button_config),
|
||||||
};
|
};
|
||||||
|
|
||||||
display_shit(&mut oled);
|
display_shit(&mut secondaries[0], "foo 1");
|
||||||
|
display_shit(&mut secondaries[1], "bar 1");
|
||||||
|
display_shit(&mut secondaries[2], "baz 1");
|
||||||
|
|
||||||
let outputs = Outputs {
|
let outputs = {
|
||||||
primary_display: display,
|
let [sec_1, sec_2, sec_3] = secondaries;
|
||||||
secondary_display_1: oled,
|
Outputs {
|
||||||
// secondary_display_2: todo!(),
|
primary_display: primary,
|
||||||
// secondary_display_3: todo!(),
|
secondary_display_1: sec_1,
|
||||||
|
secondary_display_2: sec_2,
|
||||||
|
secondary_display_3: sec_3,
|
||||||
tertiary_display: lcd,
|
tertiary_display: lcd,
|
||||||
_led_a: (),
|
_led_a: (),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("Setup complete, entering main loop");
|
log::info!("Setup complete, entering main loop");
|
||||||
@@ -173,11 +179,11 @@ async fn nfc_driver_task(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_shit(oled: &mut DualSecondaryDisplay<'static>) {
|
fn display_shit(oled: &mut DualSecondaryDisplay<'static>, text: &str) {
|
||||||
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("Hello OLED", Point::new(10, 20), text_style)
|
Text::new(text, Point::new(10, 20), text_style)
|
||||||
.draw(oled)
|
.draw(oled)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
oled.flush().unwrap();
|
oled.flush().unwrap();
|
||||||
|
|||||||
+21
-22
@@ -2,37 +2,35 @@ use display_interface_spi::SPIInterface;
|
|||||||
use embedded_graphics::draw_target::DrawTarget;
|
use embedded_graphics::draw_target::DrawTarget;
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
use embedded_graphics::prelude::RgbColor;
|
use embedded_graphics::prelude::RgbColor;
|
||||||
use embedded_hal::digital::OutputPin as EhOutputPin;
|
|
||||||
use embedded_hal_bus::spi::AtomicDevice;
|
use embedded_hal_bus::spi::AtomicDevice;
|
||||||
use embedded_hal_bus::util::AtomicCell;
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
use esp_hal::delay::Delay;
|
use esp_hal::delay::Delay;
|
||||||
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
use esp_hal::gpio::Output;
|
||||||
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
||||||
|
|
||||||
pub type PrimaryLcdDisplay<'a, BUS, DC, RES> =
|
use crate::display::shared_bus::{DisplaySpiBus, SharedOutput};
|
||||||
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
|
||||||
|
|
||||||
pub fn init_primary_lcd_on_bus<'a, BUS, CS, RES, DC>(
|
type GenericDualPrimaryDisplay<'a, BUS, DC, RES> =
|
||||||
spi_bus: &'a AtomicCell<BUS>,
|
Ili9341<SPIInterface<AtomicDevice<'a, BUS, Output<'a>, Delay>, DC>, RES>;
|
||||||
cs: CS,
|
pub type DualPrimaryDisplay<'a> =
|
||||||
reset: RES,
|
GenericDualPrimaryDisplay<'a, DisplaySpiBus, SharedOutput<'a>, Output<'a>>;
|
||||||
dc: DC,
|
|
||||||
delay: &mut Delay,
|
pub struct PrimaryDisplayPinConfiguration<'a> {
|
||||||
) -> PrimaryLcdDisplay<'a, BUS, DC, RES>
|
pub spi_bus: &'a AtomicCell<DisplaySpiBus>,
|
||||||
where
|
pub cs: Output<'a>,
|
||||||
BUS: embedded_hal::spi::SpiBus,
|
pub reset: Output<'a>,
|
||||||
CS: OutputPin + 'static,
|
pub dc: SharedOutput<'a>,
|
||||||
RES: EhOutputPin,
|
}
|
||||||
DC: EhOutputPin,
|
|
||||||
{
|
impl<'a> PrimaryDisplayPinConfiguration<'a> {
|
||||||
let cs_pin = Output::new(cs, Level::High, OutputConfig::default());
|
pub fn build(self) -> DualPrimaryDisplay<'a> {
|
||||||
let spi_dev = AtomicDevice::new(spi_bus, cs_pin, *delay).unwrap();
|
let spi_dev = AtomicDevice::new(self.spi_bus, self.cs, Delay::new()).unwrap();
|
||||||
let iface = SPIInterface::new(spi_dev, dc);
|
let iface = SPIInterface::new(spi_dev, self.dc);
|
||||||
|
|
||||||
let mut display = Ili9341::new(
|
let mut display = Ili9341::new(
|
||||||
iface,
|
iface,
|
||||||
reset,
|
self.reset,
|
||||||
delay,
|
&mut Delay::new(),
|
||||||
Orientation::Portrait,
|
Orientation::Portrait,
|
||||||
DisplaySize240x320,
|
DisplaySize240x320,
|
||||||
)
|
)
|
||||||
@@ -41,3 +39,4 @@ where
|
|||||||
display.clear(Rgb565::BLACK).unwrap();
|
display.clear(Rgb565::BLACK).unwrap();
|
||||||
display
|
display
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,34 +1,59 @@
|
|||||||
|
use alloc::format;
|
||||||
use ch1115::{Ch1115, Size128x64};
|
use ch1115::{Ch1115, Size128x64};
|
||||||
use display_interface_spi::SPIInterface;
|
use display_interface_spi::SPIInterface;
|
||||||
use embedded_hal::digital::OutputPin as EhOutputPin;
|
|
||||||
use embedded_hal_bus::spi::AtomicDevice;
|
use embedded_hal_bus::spi::AtomicDevice;
|
||||||
use embedded_hal_bus::util::AtomicCell;
|
use embedded_hal_bus::util::AtomicCell;
|
||||||
use esp_hal::delay::Delay;
|
use esp_hal::delay::Delay;
|
||||||
use esp_hal::gpio::{Level, Output, OutputConfig, OutputPin};
|
use esp_hal::gpio::Output;
|
||||||
|
|
||||||
|
use crate::display::shared_bus::{DisplaySpiBus, SharedOutput, SharedReset};
|
||||||
|
|
||||||
pub type SecondaryOledDisplay<'a, BUS, RST, DC> =
|
pub type SecondaryOledDisplay<'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>;
|
||||||
|
pub type DualSecondaryDisplay<'a> =
|
||||||
|
SecondaryOledDisplay<'a, DisplaySpiBus, SharedReset<'a>, SharedOutput<'a>>;
|
||||||
|
|
||||||
pub fn init_secondary_oled_on_bus<'a, BUS, CS, RES, DC>(
|
pub struct SecondaryDisplayPinConfiguration<'a> {
|
||||||
spi_bus: &'a AtomicCell<BUS>,
|
pub spi_bus: &'a AtomicCell<DisplaySpiBus>,
|
||||||
cs: CS,
|
pub cs_pins: [Output<'a>; 3],
|
||||||
res: RES,
|
pub res: SharedReset<'a>,
|
||||||
dc: DC,
|
pub dc: SharedOutput<'a>,
|
||||||
delay: &mut Delay,
|
}
|
||||||
) -> SecondaryOledDisplay<'a, BUS, RES, DC>
|
|
||||||
where
|
impl<'a> SecondaryDisplayPinConfiguration<'a> {
|
||||||
BUS: embedded_hal::spi::SpiBus,
|
pub fn build(self) -> [DualSecondaryDisplay<'a>; 3] {
|
||||||
CS: OutputPin + 'static,
|
let mut displays = self.cs_pins.map(|cs| {
|
||||||
RES: EhOutputPin,
|
let spi_dev = AtomicDevice::new(self.spi_bus, cs, Delay::new()).unwrap();
|
||||||
DC: EhOutputPin,
|
let interface = SPIInterface::new(spi_dev, self.dc.clone());
|
||||||
{
|
|
||||||
let cs_pin = Output::new(cs, Level::High, OutputConfig::default());
|
Ch1115::new(interface, self.res.clone(), Size128x64)
|
||||||
let spi_dev = AtomicDevice::new(spi_bus, cs_pin, *delay).unwrap();
|
});
|
||||||
let interface = SPIInterface::new(spi_dev, dc);
|
|
||||||
|
init_single_reset(&mut displays, self.res);
|
||||||
let mut display = Ch1115::new(interface, res, Size128x64);
|
|
||||||
|
displays
|
||||||
display.init(&mut Delay::new()).unwrap();
|
}
|
||||||
|
}
|
||||||
display
|
|
||||||
|
fn init_single_reset<'a: 'b, 'b>(
|
||||||
|
displays: impl IntoIterator<Item = &'b mut DualSecondaryDisplay<'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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-33
@@ -3,15 +3,16 @@ 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::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd_on_bus};
|
use crate::display::primary_lcd::DualPrimaryDisplay;
|
||||||
use crate::display::secondary_oled::{SecondaryOledDisplay, init_secondary_oled_on_bus};
|
use crate::display::primary_lcd::PrimaryDisplayPinConfiguration;
|
||||||
|
use crate::display::secondary_oled::DualSecondaryDisplay;
|
||||||
|
use crate::display::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;
|
||||||
@@ -101,13 +102,9 @@ impl<'a, P: EhOutputPin> EhOutputPin for SharedResetPin<'a, P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SharedOutput<'a> = SharedPin<'a, Output<'a>>;
|
pub type SharedOutput<'a> = SharedPin<'a, Output<'a>>;
|
||||||
type SharedReset<'a> = SharedResetPin<'a, Output<'a>>;
|
pub 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,
|
||||||
@@ -138,7 +135,12 @@ where
|
|||||||
RES2: OutputPin + 'static,
|
RES2: OutputPin + 'static,
|
||||||
DC: OutputPin + 'static,
|
DC: OutputPin + 'static,
|
||||||
{
|
{
|
||||||
pub fn build(self) -> (DualPrimaryDisplay<'static>, DualSecondaryDisplay<'static>) {
|
pub fn build(
|
||||||
|
self,
|
||||||
|
) -> (
|
||||||
|
DualPrimaryDisplay<'static>,
|
||||||
|
[DualSecondaryDisplay<'static>; 3],
|
||||||
|
) {
|
||||||
let spi = Spi::new(
|
let spi = Spi::new(
|
||||||
self.spi_peripheral,
|
self.spi_peripheral,
|
||||||
SpiConfig::default()
|
SpiConfig::default()
|
||||||
@@ -151,7 +153,6 @@ 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,
|
||||||
@@ -161,31 +162,31 @@ where
|
|||||||
Level::High,
|
Level::High,
|
||||||
OutputConfig::default(),
|
OutputConfig::default(),
|
||||||
));
|
));
|
||||||
let mut delay = Delay::new();
|
|
||||||
|
|
||||||
let primary = init_primary_lcd_on_bus(
|
let primary = PrimaryDisplayPinConfiguration {
|
||||||
bus_static,
|
spi_bus: bus_static,
|
||||||
self.cs_primary,
|
cs: low_active(self.cs_primary),
|
||||||
reset_primary,
|
reset: low_active(self.reset_primary),
|
||||||
dc.clone(),
|
dc: dc.clone(),
|
||||||
&mut delay,
|
}
|
||||||
);
|
.build();
|
||||||
|
|
||||||
// TODO
|
let secondaries = SecondaryDisplayPinConfiguration {
|
||||||
// Build display
|
spi_bus: bus_static,
|
||||||
// Trigger reset
|
cs_pins: [
|
||||||
// disable init
|
low_active(self.cs_secondary_1),
|
||||||
// rest of init code
|
low_active(self.cs_secondary_2),
|
||||||
|
low_active(self.cs_secondary_3),
|
||||||
|
],
|
||||||
let secondary = init_secondary_oled_on_bus(
|
res: reset_secondary,
|
||||||
bus_static,
|
|
||||||
self.cs_secondary_1,
|
|
||||||
reset_secondary,
|
|
||||||
dc,
|
dc,
|
||||||
&mut delay,
|
}
|
||||||
);
|
.build();
|
||||||
|
|
||||||
(primary, secondary)
|
(primary, secondaries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn low_active<'a, CS: OutputPin + 'a>(pin: CS) -> Output<'a> {
|
||||||
|
Output::new(pin, Level::High, OutputConfig::default())
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,10 +47,7 @@ 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(
|
let area = Rectangle::new(Point::new(start_x, start_y), Size::new(width, height));
|
||||||
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,15 +4,15 @@ use embedded_graphics::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::display::{
|
use crate::display::{
|
||||||
shared_bus::{DualPrimaryDisplay, DualSecondaryDisplay},
|
primary_lcd::DualPrimaryDisplay, secondary_oled::DualSecondaryDisplay,
|
||||||
tertiary_lcd::TertiaryI2cLcd,
|
tertiary_lcd::TertiaryI2cLcd,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Outputs {
|
pub struct Outputs {
|
||||||
pub primary_display: DualPrimaryDisplay<'static>,
|
pub primary_display: DualPrimaryDisplay<'static>,
|
||||||
pub secondary_display_1: DualSecondaryDisplay<'static>,
|
pub secondary_display_1: DualSecondaryDisplay<'static>,
|
||||||
// pub secondary_display_2: DualSecondaryDisplay<'static>,
|
pub secondary_display_2: DualSecondaryDisplay<'static>,
|
||||||
// pub secondary_display_3: DualSecondaryDisplay<'static>,
|
pub secondary_display_3: DualSecondaryDisplay<'static>,
|
||||||
pub tertiary_display: TertiaryI2cLcd<'static>,
|
pub tertiary_display: TertiaryI2cLcd<'static>,
|
||||||
pub _led_a: (),
|
pub _led_a: (),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user