Resources for Developers of USB Devices in the

来源:互联网 发布:做微信转账截图软件 编辑:程序博客网 时间:2024/04/28 20:44

http://www.lvr.com/hidpage.htm#MyExampleCode

brought to you by Jan Axelson

Basics | My Example Code | Other HID code | Host Programming

This page contains links to information and code samples for USB HID-class devices.

Basics

The HID FAQ answers some frequently asked questions about developing HID-class devices.

The USB Implementers Forum sponsors a HID Webpage with the specification for the HID class, Usage tables, and a Descriptor Tool for creating HID reports.

"HIDs Up" by Jan Axelson, Embedded Systems Programming (ESP), October 2000.

"Using the HID class eases the job of writing USB device drivers" by Stuart Allman. Includes a link to files for a thermometer project. The application code shows how to use RegisterDeviceNotification to detect device attachment or removal. From EDN magazine.

The HidTest utility tests HID-class devices with a variety of API calls. HidTest.zip contains the application and HidTestSource.zip contains the source files in Delphi. From Robert Marquardt.

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

A Usenet discussion about using HIDs under Windows CE. For other posts on this topic, search the newsgroups microsoft.public.windowsce* from http://groups.google.com/advanced_group_search.

My Example Code

These are grouped in Host and Device sections. Comments, suggestions, and bug reports welcome viae-mail.

Host Applications

My HID applications below communicate with generic (custom) HIDs. Editions for several programming languages are available. All support exchanging Input, Output, and Feature reports and show 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

HIDClass. Uses a delegate to perform reads in a separate thread. Updated 7/13/2005.

HIDClass using a single thread. This version will also load into and run under Visual Studio 2005 Beta 2. 8/27/2005.

HIDClass for Visual Studio 2005. Uses a delegate to perform reads in a separate thread. Adds marshaling of data from the ReadFile callback to the application's form (required by the .NET Framework 2.0). Created with Visual Basic 2005 Express Edition, Beta 2. This project will not load into earlier editions of Visual Studio. 8/29/2005.

A C# version

Visual Basic 6

Usbhidio2

Visual C++ 6

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

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

DBT_DEVTYP_DEVICEINTERFACE, PDEV_BROADCAST_DEVICEINTERFACE, HDEVNOTIFY, DEVICE_NOTIFY_WINDOW_HANDLE undeclared

Set WINVER = 0x0500 or higher in stdafx.h

For more info, go to www.groups.google.com and search on:

"DEV_BROADCAST_DEVICEINTERFACE" "undeclared identifier"

2. HidD_GetInputReport and HidD_SetInputReport require Windows XP or later.

Generic HID Device Firmware

Various HID firmware examples for communicating with the Windows host code above.

Microchip PIC18F4550

This C firmware for Microchip's full-speed USB chips is based on Microchip's Framework Firmware (mchpfsusb_ghid.zip). (Minor edits and fixes added 3/30/05.)

EZ-USB FX2

fx2hid.zip 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 Encore series

Enchid.zip runs on Cypress' Encore chips (CY637xx). Now supports Feature reports as well as Input and Output reports. Assembly code.

EZ-USB

fwhid.zip runs on Cypress' EZ-USB. C code. Read more about it.

EZ-USB Buttons and Lights

A version of John Hyde's buttons and lights code for the USBSimm. My code supports interrupt Out transfers for Output reports.

Cypress CY63000 series

Usbhidio.zip (61k) contains assembly-code firmware and host software for communicating with a HID-class device. The firmware is written for Cypress Semiconductor's CY7C63000 USB microcontroller and runs on Cypress' 3650 Developer's Kit and CY3640 Starter Kit. The host software is Visual Basic 6 code. Bug list and fixes for usbhidio.

Update notes: 3/8/00: Usbhidio has been tested and runs under Windows 2000. Under Windows 2000, use the default input.inf file instead of usbhidio.inf. 2/24/00: Cypress has discontinued the Starter Kit. The Hi-Lo EPROM programmer that had been included in the Starter Kit is available as Cypress part #CY3649.

