3.4 HID Mouse - How to use

To allow for a quick setup of both keyboard and mouse codes, each has its own function set available to simplify both setup and operations. This chapter covers the codes relevant to mouse implementation.

The mouse first need to be initialized. This is done with the USB_HIDMouseInitialize, which sets up the mouse with standard values and runs the necessary functions.

To register movement of the mouse, the USB_HIDMouseMove function is used. This function has the x and y position as input, most usually measured as change in the x and y direction since last check and sends the change in a report. The function also ensures that no invalid values such as out of bound values are reported to the host, but rather returns “UNSUPPORTED”.

The USB_HIDMouseButton function is used to manage mouse clicks, checking if the button state has changed to “pressed down”, or “lifted up” from a previous “pressed down” state.

The three functions USB_HIDMouseButtonLeft, USB_HIDMouseButtonRight and USB_HIDMouseButtonMiddle utilize the USB_HIDMouseButton function to respond to their respective mouse clicks.

To handle the transfer of reports, the USB_HIDMouseReportInSend function is used. This function is mostly used by the other mouse-related functions, and replaces the Get_Report requests. It can be freely used for extra functionality if required, such as to cover extra mouse buttons.