Search code examples
usbhid

HID Power Device specification example doesn't indicate values


I'm trying to report battery information for a battery-powered HID device (USB when plugged, BLE otherwise). Reading through the report descriptor from the example in Appendix A of Usage Tables for HID Power Devices (v1.1) I see two collections for reporting data about the battery to the host:

UsagePage(Power Device), Unit(none),
Usage(PresentStatus), Collection(Logical), ; Present status collection
    Usage(Good),
    UsagePage(Battery System), Usage(BelowRemainingCapacityLimit),
    Usage(Charging), Usage(Discharging),
    ReportSize(1), ReportCount(4), Logical Minimum (0), Logical Maximum (1), Unit(0),
    Feature(Constant, Variable, Absolute, Volatile),
End Collection(), ; End of Present Status collection
UsagePage(Power Device),
Usage(ChangedStatus), Collection(Logical), ; Changed Status collection
    Usage(Good),
    UsagePage(Battery System), Usage(BelowRemainingCapacityLimit),
    Usage(Charging), Usage(Discharging),
    ReportSize(2), ReportCount(4), Logical Minimum (0), Logical Maximum (1),
    Input(Data, Variable, Absolute, Volatile),
End Collection(), ; End of Changed Status collection

I only have a LiPo battery and a diode to charge it, so I am planning on taking out much of the rest of the power device stuff since I think I can get everything I want from the Battery System usage page. As a result I am looking at something more like (feel free to tell me if this is doomed form the start):

UsagePage(Battery System), Usage(BelowRemainingCapacityLimit),
Usage(Charging), Usage(Discharging),
ReportSize(1), ReportCount(3), Logical Minimum (0), Logical Maximum (1), Unit(0),
Feature(Constant, Variable, Absolute, Volatile),

Looking at the report from the spec, I have two questions:

  1. Why is CapacityMode only size 1? The values are 0 - 3, isn't that a size 2?

  2. What actually goes into the ChangedStatus collection? I see that the report sizes are 2 instead of 1 - are the reporting the old status on there as well? I'm not seeing anything elsewhere in the spec that gives an indication. In fact, the spec says that ChangedStatus elements should be boolean, which should be size 1, no?


Solution

    1. CapacityMode can have values 0 to 3, but if your device only supports mode 0 (capacity measured in milliamp-hours) or mode 1 (capacity measured in milliwatt-hours) then I think it is ok to have a 1-bit wide field to record this. You could even define an 8-bit field that only stores the values 0 or 1 even though it could hold values up to 255.

    2. I think the authors of the examples may have been trying to align the fields into 8 bits by making each of the 4 status bits 2-bits wide - so 0, would be stored as 00 and 1 would be stored as 01 in the report. Or it could have been a typo - I have seen many other examples in the USB specifications that have errors in them.