57 lines
1.8 KiB
Rust
57 lines
1.8 KiB
Rust
use embassy_rp::{
|
|
Peri,
|
|
gpio::{Level, Output},
|
|
spi::{self, Spi},
|
|
};
|
|
use embassy_time::Timer;
|
|
use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget};
|
|
use embedded_hal_bus::spi::ExclusiveDevice;
|
|
use mipidsi::{
|
|
Builder,
|
|
interface::SpiInterface,
|
|
models::ST7789,
|
|
options::{Orientation, Rotation},
|
|
};
|
|
use static_cell::StaticCell;
|
|
|
|
pub async fn init_display(
|
|
inner: Peri<'static, embassy_rp::peripherals::SPI0>,
|
|
clk: Peri<'static, embassy_rp::peripherals::PIN_6>,
|
|
mosi: Peri<'static, embassy_rp::peripherals::PIN_7>,
|
|
cs: Peri<'static, embassy_rp::peripherals::PIN_5>,
|
|
dc: Peri<'static, embassy_rp::peripherals::PIN_9>,
|
|
rst: Peri<'static, embassy_rp::peripherals::PIN_10>,
|
|
) -> Result<impl DrawTarget<Color = Rgb565>, ()> {
|
|
let mut spi_cfg = spi::Config::default();
|
|
spi_cfg.frequency = 62_500_000;
|
|
|
|
let spi = Spi::new_blocking_txonly(inner, clk, mosi, spi_cfg);
|
|
|
|
let cs_display = Output::new(cs, Level::Low);
|
|
let dc_display = Output::new(dc, Level::Low);
|
|
let mut rst_display = Output::new(rst, Level::Low);
|
|
|
|
rst_display.set_low();
|
|
Timer::after_millis(10).await;
|
|
rst_display.set_high();
|
|
Timer::after_millis(120).await;
|
|
|
|
let spi_dev = ExclusiveDevice::new_no_delay(spi, cs_display).expect("Error is Infallible");
|
|
|
|
static BUFFER: StaticCell<[u8; 512]> = StaticCell::new();
|
|
let buffer: &'static mut [u8; 512] = BUFFER.init([0u8; 512]);
|
|
|
|
let di = SpiInterface::new(spi_dev, dc_display, buffer);
|
|
|
|
static DELAY: StaticCell<embassy_time::Delay> = StaticCell::new();
|
|
let delay = DELAY.init(embassy_time::Delay);
|
|
|
|
let display = Builder::new(ST7789, di)
|
|
.display_size(240, 320)
|
|
.orientation(Orientation::new().rotate(Rotation::Deg90))
|
|
.init(delay)
|
|
.map_err(|_| ())?; // TODO: pass error
|
|
|
|
Ok(display)
|
|
}
|