63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
use core::error::Error;
|
|
use core::fmt::Debug;
|
|
use core::fmt::Display;
|
|
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::{DisplayError, DisplaySize240x320, Ili9341, Orientation};
|
|
|
|
use crate::drivers::spi_bus::{DisplaySpiBus, SharedOutput};
|
|
|
|
#[derive(Debug)]
|
|
pub struct PrimaryDisplayError(DisplayError);
|
|
|
|
impl Display for PrimaryDisplayError {
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
self.0.fmt(f)
|
|
}
|
|
}
|
|
|
|
impl Error for PrimaryDisplayError {}
|
|
|
|
impl From<DisplayError> for PrimaryDisplayError {
|
|
fn from(value: DisplayError) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|