There’s one thing that I think isn’t explained well in the documentation, USAGE, USAGE_PAGE, USAGE_MINIMUM and USAGE_MAXIMUM.
![mikroelektronika usb hid terminal documentation mikroelektronika usb hid terminal documentation](https://i.ytimg.com/vi/g9RNDL2lwd4/mqdefault.jpg)
This is actually the example descriptor provided with the USB HID documentation, and you can also find this as an example provided with the HID tool.Ĭool, at this point, you will have encountered some concepts that you may have questions about, you should research the following: Usage Pages
![mikroelektronika usb hid terminal documentation mikroelektronika usb hid terminal documentation](https://b3van8qm1o7ou9d3b48qdhsg-wpengine.netdna-ssl.com/wp-content/uploads/2019/07/Screenshot-Descriptor-Tab-MikroC.jpg)
So in the end, this is the USB HID report descriptor for a standard mouseĠx05, 0x01, // USAGE_PAGE (Generic Desktop) So all your data will end up looking likeĪh but we are not done, in order to make the computer know that this is a mouse, we do Which will work, but to save memory, we can do this instead You end up with something like this to represent the X axis movement We want it to take an entire byte which is 8 bitsĪnd send it to the computer as a variable relative coordinate We want it to be a signed integer that takes one byte, so it has a value between -127 and +127 (actually -128 and +127, but I want to keep things even) So now in our descriptor, our first item must describe buttons, three of themĮach button status is represented by a bit, 0 or 1īut what about the five useless padding bits? Y Axis Relative Movement as Signed IntegerĪnd then we can say our data structure in C looks like X Axis Relative Movement as Signed Integer So we can say that we want the data structure to look something like this It takes one bit to represent each button, and one byte to represent the movement on one axis as a signed integer. So we want to send data regarding the buttons and movement. Just three buttons, and movement on the X and Y axis. I’m going to try teaching you about USB HID report descriptors by walking you through writing a few.įor a simple starting point, let us make a standard mouse. Some mouse and keyboard hardware in the market today are implemented using only an 8-bit CPU. The device typically stores the HID descriptor in ROM and does not need to intrinsically understand or parse the HID descriptor. For example, a keyboard with a calculator program button can tell the host that the button’s pressed/released state is stored as the 2nd bit in the 6th byte in data packet number 4 (note: these locations are only illustrative and are device specific). This includes: how many packets the device supports, how large are the packets, and the purpose of each byte and bit in the packet. The HID descriptor is a hard coded array of bytes that describe the device’s data packets. Devices define their data packets and then present a “HID descriptor” to the host. The HID protocol makes implementation of devices very simple. It is an absolute headache to write the HID report descriptors manually (converting between binary and hex and looking up the meanings of the numbers) so this tool is essential. You’ll want to play with it as you go through this tutorial.
![mikroelektronika usb hid terminal documentation mikroelektronika usb hid terminal documentation](https://pic-microcontroller.com/wp-content/uploads/2018/06/Program-testing.jpg)
Second, go get the HID descriptor tool from the same page. Thanks for visiting! If you appreciate my content, please consider making a donation to a charity.