lcd_async/dcs.rs
1//! MIPI DCS commands.
2
3use crate::interface::Interface;
4
5#[macro_use]
6pub(crate) mod macros;
7
8mod set_address_mode;
9pub use set_address_mode::*;
10mod set_pixel_format;
11pub use set_pixel_format::*;
12mod set_column_address;
13pub use set_column_address::*;
14mod set_page_address;
15pub use set_page_address::*;
16mod set_scroll_area;
17pub use set_scroll_area::*;
18mod set_scroll_start;
19pub use set_scroll_start::*;
20mod set_tearing_effect;
21pub use set_tearing_effect::*;
22mod set_invert_mode;
23pub use set_invert_mode::*;
24
25/// Common trait for DCS commands.
26///
27/// The methods in this traits are used to convert a DCS command into bytes.
28pub trait DcsCommand {
29 /// Returns the instruction code.
30 fn instruction(&self) -> u8;
31
32 /// Fills the given buffer with the command parameters.
33 fn fill_params_buf(&self, buffer: &mut [u8]) -> usize;
34}
35
36/// An extension trait for [`Interface`] with support for writing DCS commands.
37///
38/// Commands which are part of the manufacturer independent user command set can be sent to the
39/// display by using the [`write_command`](Self::write_command) method with one of the command types
40/// in this module.
41///
42/// All other commands, which do not have an associated type in this module, can be sent using
43/// the [`write_raw`](Self::write_raw) method.
44pub trait InterfaceExt: Interface {
45 /// Sends a DCS command to the display interface.
46 fn write_command(
47 &mut self,
48 command: impl DcsCommand,
49 ) -> impl core::future::Future<Output = Result<(), Self::Error>> {
50 async move {
51 let mut param_bytes: [u8; 16] = [0; 16];
52 let n = command.fill_params_buf(&mut param_bytes);
53 self.write_raw(command.instruction(), ¶m_bytes[..n])
54 .await
55 }
56 }
57
58 /// Sends a raw command with the given `instruction` to the display interface.
59 ///
60 /// The `param_bytes` slice can contain the instruction parameters, which are sent as data after
61 /// the instruction code was sent. If no parameters are required an empty slice can be passed to
62 /// this method.
63 ///
64 /// This method is intended to be used for sending commands which are not part of the MIPI DCS
65 /// user command set. Use [`write_command`](Self::write_command) for commands in the user
66 /// command set.
67 fn write_raw(
68 &mut self,
69 instruction: u8,
70 param_bytes: &[u8],
71 ) -> impl core::future::Future<Output = Result<(), Self::Error>> {
72 async move { self.send_command(instruction, param_bytes).await }
73 }
74}
75
76impl<T: Interface> InterfaceExt for T {}
77
78// DCS commands that don't use any parameters
79
80dcs_basic_command!(
81 /// Software Reset
82 SoftReset,
83 0x01
84);
85dcs_basic_command!(
86 /// Enter Sleep Mode
87 EnterSleepMode,
88 0x10
89);
90dcs_basic_command!(
91 /// Exit Sleep Mode
92 ExitSleepMode,
93 0x11
94);
95dcs_basic_command!(
96 /// Enter Partial Mode
97 EnterPartialMode,
98 0x12
99);
100dcs_basic_command!(
101 /// Enter Normal Mode
102 EnterNormalMode,
103 0x13
104);
105dcs_basic_command!(
106 /// Turn Display Off
107 SetDisplayOff,
108 0x28
109);
110
111dcs_basic_command!(
112 /// Turn Display On
113 SetDisplayOn,
114 0x29
115);
116dcs_basic_command!(
117 /// Exit Idle Mode
118 ExitIdleMode,
119 0x38
120);
121dcs_basic_command!(
122 /// Enter Idle Mode
123 EnterIdleMode,
124 0x39
125);
126// dcs_basic_command!(
127// /// Turn off Color Invert Mode
128// ExitInvertMode,
129// 0x21
130// );
131// dcs_basic_command!(
132// /// Turn on Color Invert Mode
133// EnterInvertMode,
134// 0x20
135// );
136dcs_basic_command!(
137 /// Initiate Framebuffer Memory Write
138 WriteMemoryStart,
139 0x2C
140);