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: onlyalloc_ep(via&mut *self.bus.get()) mutates the bus, and it is called sequentially (single-threaded embedded context). - After
freeze: no&mut Bis ever created again; all&Busers are sound.
Implementations§
Source§impl<B: UsbBus> UsbBusAllocator<B>
impl<B: UsbBus> UsbBusAllocator<B>
Sourcepub fn alloc<D: EndpointDir>(
&self,
addr: Option<EndpointAddress>,
ep_type: EndpointType,
max_packet: u16,
interval: u8,
) -> UsbResult<Endpoint<'_, B, D>>
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.
Sourcepub fn control<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>
pub fn control<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>
Allocate a control endpoint (panics on allocation failure).
Sourcepub fn bulk<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>
pub fn bulk<D: EndpointDir>(&self, max_packet: u16) -> Endpoint<'_, B, D>
Allocate a bulk endpoint (panics on allocation failure).
Sourcepub fn interrupt<D: EndpointDir>(
&self,
max_packet: u16,
interval: u8,
) -> Endpoint<'_, B, D>
pub fn interrupt<D: EndpointDir>( &self, max_packet: u16, interval: u8, ) -> Endpoint<'_, B, D>
Allocate an interrupt endpoint (panics on allocation failure).
Sourcepub fn isochronous<D: EndpointDir>(
&self,
synchronization: IsoSynchronization,
usage: IsoUsage,
max_packet: u16,
interval: u8,
) -> Endpoint<'_, B, D>
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).
Sourcepub fn interface(&self) -> InterfaceNumber
pub fn interface(&self) -> InterfaceNumber
Allocate the next sequential interface number.
Sourcepub fn string(&self) -> StringIndex
pub fn string(&self) -> StringIndex
Allocate the next sequential string descriptor index.