lcd_async/models/
ili9342c.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::{ili934x, Model, ModelInitError},
8 options::ModelOptions,
9 ConfigurationError,
10};
11
12pub struct ILI9342CRgb565;
14
15pub struct ILI9342CRgb666;
17
18impl Model for ILI9342CRgb565 {
19 type ColorFormat = Rgb565;
20 const FRAMEBUFFER_SIZE: (u16, u16) = (320, 240);
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::Serial4Line | InterfaceKind::Parallel8Bit | InterfaceKind::Parallel16Bit
35 ) {
36 return Err(ModelInitError::InvalidConfiguration(
37 ConfigurationError::UnsupportedInterface,
38 ));
39 }
40
41 let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
42 ili934x::init_common(di, delay, options, pf)
43 .await
44 .map_err(Into::into)
45 }
46}
47
48impl Model for ILI9342CRgb666 {
49 type ColorFormat = Rgb666;
50 const FRAMEBUFFER_SIZE: (u16, u16) = (320, 240);
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 let pf = PixelFormat::with_all(BitsPerPixel::from_rgb_color::<Self::ColorFormat>());
72 ili934x::init_common(di, delay, options, pf)
73 .await
74 .map_err(Into::into)
75 }
76}