scsir/command/shortcut/mode/
shared_port_control.rs

1#![allow(dead_code)]
2
3use modular_bitfield_msb::prelude::*;
4
5use crate::command::get_array;
6
7use super::ModePage;
8
9pub const SHARED_PORT_CONTROL_PAGE_CODE: u8 = 0x19;
10pub const SHARED_PORT_CONTROL_SUBPAGE_CODE: u8 = 0x02;
11
12#[bitfield]
13#[derive(Clone, Copy, Debug)]
14pub struct SharedPortControlPage {
15    pub parameters_saveable: B1,
16    pub subpage_format: B1,
17    pub page_code: B6,
18    pub subpage_code: B8,
19    pub page_length: B16,
20    reserved_0: B8,
21    reserved_1: B4,
22    pub protocol_identifier: B4,
23    pub power_loss_timeout: B16,
24    reserved_2: B8,
25    pub power_grant_timeout: B8,
26    reserved_3: B48,
27}
28
29impl ModePage for SharedPortControlPage {
30    fn new() -> Self {
31        Self::new()
32    }
33
34    fn from_bytes(bytes: &[u8]) -> (Self, &[u8]) {
35        let (array, bytes) = get_array(bytes);
36
37        (Self::from_bytes(array), bytes)
38    }
39
40    fn to_bytes(&self) -> Vec<u8> {
41        self.bytes.to_vec()
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48    use std::mem::size_of;
49
50    const PAGE_LENGTH: usize = 16;
51
52    #[test]
53    fn layout_test() {
54        assert_eq!(
55            size_of::<SharedPortControlPage>(),
56            PAGE_LENGTH,
57            concat!("Size of: ", stringify!(SharedPortControlPage))
58        );
59    }
60}