Introduction to usb hid report and report Descriptor

Source: Internet
Author: User
Tags 0xc0

Discussion: http://www.ednchina.com/blog/computer00/14382/category.aspx

 

In USB, the usb host identifies the device by using various descriptors, including the device descriptor,
Configuration descriptor, interface descriptor, endpoint descriptor, string descriptor, report descriptor, and so on.
The USB Report Descriptor is a Descriptor in the HID device, which is a comparison
A complex descriptor.

Usb hid devices transmit data through reports, including input reports and output reports.
The input report is sent by a USB device to the host, for example, move the USB mouse and click the mouse.
The information is returned to the computer, and the keyboard returns the key data to the computer. The output report is sent by the host.
For USB devices, such as the Digital keypad lock lamp and uppercase letter lock lamp. Report is
A data packet contains the data to be transmitted. Input reports are input through interrupt endpoints
The output report is a little different. When the output point is not interrupted, you can control the output
When the output end point is interrupted, it is sent by the output end point.

The report descriptor describes a report and what data is used.
The usb host can analyze the meaning of the data in the report. It controls the input
The host uses the report descriptor command to obtain the report descriptor. Pay attention to this request.
Is sent to the interface, not to the device. One report descriptor can describe multiple reports.
The report is identified by the report ID, which is the first byte in the report. In the report Descriptor
If no ID is specified for a report, there is no ID field in the report, and the start is data. For more details, see
Usb hid protocol, which can be used from Http: // www.usb.org
Download.

You can use the HID Descriptor tool to generate a USB report Descriptor.
To Http: // www.usb.org
I uploaded a copy for your convenience.

Http://www.ednchina.com/Upload/Blog/2007/4/2/af7c3443-ad61-4465-ADC7-a74d28bbc322.zip

The following is a report using the USB mouse and USB keyboard generated by HID Descriptor tool.
Descriptor and report.

