Expand description
USB HID (Human Interface Device) class.
The module is split in two halves:
HidClass— the USB side. It owns the interface and the interrupt endpoints, writes the interface/HID/endpoint descriptors, serves the report descriptor, answers the HID class requests (Get/Set Report,Get/Set Idle,Get/Set Protocol) and forwards reports to the device.HidDevice— the HID side. A report descriptor, endpoint sizes and the reports the function exchanges with the host.
Ready-made functions live in the submodules:
| Function | Reports |
|---|---|
keyboard::Keyboard | boot keyboard: 8-byte input, 1-byte LED output |
mouse::Mouse | boot mouse: 4-byte input |
custom::CustomHid | caller-supplied report descriptor |
power::PowerDevice | HID Power Device: status, measurements, battery, configuration, controls |
§Example
ⓘ
use my_hal_usb::{UsbBusAllocator, UsbDeviceBuilder};
use my_hal_usb::class::hid::{HidClass, keyboard::{Keyboard, KeyboardReport}};
use my_hal_usb::MyBus;
let alloc = UsbBusAllocator::new(MyBus::new(/* peripheral */));
let mut kbd = HidClass::new(&alloc, Keyboard::new());
let mut dev = UsbDeviceBuilder::new(&alloc, 0x2E8A, 0x000B)
.product("Pico HID Keyboard")
.build();
loop {
dev.poll(&mut [&mut kbd]);
let report = KeyboardReport::default();
let _ = kbd.send_input(&report.to_bytes());
}§Reaching the device
The class owns the device, so applications drive it through
HidClass::device_mut.
Re-exports§
pub use device::HidDevice;pub use device::HidSpec;pub use device::ReportType;
Modules§
- custom
- HID function with a caller-supplied report descriptor.
- device
HidDevice— what a HID function has to provide.- hid_
descriptor_ type - HID class descriptor types.
- hid_
protocol - HID protocol (
bInterfaceProtocol), only meaningful for boot devices. - hid_
protocol_ mode - Values exchanged by
Get Protocol/Set Protocol(HID 1.11 §7.2.5). - hid_
request - HID class-specific request codes (
bRequest). - hid_
subclass - HID subclass (
bInterfaceSubClass). - keyboard
- Boot-compatible keyboard.
- mouse
- Boot-compatible mouse.
- power
- HID Power Device (UPS, power supply, battery system).