Reputation: 567
I have a Speedlink joystick which is a USB remake of the iconic Competition Pro from the Commodore/Atari era. It gives me the following report descriptor:
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x05, // Usage (Game Pad)
0xA1, 0x01, // Collection (Application)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x35, 0x00, // Physical Minimum (0)
0x46, 0xFF, 0x00, // Physical Maximum (255)
0x66, 0x00, 0x00, // Unit (None)
0x75, 0x08, // Report Size (8)
0x95, 0x02, // Report Count (2)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x04, // Usage Maximum (0x04)
0x95, 0x04, // Report Count (4)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x95, 0x04, // Report Count (4)
0x81, 0x03, // Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
The device reports its axises with a logical maximum of 255, but the "axises" are in fact comparable to a hat switch: when the stick is pushed towards one direction it sends either 0 or 255, while when in default position it sends 127.
My Issue:
As you can see there is no re-declaration of the logical maximum in the report descriptor, so when my parser reaches the part where the buttons are declared it takes the former value of 255, as the logical maximum is a global item. The four joystick buttons, though, are of course just on/off switches which will send "1" when pressed and "0" when released. As the report size for the buttons is correctly stated as 1(bit) there would of course be no possibility of any value > 1.
One observation: The X and Y axises are encapsulated in a physical collection. Could it be that global items that are defined within a collection are only valid within that collection?
Assuming that would be the case, the logical min/max declarations for the buttons would be missing in the descriptor. In all tutorials I read about HID report descriptors it is stated that, besides usage page, usage, report size and report count the logical min and max belong to the bare minimum a report descriptor would need.
Assuming however one could omit these items, there would have to be default values for missing items, which, if true, would have to be "1" for logical max for my device's report descriptor to make sense.
Could this be the case? The HID document at usb.org only says about some other items (physical maximum e.g.) that when omitted they stay in an "undefined state", but I cannot find information about any default values.
Upvotes: 0
Views: 1067
Reputation: 1740
Could it be that global items that are defined within a collection
are only valid within that collection?
No, I don't think so. A HID report parser should parse items sequentially and when a GLOBAL item is reached it should remember the value of that item until it is explicitly changed by another GLOBAL item. When a MAIN item is reached, the value of all LOCAL items are reset to "undefined" but the value of all GLOBAL items should be retained until explicitly changed to another value. My understanding is that collections merely group items together for naming purposes rather than for scoping the values of the contained items.
Could this be the case? The HID document at usb.org only says about some
other items (physical maximum e.g.) that when omitted they stay in an
"undefined state", but I cannot find information about any default
values.
I think the spec, by having an "undefined" state is delegating the assignment of default values to the host system.
Personally, I think resetting to "undefined" state is a bit vague and I would much rather see the spec changed to have all LOCAL items reset to a known state (e.g. 0) when a MAIN item is encountered - but that's not likely to happen. I suspect that many parsers would treat "undefined" as zero but that is not guaranteed.
As an aside, if that was done, it would enable a small saving in HID report descriptor sizes by allowing, for example, 15 00 (LOGICAL_MINIMUM = 0) to be replaced with just 14 - i.e. an item with a zero-length value - which could practically be interpreted as an item with a value of 0. Unfortunately the spec, although it allows for zero-length item values, does not say whether the resulting value is zero or undefined.
You are right in that a 1-bit wide field cannot have a LOGICAL_MAXIMUM greater than 1. IMHO, the report descriptor is invalid and it should be rejected at device enumeration time - although I suspect many parsers let it pass, if only because enforcing the standard may appear to be a problem with the operating system rather than the device manufacturer.
Disclaimer: The above is just my interpretation of the specifications (which are a little difficult to digest so I may well be wrong)
Upvotes: 0