usb_if/transfer/
mod.rs

1use num_enum::{FromPrimitive, IntoPrimitive};
2
3mod sync;
4pub mod wait;
5
6#[repr(u8)]
7/// The direction of the data transfer.
8#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
9pub enum Direction {
10    /// Out (Write Data)
11    Out = 0,
12    /// In (Read Data)
13    In = 1,
14}
15
16impl Direction {
17    pub fn from_address(addr: u8) -> Direction {
18        match addr & Self::MASK {
19            0 => Self::Out,
20            _ => Self::In,
21        }
22    }
23    const MASK: u8 = 0x80;
24}
25
26#[repr(C)]
27#[derive(Debug, Clone)]
28pub struct BmRequestType {
29    pub direction: Direction,
30    pub request_type: RequestType,
31    pub recipient: Recipient,
32}
33
34impl BmRequestType {
35    pub const fn new(
36        direction: Direction,
37        transfer_type: RequestType,
38        recipient: Recipient,
39    ) -> BmRequestType {
40        BmRequestType {
41            direction,
42            request_type: transfer_type,
43            recipient,
44        }
45    }
46}
47
48impl From<BmRequestType> for u8 {
49    fn from(value: BmRequestType) -> Self {
50        ((value.direction as u8) << 7) | ((value.request_type as u8) << 5) | value.recipient as u8
51    }
52}
53
54#[derive(Copy, Clone, Debug)]
55#[repr(u8)]
56pub enum RequestType {
57    Standard = 0,
58    Class = 1,
59    Vendor = 2,
60    Reserved = 3,
61}
62
63#[derive(Copy, Clone, Debug)]
64#[repr(u8)]
65pub enum Recipient {
66    Device = 0,
67    Interface = 1,
68    Endpoint = 2,
69    Other = 3,
70}
71
72#[derive(Debug, Clone, FromPrimitive, IntoPrimitive)]
73#[repr(u8)]
74pub enum Request {
75    GetStatus = 0,
76    ClearFeature = 1,
77    SetFeature = 3,
78    SetAddress = 5,
79    GetDescriptor = 6,
80    SetDescriptor = 7,
81    GetConfiguration = 8,
82    SetConfiguration = 9,
83    GetInterface = 10,
84    SetInterface = 11,
85    SynchFrame = 12,
86    SetEncryption = 13,
87    GetEncryption = 14,
88    SetHandshake = 15,
89    GetHandshake = 16,
90    SetConnection = 17,
91    SetSecurityData = 18,
92    GetSecurityData = 19,
93    SetWusbData = 20,
94    LoopbackDataWrite = 21,
95    LoopbackDataRead = 22,
96    SetInterfaceDs = 23,
97    GetFwStatus = 26,
98    SetFwStatus = 27,
99    SetSel = 48,
100    SetIsochDelay = 49,
101    #[num_enum(catch_all)]
102    Other(u8),
103}