1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// See section 9.3 of (USB2)
#[derive(Clone, Copy)]
pub struct bmRequestType {
pub direction: Direction,
pub ty: Type,
pub recipient: Recipient,
}
impl bmRequestType {
pub fn parse(bmrequesttype: u8) -> Result<Self, ()> {
let direction = Direction::_from(bmrequesttype >> 7).ok_or(())?;
let ty = Type::_from((bmrequesttype >> 5) & 0b11).ok_or(())?;
let recipient = Recipient::_from(bmrequesttype & 0b1111).ok_or(())?;
Ok(Self {
direction,
ty,
recipient,
})
}
}
repr!(u8,
/// Request direction
Direction {
/// Host to device
HostToDevice = 0,
/// Device to host
DeviceToHost = 1,
});
repr!(u8,
/// Request type
Type {
/// Standard request
Standard = 0,
/// Class-specific request
Class = 1,
/// Vendor-specific request
Vendor = 2,
});
repr!(u8,
/// Request recipient
Recipient {
/// Request recipient = device
Device = 0,
/// Request recipient = interface
Interface = 1,
/// Request recipient = endpoint
Endpoint = 2,
/// Request recipient = other
Other = 3,
});