Sunday, October 17, 2010

The HID programming

This article is from



HID webpage from the USB-IF.
Windows programming

You can use Windows' built-in HID (human interface device) drivers to communicate with devices that conform to the USB's HID class specification. There's no need for a custom driver; the device uses the drivers included in Windows. Use any programming language that supports calling API functions. The device doesn't have to have a "human interface." Any device that can function within the limits of the HID specification (control and interrupt transfers only) may be able to be designed as a HID.

Microsoft's WDK has documentation for the HID functions and an overview of how to use them. The WDK also includes the header files to use with Visual C++ programs that access HID-class devices (hidsdi.h, hidusage.h, hidpi.h).

Human Input Devices. The Windows HID API from Microsoft.

Microsoft's DirectX technology includes DirectInput, which supports communications with HID-class game controllers (in both directions, in spite of the name), without requiring custom drivers. Microsoft's DirectX Developer Center has the latest info.

Use Raw Input to read data from a specific keyboard, mouse, or game controller.

A Usenet discussion about using HIDs under Windows CE. For other posts on this topic, search the newsgroups microsoft.public.windowsce* from

HIDs Up by Jan Axelson, Embedded Systems Programming. From Embedded Systems Programming.

Using the HID class eases the job of writing USB device drivers by Stuart Allman. From EDN.

Making USB C# friendly. Article by Ashley Deakin in VSJ.

USB Complete includes three chapters on HID firmware and application programming.

Chapter 13: Human Interface Devices. From Programming the Microsoft Windows Driver Model, Second Edition by Walter Oney.



HIDMaker creates device firmware and a Windows application from information you provide. Also available are the AnyHID test program and the USBWatch software-only protocol analyzer. From Trace Systems Inc.

The SimpleHIDWrite utility tests HID-class devices. The HidTest utility also tests HIDs with a variety of API calls. contains the application and contains the source files in Delphi. All from Robert Marquardt.

Robert Marquardt's HID Controller component suite for Delphi.

USB HID API Function Library. From Kadtronix.

MouseWarrior, KeyWarrior, JoyWarrior, IO-Warrier, and IO-Warrior 24PowerVampire (for using USB as a power supply). Available as programmed chips or kits. From Code Mercenaries.

My example code

Host applications and device firmware to work with them. Thank you to everyone who has helped by contributing bug reports and often the fixes along with them.

Host applications

My HID applications below communicate with generic (custom) HIDs. Each supports exchanging Input, Output, and Feature reports and shows how to search for devices that use a particular interface GUID. All except the Visual Basic 6 code show how to use RegisterDeviceNotification and WM_DEVICE_CHANGE messages to detect when a device is attached or removed.
Visual Basic .NET

generic_hid_vb. Created with Visual Studio 2008 for the .NET Framework 2.0 or later. Updated 1/12/10.

Visual C# (C Sharp)

generic_hid_cs. Created with Visual Studio 2008 for the .NET Framework 2.0 or later. Updated 1/12/10.

usbhidio_V2.3.cs. My VB HIDClass application ported to C#. From Gordon Vance. (Bug report: change: if (MyEnvironment.Version >= Version98SE) to if (MyEnvironment.Version <= Version98SE).

Visual Basic 6


Visual C++ 6

Usbhidio_vc6. This project will load into and run in Visual Studio. The project requires the header files hid.lib, hid.h, and hidsdi.h from the WDK.

1. If you get this errror on attempting to compile:


Set WINVER = 0x0500 or higher in stdafx.h

For more info, go to and search on:

"DEV_BROADCAST_DEVICEINTERFACE" "undeclared identifier"

2. HidD_GetInputReport and HidD_SetInputReport require Windows XP or later.

Generic HID device firmware

HID firmware for communicating with the Windows host code above.
Microchip PIC18F4550 is is my Microchip PIC microcontroller firmware for generic HIDs. Written for the PIC 18F4550 and Microchip's MPLAB C18 compiler with the Microchip Application Libraries V2.6a. See the readme file to find out how to create the project in the Framework directory structure. (The Framework includes a HID example, but my code also supports vendor-defined control transfers.) Updated 4/22/10.
Older versions

Use the newest Framework and firmware unless you have a compelling reason not to.

