lcd_async/models/
ili9486.rs1use embedded_graphics_core::pixelcolor::{Rgb565, Rgb666};
2use embedded_hal_async::delay::DelayNs;
3
4use crate::{
5 dcs::{BitsPerPixel, PixelFormat, SetAddressMode},
6 interface::{Interface, InterfaceKind},
7 models::{ili948x, Model, ModelInitError},
8 options::ModelOptions,
9 ConfigurationError,
10};
11
12pub struct ILI9486Rgb565;
14
15pub struct ILI9486Rgb666;
17
18impl Model for ILI9486Rgb565 {
19 type ColorFormat = Rgb565;
20 const FRAMEBUFFER_SIZE: (u16, u16) = (320, 480);
21
22 async fn init<DELAY, DI>(
23 &mut self,
24 di: &mut DI,
25 delay: &mut DELAY,
26 options: &ModelOptions,
27 ) -> Result<SetAddressMode, ModelInitError<DI::Error>>
28 where
29 DELAY: DelayNs,
30 DI: Interface,
31 {
32 if !matches!(
33 DI::KIND,
34 InterfaceKind::Parallel8Bit | InterfaceKind::Parallel16Bit
35 ) {
36 return Err(ModelInitError::InvalidConfiguration(
37 ConfigurationError::UnsupportedInterface,
38 ));
39 }
40
41 delay.delay_us(120_000).await;
42
43 let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
44 ili948x::init_common(di, delay, options, pf).await
45 }
46}
47
48impl Model for ILI9486Rgb666 {
49 type ColorFormat = Rgb666;
50 const FRAMEBUFFER_SIZE: (u16, u16) = (320, 480);
51
52 async fn init<DELAY, DI>(
53 &mut self,
54 di: &mut DI,
55 delay: &mut DELAY,
56 options: &ModelOptions,
57 ) -> Result<SetAddressMode, ModelInitError<DI::Error>>
58 where
59 DELAY: DelayNs,
60 DI: Interface,
61 {
62 if !matches!(
63 DI::KIND,
64 InterfaceKind::Serial4Line | InterfaceKind::Parallel8Bit | InterfaceKind::Parallel16Bit
65 ) {
66 return Err(ModelInitError::InvalidConfiguration(
67 ConfigurationError::UnsupportedInterface,
68 ));
69 }
70
71 delay.delay_us(120_000).await;
72
73 let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
74 ili948x::init_common(di, delay, options, pf).await
75 }
76}