zoukankan      html  css  js  c++  java
  • USB HID Report Descriptor 报告描述符详解

    Report descriptors are composed of pieces of information. Each piece of information is called an Item.
    报告描述符由一些数据片组成。这些数据片被叫做Item。
    All items have a one-byte prefix that contains the item tag, item type, and item size. 
    每一个Item都包含一个字节的前缀,这个前缀中包含了三个信息--item tag,、item type、item size。
    An item may include optional item data。
    Item可以包含一个可选的数据段。
    The size of the data portion of an item is determined by its fundamental type.
    Item的数据部分的长度取决于Item的基本类型。
    There are two basic types of items: short items and long items.
    Item有两种基本类型:short items and long item。

    long item格式 (原文件名:long item.jpg) 


    short item格式 (原文件名:short item.jpg) 

    There are three categories of short item tags: Main, Global, and Local. 
    short item 的 item tags 有三种类型:Main, Global, and Local.

    Main items: </center>
    Main items are used to either define or group certain types of data fields within a Report descriptor. There are two types of Main items: data and non-data. Data-type Main items are used to create a field within a report and include Input, Output, and Feature. Other items do not create fields and are subsequently referred to as non-data Main items. 


    (原文件名:MAIN Item.jpg) 

    (原文件名:MAIN Item1.jpg) 
    好了,到此我们应该可以对照实际应用的报告描述符,寻找其中的 Main items了。 

    至此我们已经可以明白报告描述符中的几个MAIN Item的意义,接下来继续看Global Item 和 Local Item.

    Global Item: </center>
    Global items describe rather than define data from a control. A new Main item assumes the characteristics of the item state table. Global items can change the state table. As a result Global item tags apply to all subsequently defined items unless overridden by another Global item.  

    (原文件名:Global Item.jpg) 

    (原文件名:Global Item1.jpg) 

    至此我们已经可以明白报告描述符中的几个Global Item的意义

    Local Item: </center> 
    Local item tags define characteristics of controls. These items do not carry over to the next Main item. If a Main item defines more than one control, it may be preceded by several similar Local item tags. For example, an Input item may have several Usage tags associated with it, one for each control.  

    (原文件名:Local Item.jpg) 
    至此我们已经可以明白报告描述符中的几个Local Item的意义

    //该报告描述符号由HID Descriptor tool生成   
    以下是一个USB鼠标的报告描述符 
    code char MouseReportDescriptor[63] = {    
        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)    
        0x09, 0x06,                  // USAGE (Keyboard)    
        0xa1, 0x01,                    // COLLECTION (Application)   这就是一个MAIN Item,可以对应上图查看   
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)    
        0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)    
        0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)    
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)    
        0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)    
        0x75, 0x01,                    //   REPORT_SIZE (1)    
        0x95, 0x08,                    //   REPORT_COUNT (8)    
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
        0x95, 0x01,                    //   REPORT_COUNT (1)    
        0x75, 0x08,                    //   REPORT_SIZE (8)    
        0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
        0x95, 0x05,                    //   REPORT_COUNT (5)    
        0x75, 0x01,                    //   REPORT_SIZE (1)    
        0x05, 0x08,                    //   USAGE_PAGE (LEDs)    
        0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)    
        0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)    
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)     这就是一个MAIN Item,可以对应上图查看   
        0x95, 0x01,                    //   REPORT_COUNT (1)    
        0x75, 0x03,                    //   REPORT_SIZE (3)    
        0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)     这就是一个MAIN Item,可以对应上图查看  
        0x95, 0x06,                    //   REPORT_COUNT (6)    
        0x75, 0x08,                    //   REPORT_SIZE (8)    
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)    
        0x25, 0xFF,                    //   LOGICAL_MAXIMUM (255)    
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)    
        0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))    
        0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)    
        0x81, 0x00,                    //   INPUT (Data,Ary,Abs)     这就是一个MAIN Item,可以对应上图查看   
        0xc0                           // END_COLLECTION             这就是一个MAIN Item,可以对应上图查看          
    }; 

    --------------------------------------------------------------------------------------------------------------------------------------------------------------                               补充HID报告描述符说明.

    在USB中,USB Host是通过各种描述符来识别识别设备的,有设备描述符/配置描述符/接口描述符/断点描述符/字符串描述符/报告描述符等等.

    USB报告描述符是HID设备中的一个描述符,它是比较复杂的一个描述符.

    USB HID设备是通过报告来给传送数据的,报告有输入报告和输出报告.

    输入报告是USB设备发送数据给Host.PS:USB鼠标将鼠标移动和鼠标点击等信息返回给电脑,键盘将按键数据返回给电脑等.

    输出报告是Host发送数据给USB设备,PS:键盘上的数字键盘锁定灯和大写字母锁定灯等.

    报告是一个数据包,里面包含的是索要传送的数据.输入报告是通过中断输入断点输入的,而输出报告有点区别,当没有中断输出断点时,可以通过控制输出断电0发送,当有中断输出断点时,通过中断输出断点发出.

    而报告描述符,是描述一个报告以及报告里面的数据是用来干什么的.通过它,USB Host可以解析出报告里面的数据所表示的含义.它通过控制输入断点0返回,Host使用获取报告描述符命令来获取报告描述符,注意这个请求是发送到Interface,而不是设备.一个报告描述符可以描述多个报告,不同的报告通过Report ID来区分,Reort ID在报告最前面,即第一个byte.而当报告描述符中没有规定Report ID时,报告中就没有ID字段,开始就是数据.

  • 相关阅读:
    leetcode 33. Search in Rotated Sorted Array
    leetcode 32. Longest Valid Parentheses
    leetcode 28. Implement strStr()
    leetcode 27. Remove Element
    leetcode 26. Remove Duplicates from Sorted Array
    leetcode 24. Swap Nodes in Pairs
    leetcode 22. Generate Parentheses
    树莓派的频率管理和热控制
    sql执行insert插入一条记录同时获取刚插入的id
    全程直播个人博客重构过程,采用springboot+dubbo+jpa技术栈。
  • 原文地址:https://www.cnblogs.com/AlwaysOnLines/p/3859557.html
Copyright © 2011-2022 走看看