Wishing you all a Happy and Prosperous New Year 2009


Nov 6, 2008

The HID (Human Interface Device) Class [Or] The "Keyboard, Mouse, Joystick" Class

1. HID Class - Introduction

HID Class is most celebrated device class out of all the USB Device Classes. It is used by many different kinds of applications. Sometimes you will be surprised to know that a device that does not fit into the HID paradigm, connects to the PC using HID class. I saw some initial mobile phones connecting the PC on USB using HID class. You will also find many industrial control applications, that connect to PC uses HID class. You will not know that those devices are HID devices, because the INF(Microsoft Windows Information) file tells otherwise.
Initially the HID specification is designed with the intention to support, PC devices like keyboard, mouse, joystick etc... Because these devices fall in the category of Human Interface for the PC.
But, later HID has expanded it's reach. The HID section(See Article Related Resources) on www.usb.org has grown to huge segment. One book that covers HID to the core is USB Complete

2. Benefits of using HID device in your application

HID is almost support by all operating systems, including versions of Microsoft Windows starting from Windows 98 SE, and all most all Linux versions. What it means to you as a USB device developer is, you don't have put effort on developing OS specific device drivers. These device drivers are already available for your use. Well, If you are not developing Mouse, Joystick or Keyboard, then there is some work you have to do on PC side too, but not at the kernel level of the OS.

3. How to interact with any HID device on Windows

Once you are have your HID firmware stack ready, and your device is viewed as HID device by the OS, you can use the two standard API provided by Windows to interact directly with the HID device.
  1. Windows API functions - supplied by the HID.DLL file.
  2. Microsoft DirectX® - which provides faster, more direct access to the hardware (USB device).


4. How to interact with any HID device on Linux

Still reading! Hoping to finish it soon! :-)

5. Major concepts of HID

  1. While using HID, the class specification defines an entity called Reports. A HID Report is nothing but the data exchange format defined by the HID speciation. NOTE: User can also add his own report formats. Each report is identified by a Report Descriptor.
    The host sends and receives data by sending and requesting reports in control or interrupt transfers. The report format is flexible and can handle any type of data.
    So, when designing the device, the firmware need to be designed by keeping the standard Report formats in mind, as well as per the requirement new report formats may have to be defined.

  2. Each transaction can carry only small or moderate amounts of data, as only Interrupt transfer is supported on HID class devices. That mans Bulk, and Isochronous transfers are not supported on HID Class.
    A low speed device can transfer maximum of 8 bytes per transaction.
    A full speed device can transfer maximum of 64 bytes per transaction.
    A high speed device can transfer maximum of 1024 bytes per transaction.
    A long report can use multiple transactions.
    A device may send information at unpredictable times, well again because it uses interrupt transfer the latency is maintained as in interrupt transfers the host polls the device periodically.

  3. Many HID devices mostly send data to host, but HID specification allows devices to receive data from host. This helps in control applications, or those applications where the device need information from host for it's operations.

  4. Any device that can technically follow the HID class specification (sending & receiving data at the data rates specified for HID) can be implemented as a HID device. Some examples are Bar-code readers, Thermometers, Voltmeters and are even included in the HID specification as examples of HID devices :-). These devices mostly send data to the host computer.
    Similarly devices like Remote displays, robots or devices of any kind that receive occasional or periodic commands can also be HID devices.

  5. The HID can be implemented as one the multiple USB interfaces supported by a device. For example a video display may have a HID interface for software control of brightness, contrast etc.., while a conventional Video Class interface to manage the display.
    Another example is a USB speaker system, where volume can be controlled using HID, and the Audio class interface allows actual Audio data transfer.

  6. Two important documents for working with HIDs are "Device Class Specification for Human Interface Devices" and "HID Usage Tables".

This concludes the article on HID class.

No comments: