use embedded_graphics_core::pixelcolor::{Rgb565, Rgb666};
use embedded_hal_async::delay::DelayNs;
use crate::{
dcs::{BitsPerPixel, PixelFormat, SetAddressMode},
interface::{Interface, InterfaceKind},
models::{ili934x, Model, ModelInitError},
options::ModelOptions,
ConfigurationError,
};
pub struct ILI9341Rgb565;
pub struct ILI9341Rgb666;
impl Model for ILI9341Rgb565 {
type ColorFormat = Rgb565;
const FRAMEBUFFER_SIZE: (u16, u16) = (240, 320);
async fn init<DELAY, DI>(
&mut self,
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
) -> Result<SetAddressMode, ModelInitError<DI::Error>>
where
DELAY: DelayNs,
DI: Interface,
{
if !matches!(
DI::KIND,
InterfaceKind::Serial4Line | InterfaceKind::Parallel8Bit | InterfaceKind::Parallel16Bit
) {
return Err(ModelInitError::InvalidConfiguration(
ConfigurationError::UnsupportedInterface,
));
}
let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
ili934x::init_common(di, delay, options, pf)
.await
.map_err(Into::into)
}
}
impl Model for ILI9341Rgb666 {
type ColorFormat = Rgb666;
const FRAMEBUFFER_SIZE: (u16, u16) = (240, 320);
async fn init<DELAY, DI>(
&mut self,
di: &mut DI,
delay: &mut DELAY,
options: &ModelOptions,
) -> Result<SetAddressMode, ModelInitError<DI::Error>>
where
DELAY: DelayNs,
DI: Interface,
{
if !matches!(
DI::KIND,
InterfaceKind::Serial4Line | InterfaceKind::Parallel8Bit | InterfaceKind::Parallel16Bit
) {
return Err(ModelInitError::InvalidConfiguration(
ConfigurationError::UnsupportedInterface,
));
}
let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
ili934x::init_common(di, delay, options, pf)
.await
.map_err(Into::into)
}
}