usb-stack
MCU-independent USB device stack core, shared by the
rp2350-usb,
ch32x035-usb and
esp32p4-usb HAL crates.
The bus trait is packet-oriented and speed agnostic: a full-speed driver leaves
[UsbBus::MAX_PACKET_SIZE] at its 64-byte default, a high-speed one overrides
it (the ESP32-P4 HS core uses 512), and the classes size their endpoints from
it.
A microcontroller crate implements [UsbBus] for its USB peripheral and
re-exports this crate; everything else (device state machine, control pipe,
descriptors, classes) is hardware independent.
Adding it to a project
[]
= "0.1"
The crate is no_std and has no mandatory dependencies; enable the defmt
feature to log through defmt. It requires Rust 1.85 (edition 2024).
Layers
| Module | Contents |
|---|---|
bus |
UsbBus trait, UsbBusAllocator, PollResult |
endpoint |
EndpointAddress, EndpointType, direction markers, endpoint handles |
control |
ControlPipe (EP0 state machine) and the ControlIn / ControlOut handles classes answer requests with |
descriptor |
DescriptorWriter and standard USB constants |
device |
UsbDeviceBuilder / UsbDevice — device state machine, descriptor serving, control-transfer dispatch |
class |
UsbClass trait, CDC-ACM, HID (boot keyboard, boot mouse, custom reports, HID Power Device), GS_USB (CAN), i2c-tiny-usb, UAC 1.0 |
Implementing a bus
use ;
The bus is packet-oriented: poll reports which endpoints completed an OUT
transfer, an IN transfer or received a SETUP packet, and the device layer
drives read/write from there. Implementations own their endpoint buffers
and must keep them alive for the lifetime of the bus.
Features
defmt(off by default) — log throughdefmt.
Status
Version 0.1 — the API is still settling. Classes currently shipped: CDC-ACM, HID (boot keyboard, boot mouse, custom reports, HID Power Device), GS_USB (CAN), i2c-tiny-usb and UAC 1.0.
See CHANGELOG.md for the release history.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.