USB Component  Version 6.12.0
MDK Middleware for USB Device and Host Communication
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
Interface to an USB Host Computer

Most of the available USB Device Classes are directly supported in operating systems. There is no need to install a particular driver on the USB Host Computer to connect to the USB Device peripheral.

Some software needs to be written for the USB Host Computer when USB Driver classes are used to provide application specific functionality. For example, the USB HID Device Class may be used for generic data exchange. Therefore the data exchange interface needs to be developed at the USB Host Computer.

Refer to the following web pages for more information on USB Host software development:

Software Utilities

The USB Component comes with a set of software utilities that you can use as templates to create your own programs for the USB Host computer. The utilities are specific for the different USB Device Classes. These are the available utilities:

  • The HID Client Application can be used to interact with an USB HID Device. You can toggle LEDs on the development board and check the state of the on-board push-buttons.

HID Client Application

If you are using the USB Device HID code, there's a way to test the functionality of that code together with a Windows PC. The HIDClient.exe utility is located in "C:\Keil\ARM\Utilities\HID_Client\Release" and can run stand-alone without the need to install the software. To check the client utility with your board, do the following:

  1. Download the application to your board.
  2. Verify all jumper settings on the board.
  3. Connect the board to a Windows PC. The PC should recognize the HID device and install the correct driver automatically.
  4. Run "C:\Keil\ARM\Utilities\HID_Client\Release\HIDClient.exe".
  5. Select the Device to establish the communication channel.
  6. Test the application by pressing the correct buttons (refer to the application's Abstract.txt file) on your development board and/or check the right boxes in the client application to see the LEDs flashing.
hid_client_test.png

HID Client Source Code

The source code of the HID Client application is available in "C:\Keil\ARM\Utilities\HID_Client". Visual Studio 2005 and 2010 based projects are available (HIDClient.vproj). The structure of the project is as follows:

HIDClientSolutionExplorer.png

Header Files

  • HID.h includes the function declarations of the functions that are defined in HID.cpp.
  • HIDClient.h is the main header file for the application. It includes other project specific headers (including Resource.h) and declares the CHIDClientApp application class.
  • HIDClientDlg.h defines the behaviour of the application's main dialogue.

Resource Files

  • HIDClient.ico is an icon file, which is used as the application's icon. This icon is included by the main resource file HIDClient.rc.
  • HIDClient.rc2 contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file.

Source Files

  • HID.cpp contains the necessary functions that are used in this example application to communicate with an USB HID device. All available functions in Windows for HID interaction are explained here: Introduction to HID Concepts
    • The function HID_Init initializes the HID class to be used with the USB Host.
    • The function HID_UnInit de-initializes the HID class from the USB Host.
    • The function HID_FindDevices scans the USB Bus and lists all available HID devices for connection to the application. This information is obtained from the Device Descriptor that is generated by the USB Component using the configuration files.
    • The function HID_GetName evaluates the Product String of the device to be shown in the drop down box of the application.
    • The function HID_GetInputReportSize extracts the value of USBD_HIDn_IN_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • The function HID_GetOutputReportSize extracts the value of USBD_HIDn_OUT_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • The function HID_GetFeatureReportSize extracts the value of USBD_HIDn_FEAT_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • The function HID_Open opens the device.
    • The function HID_GetSelectedDevice returns the selected device.
    • The function HID_Close closes the device.
    • The function HID_Read initiates a USBD_HIDn_GetReport within the device to send data to the USB Host.
    • The function HID_Write triggers a USBD_HIDn_SetReport within the device to read data sent from the USB Host.
    • The functions HID_GetFeature and HID_SetFeature work on the USB HID Device's feature report (which is optional).
  • HIDClient.cpp is the main application source file that contains the application class CHIDClientApp.
  • HIDClient.rc is a listing of all of the Microsoft Windows resources that the program uses (located in the res subdirectory).
  • HIDClientDlg.cpp implements the code of the client's dialogue and calls the functions specified in HID.cpp. This is the actual place where the interaction between the USB Host and the USB Device is defined.