embassy-usb-driver

Crates

git

Versions

default

Flavors

Skip to main content

EndpointIn

Trait EndpointIn 

Source
pub trait EndpointIn: Endpoint {
    // Required method
    async fn write_transfer(
        &mut self,
        buf: &[u8],
        needs_zlp: bool,
    ) -> Result<(), EndpointError>;
}
Expand description

IN Endpoint trait.

Required Methods§

Source

async fn write_transfer( &mut self, buf: &[u8], needs_zlp: bool, ) -> Result<(), EndpointError>

Write all the data from buf to the endpoint as a transfer.

What makes up a transfer depends on the endpoint type, see below.

When this returns is implementation-defined, for all endpoint types. Drivers may either:

  • queue the data and return immediately, or
  • wait until the host has collected it.
§Bulk and interrupt endpoints

The driver splits buf into packets of max_packet_size bytes, the last one possibly shorter, and sends them. A zero-length packet (ZLP) is sent:

  • after the data, to end the transfer, if needs_zlp is true and buf.len() is an exact non-zero multiple of max_packet_size.
  • alone, if buf is empty.
§Isochronous endpoints

buf is the data to send in a single service interval. An empty buf is sent as a zero-length packet. needs_zlp is ignored.

buf.len() must be at most the following, or this fails with EndpointError::BufferOverflow without sending anything:

  • full speed: max_packet_size
  • high speed: max_packet_size * (additional_transactions + 1)
  • SuperSpeed: bytes_per_interval

The data goes out when the host next polls the endpoint, which it does once per service interval. The driver offers it for at least one full service interval. If the host still hasn’t collected it after that, what happens is implementation-defined. The driver may:

  • keep offering it, so it’s sent late, at a later poll, or
  • drop it, without an error.

In a service interval with no data written, what the driver sends is implementation-defined. It may send either:

  • a zero-length packet, or
  • no answer, which the host will see as an error.
§Errors

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§