3.3 HID - How to use

To assist the usage of the HID class, a set of functions exists to improve the ease of use for projects. The USB HID class support functions aim to simplify the standard routine necessary for communication with HID devices.

The USB_HIDRequestHandler function is a key component of the function set, ensuring smooth communication between the host and client. It includes handling set up and settings through protocol and idle rate commands, handling reports, and the USB_REQUEST_GET_DESCRIPTOR command for collecting the device descriptor. Any commands outside these will return “UNSUPPORTED.”

It is best to place the USB_HIDRequestHandler function in a continuous loop in the project’s main function handling any incoming requests or through an interrupt routine that triggers when new data are received to set up optimally.

The USB_HIDRequestHandler function contains the necessary routines for handling the three key function pairs of HID Get_Idle and Set_Idle, Get_Report and Set_Report, and Get_Protocol and Set_Protocol.

Get_Report and Set_Report are likely the most called requests when using USB HID. These allow the user to communicate to the device that the host either requires the current report sent to it from the client or to send a report to the client.

Get_Idle and Set_Idle are used to get and set the current idle rate of a client. This idle rate refers to a time interval between any regularly sent packages while no changes in the device have occurred in position, state of the device, or similar. Using the Set_Idle allows the adjustment of the idle rate to optimize it to the current tasks, such as to avoid clogging up the system with idle reports or to ensure a high rate of idle feedback (e.g., if keep-alive is important).

Get_Protocol and Set_Protocol are helpful functions for initializing the client, allowing to change between the two supported protocols for HID clients: boot and report protocols. The boot protocol is much simpler and is best for mice and simple keyboards. The report protocol is more advanced and, by that, more optimal for complex devices.