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

Locating a Specific HID Device/Interface on the System and Opening It

Throughout the rest of this document, the following terms are used:

  • HID device: A device in Windows HID device list
  • Physical USB device: An actual piece of USB hardware, with its own unique address on the USB bus
  • HID interface: An interface declared within the USB descriptors of a physical USB device. It may be the only interface on the device, or it may be one of several as part of a composite USB device. An HID interface is associated with an HID device in Windows.

As the host application developer sets about accessing the USB device, he or she generally knows the VID/PID pair of the device to which it is being associated, because both are usually designed by the same party. The process therefore begins with calling HID_GetSerNums(). This function receives a VID/PID as parameters and returns a list of serial numbers, each of which represents a physical USB device on the bus associated with that VID/PID. The application may choose to interact with only one of these physical devices, or it could be given capability of interacting with multiple devices.

The application developer also generally knows how many interfaces each of these physical devices has. If somehow this is not known, the function HID_GetNumOfInterfaces() can be called. When HID_Open() is called to open the device, it is necessary to know the total number of HID interfaces on the physical device.

When the VID, PID, and serial number are used to filter the HID device list, all that remains is a list that represents all of the HID interfaces in the physical USB device described by those parameters. This list is usually one or two, but can be as many as eight on an MSP430. The order of this list is the same as the order in which the HID interfaces were listed in the physical device's USB descriptors. In this way, the host application and MSP430 application using the API stack can "find" each other, forming a complete data link.

Armed with the VID/PID, serial number, and index of the desired HID interface within the USB device, the application can call HID_Open() to open a connection to the HID interface on the physical USB device.

When the application is finished using the device (for example when exiting the program), the application should close any open HID devices with HID_Close().