lcd_async/dcs/
set_scroll_start.rs

1//! Module for the VSCAD visual scroll offset instruction constructors
2
3use super::DcsCommand;
4
5/// Set Scroll Start
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct SetScrollStart(u16);
8
9impl SetScrollStart {
10    /// Creates a new Set Scroll Start command.
11    pub const fn new(offset: u16) -> Self {
12        Self(offset)
13    }
14}
15
16impl DcsCommand for SetScrollStart {
17    fn instruction(&self) -> u8 {
18        0x37
19    }
20
21    fn fill_params_buf(&self, buffer: &mut [u8]) -> usize {
22        let bytes = self.0.to_be_bytes();
23        buffer[0] = bytes[0];
24        buffer[1] = bytes[1];
25
26        2
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn vscad_fills_offset_properly() {
36        let vscad = SetScrollStart::new(320);
37
38        let mut buffer = [0u8; 2];
39        assert_eq!(vscad.fill_params_buf(&mut buffer), 2);
40        assert_eq!(buffer, [0x1, 0x40]);
41    }
42}