@@ -199,49 +199,56 @@ impl<B: UsbBus> Endpoint<'_, B, In> {
199
199
impl < B : UsbBus > Endpoint < ' _ , B , Out > {
200
200
/// Reads a single packet of data and returns the length of the packet
201
201
///
202
- /// The buffer should be large enough to fit at least as many bytes as the `max_packet_size`
203
- /// specified when allocating the endpoint.
202
+ /// The buffer should be large enough to fit at least as many bytes as the
203
+ /// `max_packet_size` specified when allocating the endpoint.
204
204
///
205
205
/// # Errors
206
206
///
207
- /// Note: USB bus implementation errors are directly passed through, so be prepared to handle
208
- /// other errors as well.
207
+ /// Note: USB bus implementation errors are directly passed through, so be
208
+ /// prepared to handle other errors as well.
209
209
///
210
- /// * [`WouldBlock`](crate::UsbError::WouldBlock) - There is no packet to be read. Note that
211
- /// this is different from a received zero-length packet, which is valid and significant in
212
- /// USB. A zero-length packet will return `Ok(0)`.
213
- /// * [`BufferOverflow`](crate::UsbError::BufferOverflow) - The received packet is too long to
214
- /// fit in `data`. This is generally an error in the class implementation.
215
- /// * [`InvalidState`](crate::UsbError::InvalidState) - The received packet is a SETUP
216
- /// transaction, and needs to be read through [`read_setup()`](Endpoint::read_setup())
217
- /// instead.
210
+ /// * [`WouldBlock`](crate::UsbError::WouldBlock) - There is no OUT packet
211
+ /// to be read. Note that this is different from a received zero-length
212
+ /// packet, which is valid and significant in USB. A zero-length packet
213
+ /// will return `Ok(0)`.
214
+ ///
215
+ /// `WouldBlock` is also returned when the endpoint received a SETUP
216
+ /// transaction, which can be read through
217
+ /// [`read_setup()`](Endpoint::read_setup()).
218
+ /// * [`BufferOverflow`](crate::UsbError::BufferOverflow) - The received
219
+ /// packet is too long to fit in `data`. This is generally an error in the
220
+ /// class implementation.
218
221
pub fn read ( & self , data : & mut [ u8 ] ) -> Result < usize > {
219
222
self . bus ( ) . read ( self . address , data)
220
223
}
221
224
222
- /// Reads a single packet of SETUP data and returns the length of the packet
225
+ /// Reads a single packet of SETUP data and returns it
226
+ ///
227
+ /// USB Spec 2.0 5.5.3 Control Transfer Packet Size Constraints: "A Setup
228
+ /// packet is always eight bytes."
223
229
///
224
- /// The buffer should be large enough to fit at least as many bytes as the `max_packet_size`
225
- /// specified when allocating the endpoint. See [`UsbBus::read_setup()`] for rationale for two
226
- /// distinct read methods.
230
+ /// See [`UsbBus::read_setup()`] for rationale for two distinct read
231
+ /// methods.
227
232
///
228
233
/// # Errors
229
234
///
230
- /// Note: USB bus implementation errors are directly passed through, so be prepared to handle
231
- /// other errors as well.
235
+ /// Note: USB bus implementation errors are directly passed through, so be
236
+ /// prepared to handle other errors as well.
232
237
///
233
- /// * [`WouldBlock`](crate::UsbError::WouldBlock) - There is no packet to be read. Note that
234
- /// this is different from a received zero-length packet, which is valid and significant in
235
- /// USB. A zero-length packet will return `Ok(0)`.
236
- /// * [`BufferOverflow`](crate::UsbError::BufferOverflow) - The received packet is too long to
237
- /// fit in `data`. This is generally an error in the class implementation.
238
- pub fn read_setup ( & self , data : & mut [ u8 ] ) -> Result < usize > {
238
+ /// * [`WouldBlock`](crate::UsbError::WouldBlock) - There is no packet to be
239
+ /// read. Note that this is different from a received zero-length packet,
240
+ /// which is valid and significant in USB. A zero-length packet will
241
+ /// return `Ok(0)`.
242
+ /// * [`InvalidEndpoint`](crate::UsbError::InvalidEndpoint) - SETUP packets
243
+ /// can only be read from Control endpoints, this error is returned if the
244
+ /// method is called on any other type endpoint.
245
+ pub fn read_setup ( & self ) -> Result < [ u8 ; 8 ] > {
239
246
// SETUP transactions can only occur on control endpoints
240
247
if self . ep_type != EndpointType :: Control {
241
- Err ( UsbError :: InvalidEndpoint )
242
- } else {
243
- self . bus ( ) . read_setup ( self . address , data)
248
+ return Err ( UsbError :: InvalidEndpoint ) ;
244
249
}
250
+
251
+ self . bus ( ) . read_setup ( self . address )
245
252
}
246
253
}
247
254
0 commit comments