pub trait UsbPipe<T: Type, D: Direction> {
// Required methods
async fn control_in(
&mut self,
setup: &[u8; 8],
buf: &mut [u8],
) -> Result<usize, PipeError>
where T: IsControl,
D: IsIn;
async fn control_out(
&mut self,
setup: &[u8; 8],
buf: &[u8],
) -> Result<(), PipeError>
where T: IsControl,
D: IsOut;
fn retarget_pipe(
&mut self,
addr: u8,
endpoint: &EndpointInfo,
split: Option<SplitInfo>,
) -> Result<(), HostError>;
async fn request_in(&mut self, buf: &mut [u8]) -> Result<usize, PipeError>
where D: IsIn;
async fn request_out(
&mut self,
buf: &[u8],
ensure_transaction_end: bool,
) -> Result<(), PipeError>
where D: IsOut;
fn set_timeout(&mut self, timeout: TimeoutConfig)
where T: IsControl;
fn reset_data_toggle(&mut self)
where T: IsBulkOrInterrupt;
}Expand description
§USB Pipes
These contain the required information to send a packet correctly to a device endpoint.
The information is carried with the pipe on creation (see UsbHostDriver::alloc_pipe).
It is up to the HAL’s driver how to implement concurrent requests, some hardware IP may allow for multiple hardware channels while others may only have a single channel which needs to be multiplexed in software, while others still use DMA request linked-lists. Any of these are compatible with the UsbPipe with varying degrees of sync primitives required.
§NAK handling
Implementations must retry on NAK if appropriate for the transfer type.
- For control transfers, the implementation should retry until the configurable timeout expires (see
UsbPipe::set_timeout). - For bulk transfers, the implementation must retry indefinitely. Use
embassy_time::with_timeoutaround the future to impose a deadline; dropping the future must abort the transfer. - For interrupt transfers, a NAK indicates no data is available; the implementation should poll again at the next interval.
§Data toggle
Implementations are responsible for maintaining the data toggle sequence for bulk and interrupt endpoints. The toggle is initialized to DATA0 when the pipe is allocated and should advance after each successful transfer.
§Cancellation
All transfer methods (control_in, control_out, request_in, request_out) are asynchronous.
If the returned future is dropped before completion, the implementation must abort the in-progress
transfer and leave the pipe in a consistent state for future requests.
Required Methods§
Sourceasync fn control_in(
&mut self,
setup: &[u8; 8],
buf: &mut [u8],
) -> Result<usize, PipeError>
async fn control_in( &mut self, setup: &[u8; 8], buf: &mut [u8], ) -> Result<usize, PipeError>
Send IN control request.
Returns the number of bytes received into buf.
Sourceasync fn control_out(
&mut self,
setup: &[u8; 8],
buf: &[u8],
) -> Result<(), PipeError>
async fn control_out( &mut self, setup: &[u8; 8], buf: &[u8], ) -> Result<(), PipeError>
Send OUT control request
Sourcefn retarget_pipe(
&mut self,
addr: u8,
endpoint: &EndpointInfo,
split: Option<SplitInfo>,
) -> Result<(), HostError>
fn retarget_pipe( &mut self, addr: u8, endpoint: &EndpointInfo, split: Option<SplitInfo>, ) -> Result<(), HostError>
Retargets pipe to a new endpoint, may error if the underlying driver runs out of resources.
See UsbHostDriver::alloc_pipe for the meaning of split.
Sourceasync fn request_in(&mut self, buf: &mut [u8]) -> Result<usize, PipeError>where
D: IsIn,
async fn request_in(&mut self, buf: &mut [u8]) -> Result<usize, PipeError>where
D: IsIn,
Send IN request of type other from control For interrupt pipes this will return the result of the next successful interrupt poll
Sourceasync fn request_out(
&mut self,
buf: &[u8],
ensure_transaction_end: bool,
) -> Result<(), PipeError>where
D: IsOut,
async fn request_out(
&mut self,
buf: &[u8],
ensure_transaction_end: bool,
) -> Result<(), PipeError>where
D: IsOut,
Send OUT request of type other from control ensure_transaction_end: Send a zero length packet at the end of transaction if last packet is of max size.
Sourcefn set_timeout(&mut self, timeout: TimeoutConfig)where
T: IsControl,
fn set_timeout(&mut self, timeout: TimeoutConfig)where
T: IsControl,
Configure the timeouts of this pipe.
Sourcefn reset_data_toggle(&mut self)where
T: IsBulkOrInterrupt,
fn reset_data_toggle(&mut self)where
T: IsBulkOrInterrupt,
Reset the host-side data toggle on this pipe to DATA0.
The caller must invoke this method after:
CLEAR_FEATURE(ENDPOINT_HALT)successfully clears a functional stall on this endpoint.SET_CONFIGURATIONsucceeds (all non-control endpoints on the affected interfaces must be reset).SET_INTERFACEsucceeds (all non-control endpoints on the affected interface must be reset).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.