HID Class Overview
Overview
A HID device is composed of the following endpoints:
- A pair of control IN and OUT endpoints called the default endpoint.
- An interrupt IN endpoint.
- An optional interrupt OUT endpoint.
Table - HID Class Endpoints Usage describes the usage of the different endpoints:
Endpoint | Direction | Usage |
---|---|---|
Control IN | Device-to-host | Standard requests for enumeration, class-specific requests, and data communication (Input, Feature reports sent to the host with GET_REPORT request). |
Control OUT | Host-to-device | Standard requests for enumeration, class-specific requests and data communication (Output, Feature reports received from the host with SET_REPORT request). |
Interrupt IN | Device-to-host | Data communication (Input and Feature reports). |
Interrupt OUT | Host-to-device | Data communication (Output and Feature reports). |
Report
A host and a HID device exchange data using reports. A report contains formatted data giving information about controls and other physical entities of the HID device. A control is manipulable by the user and operates an aspect of the device. For instance, a control can be a button on a mouse or a keyboard, a switch, etc. Other entities inform the user about the state of certain device’s features. For instance, LEDs on a keyboard notify the user about the caps lock on, the numeric keypad active, etc.
The format and the use of a report data is understood by the host by analyzing the content of a Report descriptor. Analyzing the content is done by a parser. The Report descriptor describes the data provided by each control in a device. It is composed of items. An item is a piece of information about the device and consists of a 1-byte prefix and variable-length data. Refer to “Device Class Definition for Human Interface Devices (HID) Version 1.11”, section 5.6 and 6.2.2 for more details about the item format.
There are three principal types of items:
- Main item defines or groups certain types of data fields.
- Global item describes data characteristics of a control.
- Local item describes data characteristics of a control.
Each item type is defined by different functions. An item function can also be called a tag. An item function can be seen as a sub-item that belongs to one of the three principal item types. Table - Item’s Function Description for each Item Type gives a brief overview of the item’s functions in each item type. For a complete description of the items in each category, refer to “Device Class Definition for Human Interface Devices (HID) Version 1.11”, section 6.2.2.
Item type | Item function | Description |
---|---|---|
Main | Input | Describes information about the data provided by one or more physical controls. |
Output | Describes data sent to the device. | |
Feature | Describes device configuration information sent to or received from the device which influences the overall behavior of the device or one of its components. | |
Collection | Group related items (Input, Output or Feature). | |
End of Collection | Closes a collection. | |
Global | Usage Page | Identifies a function available within the device. |
Logical Minimum | Defines the lower limit of the reported values in logical units. | |
Logical Maximum | Defines the upper limit of the reported values in logical units. | |
Physical Minimum | Defines the lower limit of the reported values in physical units, that is the Logical Minimum expressed in physical units. | |
Physical Maximum | Defines the upper limit of the reported values in physical units, that is the Logical Maximum expressed in physical units. | |
Unit Exponent | Indicates the unit exponent in base 10. The exponent ranges from -8 to +7. | |
Unit | Indicates the unit of the reported values. For instance, length, mass, temperature units, etc. | |
Report Size | Indicates the size of the report fields in bits. | |
Report ID | Indicates the prefix added to a particular report. | |
Report Count | Indicates the number of data fields for an item. | |
Push | Places a copy of the global item state table on the CPU stack. | |
Pop | Replaces the item state table with the last structure from the stack. | |
Local | Usage | Represents an index to designate a specific Usage within a Usage Page. It indicates the vendor’s suggested use for a specific control or group of controls. A usage supplies information to an application developer about what a control is actually measuring. |
Usage Minimum | Defines the starting usage associated with an array or bitmap. | |
Usage Maximum | Defines the ending usage associated with an array or bitmap. | |
Designator Index | Determines the body part used for a control. Index points to a designator in the Physical descriptor. | |
Designator Minimum | Defines the index of the starting designator associated with an array or bitmap. | |
Designator Maximum | Defines the index of the ending designator associated with an array or bitmap. | |
String Index | String index for a String descriptor. It allows a string to be associated with a particular item or control. | |
String Minimum | Specifies the first string index when assigning a group of sequential strings to controls in an array or bitmap. | |
String Maximum | Specifies the last string index when assigning a group of sequential strings to controls in an array or bitmap. | |
Delimiter | Defines the beginning or end of a set of local items. |
A control’s data must define at least the following items:
- Input, Output or Feature Main items.
- Usage Local item.
- Usage Page Global item.
- Logical Minimum Global item.
- Logical Maximum Global item.
- Report Size Global item.
- Report Count Global item.
Table - HID Class Endpoints Usage shows the representation of a Mouse Report descriptor content from a host HID parser perspective. The mouse has three buttons (left, right and wheel). The code presented in Listing - Mouse Report Descriptor Example is an example of code implementation corresponding to this mouse Report descriptor representation.
(1) The Usage Page item function specifies the general function of the device. In this example, the HID device belongs to a generic desktop control.
(2) The Collection Application groups Main items that have a common purpose and may be familiar to applications. In the diagram, the group is composed of three Input Main items. For this collection, the suggested use for the controls is a mouse as indicated by the Usage item.
(3) Nested collections may be used to give more details about the use of a single control or group of controls to applications. In this example, the Collection Physical, nested into the Collection Application, is composed of the same 3 Input items forming the Collection Application. The Collection Physical is used for a set of data items that represent data points collected at one geometric point. In the example, the suggested use is a pointer as indicated by the Usage item. Here the pointer usage refers to the mouse position coordinates and the system software will translate the mouse coordinates in movement of the screen cursor.
(4) Nested usage pages are also possible and give more details about a certain aspect within the general function of the device. In this case, two Inputs items are grouped and correspond to the buttons of the mouse. One Input item defines the three buttons of the mouse (right, left and wheel) in terms of number of data fields for the item (Report Count item), size of a data field (Report Size item) and possible values for each data field (Usage Minimum and Maximum, Logical Minimum and Maximum items). The other Input item is a 13-bit constant allowing the Input report data to be aligned on a byte boundary. This Input item is used only for padding purpose.
(5) Another nested usage page referring to a generic desktop control is defined for the mouse position coordinates. For this usage page, the Input item describes the data fields corresponding to the x- and y-axis as specified by the two Usage items.
After analyzing the previous mouse Report descriptor content, the host’s HID parser is able to interpret the Input report data sent by the device with an interrupt IN transfer or in response to a GET_REPORT
request. The Input report data corresponding to the mouse Report descriptor shown in Figure - Report Descriptor Content from a Host HID Parser View is presented in Table - Input Report Sent to Host and Corresponding to the State of a 3-Buttons Mouse. The total size of the report data is 4 bytes. Different types of reports may be sent over the same endpoint. For the purpose of distinguishing the different types of reports, a 1-byte report ID prefix is added to the data report. If a report ID was used in the example of the mouse report, the total size of the report data would be 5 bytes.
Bit offset | Bit count | Description |
---|---|---|
0 | 1 | Button 1 (left button). |
1 | 1 | Button 2 (right button). |
2 | 1 | Button 3 (wheel button). |
3 | 13 | Not used. |
16 | 8 | Position on axis X. |
24 | 8 | Position on axis Y. |
A Physical descriptor indicates the part or parts of the body intended to activate a control or controls. An application may use this information to assign a functionality to the control of a device. A Physical descriptor is an optional class-specific descriptor and most devices have little gain for using it. Refer to “Device Class Definition for Human Interface Devices (HID) Version 1.11” section 6.2.3 for more details about this descriptor.