4 releases (breaking)

0.3.0 Aug 5, 2024
0.2.0 May 20, 2024
0.1.0 Jan 11, 2024
0.0.0 Apr 21, 2021

#37 in Hardware support

Download history 1635/week @ 2024-08-19 2235/week @ 2024-08-26 3140/week @ 2024-09-02 2450/week @ 2024-09-09 2903/week @ 2024-09-16 2373/week @ 2024-09-23 1529/week @ 2024-09-30 1778/week @ 2024-10-07 1350/week @ 2024-10-14 1988/week @ 2024-10-21 1832/week @ 2024-10-28 2025/week @ 2024-11-04 1722/week @ 2024-11-11 2189/week @ 2024-11-18 1463/week @ 2024-11-25 1309/week @ 2024-12-02

6,727 downloads per month
Used in 17 crates (14 directly)

MIT/Apache

495KB
10K SLoC

embassy-usb

Async USB device stack for embedded devices in Rust.

Features

  • Native async.
  • Fully lock-free: endpoints are separate objects that can be used independently without needing a central mutex. If the driver supports it, they can even be used from different priority levels.
  • Suspend/resume, remote wakeup.
  • USB composite devices.
  • Ergonomic descriptor builder.
  • Ready-to-use implementations for a few USB classes (note you can still implement any class yourself outside the crate).
    • Serial ports (CDC ACM)
    • Ethernet (CDC NCM)
    • Human Interface Devices (HID)
    • MIDI

Adding support for new hardware

To add embassy-usb support for new hardware (i.e. a new MCU chip), you have to write a driver that implements the embassy-usb-driver traits.

Driver crates should depend only on embassy-usb-driver, not on the main embassy-usb crate. This allows existing drivers to continue working for newer embassy-usb major versions, without needing an update, if the driver trait has not had breaking changes.

Configuration

embassy-usb has some configuration settings that are set at compile time, affecting sizes and counts of buffers.

They can be set in two ways:

  • Via Cargo features: enable a feature like <name>-<value>. name must be in lowercase and use dashes instead of underscores. For example. max-interface-count-3. Only a selection of values is available, check Cargo.toml for the list.
  • Via environment variables at build time: set the variable named EMBASSY_USB_<value>. For example EMBASSY_USB_MAX_INTERFACE_COUNT=3 cargo build. You can also set them in the [env] section of .cargo/config.toml. Any value can be set, unlike with Cargo features.

Environment variables take precedence over Cargo features. If two Cargo features are enabled for the same setting with different values, compilation fails.

MAX_INTERFACE_COUNT

Max amount of interfaces that can be created in one device. Default: 4.

Interoperability

This crate can run on any executor.

Dependencies

~6.5MB
~117K SLoC