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