62 lines
1.8 KiB
Rust
62 lines
1.8 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_bus::spi::ExclusiveDevice;
|
|
use esp_hal::delay::Delay;
|
|
use esp_hal::gpio::{Level, Output, OutputConfig};
|
|
use esp_hal::peripherals::{GPIO10, GPIO11, GPIO12, GPIO35, GPIO36, GPIO37, SPI2};
|
|
use esp_hal::spi::{
|
|
Mode,
|
|
master::{Config, Spi},
|
|
};
|
|
use esp_hal::time::Rate;
|
|
use ili9341::{DisplaySize240x320, Ili9341, Orientation};
|
|
|
|
pub type PrimaryLcdDisplay<'a> = Ili9341<
|
|
SPIInterface<ExclusiveDevice<Spi<'a, esp_hal::Blocking>, Output<'a>, Delay>, Output<'a>>,
|
|
Output<'a>,
|
|
>;
|
|
|
|
pub fn init_primary_lcd(
|
|
spi2: SPI2<'static>,
|
|
sck: GPIO36<'static>,
|
|
mosi: GPIO35<'static>,
|
|
miso: GPIO37<'static>,
|
|
cs: GPIO11<'static>,
|
|
reset: GPIO10<'static>,
|
|
dc: GPIO12<'static>,
|
|
) -> PrimaryLcdDisplay<'static> {
|
|
let freq = Rate::from_khz(60_000);
|
|
log::info!("Display freq: {freq}");
|
|
|
|
let spi_bus = Spi::new(
|
|
spi2,
|
|
Config::default().with_frequency(freq).with_mode(Mode::_0),
|
|
)
|
|
.unwrap()
|
|
.with_sck(sck)
|
|
.with_mosi(mosi)
|
|
.with_miso(miso);
|
|
|
|
let mut delay = Delay::new();
|
|
|
|
let cs_main = Output::new(cs, Level::High, OutputConfig::default());
|
|
let spi_dev = ExclusiveDevice::new(spi_bus, cs_main, delay).unwrap();
|
|
let reset_main = Output::new(reset, Level::High, OutputConfig::default());
|
|
let spi_dc = Output::new(dc, Level::High, OutputConfig::default());
|
|
let iface = SPIInterface::new(spi_dev, spi_dc);
|
|
|
|
let mut display = Ili9341::new(
|
|
iface,
|
|
reset_main,
|
|
&mut delay,
|
|
Orientation::Portrait,
|
|
DisplaySize240x320,
|
|
)
|
|
.unwrap();
|
|
|
|
display.clear(Rgb565::BLACK).unwrap();
|
|
display
|
|
}
|