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