1use crate::interface::{self, DisplayInterface};
2use embedded_graphics::prelude::GrayColor;
3use embedded_hal::blocking::delay::DelayUs;
4
5pub use self::ssd1608::SSD1608;
6
7mod ssd1608;
8
9pub trait Driver {
11 type Error;
12
13 fn wake_up<DI: DisplayInterface, DELAY: DelayUs<u32>>(
15 di: &mut DI,
16 delay: &mut DELAY,
17 ) -> Result<(), Self::Error>;
18
19 fn set_shape<DI: DisplayInterface>(di: &mut DI, x: u16, y: u16) -> Result<(), Self::Error>;
21
22 fn update_frame<'a, DI: DisplayInterface, I>(di: &mut DI, buffer: I) -> Result<(), Self::Error>
23 where
24 I: IntoIterator<Item = &'a u8>;
25
26 fn turn_on_display<DI: DisplayInterface>(di: &mut DI) -> Result<(), Self::Error>;
27
28 fn sleep<DI: DisplayInterface, DELAY: DelayUs<u32>>(
29 _di: &mut DI,
30 _delay: &mut DELAY,
31 ) -> Result<(), Self::Error> {
32 Ok(())
33 }
34}
35
36pub trait MultiColorDriver: Driver {
37 fn update_channel_frame<'a, DI: DisplayInterface, I>(
38 di: &mut DI,
39 channel: u8,
40 buffer: I,
41 ) -> Result<(), Self::Error>
42 where
43 I: IntoIterator<Item = &'a u8>;
44}
45
46pub trait GrayScaleDriver<Color: GrayColor>: Driver {
47 fn setup_gray_scale<DI: DisplayInterface>(di: &mut DI) -> Result<(), Self::Error>;
50
51 fn restore_normal_mode<DI: DisplayInterface>(di: &mut DI) -> Result<(), Self::Error>;
52}
53
54pub struct SSD1619A;
57
58impl Driver for SSD1619A {
59 type Error = interface::DisplayError;
60
61 fn wake_up<DI: DisplayInterface, DELAY: DelayUs<u32>>(
62 di: &mut DI,
63 delay: &mut DELAY,
64 ) -> Result<(), Self::Error> {
65 di.reset(delay, 200_000, 200_000);
66 di.busy_wait();
67
68 di.send_command(0x12)?; di.busy_wait();
70
71 di.send_command_data(0x74, &[0x54])?;
73 di.send_command_data(0x7e, &[0x3b])?;
74
75 di.send_command_data(0x2b, &[0x03, 0x63])?; di.send_command_data(0x0c, &[0x8b, 0x9c, 0x96, 0x0f])?; di.send_command_data(0x01, &[0x2b, 0x01, 0x00])?; di.send_command_data(0x11, &[0b11])?; di.send_command_data(0x03, &[0x20])?; di.send_command_data(0x3C, &[0x01])?; di.send_command_data(0x18, &[0x80])?;
100 di.send_command_data(0x22, &[0xb9])?; di.send_command(0x20)?;
104 di.busy_wait();
105
106 Ok(())
107 }
108
109 fn set_shape<DI: DisplayInterface>(di: &mut DI, x: u16, y: u16) -> Result<(), Self::Error> {
110 di.send_command_data(0x44, &[0x00, ((x - 1) >> 3) as u8])?;
112
113 di.send_command_data(
115 0x45,
116 &[0x00, 0x00, ((y - 1) & 0xff) as u8, ((y - 1) >> 8) as u8],
117 )?;
118 di.send_command_data(0x4e, &[0])?; di.send_command_data(0x4f, &[0, 0])?; Ok(())
122 }
123
124 fn update_frame<'a, DI: DisplayInterface, I>(di: &mut DI, buffer: I) -> Result<(), Self::Error>
125 where
126 I: IntoIterator<Item = &'a u8>,
127 {
128 di.send_command_data(0x4e, &[0])?; di.send_command_data(0x4f, &[0, 0])?; di.send_command(0x24)?;
132 di.send_data_from_iter(buffer)?;
133
134 Ok(())
135 }
136
137 fn turn_on_display<DI: DisplayInterface>(di: &mut DI) -> Result<(), Self::Error> {
138 di.send_command_data(0x22, &[0xf7])?; di.send_command(0x20)?; di.busy_wait();
141 Ok(())
142 }
143}
144
145impl MultiColorDriver for SSD1619A {
146 fn update_channel_frame<'a, DI: DisplayInterface, I>(
147 di: &mut DI,
148 channel: u8,
149 buffer: I,
150 ) -> Result<(), Self::Error>
151 where
152 I: IntoIterator<Item = &'a u8>,
153 {
154 di.send_command_data(0x4e, &[0])?; di.send_command_data(0x4f, &[0, 0])?; if channel == 0 {
158 di.send_command(0x24)?;
159 di.send_data_from_iter(buffer)?;
160 } else if channel == 1 {
161 di.send_command(0x26)?;
162 di.send_data_from_iter(buffer)?;
163 } else {
164 }
166
167 Ok(())
168 }
169}