Skip to main content

UsbBusAllocator

Struct UsbBusAllocator 

Source
pub struct UsbBusAllocator<B: UsbBus> { /* private fields */ }
Expand description

Wraps a UsbBus during the endpoint-allocation phase.

Classes call the bulk, interrupt, interface, and string helper methods in their constructors to obtain typed endpoint handles and resource indices. Once all classes are constructed, UsbDevice::build calls freeze() internally, which enables the peripheral and returns a &B reference that persists for the allocator’s lifetime.

§Why no mem::forget

The original usb-device crate used mem::forget on a RefMut guard to permanently lock a RefCell<B>. This crate instead uses UnsafeCell<B> + Cell<bool> for the frozen flag. The safety invariant is:

  • Before freeze: only alloc_ep (via &mut *self.bus.get()) mutates the bus, and it is called sequentially (single-threaded embedded context).
  • After freeze: no &mut B is ever created again; all &B users are sound.

Implementations§

Source§

impl<B: UsbBus> UsbBusAllocator<B>

Source

pub fn new(bus: B) -> Self

Wrap a bus implementation. The bus must not yet be enabled.

Source

pub fn alloc<D: EndpointDir>( &self, addr: Option<EndpointAddress>, ep_type: EndpointType, max_packet: u16, interval: u8, ) -> UsbResult<Endpoint<'_, B, D>>

Allocate an endpoint with the specified direction and parameters.

This delegates to UsbBus::alloc_ep. Prefer the typed helpers (bulk, interrupt, …) in class constructors.

Source

pub fn control<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>

Allocate a control endpoint (panics on allocation failure).

Source

pub fn bulk<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>

Allocate a bulk endpoint (panics on allocation failure).

Source

pub fn interrupt<D: EndpointDir>( &self, max_packet: u16, interval: u8, ) -> Endpoint<'_, B, D>

Allocate an interrupt endpoint (panics on allocation failure).

Source

pub fn isochronous<D: EndpointDir>( &self, synchronization: IsoSynchronization, usage: IsoUsage, max_packet: u16, interval: u8, ) -> Endpoint<'_, B, D>

Allocate an isochronous endpoint (panics on allocation failure).

Source

pub fn interface(&self) -> InterfaceNumber

Allocate the next sequential interface number.

Source

pub fn string(&self) -> StringIndex

Allocate the next sequential string descriptor index.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.