Expand description
HID Power Device (UPS, power supply, battery system).
Implements the Universal Serial Bus Usage Tables for HID Power Devices
(Power Device page 0x84 and Battery System page 0x85). A power device is
an ordinary HID device: it uses the HID descriptors and endpoints, and only
differs in its report descriptor and report layout.
§Reports
| Report ID | Type | Direction | Payload |
|---|---|---|---|
| 1 | Input | device → host | PowerStatus present + changed status |
| 2 | Input | device → host | PowerMeasures voltage, current, … |
| 3 | Input | device → host | BatteryState battery flags and charge |
| 4 | Feature | both | PowerConfig configuration values |
| 5 | Output | host → device | PowerControls switch commands |
Input reports are pushed to the interrupt IN endpoint by
PowerDevice::poll, which the HidClass calls on every
device poll. A report whose contents did not change is not re-sent, so the
host sees a new input report whenever something actually changed.
Feature writes (report 4) and output reports (report 5) are buffered and
picked up by the application through PowerDevice::take_config_write and
PowerDevice::take_controls. Feature reads return the values last passed
to PowerDevice::set_config — i.e. what the device actually applied, not
what the host requested.
§Units
Values follow the units in the specification’s HID unit table:
| Field | Unit | Scale |
|---|---|---|
| Voltage, transfer voltages | Volt (unit exponent −2) | centivolt |
| Current | Amp (unit exponent −2) | centiamp |
| Frequency | Hertz | hertz |
| Percent load, state of charge | none | percent |
| Temperature | Kelvin | kelvin |
| Delays | second | second |
| Runtime to empty | none | minute (as in Smart Battery) |
Numeric fields are clamped to the logical range 0..=32767 declared in the
report descriptor.
§Example
use my_hal_usb::{UsbBusAllocator, UsbDeviceBuilder};
use my_hal_usb::class::hid::{HidClass, power::{PowerConfig, PowerDevice, PowerStatus}};
use my_hal_usb::MyBus;
let alloc = UsbBusAllocator::new(MyBus::new(/* peripheral */));
let mut power = HidClass::new(&alloc, PowerDevice::power_supply());
let mut dev = UsbDeviceBuilder::new(&alloc, 0x2E8A, 0x000D)
.product("Bench Power Supply")
.build();
power.device_mut().set_config(PowerConfig::default());
power.device_mut().set_status(
PowerStatus::PRESENT | PowerStatus::GOOD | PowerStatus::USED,
PowerStatus::NONE,
);
loop {
dev.poll(&mut [&mut power]);
if let Some(controls) = power.device_mut().take_controls() {
// host pressed a switch in the output report
}
}Modules§
- battery_
usage - Battery System page (
0x85) usage IDs. - power_
usage - Power Device page (
0x84) usage IDs. - report_
id - Report IDs used by a
PowerDevice.
Structs§
- Battery
State - Battery status and charge (input report 3).
- Battery
Status - Battery status flags (input report 3).
- Power
Config - Configuration values (feature report 4).
- Power
Controls - Switch commands (output report 5).
- Power
Device - HID Power Device: a UPS or power supply.
- Power
Measures - Measurements (input report 2).
- Power
Status - Present-status and changed-status flags (input report 1).
Enums§
- Power
Device Type - Application collection usage — the device type the host sees.
Constants§
- POWER_
SUPPLY_ REPORT_ DESCRIPTOR - Report descriptor of a power supply (
PowerDeviceType::PowerSupply). - UPS_
REPORT_ DESCRIPTOR - Report descriptor of a UPS (
PowerDeviceType::Ups).