Cypress CY63000 firmware plus Visual Basic code using an ActiveX Exe server

HIDDemo2.zip (70k) is an enhanced version of usbhidio. Like usbhidio, HIDDemo2 contains CY7C63000 firmware and a Visual-Basic application for communicating with a HID-class device. But the Visual-Basic project includes an ActiveX Exe server that handles reading from the device. The ReadFile API function that reads from the device is a blocking call, so the calling thread has to wait for the device to send the requested amount of data. Because the server runs in its own thread, it can wait for data and notify the application when it has a report, without blocking the main application's thread.

The tradeoff is that the application as a whole is more complicated, but this method does offer an option for devices that send data infrequently or applications that can't afford to wait. The included readme file has more details.

The firmware has minor changes from usbhidio. The device prepares an Input report just once every 5 seconds. And the first byte in the Input and Output reports is used to inform the server when to stop reading from the device (so the server's thread can close).

Other HID Code

Various code from other sources.

Device Firmware for Use with My VB and VC++ HID Applications

These firmware examples are designed to work with my PC HID applications above.

Cypress 66113

Hidhub1.zip 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 PIC16C745

Firmware for the PIC16C745/765 to enable using my hidvb and usbhidioc software. From Microchip. For more PIC advice, see USB Device Development Notes from Alan Macek.

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

A tip from a user of PICBasic: the usb demo programs that come with PICBasic depend on several support files, which are preconfigured so that the usbmouse.bas runs out of the box. However, when you try to do anything else, you need to modify these files. For example, to get the jademo program to work, you modify the USBDESC.ASM to use the demo JADESC.ASM file instead of the demo MOUSEDESC.ASM file.

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.

PC Applications

usbhidio.cs.zip is a version of my usbhidio application for C#. From Erick Woods. Some reported bugs.

USBSharp.zip contains my usbhidioc application ported to C#. From Camilo Toro.

The PICdotNET DLL is a replacement for Microchip's HIDCOMM control.Written in Visual Basic .NET. From Mio.

Additional Firmware HID Examples

Atmel

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

DIY USB Joystick Controller Project. Uses an ATMEGA8-16PI. From Mindaugas Milasauskas.

Cypress

Example HID Firmware in C for Cypress enCoRe devices with an excellent writeup. From Stephen Santarelli.

John Hyde's USB Design By Example site has HID examples in VB and VC++. John's Design Guide for the USBSimm has a version of his buttons and lights example code that runs on the USBSimm. And I have a version of the USBSimm's buttons and lights firmware that supports interrupt Out transfers (zip file, 39k). (If a HID has an interrupt Out endpoint, the HID drivers under Windows 98 SE and later will use interrupt transfers (instead of control transfers with Set_Report) for Output reports.)

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

Microchip's Framework firmware for the PIC18F4550 includes a mouse example.

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)

National Semiconductor

National Semiconductor has an example C++ application using HID functions in the sample firmware for its USBN9603 Developer's Board.

Philips

USB Engine is firmware for the Atmel Flash AVR and PDIUSBD12. From Jens Peter Holme.

HID Development Hardware

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.

Host Programming

Windows Information

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 Visual Basic, Visual C++, Delphi, or 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 Windows DDK has documentation for the HID functions and an overview of how to use them. The examples include a C application (hclient) that uses HID functions. The DDK also includes the header files to use with Visual C++ programs that access HID-class devices (hidsdi.h, hidusage.h, hidpi.h).

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.

USB Driver Uses the Largest Supported Report Size (Microsoft Knowledge Base Article 249635). Describes a problem with the HID driver in Windows 98 SE.

Input/HID Technologies. HID information from Windows Hardware and Driver Central (WHDC).

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

Windows Code

 

Robert Marquardt has a very complete HID Controller component suite for Delphi.

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

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.

USB HID API Function Library. From Kadtronix.

Other Operating Systems

 

USB HID for Linux USB tutorial by Brad Hards