@@ -29,21 +29,81 @@ pub type EndpointOut<'a, B> = Endpoint<'a, B, Out>;
29
29
/// A device-to-host (IN) endpoint.
30
30
pub type EndpointIn < ' a , B > = Endpoint < ' a , B , In > ;
31
31
32
- /// USB endpoint transfer type. The values of this enum can be directly cast into `u8` to get the
33
- /// transfer bmAttributes transfer type bits.
34
- #[ repr( u8 ) ]
32
+ /// Isochronous transfers employ one of three synchronization schemes. See USB 2.0 spec 5.12.4.1.
33
+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
34
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
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
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
50
+ pub enum IsochronousUsageType {
51
+ /// Endpoint is used for isochronous data.
52
+ Data ,
53
+ /// Feedback for synchronization.
54
+ Feedback ,
55
+ /// Endpoint is data and provides implicit feedback for synchronization.
56
+ ImplicitFeedbackData ,
57
+ }
58
+
59
+ /// USB endpoint transfer type.
35
60
#[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
36
61
#[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
37
62
pub enum EndpointType {
38
63
/// Control endpoint. Used for device management. Only the host can initiate requests. Usually
39
64
/// used only endpoint 0.
40
- Control = 0b00 ,
41
- /// Isochronous endpoint. Used for time-critical unreliable data. Not implemented yet.
42
- Isochronous = 0b01 ,
65
+ Control ,
66
+ /// Isochronous endpoint. Used for time-critical unreliable data.
67
+ ///
68
+ /// See USB 2.0 spec section 5.12 "Special Considerations for Isochronous Transfers"
69
+ Isochronous {
70
+ /// Synchronization model used for the data stream that this endpoint relates to.
71
+ synchronization : IsochronousSynchronizationType ,
72
+ /// Endpoint's role in the synchronization model selected by [Self::Isochronous::synchronization].
73
+ usage : IsochronousUsageType ,
74
+ } ,
43
75
/// Bulk endpoint. Used for large amounts of best-effort reliable data.
44
- Bulk = 0b10 ,
76
+ Bulk ,
45
77
/// Interrupt endpoint. Used for small amounts of time-critical reliable data.
46
- Interrupt = 0b11 ,
78
+ Interrupt ,
79
+ }
80
+
81
+ impl EndpointType {
82
+ /// Format EndpointType for use in bmAttributes transfer type field USB 2.0 spec section 9.6.6
83
+ pub fn to_bm_attributes ( & self ) -> u8 {
84
+ match self {
85
+ EndpointType :: Control => 0b00 ,
86
+ EndpointType :: Isochronous {
87
+ synchronization,
88
+ usage,
89
+ } => {
90
+ let sync_bits = match synchronization {
91
+ IsochronousSynchronizationType :: NoSynchronization => 0b00 ,
92
+ IsochronousSynchronizationType :: Asynchronous => 0b01 ,
93
+ IsochronousSynchronizationType :: Adaptive => 0b10 ,
94
+ IsochronousSynchronizationType :: Synchronous => 0b11 ,
95
+ } ;
96
+ let usage_bits = match usage {
97
+ IsochronousUsageType :: Data => 0b00 ,
98
+ IsochronousUsageType :: Feedback => 0b01 ,
99
+ IsochronousUsageType :: ImplicitFeedbackData => 0b10 ,
100
+ } ;
101
+ ( usage_bits << 4 ) | ( sync_bits << 2 ) | 0b01
102
+ }
103
+ EndpointType :: Bulk => 0b10 ,
104
+ EndpointType :: Interrupt => 0b11 ,
105
+ }
106
+ }
47
107
}
48
108
49
109
/// Handle for a USB endpoint. The endpoint direction is constrained by the `D` type argument, which
0 commit comments