Author Topic: Interesting HID report descriptor discovery  (Read 10748 times)

android

  • Member
  • ***
  • Posts: 5
Interesting HID report descriptor discovery
« on: March 16, 2016, 07:39:21 am »
I can't believe I've only just realised this (since it seems like I've read the HID spec a million times)...

For  HID report descriptor items where the item value is zero (0), then usually I've seen a 1-byte length value specified, followed by a 0x00.
For example, LOGICAL_MINIMUM (0) is mostly coded as:

Code: [Select]
0x15, 0x00
Alternatively, you could code the same value (0) as either a 2- or 4-byte value as follows (but why would you?):

Code: [Select]
0x16, 0x00, 0x00
0x17, 0x00, 0x00, x00, 0x00

What I completely missed was that you can specify a 0-length value - for which the item value can only be 0 - as follows:

Code: [Select]
0x14
All of the above encodings means exactly the same thing: LOGICAL_MINIMUM (0)

Now we can all save a byte here and there!
Ok, it's not much, but when you're storing a report descriptor in a microcontroller every byte counts!  ;D

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interesting HID report descriptor discovery
« Reply #1 on: March 16, 2016, 10:50:55 am »
Interesting. Are you aware of documentation for this? I found:

6.2.2.4 in the HID spec:

An Input item could have a data size of zero (0) bytes. In this case the value of
each data bit for the item can be assumed to be zero. This is functionally
identical to using a item tag that specifies a 4-byte data item followed by four
zero bytes.

But this applies only to Input items, which are Main items, and logical minimum is a Global item.

Also:

The default data value for all Main items is zero (0).

But I didn't see a default value for Global items in the spec.

android

  • Member
  • ***
  • Posts: 5
Re: Interesting HID report descriptor discovery
« Reply #2 on: March 18, 2016, 06:23:49 am »
Yes, the specification is a little non-specific (:D) on this, but the committee went to a lot of trouble to allow all items (main, global and local) to have a 2-bit length code (allowing 0-, 1-, 2-, and 4-byte data values). It seems reasonable to assume that 0 length also implies a 0 data value.

The example I found with 0-byte LOGICAL_MINIMUM  (and PHYSICAL_MINIMUM) was from http://lxr.free-electrons.com/source/drivers/hid/hid-lg.c

It promises to be an economical way to reset PHYSICAL_MINIMUM/PHYSICAL_MAXIMUM to the default 0 (which seems to be a common enough omission in many report descriptors I've seen ... often resulting in physical units being applied inappropriately to subsequent items).

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Interesting HID report descriptor discovery
« Reply #3 on: March 18, 2016, 11:30:36 am »
Ah, I see. The bSize member of any short item can have a size of 0 bytes (6.2.2.2). Nice!