hid报告描述符的两个字节报告计数

时间:2016-04-20 16:50:47

标签: hid descriptor

我正在尝试为USB 3.0创建一个HID报告描述符,报告计数为1024字节。 usb.org上针对HID的文档似乎没有提到两个字节的报告计数。尽管如此,我看到有些人使用0x96(而不是0x95)来输入两个字节的数,例如:

0x96,0x00,0x02,// REPORT_COUNT(512)

取自这里: Custom HID device HID report descriptor

同样,从同一个例子中,0x26用于两个字节的逻辑最大值。

我的问题:这个0x96和0x26字段来自哪里?我没有看到它的文档。

由于

1 个答案:

答案 0 :(得分:1)

REPORT_COUNT is defined in the Device Class Definition for HID 1.11 document in section 6.2.2.7 Global Items on page 36 as:

Report Count 1001 01 nn Unsigned integer specifying the number of data
                        fields for the item; determines how many fields are included in the
                        report for this particular item (and consequently how many bits are
                        added to the report).

The nn in the above code is the item length indicator (bSize) and is defined earlier in section 6.2.2.2 Short Items as:

bSize Numeric expression specifying size of data: 
      0 = 0 bytes 
      1 = 1 byte 
      2 = 2 bytes 
      3 = 4 bytes

Rather confusingly, the valid values of bSize are listed in decimal. So, in binary, the bits for nn would be:

00 = 0 bytes (i.e. there is no data associated with this item)
01 = 1 byte
10 = 2 bytes
11 = 4 bytes

Putting it all together for REPORT_COUNT, which is an unsigned integer, the following alternatives could be specified:

1001 01 00 = 0x94 = REPORT_COUNT with no length (can only have value 0?)
1001 01 01 = 0x95 = 1-byte REPORT_COUNT (can have a value from 0 to 255)
1001 01 10 = 0x96 = 2-byte REPORT_COUNT (can have a value from 0 to 65535)
1001 01 11 = 0x97 = 4-byte REPORT_COUNT (can have a value from 0 to 4294967295)

Similarly, for LOGICAL_MAXIMUM, which is a signed integer (usually, there is an exception):

0010 01 00 = 0x24 = LOGICAL_MAXIMUM with no length (can only have value 0?)
0010 01 01 = 0x25 = 1-byte LOGICAL_MAXIMUM (can have a values from -128 to 127)
0010 01 10 = 0x26 = 2-byte LOGICAL_MAXIMUM (can have a value from -32768 to 32767)
0010 01 11 = 0x27 = 4-byte LOGICAL_MAXIMUM (can have a value from -2147483648 to 2147483647)

The specification is unclear on what value a zero-length item defaults to in general. It only mentions, at the end of section 6.2.2.4 Main Items, that MAIN item types and, within that type, INPUT item tags, have a default value of 0:

Remarks - The default data value for all Main items is zero (0).
        - 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.

It would be reasonable to assume 0 as the default for other item types too, but for REPORT_COUNT (a GLOBAL item) a value of 0 is not really a sensible default (IMHO). The specification doesn't really say.

相关问题