@@ -199,49 +199,56 @@ impl<B: UsbBus> Endpoint<'_, B, In> {
199199impl < B : UsbBus > Endpoint < ' _ , B , Out > {
200200 /// Reads a single packet of data and returns the length of the packet
201201 ///
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.
204204 ///
205205 /// # Errors
206206 ///
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.
209209 ///
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.
218221 pub fn read ( & self , data : & mut [ u8 ] ) -> Result < usize > {
219222 self . bus ( ) . read ( self . address , data)
220223 }
221224
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."
223229 ///
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.
227232 ///
228233 /// # Errors
229234 ///
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.
232237 ///
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 ] > {
239246 // SETUP transactions can only occur on control endpoints
240247 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 ) ;
244249 }
250+
251+ self . bus ( ) . read_setup ( self . address )
245252 }
246253}
247254
0 commit comments