Code char KeyBoardReportDescriptor [63] = {
// Indicates that the usage page is a universal desktop device.
0x05, 0x01, // USAGE_PAGE (Generic Desktop)

// Indicates that the keyboard is used.
0x09, 0x06, // USAGE (Keyboard)

// Indicates the application set, which must end with END_COLLECTION. For details, see END_COLLECTION.
0xa1, 0x01, // COLLECTION (Application)

// Indicates that the usage page is a button
0x05, 0x07, // USAGE_PAGE (Keyboard)

// Minimum usage value. The value is the left ctrl key.
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
// Maximum usage value. The right GUI key is used here, that is, the window key.
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
// The logical minimum value is 0.
0x15, 0x00, // LOGICAL_MINIMUM (0)
// The logical maximum value is 1.
0x25, 0x01, // LOGICAL_MAXIMUM (1)
// The report size (that is, the width of this field) is 1 bit. Therefore, the minimum logical value is 0 and the maximum logical value is 1.
0x75, 0x01, // REPORT_SIZE (1)
// The number of reports is 8, that is, there are a total of 8 bits
0x95, 0x08, // REPORT_COUNT (8)
// Input, variable, value, and absolute value. General report absolute values such as keyboards,
// When the mouse moves, the relative value of the report indicates how much the mouse moves.
0x81, 0x02, // INPUT (Data, Var, Abs)
// The above items describe a field used for input, which is a total of 8 bits, each bit represents a key
// From the left ctrl key to the right GUI key. The eight bits exactly constitute a byte, which is located in the first byte of the report.
// Its leading bit, that is, bit-0 corresponds to the left ctrl key. If the returned data is 1, the left ctrl key is pressed,
// Otherwise, the left ctrl key is not pressed. The highest bit, that is, bit-7, indicates the press condition of the right GUI key. Several digits in the middle,
// It must be determined based on the purpose page table (HID Usage Tables) specified in the HID protocol. It is usually used to indicate
// Special keys, such as ctrl, shift, and del

 

// The number of such data segments is 1
0x95, 0x01, // REPORT_COUNT (1)
// The length of each segment is 8 bits
0x75, 0x08, // REPORT_SIZE (8)
// Input, constant, value, and absolute value
0x81, 0x03, // INPUT (Cnst, Var, Abs)

// The above eight bits are constants and the device must return 0

// The number of such data segments is 5
0x95, 0x05, // REPORT_COUNT (5)
// The size of each segment is 1 bit
0x75, 0x01, // REPORT_SIZE (1)
// The usage is LED, which is used to control the LEDs on the keyboard. Therefore, the following shows that it is used for output.
0x05, 0x08, // USAGE_PAGE (LEDs)
// The minimum usage value is Num Lock, that is, the number key Lock lamp.
0x19, 0x01, // USAGE_MINIMUM (Num Lock)
// The maximum usage value is Kana. I don't know what the lamp is. ^_^
0x29, 0x05, // USAGE_MAXIMUM (Kana)
// As mentioned above, this field is used for output to control the LED. Variable, value, and absolute value.
// 1 indicates that the light is on, and 0 indicates that the light is off
0x91, 0x02, // OUTPUT (Data, Var, Abs)

// The number of such data segments is 1
0x95, 0x01, // REPORT_COUNT (1)
// The size of each segment is 3 bits
0x75, 0x03, // REPORT_SIZE (3)
// Used for output, constant, value, absolute
0x91, 0x03, // OUTPUT (Cnst, Var, Abs)
// Because it needs to be aligned by byte, only 5 bits are used for the LED control,
// Therefore, three unnecessary bits need to be appended and set as constants.

 

// The number of reports is 6
0x95, 0x06, // REPORT_COUNT (6)
// The size of each segment is 8 bits
0x75, 0x08, // REPORT_SIZE (8)
// The logical minimum value is 0.
0x15, 0x00, // LOGICAL_MINIMUM (0)
// The maximum logical value is 255.
0x25, 0xFF, // LOGICAL_MAXIMUM (255)
// Use the button
0x05, 0x07, // USAGE_PAGE (Keyboard)
// The minimum value is 0.
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated ))
// The maximum value is 0x65.
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
// Input, variable, array, and absolute value
0x81, 0x00, // INPUT (Data, Ary, Abs)
// The preceding six 8-bit arrays are defined. Each 8-Bit Array (that is, one byte) is used to represent a key.
// There are 6 buttons to press. If no buttons are pressed, all return 0. If too many keys are pressed, the keyboard scans the system.
// If keys cannot be distinguished, 0x01 is returned, that is, 6 0x01 keys are returned. If a key is pressed, the first of the six bytes
// Each byte is the corresponding key value (for specific values, see HID Usage Tables). If two keys are pressed, the values are 1st and 2.
// Bytes are the corresponding key values, and so on.

// Close the set to keep up with the corresponding
0xc0 // END_COLLECTION
};

 

Through the above analysis, we know that there is only one report in this report, so there is no report ID,
Therefore, the returned data is actually used. 8-byte input and 1-byte output. The entered
The first byte is used to indicate special keys, and the second byte is retained. The next six bytes are normal keys. If
If only the left ctrl key is pressed, the return value is 01 00 00 00 00 00 00 (hexadecimal). If
If only number key 1 is pressed, 00 00 59 00 00 00 00 00 is returned.
If keys 1 and 2 are pressed at the same time, 00 00 59 5A 00 00 00 is returned. If
Press the Left shift key, then 02 00 59 5A 00 00 00,
Then release the 1 key, and then return 02 00 5A 00 00 00 00,
If all the buttons are released, 00 00 00 00 00 is returned.
These data (that is, reports) are returned by the interrupt endpoint. When you press the Num Lock key, the PC will send
Output report. From the report descriptor, we know that the LED of Num Lock corresponds to the leading bit of the output report,
When the keypad is opened, xxxxxxx1 is output (binary, x is determined by other LED States );
When the keypad is disabled, xxxxxxx0 is output (same as before ). You can control the number key to lock the LED by removing the leading digit.

 

