Skip to end of metadata
Go to start of metadata

HID Class Mouse Example

This example emulates a mouse moving back and forth.

This example will allow you to accomplish the following tasks:

  • Initialize the HID class
  • Create a HID class instance
  • Add the HID class instance to the Full-Speed configuration
  • Add the HID class instance to the High-Speed configuration (if available)
  • Create a kernel task that emulates the mouse movement

Running the Demo Application

The mouse demo does not require anything extra on the PC. You just need to plug the HID device running the mouse demo to the PC and see the screen cursor moving.

Figure - HID Mouse Demo illustrates the mouse demo with the host and device interactions:

HID Mouse Demo
Figure - HID Mouse Demo

(1) On the device side, the task Ex_USBD_HID_MouseTask() simulates a mouse movement by setting the coordinates X and Y to a certain value and by sending an Input report that contains these coordinates. The Input report is sent by calling the USBD_HID_Wr() function through the interrupt IN endpoint. The mouse demo does not simulate any button clicks; only mouse movement.

(2) The host PC polls the HID device periodically following the polling interval of the interrupt IN endpoint. The polling interval is specified in the Endpoint descriptor matching to the interrupt IN endpoint. The host receives and interprets the Input report content. The simulated mouse movement is translated into a movement of the screen cursor. While the device side application is running, the screen cursor moves endlessly.


This example makes use of only one API call named Ex_USBD_HID_Init(). This function is normally called from a USB device core example.