Skip to main content

Module hid

Module hid 

Source
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:

FunctionReports
keyboard::Keyboardboot keyboard: 8-byte input, 1-byte LED output
mouse::Mouseboot mouse: 4-byte input
custom::CustomHidcaller-supplied report descriptor
power::PowerDeviceHID 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).

Structs§

HidClass
USB HID class — the transport for a HidDevice.