Skip to main content

lcd_async/dcs/
set_scroll_area.rs

1//! Module for the VSCRDEF visual scroll definition instruction constructors
2
3use super::DcsCommand;
4
5/// Set Scroll Area
6#[derive(Debug, Clone, PartialEq, Eq)]
7#[cfg_attr(feature = "defmt", derive(defmt::Format))]
8pub struct SetScrollArea {
9    tfa: u16,
10    vsa: u16,
11    bfa: u16,
12}
13
14impl SetScrollArea {
15    /// Creates a new Set Scroll Area command.
16    ///
17    /// VSA should default to the display's height (or width) framebuffer size.
18    pub const fn new(tfa: u16, vsa: u16, bfa: u16) -> Self {
19        Self { tfa, vsa, bfa }
20    }
21}
22
23impl DcsCommand for SetScrollArea {
24    fn instruction(&self) -> u8 {
25        0x33
26    }
27
28    fn fill_params_buf(&self, buffer: &mut [u8]) -> usize {
29        let tfa_bytes = self.tfa.to_be_bytes();
30        let vsa_bytes = self.vsa.to_be_bytes();
31        let bfa_bytes = self.bfa.to_be_bytes();
32
33        buffer[0] = tfa_bytes[0];
34        buffer[1] = tfa_bytes[1];
35        buffer[2] = vsa_bytes[0];
36        buffer[3] = vsa_bytes[1];
37        buffer[4] = bfa_bytes[0];
38        buffer[5] = bfa_bytes[1];
39
40        6
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn vscrdef_fills_buffer_properly() {
50        let vscrdef = SetScrollArea::new(0, 320, 0);
51
52        let mut buffer = [0u8; 6];
53        assert_eq!(vscrdef.fill_params_buf(&mut buffer), 6);
54        assert_eq!(buffer, [0, 0, 0x1, 0x40, 0, 0]);
55    }
56}