Using the HID Class Demo Application

Micrium provides a demo application that lets you test and evaluate the class implementation. Source template files are provided for the device. Executable and source files are provided for Windows host PC.

Note that the demo application provided by Micriµm is only an example and is intended to be used as a starting point to develop your own application.

Configuring PC and Device Applications

The HID class provides two demos:

  • Mouse demo exercises Input reports sent to the host. Each report gives periodically the current state of a simulated mouse.
  • Vendor-specific demo exercises Input and Output reports. The host sends an Output report or receives an Input report according to your choice.

On the device side, the demo application file, app_usbd_hid.c, offering the two HID demos is provided for µC/OS-II and µC/OS-III. It is located in this folder:

  • \Micrium\Software\uC-USB-Device-V4\App\Device\

The use of these constants usually defined in app_cfg.h or  app_usbd_cfg.h allows you to use one of the HID demos.

Table - Device Application Constants Configuration
ConstantDescriptionFile
APP_CFG_USBD_HID_ENGeneral constant to enable the HID class demo application. Must be set to DEF_ENABLED. app_usbd_cfg.h
APP_CFG_USBD_HID_TEST_MOUSE_ENEnables or disables the mouse demo. The possible values are DEF_ENABLED or DEF_DISABLED. If the constant is set to DEF_DISABLED, the vendor-specific demo is enabled. app_usbd_cfg.h
APP_CFG_USBD_HID_MOUSE_TASK_PRIOPriority of the task used by the mouse demo. app_cfg.h
APP_CFG_USBD_HID_READ_TASK_PRIOPriority of the read task used by the vendor-specific demo. app_cfg.h
APP_CFG_USBD_HID_WRITE_TASK_PRIOPriority of the write task used by the vendor-specific demo. app_cfg.h
APP_CFG_USBD_HID_TASK_STK_SIZEStack size of the tasks used by mouse or vendor-specific demo. A default value can be 256. app_cfg.h


On the Windows side, the mouse demo influences directly the cursor on your monitor while the vendor-specific demo requires a custom application. The latter is provided by a Visual Studio solution located in this folder:

  • \Micrium\Software\uC-USB-Device-V4\App\Host\OS\Windows\HID\Visual Studio 2010

The solution HID.sln contains two projects:

  • “HID - Control” tests the Input and Output reports transferred through the control endpoints. The class-specific requests GET_REPORT and SET_REPORT allows the host to receive Input reports and send Output reports respectively.
  • “HID - Interrupt” tests the Input and Output reports transferred through the interrupt IN and OUT endpoints.

An HID device is defined by a Vendor ID (VID) and Product ID (PID). The VID and PID will be retrieved by the host during the enumeration to build a string identifying the HID device. The “HID - Control” and “HID - Interrupt” projects contain both a file named app_hid_common.c. This file declares the following local constant:

	static  const  TCHAR  App_DevPathStr[] = _TEXT("hid#vid_fffe&pid_1234");  (1)

(1) This constant allows the application to detect a specified HID device connected to the host. The VID and PID given in App_DevPathStr variable must match with device side values. The device side VID and PID are defined in the USBD_DEV_CFG structure in the file usbd_dev_cfg.c. Refer to the Modify Device Configuration section for more details about the USBD_DEV_CFG structure. In this example, VID = fffe and PID = 1234 in hexadecimal format.


Running the Demo Application

The mouse demo does not require anything on the Windows side. 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 presents the mouse demo with the host and device interactions:

Figure - HID Mouse Demo

HID Mouse Demo

(1) On the device side, the task App_USBD_HID_MouseTask() simulates a mouse movement by setting the coordinates X and Y to a certain value and by sending the 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 Windows 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.


The vendor-specific demo requires you to launch a Windows executable. Two executables are already provided in the following folder:

  • \Micrium\Software\uC-USB-Device-V4\App\Host\OS\Windows\HID\Visual Studio 2010\exe\

The two executables have been generated with a Visual Studio 2010 project available in \Micrium\Software\uC-USB-Device-V4\App\Host\OS\Windows\HID\Visual Studio 2010\.

  • HID - Control.exe for the vendor-specific demo utilizing the control endpoints to send Output reports or receive Input reports.
  • HID - Interrupt.exe for the vendor-specific demo utilizing the interrupt endpoints to send Output reports or receive Input reports.

Figure - HID Vendor-Specific Demo presents the vendor-specific demo with the host and device interactions:

Figure - HID Vendor-Specific Demo

HID Vendor-Specific Demo

(1) A menu will appear after launching HID - Control.exe. You will have three choices: “1. Sent get report”, “2. Send set report” and “3. Exit”. Choice 1 will send a GET_REPORT request to obtain an Input report from the device. The content of the Input report will be displayed in the console. Choice 2 will send a SET_REPORT request to send an Output report to the device.

(2) A menu will appear after launching HID - Interrupt.exe. You will have three choices: “1. Read from device”, “2. Write from device” and “3. Exit”. The choice 1 will initiate an interrupt IN transfer to obtain an Input report from the device. The content of the Input report will be displayed in the console. Choice 2 will initiate an interrupt OUT transfer to send an Output report to the device.

(3) On the device side, the task App_USBD_HID_ReadTask() is used to receive Output reports from the host. The synchronous HID read function, USBD_HID_Rd(), will receive the Output report data. Nothing is done with the received data. The Output report has a size of 4 bytes.

(4) Another task, App_USBD_HID_WriteTask(), will send Input reports to the host using the synchronous HID write function, USBD_HID_Wr(). The Input report has a size of 4 bytes.


Figure - HID - Control.exe (Vendor-Specific Demo) and Figure - HID - Interrupt.exe (Vendor-Specific Demo) show screenshot examples corresponding to HID - Control.exe and HID - Interrupt.exe respectively.

Figure - HID - Control.exe (Vendor-Specific Demo)

HID - Control.exe (Vendor-Specific Demo)

Figure - HID - Interrupt.exe (Vendor-Specific Demo)

HID - Interrupt.exe (Vendor-Specific Demo)