Skip to main content

Module usb

Module usb 

Source
Expand description

USB-HID device stack.

Initialises an embassy-usb device that exposes one vendor-defined HID interface, per the project’s USB protocol (see crate hsm-usb-protocol).

The two endpoints are split into a [embassy_usb::class::hid::HidReader] (host -> token) and a [embassy_usb::class::hid::HidWriter] (token -> host). They are owned by separate async tasks in crate::tasks so reads and writes proceed independently.

Β§Lifetime model

[embassy_usb::class::hid::State] is invariant over its lifetime parameter, which means the 'd lifetime tag of the [HidReaderWriter] must match exactly the lifetime tag of the State it borrows. We therefore take the State as a separate parameter to build_usb with its own borrow, and the device lifetime 'd is derived from whichever borrow is shortest. In practice both borrows come from static storage at the call site, so 'd = 'static.

StructsΒ§

Irqs πŸ”’
UsbBuffers πŸ”’
Descriptor and control-transfer buffers borrowed by the embassy-usb builder for the lifetime of the device.

ConstantsΒ§

REPORT_SIZE πŸ”’
Size of the HID report in bytes (matches HID_REPORT_SIZE).

FunctionsΒ§

USBCTRL_IRQ πŸ”’ ⚠
build_usb πŸ”’
Build the USB device with one HID interface.

Type AliasesΒ§

HidRx πŸ”’
HID reader half: receives host -> token reports.
HidTx πŸ”’
HID writer half: sends token -> host reports.
UsbStack πŸ”’
embassy-usb device handle. Spawn its run future to keep the USB stack alive.