60 lines
1.9 KiB
Rust
60 lines
1.9 KiB
Rust
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::display::shared_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();
|
|
}
|
|
}
|