USB Component  Version 6.6
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
HID: Human Interface Device Class

USB Host functions to support Human Interface Device (HID) USB Devices. More...

Content

 User API
 User API reference of the Human Interface Device Class.
 
 Configuration
 Configuration of the USB Host HID Class in µVision.
 

Description

USB Host functions to support Human Interface Device (HID) USB Devices.

The HID class in the USB Component is used for attaching input devices to your system.

Refer to:

Software Structure
The application starts the USB Host by calling USBH_Initialize. The USB Host Core will wait until an USB HID device is attached to the system. As soon as this happens it will enumerate the device and it will be ready to be used by the application. The handling of the HID class events is implemented in USBH_HID_Thread.

The transmit functions USBH_HID_Read and USBH_HID_Write will be called by the user thread directly to communicate with the HID device.

msc_inline_mscgraph_10

Implementation

To create an USB Host with support for the HID class:

Code Example

/*------------------------------------------------------------------------------
USB Host Thread
*----------------------------------------------------------------------------*/
void USBH_Thread (void const *arg) {
char con = 0; /* Connection status of keyboard */
char con_ex = 40; /* Previous connection status
+ initial time in 100 ms
intervals for initial display */
char out = 1; /* Output to keyboard LEDs */
USBH_Initialize (0); /* Initialize USB Host 0 */
USBH_Initialize (1); /* Initialize USB Host 1 */
while (1) {
con = USBH_HID_GetDeviceStatus(0) == usbOK; /* Get kbd connection status */
if ((con ^ con_ex) & 1) { /* If connection status changed */
if (con) {
USBH_HID_Write (0,(uint8_t *)&out,1);/* Turn on NUM LED */
printf ("\nKeyboard connected\n");
} else {
printf ("\nKeyboard disconnected ...\n");
}
con_ex = con;
} else if (con_ex > 1) { /* If initial time active */
con_ex -= 2; /* Decrement initial time */
if ((con_ex <= 1) && (!con)) { /* If initial time expired */
printf ("\nNo keyboard connected ... \n");
con_ex = con;
} else {
osDelay(200);
}
}
osDelay(100);
}
}
osThreadDef(USBH_Thread, osPriorityNormal, 1, NULL);