Struct usb_device::endpoint::Endpoint
source · pub struct Endpoint<'a, B: UsbBus, D: EndpointDirection> { /* private fields */ }
Expand description
Handle for a USB endpoint. The endpoint direction is constrained by the D
type argument, which
must be either In
or Out
.
Implementations
sourceimpl<B: UsbBus, D: EndpointDirection> Endpoint<'_, B, D>
impl<B: UsbBus, D: EndpointDirection> Endpoint<'_, B, D>
sourcepub fn address(&self) -> EndpointAddress
pub fn address(&self) -> EndpointAddress
Gets the endpoint address including direction bit.
sourcepub fn ep_type(&self) -> EndpointType
pub fn ep_type(&self) -> EndpointType
Gets the endpoint transfer type.
sourcepub fn max_packet_size(&self) -> u16
pub fn max_packet_size(&self) -> u16
Gets the maximum packet size for the endpoint.
sourceimpl<B: UsbBus> Endpoint<'_, B, In>
impl<B: UsbBus> Endpoint<'_, B, In>
sourcepub fn write(&self, data: &[u8]) -> Result<usize>
pub fn write(&self, data: &[u8]) -> Result<usize>
Writes a single packet of data to the specified endpoint and returns number of bytes actually written.
The only reason for a short write is if the caller passes a slice larger than the amount of memory allocated earlier, and this is generally an error in the class implementation.
Errors
Note: USB bus implementation errors are directly passed through, so be prepared to handle other errors as well.
InvalidEndpoint
- Theep_addr
does not point to a valid endpoint that was previously allocated withUsbBus::alloc_ep
.WouldBlock
- A previously written packet is still pending to be sent.
sourceimpl<B: UsbBus> Endpoint<'_, B, Out>
impl<B: UsbBus> Endpoint<'_, B, Out>
sourcepub fn read(&self, data: &mut [u8]) -> Result<usize>
pub fn read(&self, data: &mut [u8]) -> Result<usize>
Reads a single packet of data from the specified endpoint and returns the actual length of the packet.
This should also clear any NAK flags and prepare the endpoint to receive the next packet.
Errors
Note: USB bus implementation errors are directly passed through, so be prepared to handle other errors as well.
InvalidEndpoint
- Theep_addr
does not point to a valid endpoint that was previously allocated withUsbBus::alloc_ep
.WouldBlock
- There is no packet to be read. Note that this is different from a received zero-length packet, which is valid in USB. A zero-length packet will returnOk(0)
.BufferOverflow
- The received packet is too long to fix inbuf
. This is generally an error in the class implementation.