I want to use stm32 for a wireless mouse and mouse remote control. I haven't found the complete USB mouse and keyboard protocol for several days. Finally, I collected and sorted a copy, hoping to help my friends in need.
If you don't talk nonsense, go to the topic:
The data sent by the mouse to the PC is 4 bytes each time.
Byte1 byte2 byte3 byte4
The definitions are as follows:
Byte1 --
| -- Bit7: 1 indicates that the variation of the Y coordinate exceeds-256 ~ The value range is 255. 0 indicates no overflow.
| -- Bit6: 1 indicates that the X coordinate variation exceeds-256 ~ The value range is 255. 0 indicates no overflow.
| -- Bit5: The symbol bit of Y coordinate change. 1 indicates a negative number, that is, move the mouse down.
| -- Bit4: The symbol bit of X coordinate change. 1 indicates a negative number, that is, move the cursor to the left.
| -- Bit3: constant is 1
| -- Bit2: 1 indicates that the key is pressed
| -- Bit1: 1 indicates right-click and press
| -- Bit0: 1 indicates that the left button is pressed.
Byte2 -- X coordinate variation, which is a 9-bit symbol number with bit4 of byte. A negative number indicates moving to the left, and a positive number table shifts to the right. Use the complement code to indicate the change quantity.
Byte3 -- y coordinate variation, which is a 9-bit symbol with bit5 of byte. A negative number indicates moving downward, while a positive number table is moving. Use the complement code to indicate the change quantity.
Byte4 -- wheel change.
Because there is no USB mouse on the hand, no tests are performed on the 4-7 bits of byte1. For byte2 byte3, if the 4-7 bits of byte1 are all 0, the positive and negative values of byte2 byte3 indicate the direction of the mouse movement.
The data sent by the keyboard to the PC is 8 bytes each time.
Byte1 byte2 byte3 byte4 byte5 byte6 byte7 byte8
The definitions are as follows:
Byte1 --
| -- Bit0: whether to press left control. Press 1.
| -- Bit1: Whether left shift is pressed. Press 1.
| -- Bit2: Whether left ALT is pressed. Press 1.
| -- Bit3: whether to press left gui. press 1.
| -- Bit4: whether to press right control. Press 1.
| -- Bit5: whether to press right shift. Press 1.
| -- Bit6: whether to press right ALT, and press 1
| -- Bit7: whether to press right gui. press 1.
Byte2 -- unknown for the time being. In some cases, it is a reserved bit.
BYTE3--BYTE8-these six are normal buttons
The keyboard is tested.
For example, the keyboard sends a frame of Data 02 00 0x04 0x05 00 00 00 00
Indicates that the Left Shift + 'A' + 'B' keys are simultaneously pressed.
The key code is different from the PS2 keyboard. For details, see the attachment.
USB hid to PS2 scan code comparison table Ourdev_651088nz5ek1_pdf (file size: 133 K) (Original file name: USB hid to PS2 scan code translation table. pdf)
Note:
Refer to the report descriptor for the lily net (http://www.baiheee.com/OpenSource/Easy%20USB%2051%20Programer/Easy%20USB%2051%20Programer12.htm) keyboard, as shown below
/*************************************** **************************************** ************/
// Only the description of the second byte is listed here
// 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
/*************************************** **************************************** ************/
It only indicates that this is an input data in bytes and does not specify its value range.
This is also described in the report descriptor of the hid1.11 protocol appendix B --> B .1 Protocol 1 (keyboard) (59 pages of the hid1.11 protocol)
/***************************** **************************************** * ********************/
report count (1 ),
report size (8),
input (constant ),; reserved byte
report count (5),
report size (1),
/*********************************** **************************************** * ***************/
in the notes, this byte is reserved.
here, I also upload hid1.11 for your research.
ourdev_651409jxhoad.pdf (file size: 661 K) (original file name: hid1.11 .pdf)
ourdev_651410wjinwh.pdf (file size: 745 K) (original file name: hid 1.12.pdf)