vex_rt/
peripherals.rs

1//! Peripherals.
2
3use crate::adi::AdiPort;
4use crate::{
5    bindings,
6    controller::{Controller, ControllerId},
7    smart_port::SmartPort,
8};
9
10/// A struct which represents all the peripherals on the V5 brain.
11pub struct Peripherals {
12    /// Primary Controller.
13    pub master_controller: Controller,
14    /// Partner Controller.
15    pub partner_controller: Controller,
16    /// Smart Port 1.
17    pub port01: SmartPort,
18    /// Smart Port 2.
19    pub port02: SmartPort,
20    /// Smart Port 3.
21    pub port03: SmartPort,
22    /// Smart Port 4.
23    pub port04: SmartPort,
24    /// Smart Port 5.
25    pub port05: SmartPort,
26    /// Smart Port 6.
27    pub port06: SmartPort,
28    /// Smart Port 7.
29    pub port07: SmartPort,
30    /// Smart Port 8.
31    pub port08: SmartPort,
32    /// Smart Port 9.
33    pub port09: SmartPort,
34    /// Smart Port 10.
35    pub port10: SmartPort,
36    /// Smart Port 11.
37    pub port11: SmartPort,
38    /// Smart Port 12.
39    pub port12: SmartPort,
40    /// Smart Port 13.
41    pub port13: SmartPort,
42    /// Smart Port 14.
43    pub port14: SmartPort,
44    /// Smart Port 15.
45    pub port15: SmartPort,
46    /// Smart Port 16.
47    pub port16: SmartPort,
48    /// Smart Port 17.
49    pub port17: SmartPort,
50    /// Smart Port 18.
51    pub port18: SmartPort,
52    /// Smart Port 19.
53    pub port19: SmartPort,
54    /// Smart Port 20.
55    pub port20: SmartPort,
56    /// Smart Port 21.
57    pub port21: SmartPort,
58    /// ADI Port 1 / A.
59    pub port_a: AdiPort,
60    /// ADI Port 2 / B.
61    pub port_b: AdiPort,
62    /// ADI Port 3 / C.
63    pub port_c: AdiPort,
64    /// ADI Port 4 / D.
65    pub port_d: AdiPort,
66    /// ADI Port 5 / E.
67    pub port_e: AdiPort,
68    /// ADI Port 6 / F.
69    pub port_f: AdiPort,
70    /// ADI Port 7 / G.
71    pub port_g: AdiPort,
72    /// ADI Port 8 / H.
73    pub port_h: AdiPort,
74}
75
76impl Peripherals {
77    /// Constructs a [`Peripherals`] struct unsafely.
78    ///
79    /// # Safety
80    ///
81    /// This function is unsafe because it allows the user to create multiple
82    /// mutable references to the V5's peripherals. You likely want to use the
83    /// peripherals object passed into
84    /// [`Robot::initialize`](crate::robot::Robot::initialize()) instead.
85    pub unsafe fn new() -> Self {
86        Peripherals {
87            master_controller: Controller::new(ControllerId::Master),
88            partner_controller: Controller::new(ControllerId::Partner),
89            port01: SmartPort::new(1),
90            port02: SmartPort::new(2),
91            port03: SmartPort::new(3),
92            port04: SmartPort::new(4),
93            port05: SmartPort::new(5),
94            port06: SmartPort::new(6),
95            port07: SmartPort::new(7),
96            port08: SmartPort::new(8),
97            port09: SmartPort::new(9),
98            port10: SmartPort::new(10),
99            port11: SmartPort::new(11),
100            port12: SmartPort::new(12),
101            port13: SmartPort::new(13),
102            port14: SmartPort::new(14),
103            port15: SmartPort::new(15),
104            port16: SmartPort::new(16),
105            port17: SmartPort::new(17),
106            port18: SmartPort::new(18),
107            port19: SmartPort::new(19),
108            port20: SmartPort::new(20),
109            port21: SmartPort::new(21),
110            port_a: AdiPort::new(1, bindings::INTERNAL_ADI_PORT as u8),
111            port_b: AdiPort::new(2, bindings::INTERNAL_ADI_PORT as u8),
112            port_c: AdiPort::new(3, bindings::INTERNAL_ADI_PORT as u8),
113            port_d: AdiPort::new(4, bindings::INTERNAL_ADI_PORT as u8),
114            port_e: AdiPort::new(5, bindings::INTERNAL_ADI_PORT as u8),
115            port_f: AdiPort::new(6, bindings::INTERNAL_ADI_PORT as u8),
116            port_g: AdiPort::new(7, bindings::INTERNAL_ADI_PORT as u8),
117            port_h: AdiPort::new(8, bindings::INTERNAL_ADI_PORT as u8),
118        }
119    }
120}