vex_rt/adi/
expander.rs

1use crate::bindings;
2
3use super::AdiPort;
4
5/// A struct which represents a V5 ADI expander.
6pub struct AdiExpander {
7    /// ADI Port 1 / A.
8    pub port_a: AdiPort,
9    /// ADI Port 2 / B.
10    pub port_b: AdiPort,
11    /// ADI Port 3 / C.
12    pub port_c: AdiPort,
13    /// ADI Port 4 / D.
14    pub port_d: AdiPort,
15    /// ADI Port 5 / E.
16    pub port_e: AdiPort,
17    /// ADI Port 6 / F.
18    pub port_f: AdiPort,
19    /// ADI Port 7 / G.
20    pub port_g: AdiPort,
21    /// ADI Port 8 / H.
22    pub port_h: AdiPort,
23}
24
25impl AdiExpander {
26    /// Initializes an ADI expander on a V5 Smart Port
27    ///
28    /// # Safety
29    ///
30    /// This function is unsafe because it allows the user to create multiple
31    /// mutable references to the same ADI expander. You likely want to
32    /// implement [`Robot::new()`](crate::robot::Robot::new()) instead.
33    pub unsafe fn new(smart_port: u8) -> Self {
34        assert!(
35            (1..22).contains(&smart_port) || smart_port == bindings::INTERNAL_ADI_PORT as u8,
36            "Cannot construct an ADI port with ADI extender on smart port {}",
37            smart_port
38        );
39        Self {
40            port_a: AdiPort::new(1, smart_port),
41            port_b: AdiPort::new(2, smart_port),
42            port_c: AdiPort::new(3, smart_port),
43            port_d: AdiPort::new(4, smart_port),
44            port_e: AdiPort::new(5, smart_port),
45            port_f: AdiPort::new(6, smart_port),
46            port_g: AdiPort::new(7, smart_port),
47            port_h: AdiPort::new(8, smart_port),
48        }
49    }
50}