Table of Contents |
---|
maxLevel | 3 |
---|
minLevel | 2 |
---|
indent | 20px |
---|
|
...
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.
Anchor |
---|
| Table - Device Application Constants Configuration |
---|
| Table - Device Application Constants Configuration |
---|
|
Panel |
---|
borderWidth | 0 |
---|
title | Table - Device Application Constants Configuration |
---|
|
Constant | Description | File |
---|
APP_CFG_USBD_HID_EN | General constant to enable the HID class demo application. Must be set to DEF_ENABLED . | app_usbd_cfg.h | APP_CFG_USBD_HID_TEST_MOUSE_EN | Enables 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_PRIO | Priority of the task used by the mouse demo. | app_cfg.h | APP_CFG_USBD_HID_READ_TASK_PRIO | Priority of the read task used by the vendor-specific demo. | app_cfg.h | APP_CFG_USBD_HID_WRITE_TASK_PRIO | Priority of the write task used by the vendor-specific demo. | app_cfg.h | APP_CFG_USBD_HID_TASK_STK_SIZE | Stack 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:
...
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:
Anchor |
---|
| Listing - Windows Application and String to Detect a Specific HID Device |
---|
| Listing - Windows Application and String to Detect a Specific HID Device |
---|
|
Code Block |
---|
language | cpp |
---|
linenumbers | true |
---|
|
static const TCHAR App_DevPathStr[] = _TEXT("hid#vid_fffe&pid_1234"); (1) |
Panel |
---|
|
(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.
presents Figure - HID Mouse Demo presents the mouse demo with the host and device interactions:
Anchor |
---|
| Figure - HID Mouse Demo |
---|
| Figure - HID Mouse Demo |
---|
|
Panel |
---|
borderWidth | 0 |
---|
title | Figure - HID Mouse Demo |
---|
|
Image Added |
Panel |
---|
|
(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:
...
- 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.
presents Figure - HID Vendor-Specific Demo presents the vendor-specific demo with the host and device interactions:
...
Anchor |
---|
| Figure - HID Vendor-Specific Demo |
---|
| Figure - HID Vendor-Specific Demo |
---|
|
Panel |
---|
borderWidth | 0 |
---|
title | Figure - HID Vendor-Specific Demo |
---|
|
Image Added |
Panel |
---|
|
(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.
Anchor |
---|
| Figure - HID - Control.exe (Vendor-Specific Demo) |
---|
| Figure - HID - Control.exe (Vendor-Specific Demo) |
---|
|
Panel |
---|
borderWidth | 0 |
---|
title | Figure - HID - Control.exe (Vendor-Specific Demo) |
---|
|
Image Added |
Anchor |
---|
| Figure - HID - Interrupt.exe (Vendor-Specific Demo) |
---|
| Figure - HID - Interrupt.exe (Vendor-Specific Demo) |
---|
|
Panel |
---|
borderWidth | 0 |
---|
title | Figure - HID - Interrupt.exe (Vendor-Specific Demo) |
---|
|
Image Added |