use embedded_graphics_core::pixelcolor::Rgb565;
use embedded_hal::delay::DelayNs;
use mipidsi::{
dcs::{
BitsPerPixel, EnterNormalMode, ExitSleepMode, InterfaceExt, PixelFormat, SetAddressMode,
SetDisplayOn, SetInvertMode, SetPixelFormat,
},
interface::Interface,
models::{Model, ModelInitError},
options::ModelOptions,
};
pub struct ExternalST7789;
impl Model for ExternalST7789 {
type ColorFormat = Rgb565;
const FRAMEBUFFER_SIZE: (u16, u16) = (240, 320);
fn init<DELAY, DI>(
&mut self,
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
) -> Result<SetAddressMode, ModelInitError<DI::Error>>
where
DELAY: DelayNs,
DI: Interface,
{
let madctl = SetAddressMode::from(options);
delay.delay_us(150_000);
di.write_command(ExitSleepMode)?;
delay.delay_us(10_000);
di.write_command(madctl)?;
di.write_command(SetInvertMode::new(options.invert_colors))?;
let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
di.write_command(SetPixelFormat::new(pf))?;
delay.delay_us(10_000);
di.write_command(EnterNormalMode)?;
delay.delay_us(10_000);
di.write_command(SetDisplayOn)?;
delay.delay_us(120_000);
Ok(madctl)
}
}