|
1 |
| -pub mod hd44780; |
2 | 1 | pub mod aip31068;
|
| 2 | +pub mod hd44780; |
| 3 | +pub mod st7032i; |
| 4 | +pub mod standard; |
3 | 5 |
|
4 | 6 | use embedded_hal::{delay::DelayNs, i2c};
|
5 | 7 |
|
6 |
| -use crate::{CharacterDisplayError, DeviceSetupConfig}; |
| 8 | +use crate::{CharacterDisplayError, DeviceSetupConfig, LcdDisplayType}; |
7 | 9 |
|
8 |
| -pub trait DriverTrait<I2C, DELAY>: Default |
| 10 | +/// Trait for device hardware implementations. Embodies the hardware-specific |
| 11 | +/// functionality of the device driver IC. The trait is intended to be implemented |
| 12 | +/// for the specific device driver ICs. |
| 13 | +pub trait DeviceHardwareTrait<I2C, DELAY> |
9 | 14 | where
|
10 | 15 | I2C: i2c::I2c,
|
11 | 16 | DELAY: DelayNs,
|
12 | 17 | {
|
| 18 | + fn new(config: DeviceSetupConfig<I2C, DELAY>) -> Self; |
13 | 19 | /// returns the default I2C address for the device
|
14 | 20 | fn default_i2c_address() -> u8;
|
15 | 21 |
|
16 | 22 | /// returns whether reads are supported by the device
|
17 | 23 | fn supports_reads() -> bool;
|
18 | 24 |
|
19 |
| - /// Initialize the display |
20 |
| - fn init( |
| 25 | + /// returns LCD type |
| 26 | + fn lcd_type(&self) -> LcdDisplayType; |
| 27 | + |
| 28 | + /// returns configured i2c address |
| 29 | + fn i2c_address(&self) -> u8; |
| 30 | + |
| 31 | + /// return a immutable reference to the delay object |
| 32 | + fn delay(&mut self) -> &mut DELAY; |
| 33 | + |
| 34 | + /// returns the i2c object. mostly used for testing |
| 35 | + fn i2c(&mut self) -> &mut I2C; |
| 36 | + |
| 37 | + /// initializes the device hardware. On `Ok`, returns the initial configuration |
| 38 | + /// of the device. The configuration is a tuple of three bytes: |
| 39 | + /// (display_function, display_control, display_mode) |
| 40 | + fn init(&mut self) -> Result<(u8, u8, u8), CharacterDisplayError<I2C>>; |
| 41 | + |
| 42 | + fn write_bytes( |
21 | 43 | &mut self,
|
22 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 44 | + rs_setting: bool, |
| 45 | + data: &[u8], |
| 46 | + ) -> Result<(), CharacterDisplayError<I2C>>; |
| 47 | +} |
| 48 | + |
| 49 | +/// Trait for display actions. Embodies the display commnands that can be performed on the device. |
| 50 | +/// Works with the `DeviceHardwareTrait` to perform the actions on the device to effect the desire |
| 51 | +/// display operation. |
| 52 | +pub trait DisplayActionsTrait<I2C, DELAY, DEVICE>: Default |
| 53 | +where |
| 54 | + I2C: i2c::I2c, |
| 55 | + DELAY: DelayNs, |
| 56 | + DEVICE: DeviceHardwareTrait<I2C, DELAY>, |
| 57 | +{ |
| 58 | + /// Initialize the display state. Intended to be called once after the device is initialized |
| 59 | + /// and before any other operations are performed. The three parameters are the initial values |
| 60 | + /// and are recieved from the `DeviceHardwareTrait::init` method of the device. |
| 61 | + fn init_display_state( |
| 62 | + &mut self, |
| 63 | + display_function: u8, |
| 64 | + display_control: u8, |
| 65 | + display_mode: u8, |
23 | 66 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
24 | 67 |
|
25 | 68 | /// Clear the display
|
26 |
| - fn clear( |
27 |
| - &mut self, |
28 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
29 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 69 | + fn clear(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
30 | 70 |
|
31 | 71 | /// Set the cursor to the home position.
|
32 |
| - fn home( |
33 |
| - &mut self, |
34 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
35 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 72 | + fn home(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
36 | 73 |
|
37 | 74 | /// Set the cursor position at specified column and row. Columns and rows are zero-indexed.
|
38 | 75 | fn set_cursor(
|
39 | 76 | &mut self,
|
40 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 77 | + device: &mut DEVICE, |
41 | 78 | col: u8,
|
42 | 79 | row: u8,
|
43 | 80 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
44 | 81 |
|
45 | 82 | /// Set the cursor visibility.
|
46 | 83 | fn show_cursor(
|
47 | 84 | &mut self,
|
48 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 85 | + device: &mut DEVICE, |
49 | 86 | show_cursor: bool,
|
50 | 87 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
51 | 88 |
|
52 | 89 | /// Set the cursor blinking.
|
53 | 90 | fn blink_cursor(
|
54 | 91 | &mut self,
|
55 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 92 | + device: &mut DEVICE, |
56 | 93 | blink_cursor: bool,
|
57 | 94 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
58 | 95 |
|
59 | 96 | /// Set the display visibility.
|
60 | 97 | fn show_display(
|
61 | 98 | &mut self,
|
62 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 99 | + device: &mut DEVICE, |
63 | 100 | show_display: bool,
|
64 | 101 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
65 | 102 |
|
66 | 103 | /// Scroll display left.
|
67 |
| - fn scroll_left( |
68 |
| - &mut self, |
69 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
70 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 104 | + fn scroll_left(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
71 | 105 |
|
72 | 106 | /// Scroll display right.
|
73 |
| - fn scroll_right( |
74 |
| - &mut self, |
75 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
76 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 107 | + fn scroll_right(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
77 | 108 |
|
78 | 109 | /// Set the text flow direction to left to right.
|
79 |
| - fn left_to_right( |
80 |
| - &mut self, |
81 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
82 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 110 | + fn left_to_right(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
83 | 111 |
|
84 | 112 | /// Set the text flow direction to right to left.
|
85 |
| - fn right_to_left( |
86 |
| - &mut self, |
87 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
88 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 113 | + fn right_to_left(&mut self, device: &mut DEVICE) -> Result<(), CharacterDisplayError<I2C>>; |
89 | 114 |
|
90 | 115 | /// Set the auto scroll mode.
|
91 | 116 | fn autoscroll(
|
92 | 117 | &mut self,
|
93 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 118 | + device: &mut DEVICE, |
94 | 119 | autoscroll: bool,
|
95 | 120 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
96 | 121 |
|
97 | 122 | /// Prints a string to the LCD at the current cursor position of the active device.
|
98 |
| - fn print( |
99 |
| - &mut self, |
100 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
101 |
| - text: &str, |
102 |
| - ) -> Result<(), CharacterDisplayError<I2C>>; |
| 123 | + fn print(&mut self, device: &mut DEVICE, text: &str) -> Result<(), CharacterDisplayError<I2C>>; |
103 | 124 |
|
104 | 125 | /// Sets the backlight on or off
|
105 | 126 | fn backlight(
|
106 | 127 | &mut self,
|
107 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 128 | + device: &mut DEVICE, |
108 | 129 | on: bool,
|
109 | 130 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
110 | 131 |
|
111 | 132 | /// creates a new custom character
|
112 | 133 | fn create_char(
|
113 | 134 | &mut self,
|
114 |
| - device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 135 | + device: &mut DEVICE, |
115 | 136 | location: u8,
|
116 | 137 | charmap: [u8; 8],
|
117 | 138 | ) -> Result<(), CharacterDisplayError<I2C>>;
|
118 | 139 |
|
119 | 140 | /// read bytes from the active controller of the device. The size of the buffer is the number of bytes to read.
|
120 | 141 | fn read_device_data(
|
121 | 142 | &self,
|
122 |
| - _device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 143 | + _device: &mut DEVICE, |
123 | 144 | _buffer: &mut [u8],
|
124 | 145 | ) -> Result<(), CharacterDisplayError<I2C>> {
|
125 |
| - unimplemented!("Reads are not supported for device"); |
| 146 | + #[cfg(feature = "defmt")] |
| 147 | + defmt::warn!("Reading data is not supported on this display"); |
| 148 | + Err(CharacterDisplayError::UnsupportedOperation) |
126 | 149 | }
|
127 | 150 |
|
128 | 151 | fn read_address_counter(
|
129 | 152 | &mut self,
|
130 |
| - _device: &mut DeviceSetupConfig<I2C, DELAY>, |
| 153 | + _device: &mut DEVICE, |
131 | 154 | ) -> Result<u8, CharacterDisplayError<I2C>> {
|
132 |
| - unimplemented!("Reads are not supported for device"); |
| 155 | + #[cfg(feature = "defmt")] |
| 156 | + defmt::warn!("Reading the address counter is not supported on this display"); |
| 157 | + Err(CharacterDisplayError::UnsupportedOperation) |
| 158 | + } |
| 159 | + |
| 160 | + /// Set the contrast of the display. This is not supported by all devices. |
| 161 | + fn set_contrast( |
| 162 | + &mut self, |
| 163 | + _device: &mut DEVICE, |
| 164 | + _contrast: u8, |
| 165 | + ) -> Result<(), CharacterDisplayError<I2C>> { |
| 166 | + #[cfg(feature = "defmt")] |
| 167 | + defmt::warn!("Setting contrast is not supported on this display"); |
| 168 | + Err(CharacterDisplayError::UnsupportedOperation) |
133 | 169 | }
|
134 | 170 | }
|
0 commit comments