embassy-usb-driver

Crates

git

Versions

default

Flavors

Skip to main content

IsoEndpointIn

Trait IsoEndpointIn 

Source
pub trait IsoEndpointIn: Endpoint {
    type Slot<'a>: IsoInSlot
       where Self: 'a;

    // Required method
    async fn ready(
        &mut self,
    ) -> Result<(Option<NonZeroU32>, Self::Slot<'_>), EndpointDisabledError>;
}
Expand description

Isochronous IN endpoint trait.

Drivers implement this only when they can schedule transfers by service interval and drop uncollected transfers instead of sending them late.

Required Associated Types§

Source

type Slot<'a>: IsoInSlot
where Self: 'a,

A reserved slot borrowing this endpoint.

Required Methods§

Source

async fn ready( &mut self, ) -> Result<(Option<NonZeroU32>, Self::Slot<'_>), EndpointDisabledError>

Wait until the next transfer can be queued, returning

  • the number of skipped service intervals (if any) since the service interval of the last IsoInSlot::write, and

  • an IsoInSlot for the next available service interval.

Service intervals are skipped if a transfer isn’t submitted in time.

Skipped service intervals are handled in an implementation defined way: the device may either respond to the host’s request with an empty transfer, or not respond to the host at all.

After the endpoint is enabled, the skipped service interval count will stay at zero until the first call to IsoInSlot::write.

After that, if ready is called too late for the next sequential service interval, it will return the number of service intervals that were skipped.

IsoInSlot::write will always reset the skipped service interval count to zero, regardless of whether it returns an error or not.

If IsoInSlot::write returns an error, the service interval has been or will be skipped, but it will not increment the skipped service interval counter, which will stay at zero.

When the endpoint is disabled, any transfers in the queue will be silently dropped. If there is an active IsoInSlot, it’s transfer will be dropped even if IsoInSlot::write returns Ok

§Cancel safety

Dropping this future will not reset the skipped service interval count or reserve a service interval and queue slot.

Dropping the slot before calling IsoInSlot::write will roll back the effects of ready. The service interval and queue slot will no longer be reserved and the skipped service interval count will not be reset.

§Examples
async fn example(mut ep: impl IsoEndpointIn, mut get_packet: impl FnMut() -> [u8; 8]) {
    assert!(ep.info().max_packet_size >= 8);
    ep.wait_enabled().await;
    loop {
        let Ok((skipped, slot)) = ep.ready().await else {
            break;
        };
        if let Some(skipped) = skipped {
            // throw away packets to avoid desynchronization
            for _ in 0..skipped.get() {
                let _ = get_packet();
            }
        }
        match slot.write(&get_packet()) {
            // In this case, we don't care if we may have sent an
            // empty packet instead of the real packet
            Ok(()) | Err(IsoWriteError::TooLate) => {}

            // We already checked that our max transfer size is big enough
            Err(IsoWriteError::BufferOverflow) => unreachable!(),

            // The error is non-exhaustive, so we need to handle future errors
            Err(err) => panic!("{}", err),
        }
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§