Skip to main content

lcd_async/dcs/
set_column_address.rs

1//! Module for the CASET address window instruction constructors
2
3use super::DcsCommand;
4
5/// Set Column Address
6#[derive(Debug, Clone, PartialEq, Eq)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8pub struct SetColumnAddress {
9    start_column: u16,
10    end_column: u16,
11}
12
13impl SetColumnAddress {
14    /// Creates a new Set Column Address command.
15    pub const fn new(start_column: u16, end_column: u16) -> Self {
16        Self {
17            start_column,
18            end_column,
19        }
20    }
21}
22
23impl DcsCommand for SetColumnAddress {
24    fn instruction(&self) -> u8 {
25        0x2A
26    }
27
28    fn fill_params_buf(&self, buffer: &mut [u8]) -> usize {
29        buffer[0..2].copy_from_slice(&self.start_column.to_be_bytes());
30        buffer[2..4].copy_from_slice(&self.end_column.to_be_bytes());
31
32        4
33    }
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn caset_fills_data_properly() {
42        let caset = SetColumnAddress::new(0, 320);
43
44        let mut buffer = [0u8; 4];
45        assert_eq!(caset.fill_params_buf(&mut buffer), 4);
46        assert_eq!(buffer, [0, 0, 0x1, 0x40]);
47    }
48}