The following report descriptor is a USB mouse report descriptor, which is easier than the keyboard.
It describes four bytes. The first byte indicates the button, and the second byte indicates the X axis (that is, moving the cursor left and right,
0 indicates not moving, positive value indicates moving to the right, negative value indicates moving to the left), and the third byte indicates the Y axis (that is, the mouse
Move up or down. 0 indicates not moving. positive value indicates moving down, negative value indicates moving up), fourth byte
Indicates the scroll wheel of the mouse (positive value indicates scroll up, and negative value indicates scroll down ).

Code char MouseReportDescriptor [52] = {
// Universal desktop device
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
// Mouse
0x09, 0x02, // USAGE (Mouse)
// Set
0xa1, 0x01, // COLLECTION (Application)
// Pointer Device
0x09, 0x01, // USAGE (Pointer)
// Set
0xa1, 0x00, // COLLECTION (Physical)
// Press the button
0x05, 0x09, // USAGE_PAGE (Button)
// Use the minimum value of 1
0x19, 0x01, // USAGE_MINIMUM (Button 1)
// Use the maximum value of 3. 1 indicates the left button, 2 indicates the right button, and 3 indicates the middle key.
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
// The logical minimum value is 0.
0x15, 0x00, // LOGICAL_MINIMUM (0)
// Logical maximum value 1
0x25, 0x01, // LOGICAL_MAXIMUM (1)
// 3
0x95, 0x03, // REPORT_COUNT (3)
// The size is 1 bit.
0x75, 0x01, // REPORT_SIZE (1)
// Input, variable, value, and absolute value
// The above three bits indicate the three buttons of the mouse respectively, and the lowest bit (bit-0) is the left button
// Right-click bit-1, and right-click bit-2. When you press the button, the corresponding bit value is 1, and when you release the button, the corresponding value is 0.
0x81, 0x02, // INPUT (Data, Var, Abs)

// Fill in 5 bits to complement one byte
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x05, // REPORT_SIZE (5)
0x81, 0x03, // INPUT (Cnst, Var, Abs)

// The usage page is generic Desktop
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
// Use X
0x09, 0x30, // USAGE (X)
// Use Y
0x09, 0x31, // USAGE (Y)
// Use Wheel
0x09, 0x38, // USAGE (Wheel)
// The logical minimum value is-127.
0x15, 0x81, // LOGICAL_MINIMUM (-127)
// The maximum logical value is + 127
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
// The size is 8 bits
0x75, 0x08, // REPORT_SIZE (8)
// The number is three, that is, x, y, and scroll wheel.
0x95, 0x03, // REPORT_COUNT (3)
// Input, variable, value, Relative Value
0x81, 0x06, // INPUT (Data, Var, Rel)

// Close the set
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};

 

 

Through the preceding report analysis, we know that the report returns 4 bytes without the report ID. If you press the left mouse button,
01 00 00 00 (hexadecimal value) is returned. If you right-click the value, 02 00 00 00 is returned. If you press the key,
The return value is 04 00 00. If the three keys are simultaneously pressed, the return value is 07 00 00. If you move the cursor to the right
The second byte returns a positive value. The larger the value, the faster the moving speed. And so on.

 

Here we will only give a brief introduction to the report descriptor. For more information, see usb hid protocol and HID Usage Tables,
From Http: // www.usb.org
Download.

According to the actual design of the USB keyboard and USB mouse:

USB keyboard:
Http://computer00.21ic.org/user1/2198/archives/2007/36484.html

Http://www.ednchina.com/blog/computer00/20134/message.aspx

USB mouse:
Http://computer00.21ic.org/user1/2198/archives/2007/36520.html

Http://www.ednchina.com/blog/computer00/20135/message.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.