Expand description
This library allows implementation of USB peripherals, so called USB gadgets, on Linux devices that have a USB device controller (UDC). Both, pre-defined USB functions and fully custom implementations of the USB interface are supported.
The following pre-defined USB functions, implemented by kernel drivers, are supported:
- network interface: CDC ECM, ECM subset, EEM, NCM, RNDIS
- serial port: CDC ACM, generic
- human interface device (HID)
- mass-storage device (MSD)
- printer device
- musical instrument digital interface (MIDI)
- audio device: UAC1 and UAC2
- video device (UVC)
In addition fully custom USB functions can be implemented in user-mode Rust code.
Support for OS-specific descriptors and WebUSB is also provided.
§Requirements
A USB device controller (UDC) supported by Linux is required.
The Linux kernel configuration options CONFIG_USB_GADGET and CONFIG_USB_CONFIGFS
need to be enabled.
root permissions are required to configure USB gadgets and
the configfs filesystem needs to be mounted.
Some settings are only supported by newer kernels.
Optional settings are only written when set; if left at None, the kernel default is used.
Setting an option that is unsupported by the running kernel makes registration
fail with an error of kind ErrorKind::Unsupported.
The exceptions are OS descriptors and WebUSB, which are skipped with a warning.
§Usage
Start defining a USB gadget by calling Gadget::new.
When the gadget is fully specified, call Gadget::bind to register it with
a USB device controller (UDC).
Modules§
- function
- USB gadget functions.
Structs§
- Class
- USB gadget or interface class.
- Config
- USB gadget configuration.
- Gadget
- USB gadget definition.
- Id
- USB gadget id.
- OsDescriptor
- USB gadget operating system descriptor.
- RegFunction
- USB gadget registered with the system.
- RegGadget
- If this was obtained by calling
Gadget::bind, the USB gadget will be unbound and removed when this is dropped. - Strings
- USB gadget description strings.
- Udc
- USB device controller (UDC).
- WebUsb
- USB gadget WebUSB descriptor.
Enums§
- Language
- USB language id.
- Speed
- USB speed.
- UdcState
- USB device controller (UDC) connection state.
- UsbVersion
- USB version.
- WebUsb
Version - WebUSB version.
Constants§
- GADGET_
IOC_ MAGIC - USB gadget ioctl magic byte.
Functions§
- default_
udc - The default USB device controller (UDC) in the system by alphabetical sorting.
- registered
- Get all USB gadgets registered on the system.
- remove_
all - Remove all USB gadgets defined on the system.
- udcs
- Gets the available USB device controllers (UDCs) in the system.
- unbind_
all - Unbind all USB gadgets defined on the system.