microsoft/hidtools

Constant support

Closed this issue · 1 comments

To be able to "tell the truth" better in the descriptor, and also to potentially increase performance, it would be very valuable to be able to set constants in the report.

Currently, the only time I see Kind.Constant being used is for padding. We should be able to assign Constant to selected fields such as fixed device attribute/feature reports, and in the TOML provide the fixed value to be assigned to the struct field in C++ generation.

The closest I can current get to communicating this intent in a variableItem is to set a logicalValueRange with the lower and upper bound equal, but this still produces Variable.

Interestingly, if I set LogicalMinimum(0), LogicalMaximum(0) then Waratah completely omits a ReportSize - seemingly assuming sizeInBits = 0, even though if I write the latter explicitly it's rejected. Caused by contiguous attribute optimization; bit size is still correctly 1

HID doesn't have the idea of 'fixed constants' (e.g. C++ const). 'Constant' in HID means that the value can't be modified by the Host (so, only interesting when applied to Feature Reports), not that the value can't change over subsequent reports sent from Device->Host

From the HID spec

"Indicates whether the item is data or a constant value. Data indicates the item is
defining report fields that contain modifiable device data. Constant indicates the item is a static read-only field in a report and cannot be modified (written) by the host."