Skip to main content

lcd_async/dcs/
set_page_address.rs

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