44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
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
|
|
}
|