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