For the Framework V2.5.
For the Framework V2.3.
For the Framework. V2.1. Generic_HID_C18_FSUSB
For the Framework V1.x.

Cypress Semiconductor EZ-USB FX2 runs on Cypress' FX2 EZ-USB chips at full and high speeds. It's adapted from Cypress' frameworks examples and requires the full version of the Keil C compiler.

Cypress Semiconductor Encore for Cypress Encore chips (CY637xx). Assembly code.

Cypress Semiconductor EZ-USB for Cypress EZ-USB chips. In C. More information.

Cypress Semiconductor EZ-USB Buttons and Lights

A version of John Hyde's buttons and lights code for the USBSimm module. (The module is no longer available.) My code supports interrupt Out transfers for Output reports.

Cypress Semiconductor CY63000 (61k) contains assembly-code firmware and host software for communicating with a Cypress CY7C63000 microcontroller (obsolete). The code runs on Cypress' 3650 Developer's Kit and CY3640 Starter Kit. Cypress has discontinued the Starter Kit. The Hi-Lo EPROM programmer included in the Starter Kit was Cypress part CY3649. The host software is Visual Basic 6 code. Bug list and fixes for usbhidio.

Cypress Semiconductor CY63000 firmware plus Visual Basic code using an ActiveX Exe server (70k) is an enhanced version of usbhidio. Like usbhidio that uses an ActiveX Exe server to handle reading from the device.

Other code

Code from other sources.
Device firmware for use with my .NET HID applications

These firmware examples are designed to work with my PC HID applications above.
Cypress Semiconductor 66113 contains a version of my generic HID-class firmware for Cypress' CY7C66113 hub & peripheral chip. The firmware enumerates as a compound device made up of a 4-port hub and my usbhidio device. It runs on the 3652 development kit and will communicate with my hidvb and usbhidioc software. This code is provided by Mat Laibowitz.

Microchip PIC

Firmware for the PIC16C745/765 to enable using my HID .NET and usbhidioc software. From Microchip. For more PIC advice, see USB and PIC Microprocessors 16C745 and 18F2455 from Alan Macek.

Assembly code and C firmware for the PIC16C745 and PIC18F2455. From Bradley A. Minch at Olin College

The PICBasic Pro Basic compiler includes instructions to perform HID communications, for use with PICMicros with USB support. From microEngineering Labs Inc.

My Very First USB Peripheral. A description of a PIC16C745 HID project. From Technology Stir Fry.

More HID firmware

Atmel's AT90USBKey demonstration board for the AT90USB AVR microcontroller has generic HID, keyboard, and mouse applications.

Automator is a HID project for the Atmel AVR-USB. Includes host code. From Objective Development Software.

Cypress Semiconductor

Example HID Firmware in C for Cypress enCoRe devices. From Stephen Santarelli.

John Hyde's USB Design By Example site has HID examples in Visual Basic and Visual C++. I have a version of the buttons and lights firmware that supports interrupt Out transfers.

The MO1002 USB to UART is a HID device that translates between asynchronous serial data and USB using Windows' HID drivers. Includes schematics, firmware, and a Visual C++ application. The chip used is Cypress' CY7C63001. From Moto Development Group.


Microchip's USB Framework firmware includes HID examples..

FMSUSB is a RC(PPM) to FMS (Flying Model Simulator) USB interface. Uses a PIC16C745. From Walter Zanette.

A firmware-only HID (no hardware device controller) using a Microchip 16F84A to control a parallel LCD module (HD44780 compatible) via USB. (Spanish)

RcJoystick NG is an interface between a USB port and the buddy box connector on many RC Transmitters. From Alessio e Andrea.

ST-Ericsson (formerly NXP Semiconductors/Philips)

Interfacing a Game Boy Advance to a PC using a PIC16F877 and PDIUSBD12. From Rob Meerman.

Host code

HID USB Driver / Library. A C# DLL. From Florian Leitner.

USB Hid Device Library for .NET. From Mike O'Brien.

HID component for C# .NET. A project from the Avans Hogeschool in The Netherlands.

Controlling the Logitech iFeel Mouse. Experiments with force feedback. Daniel C. Moore

No comments:

Post a Comment