Home |
HID (Human Interface Devices) |
HID (Human Interface Devices)HID is one of the most frequently used USB classes. The HID class specification http://www.usb.org/developers/devclass_docs/HID1_11.pdf was primarily defined for devices that are used by humans to control the operation of computer systems. Typical examples of HID class devices include keyboards, mice, trackballs, and joysticks. An HID device may have knobs, switches, buttons, sliders, throttles, steering wheels, rudder pedals, etc. The HID class is also frequently used for devices that may not require human interaction but provide data in a similar format as HID class devices. Examples are bar-code readers, thermometers, or voltmeters. Since Windows includes a class driver for HID devices, many USB devices for industrial or laboratory equipment use the HID class. Unlike many other classes, the format of the data an HID device can send to the host is not defined by the class specification. Instead, HID devices are required to provide one or more Report Descriptors which enumerate all data fields of a report the device can send. The interface of an HID device must publish an Interrupt endpoint used to transfer this report. For each field in the report, the Report Descriptor defines how many bits the field consumes, how often this data is repeated, and which Usage Page and Usage it has. The Usage Pages and Usages are values published in the HID Usage Tables specification http://www.usb.org/developers/devclass_docs/Hut1_11.pdf and describe which type of data the field contains. Unfortunately, HID Report Descriptors have a rather complex structure and are difficult to read. Demo program HIDShow contains a simple HID Report Descriptor parser. Here is an example dump of the Report Descriptor of a USB mouse: HID Descriptor version 1.10, Country: 0 Report: Usage Page(1) Usage(2) Collection(Application (mouse, keyboard)) Usage(1) Collection(Physical (group of axes)) Usage Page(9) Usage Minimum(1) Usage Maximum(3) Logical Minimum(0) Logical Maximum(1) Report Count(3) Report Size(1) Input(Data Var Abs NoWrap Linear Pref NoNull NonVol BitField) Report Count(1) Report Size(5) Input(Const Array Abs NoWrap Linear Pref NoNull NonVol BitField) Usage Page(1) Usage(48) Usage(49) Usage(56) Logical Minimum(129) Logical Maximum(127) Report Size(8) Report Count(3) Input(Data Var Rel NoWrap Linear Pref NoNull NonVol BitField) End Collection() Usage(60) Logical Minimum(0) Logical Maximum(1) Report Size(1) Report Count(1) Feature(Data Var Abs NoWrap Linear NoPref NoNull NonVol BitField) Report Count(7) Feature(Const Array Abs NoWrap Linear Pref NoNull NonVol BitField) End Collection() The interesting items are Input which add a field to the report. The Input item itself defines a set of flags for the field. Other field properties precede the Input item. In the example above, the first Input item specifies Usage Page 9 (Button Page), Usage range 1-3 (in Usage Page 9, Usage 1 is defined as "Button 1 (primary/trigger)", 2 is "Button 2 (secondary)", and 3 is "Button 3 (tertiary)"), size 1 bit, repeat 3 times. Thus, the report generated by this device starts with 3 individual bits, each describing a button. The second Input item is not preceded by any Usage. Here, it defines an unused (padding) field of 5 bits. The third and last Input item specifies Usage Page 1 (Generic Desktop Page) and Usages 48, 49, and 56 which are X, Y, and Z coordinates, respectively, with 8 bits each, repeated 3 times. This field is an array of 3 bytes. HIDShow uses this information to generate a C/C++ structure declaration for the data sent by this device: typedef struct { BYTE D0_0:1; // Data Var Abs NoWrap Linear Pref NoNull NonVol BitField BYTE D0_1:1; // Data Var Abs NoWrap Linear Pref NoNull NonVol BitField BYTE D0_2:1; // Data Var Abs NoWrap Linear Pref NoNull NonVol BitField BYTE P1:5; // padding char D2[3]; // Data Var Rel NoWrap Linear Pref NoNull NonVol BitField BYTE Pad[4]; } HID_046D_C001_0_0_Data; The final Pad[4] array is generated by HIDShow because the endpoint on which this data structure is transferred from the mouse has a packet length of 8 bytes, but the Report Descriptor only defines 4 bytes worth of data. An application can use this structure to receive on the device's Interrupt endpoint, as demonstrated by program HIDDemo. Porting RTUSB-32 to other Platforms
|