Debian Codegraph @

src/transfer/control.rs

raw symbols SCIP
1 use superrust-analyzer cargo nusb 0.1.13 transfer/::{ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#, TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest#};
2
3 /// Transfer direction
4 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
5 #[repr(u8)]
6 pub enum Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction# {
7 /// Host to device
8 Outrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#Out# = 0,
9
10 /// Device to host
11 Inrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#In# = 1,
12 }
13
14 /// Specification defining the request.
15 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
16 #[repr(u8)]
17 pub enum ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType# {
18 /// Request defined by the USB standard.
19 Standardrust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#Standard# = 0,
20
21 /// Request defined by the standard USB class specification.
22 Classrust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#Class# = 1,
23
24 /// Non-standard request.
25 Vendorrust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#Vendor# = 2,
26 }
27
28 /// Entity targeted by the request.
29 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
30 #[repr(u8)]
31 pub enum Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient# {
32 /// Request made to device as a whole.
33 Devicerust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#Device# = 0,
34
35 /// Request made to specific interface.
36 Interfacerust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#Interface# = 1,
37
38 /// Request made to specific endpoint.
39 Endpointrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#Endpoint# = 2,
40
41 /// Other request.
42 Otherrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#Other# = 3,
43 }
44
45 /// SETUP packet without direction or buffers
46 pub struct Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control# {
47 /// Request type used for the `bmRequestType` field sent in the SETUP packet.
48 #[doc(alias = "bmRequestType")]
49 pub control_typerust-analyzer cargo nusb 0.1.13 transfer/control/Control#control_type.: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#,
50
51 /// Recipient used for the `bmRequestType` field sent in the SETUP packet.
52 #[doc(alias = "bmRequestType")]
53 pub recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Control#recipient.: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#,
54
55 /// `bRequest` field sent in the SETUP packet.
56 #[doc(alias = "bRequest")]
57 pub requestrust-analyzer cargo nusb 0.1.13 transfer/control/Control#request.: u8,
58
59 /// `wValue` field sent in the SETUP packet.
60 #[doc(alias = "wValue")]
61 pub valuerust-analyzer cargo nusb 0.1.13 transfer/control/Control#value.: u16,
62
63 /// `wIndex` field sent in the SETUP packet.
64 ///
65 /// For [`Recipient::Interface`] this is the interface number. For [`Recipient::Endpoint`] this is the endpoint number.
66 #[doc(alias = "wIndex")]
67 pub indexrust-analyzer cargo nusb 0.1.13 transfer/control/Control#index.: u16,
68 }
69
70 impl Controlrust-analyzer cargo nusb 0.1.13 transfer/control/Control# {
71 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn request_typerust-analyzer cargo nusb 0.1.13 transfer/control/impl#[Control]request_type().(&self, direction: Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#) -> u8 {
72 request_typerust-analyzer cargo nusb 0.1.13 transfer/control/request_type().(direction, self.control_typerust-analyzer cargo nusb 0.1.13 transfer/control/Control#control_type., self.recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Control#recipient.)
73 }
74 }
75
76 /// SETUP packet and associated data to make an **OUT** request on a control endpoint.
77 pub struct ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#<'a> {
78 /// Request type used for the `bmRequestType` field sent in the SETUP packet.
79 #[doc(alias = "bmRequestType")]
80 pub control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#control_type.: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#,
81
82 /// Recipient used for the `bmRequestType` field sent in the SETUP packet.
83 #[doc(alias = "bmRequestType")]
84 pub recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#recipient.: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#,
85
86 /// `bRequest` field sent in the SETUP packet.
87 #[doc(alias = "bRequest")]
88 pub requestrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#request.: u8,
89
90 /// `wValue` field sent in the SETUP packet.
91 #[doc(alias = "wValue")]
92 pub valuerust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#value.: u16,
93
94 /// `wIndex` field sent in the SETUP packet.
95 ///
96 /// For [`Recipient::Interface`] this is the interface number. For [`Recipient::Endpoint`] this is the endpoint number.
97 #[doc(alias = "wIndex")]
98 pub indexrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#index.: u16,
99
100 /// Data to be sent in the data stage.
101 #[doc(alias = "wLength")]
102 pub datarust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#data.: &'a [u8],
103 }
104
105 impl<'a> ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#<'a> {
106 #[allow(unused)]
107 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn setup_packetrust-analyzer cargo nusb 0.1.13 transfer/control/impl#[`ControlOut<'a>`]setup_packet().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<[u8; SETUP_PACKET_SIZErust-analyzer cargo nusb 0.1.13 transfer/control/SETUP_PACKET_SIZE.], ()> {
108 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pack_setuprust-analyzer cargo nusb 0.1.13 transfer/control/pack_setup().(
109 Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#::Outrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#Out#,
110 self.control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#control_type.,
111 self.recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#recipient.,
112 self.requestrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#request.,
113 self.valuerust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#value.,
114 self.indexrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#index.,
115 self.datarust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#data..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().,
116 ))
117 }
118
119 #[allow(unused)]
120 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn request_typerust-analyzer cargo nusb 0.1.13 transfer/control/impl#[`ControlOut<'a>`]request_type().(&self) -> u8 {
121 request_typerust-analyzer cargo nusb 0.1.13 transfer/control/request_type().(Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#::Outrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#Out#, self.control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#control_type., self.recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#recipient.)
122 }
123 }
124
125 impl TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest# for ControlOutrust-analyzer cargo nusb 0.1.13 transfer/control/ControlOut#<'_> {
126 type Responserust-analyzer cargo nusb 0.1.13 transfer/control/impl#[`ControlOut<'_>`][TransferRequest]Response# = ResponseBufferrust-analyzer cargo nusb 0.1.13 transfer/buffer/ResponseBuffer#;
127 }
128
129 /// SETUP packet to make an **IN** request on a control endpoint.
130 pub struct ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn# {
131 /// Request type used for the `bmRequestType` field sent in the SETUP packet.
132 #[doc(alias = "bmRequestType")]
133 pub control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#control_type.: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#,
134
135 /// Recipient used for the `bmRequestType` field sent in the SETUP packet.
136 #[doc(alias = "bmRequestType")]
137 pub recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#recipient.: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#,
138
139 /// `bRequest` field sent in the SETUP packet.
140 #[doc(alias = "bRequest")]
141 pub requestrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#request.: u8,
142
143 /// `wValue` field sent in the SETUP packet.
144 #[doc(alias = "wValue")]
145 pub valuerust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#value.: u16,
146
147 /// `wIndex` field sent in the SETUP packet.
148 ///
149 /// For [`Recipient::Interface`] this is the interface number. For [`Recipient::Endpoint`] this is the endpoint number.
150 #[doc(alias = "wIndex")]
151 pub indexrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#index.: u16,
152
153 /// Number of bytes to be read in the data stage.
154 #[doc(alias = "wLength")]
155 pub lengthrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#length.: u16,
156 }
157
158 impl ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn# {
159 #[allow(unused)]
160 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn setup_packetrust-analyzer cargo nusb 0.1.13 transfer/control/impl#[ControlIn]setup_packet().(&self) -> [u8; SETUP_PACKET_SIZErust-analyzer cargo nusb 0.1.13 transfer/control/SETUP_PACKET_SIZE.] {
161 pack_setuprust-analyzer cargo nusb 0.1.13 transfer/control/pack_setup().(
162 Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#::Inrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#In#,
163 self.control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#control_type.,
164 self.recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#recipient.,
165 self.requestrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#request.,
166 self.valuerust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#value.,
167 self.indexrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#index.,
168 self.lengthrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#length.,
169 )
170 }
171
172 #[allow(unused)]
173 pub(craterust-analyzer cargo nusb 0.1.13 crate/) fn request_typerust-analyzer cargo nusb 0.1.13 transfer/control/impl#[ControlIn]request_type().(&self) -> u8 {
174 request_typerust-analyzer cargo nusb 0.1.13 transfer/control/request_type().(Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#::Inrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#In#, self.control_typerust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#control_type., self.recipientrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn#recipient.)
175 }
176 }
177
178 pub(craterust-analyzer cargo nusb 0.1.13 crate/) const SETUP_PACKET_SIZErust-analyzer cargo nusb 0.1.13 transfer/control/SETUP_PACKET_SIZE.: usize = 8;
179
180 fn pack_setuprust-analyzer cargo nusb 0.1.13 transfer/control/pack_setup().(
181 direction: Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#,
182 control_type: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#,
183 recipient: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#,
184 request: u8,
185 value: u16,
186 index: u16,
187 length: u16,
188 ) -> [u8; SETUP_PACKET_SIZErust-analyzer cargo nusb 0.1.13 transfer/control/SETUP_PACKET_SIZE.] {
189 let bmrequesttype = request_typerust-analyzer cargo nusb 0.1.13 transfer/control/request_type().(direction, control_type, recipient);
190
191 [
192 bmrequesttype,
193 request,
194 (value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0xFF) as u8,
195 (value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().8) as u8,
196 (index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0xFF) as u8,
197 (index rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().8) as u8,
198 (length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0xFF) as u8,
199 (length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().8) as u8,
200 ]
201 }
202
203 fn request_typerust-analyzer cargo nusb 0.1.13 transfer/control/request_type().(direction: Directionrust-analyzer cargo nusb 0.1.13 transfer/control/Direction#, control_type: ControlTyperust-analyzer cargo nusb 0.1.13 transfer/control/ControlType#, recipient: Recipientrust-analyzer cargo nusb 0.1.13 transfer/control/Recipient#) -> u8 {
204 ((direction as u8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().7) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().((control_type as u8) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<i32>`]shl().5) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().(recipient as u8)
205 }
206
207 impl TransferRequestrust-analyzer cargo nusb 0.1.13 transfer/internal/TransferRequest# for ControlInrust-analyzer cargo nusb 0.1.13 transfer/control/ControlIn# {
208 type Responserust-analyzer cargo nusb 0.1.13 transfer/control/impl#[ControlIn][TransferRequest]Response# = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>;
209 }