@@ -30,20 +30,68 @@ pub type EndpointOut<'a, B> = Endpoint<'a, B, Out>;
30
30
/// A device-to-host (IN) endpoint.
31
31
pub type EndpointIn < ' a , B > = Endpoint < ' a , B , In > ;
32
32
33
- /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the
34
- /// transfer bmAttributes transfer type bits.
35
- #[ repr( u8 ) ]
33
+ /// Isochronous transfers employ one of three synchronization schemes. See USB 2.0 spec 5.12.4.1.
34
+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
35
+ pub enum IsochronousSynchronizationType {
36
+ /// Synchronization is not implemented for this endpoint.
37
+ NoSynchronization ,
38
+ /// Source and Sink sample clocks are free running.
39
+ Asynchronous ,
40
+ /// Source sample clock is locked to Sink, Sink sample clock is locked to data flow.
41
+ Adaptive ,
42
+ /// Source and Sink sample clocks are locked to USB SOF.
43
+ Synchronous ,
44
+ }
45
+
46
+ /// Intended use of an isochronous endpoint, see USB 2.0 spec sections 5.12 and 9.6.6.
47
+ /// Associations between data and feedback endpoints are described in section 9.6.6.
48
+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
49
+ pub enum IsochronousUsageType {
50
+ /// Endpoint is used for isochronous data.
51
+ Data ,
52
+ /// Feedback for synchronization.
53
+ Feedback ,
54
+ /// Endpoint is data and provides implicit feedback for synchronization.
55
+ ImplicitFeedbackData ,
56
+ }
57
+
58
+ /// USB endpoint transfer type.
36
59
#[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
37
60
pub enum EndpointType {
38
61
/// Control endpoint. Used for device management. Only the host can initiate requests. Usually
39
62
/// used only endpoint 0.
40
- Control = 0b00 ,
41
- /// Isochronous endpoint. Used for time-critical unreliable data. Not implemented yet.
42
- Isochronous = 0b01 ,
63
+ Control ,
64
+ /// Isochronous endpoint. Used for time-critical unreliable data.
65
+ Isochronous ( ( IsochronousSynchronizationType , IsochronousUsageType ) ) ,
43
66
/// Bulk endpoint. Used for large amounts of best-effort reliable data.
44
- Bulk = 0b10 ,
67
+ Bulk ,
45
68
/// Interrupt endpoint. Used for small amounts of time-critical reliable data.
46
- Interrupt = 0b11 ,
69
+ Interrupt ,
70
+ }
71
+
72
+ impl EndpointType {
73
+ /// Format EndpointType for use in bmAttributes transfer type field USB 2.0 spec section 9.6.6
74
+ pub fn to_bm_attributes ( & self ) -> u8 {
75
+ match self {
76
+ EndpointType :: Control => 0b00 ,
77
+ EndpointType :: Isochronous ( ( sync_type, usage_type) ) => {
78
+ let sync_bits = match sync_type {
79
+ IsochronousSynchronizationType :: NoSynchronization => 0b00 ,
80
+ IsochronousSynchronizationType :: Asynchronous => 0b01 ,
81
+ IsochronousSynchronizationType :: Adaptive => 0b10 ,
82
+ IsochronousSynchronizationType :: Synchronous => 0b11 ,
83
+ } ;
84
+ let usage_bits = match usage_type {
85
+ IsochronousUsageType :: Data => 0b00 ,
86
+ IsochronousUsageType :: Feedback => 0b01 ,
87
+ IsochronousUsageType :: ImplicitFeedbackData => 0b10 ,
88
+ } ;
89
+ ( usage_bits << 4 ) | ( sync_bits << 2 ) | 0b01
90
+ }
91
+ EndpointType :: Bulk => 0b10 ,
92
+ EndpointType :: Interrupt => 0b11 ,
93
+ }
94
+ }
47
95
}
48
96
49
97
/// Handle for a USB endpoint. The endpoint direction is constrained by the `D` type argument, which
0 commit comments