SLAA453A january   2011  – may 2023

 

  1.   1
  2. 1MSP430™ USB HID Windows API Programmer's Guide
  3. 2Introduction
  4. 3Implementation
    1. 3.1 Overview
    2. 3.2 File Organization
    3. 3.3 System Requirements
    4. 3.4 MSP430 USB API Stacks
    5. 3.5 How Windows Maps Physical USB HID Devices to the Host Application
    6. 3.6 Locating a Specific HID Device/Interface on the System and Opening It
    7. 3.7 Sending/Receiving Data
    8. 3.8 Detecting the Dynamic Connection/Disconnection of HID Devices
  5. 4Function Call Reference
    1. 4.1 Device Connection Management and Initialization Calls
      1. 4.1.1 VOID HID_Init(struct strHidDevice* pstrHidDevice)
      2. 4.1.2 DWORD HID_GetSerNums(WORD vid, WORD pid, struct strTrackSerialNumbers *serialNumList)
      3. 4.1.3 DWORD HID_GetNumOfInterfaces(WORD vid, WORD pid, DWORD numSerNums)
      4. 4.1.4 BYTE HID_Open(struct strHidDevice* pstrHidDevice, WORD vid, WORD pid, DWORD deviceIndex, char serialNumber[SERNUM_LEN], DWORD totalDevNum, DWORD totalSerNum)
      5. 4.1.5 BYTE HID_Close(struct strHidDevice* pstrHidDevice)
      6. 4.1.6 BYTE HID_GetVersionNumber(struct strHidDevice* pstrHidDevice, USHORT * VersionNumber)
    2. 4.2 Sending/Receiving Data
      1. 4.2.1 BYTE HID_WriteFile(struct strHidDevice* pstrHidDevice, BYTE* buffer, DWORD bufferSize, DWORD* bytesSent)
      2. 4.2.2 BYTE HID_ReadFile(struct strHidDevice* pStrHidDevice, BYTE* buffer, DWORD bufferSize, DWORD* bytesReturned)
    3. 4.3 Plug and Play Management
      1. 4.3.1 BYTE HID_RegisterForDeviceNotification(HWND hWnd, HDEVNOTIFY* diNotifyHandle)
      2. 4.3.2 BYTE HID_UnregisterForDeviceNotification(HDEVNOTIFY* diNotifyHandle)
      3. 4.3.3 BOOL IsDeviceAffected(struct strHidDevice* pstrHidDevice)
  6. 5Demo Application
  7. 6MSP430 USB Tool Suite
  8.   HID Interface Data Structure: strHidDevice
  9.   Format of Reports on HID-Datapipe Devices
  10.   C References
  11.   C Revision History

Demo Application

A simple demo application is provided which shows how to use the API. The application can be thought of as similar to a COM port terminal application, like Hyperterminal. It sends and receives chunks of data in a similar fashion, except it does over an HID interface.

GUID-80B2D79B-AAE7-490D-8B67-92EB46B6F3FA-low.gifFigure 5-1 Demo Application Window

To operate the program, attach an MSP430 running the HID API stack, using the datapipe function calls. Several examples of this are provided with the API stack distribution. There are examples of single-interface HID, a CDC+HID composite device, and an HID+HID composite device. All of these can be used with this demo application.

The VID and PID fields in the GUI select the VID/PID for which the application should search. After entering them, press the "Set VID/PID" button.

When the VID/PID has been set, the application determines how many physical devices are attached to the system matching this VID/PID. It finds their serial numbers and posts them in the "Serial Number" combo box. It automatically selects the first serial number in the list, and proceeds to determine the number of HID interfaces present on that device. It loads the "Interface" combo box with a string for each one of these interfaces: "HID 0", "HID 1", etc. If there are any HID interfaces found, then "HID 0" is selected by default.

Press the "Connect" button. This opens a data connection with the USB device. If successful, the string below the button indicates it as such. If it is not successful, try the following:

  • Check the Windows Device Manager to ensure that the device successfully enumerated on the system as an HID device
  • Ensure the device is equipped with the MSP430 HID API stack, running an HID-datapipe application
  • Ensure that the VID/PID shown in descriptors.h is the same pair entered into the demo app's fields, and that the "Set VID/PID" button was pressed.

Once the connection is initialized, data can be sent to the device by entering text and pressing "Send". Data received by the application from the device at any time is displayed in the large text field. The receive window can be cleared with the "Clear" button.

If the HID device is removed from the bus while another device is being accessed, or if another HID device of this VID/PID is added, the application automatically updates the pulldown menu list.