Briefly
USB protocol is widely used in the computer, when the external USB device is plugged in, it will be detected and initialized and started, and then follow the USB protocol to transmit data, supply is used for acquisition.
USB devices are so diverse that they are divided into different device classes (Devices Class), and HID (Human Interface device class, man-machine interface) is a particularly important category. There are, of course, many other common device classes:
What is HID
Interactive? is still relatively general, the specific definition of HID is "HID device refers to those can be used to control and operate the computer system equipment." Some of its common examples are:
- Keyboards and pointing devices--such as standard mouse,trackballs, joystick
- Panel control devices-such as knobs, switches, buttons, and sliders
- On similar phones, the control devices on the VCR remote control-such as data gloves, throttles, steering wheels, and rudder pedals
- Some control devices that may not require human input but output data-such as Bar-code readers, thermometers, voltmeters
HID Device Management
HID device information is stored in its ROM, known as descriptor (descriptors, or more appropriate in English) structure, so in the design of the implementation of their own HID device, to understand or define the descriptor should be the most critical step. As shown below, descriptors consists of information and data:
In different stages and states of the device, many different classes of descriptor are involved:
This hid in the development of the most contact is the report descriptor, because the report descriptor are used to transfer all kinds of application data.
The reason HID uses report descriptor is primarily extensibility considerations, with report representing the type of data it transmits, so that for different hid devices, there is no need to define a subclass for each. When the HID device is detected, the report descriptor will be loaded and parsed.
Report Descriptor Format
The data organization of report descriptor is a piece of information, each piece of information is called item:
Item Format
The format of the item mentioned above is expressed as follows:
The first byte of item can represent the type of item, which is a long item or short item, as follows is a long item example:
Item Parser
Item parser extracts each item from the received report descriptor data, one at a corresponding location on the Item State table. This is the process of item parser:
When a main item is found, it is necessary to assign and initialize a report structure and place the local item in the report structure. The global item is applicable for all report structures, except that global item will work on all of the report structures that follow it.
Understanding of Push and Pop item:
The Item State table is equivalent to a global variable and can only be staged with one Item State table (representing the overall data for a report descriptor), and there is another stack that will be able to put the item state of a moment A snapshot of table is placed in the stack, and when the next item State table global variable changes to use the previous Item State table content, the item State table that is staged in the stack will work.
Usages
To indicate the purpose of the data in the report descriptor, there will be multiple usage in one report descriptor, because the data is a shard (items).
Usage is divided into page and ID combinations, which can be used to represent more uses, that is, by two levels to differentiate the purpose, first for the purpose page, and then for the purpose of the purpose of the page:
Reports
The report is the end of the actual use of HID for useful data transmission, the previous usage when the HID device just access, will be read, and the report descriptor by the host, HID device can send reports to host, You can also receive reports from host. There are three categories of reports:
Sometimes a report descriptor only describes a report, and there is no need to distinguish which report is the problem:
Sometimes, when a report descriptor describes several report, it is time to introduce a report ID to identify which report's data:
Strings
In general, in the user-defined data segment use, at this time the use of strings is necessary, because a more detailed description.
strings, like usage, is not required for an item.
Multi-byte value format
Some values are variable, that is, within a certain range, this value may be represented in multiple byte regions, and these bits are arranged in accordance with little endian, as an example:
Orientation
Some directional data representation, HID equipment generally has a uniform direction of the provisions:
As above is the direction of the coordinates of the positive and negative provisions, there is also on (1)/off (0) and True (1)/false (0) of the uniform provisions.
Null Values
HID devices have the ability to ignore some data segments in a report. This means that by declaring a bit area in the report, you can place a value that is larger than the actual control-generated data (a control is one that controls, such as a key press, and data to describe the connotation of a control).
When host or device receives this data beyond the actual control meaning, it does not change the data.
If a data segment of the report is sent to the device, application does not change it, and the data segment should provide a null Value.
Null Value Example:
For example, a 8 bit data segment, the data can be represented from 0 to 0xFF, but the data segment has declared the valid range is 0 to 0x7f, the received value between 0x80 to 0xFF will be ignored.
Descriptor of HID Devices
Three kinds of Descriptor,hid descriptor, Report descriptor and physical descriptor.
HID Descriptor
Report Descriptor
The meaning of report descriptor:
By looking at the report Descriptor,app you can know the meaning of the data of the HID device in detail, and then do the corresponding processing.
The global and local item is an additional qualification to the main item content:
Control's description again:
A HID device may have multiple controls, a control is a controlling function, such as a key control function, an LED control function and so on.
The item that the report must have
Description of the type of input (Output or Feature):
Feature item, is the host can be application to set some features of the device, such as reset coordinates origin, scanning frequency, and so on, these settings may not be obvious to the device, is a change in the device's internal characteristics of some properties.
Output, however, is some command-control actions performed on the device, such as lighting, playing audio, and so on.
Physical descriptor
It is used to describe the physical requirements of a person in controlling an action. For example, to press the second button, you need to use the left hand, such as such a description.
[HID] Spec Simple Reading