1use crate::command::{Command, DataInterval, DataPolarity};
2use crate::config::Config;
3use crate::interface::DisplayInterface;
4use hal;
5
6pub const MAX_GATE_OUTPUTS: u16 = 296;
9pub const MAX_SOURCE_OUTPUTS: u8 = 160;
11
12pub struct Dimensions {
14 pub rows: u16,
18 pub cols: u8,
22}
23
24#[derive(Clone, Copy)]
30pub enum Rotation {
31 Rotate0,
32 Rotate90,
33 Rotate180,
34 Rotate270,
35}
36
37impl Default for Rotation {
38 fn default() -> Self {
40 Rotation::Rotate0
41 }
42}
43
44pub struct Display<I>
46where
47 I: DisplayInterface,
48{
49 interface: I,
50 config: Config,
51}
52
53impl<I> Display<I>
54where
55 I: DisplayInterface,
56{
57 pub fn new(interface: I, config: Config) -> Self {
61 Self { interface, config }
62 }
63
64 pub fn reset<D: hal::delay::DelayNs>(&mut self, delay: &mut D) -> Result<(), I::Error> {
68 self.interface.reset(delay);
69 self.init(delay)
70 }
71
72 fn init<D: hal::delay::DelayNs>(&mut self, delay: &mut D) -> Result<(), I::Error> {
74 self.config.power_setting.execute(&mut self.interface)?;
75 self.config
76 .booster_soft_start
77 .execute(&mut self.interface)?;
78 Command::PowerOn.execute(&mut self.interface)?;
79 delay.delay_ms(200);
80 self.config.panel_setting.execute(&mut self.interface)?;
81 Command::VCOMDataIntervalSetting(0x0, DataPolarity::Both, DataInterval::V10)
82 .execute(&mut self.interface)?;
83 self.config.pll.execute(&mut self.interface)?;
84 Command::VCMDCSetting(0xA).execute(&mut self.interface)?;
85 delay.delay_ms(20);
86 Command::ResolutionSetting(self.config.dimensions.cols, self.config.dimensions.rows)
87 .execute(&mut self.interface)?;
88 Ok(())
89 }
90
91 pub fn signal_update(&mut self) -> Result<(), I::Error> {
93 Command::DisplayRefresh.execute(&mut self.interface)
95 }
96
97 fn power_down(&mut self) -> Result<(), I::Error> {
98 self.interface.busy_wait();
99 Command::VCOMDataIntervalSetting(0x0, DataPolarity::BWOnly, DataInterval::V10)
100 .execute(&mut self.interface)?;
101 Command::VCMDCSetting(0).execute(&mut self.interface)?;
102 Command::PowerOff.execute(&mut self.interface)
103 }
104
105 pub fn deep_sleep(&mut self) -> Result<(), I::Error> {
110 self.power_down()?;
111 Command::DeepSleep.execute(&mut self.interface)
112 }
113
114 pub fn rows(&self) -> u16 {
116 self.config.dimensions.rows
117 }
118
119 pub fn cols(&self) -> u8 {
121 self.config.dimensions.cols
122 }
123
124 pub fn rotation(&self) -> Rotation {
126 self.config.rotation
127 }
128
129 pub fn interface(&mut self) -> &mut I {
131 &mut self.interface
132 }
133}