【问题标题】:Two byte report count for hid report descriptor隐藏报告描述符的两字节报告计数
【发布时间】:2016-08-13 12:21:12
【问题描述】:

我正在尝试为 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 字段是从哪里来的?我没有看到任何文档。

【问题讨论】:

    标签: hid descriptor


    【解决方案1】:

    REPORT_COUNT 在第 36 页的 6.2.2.7 全局项目部分的 Device Class Definition for HID 1.11 文档中定义为:

    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).
    

    上述代码中的 nn 是项目长度指示符 (bSize),在前面的 6.2.2.2 短项目小节中定义为:

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

    相当令人困惑的是,bSize 的有效值以十进制列出。因此,在二进制中,nn 的位将是:

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

    将 REPORT_COUNT 放在一起,这是一个无符号整数,可以指定以下替代方案:

    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)
    

    同理,对于LOGICAL_MAXIMUM,它是一个有符号整数(通常有例外):

    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)
    

    规范不清楚零长度项目的默认值通常是什么。它仅在 6.2.2.4 主要项目部分的末尾提到,主要项目类型以及该类型中的 INPUT 项目标签具有默认值 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.
    

    假设 0 作为其他项目类型的默认值也是合理的,但对于 REPORT_COUNT(一个 GLOBAL 项目),值 0 并不是一个合理的默认值(恕我直言)。规范并没有真正说明。

    【讨论】:

    • 很好的答案。谢谢!
    • Windows HID 解析器不接受未指定的零大小项目(虽然它们在 Mac OS、iOS 和 Linux 上工作)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多