Skip to content
jcoenraadts edited this page Sep 16, 2013 · 2 revisions

HID USB communication Explained

The transfer of data under USB is performed using so-called 'reports'. These can be defined as 'in' or 'out' reports from the point of view of the host. Each USB device has a number of 'endpoints' which are really just memory buffers where data is accumulated during a transfer. When a USB host (normally a PC) executes a transfer, a report is delivered to (or read from) the endpoint of the USB device. When a transfer is complete, the report data can be read from the endpoint and acted upon.

Under USB, communications fall into three broad categories, called transfers:

  • Bulk transfers - Typically used for larger amounts of data for which timing is not such an issue. A good example of this is for flash drives, cameras etc. These transfer types are given the lowest priority on the bus.

  • Interrupt transfers - Despite the name, these are really periodic data packets, rather than interrupts in the context of firmware. The HID device class uses interrupt transfers exclusively for user data. The HID device firmware specifies a period between transfers in milliseconds, with 1ms being the shortest (ie highest frequency).

  • Control transfers - Used during the enumeration and handshaking phases of the communication. These transfers may also include a keep-alive transfer which is designed to allow the operating system to maintain control over which devices are connected and/or suspended.

The length of HID reports is defined by the device itself. they can be any size up to 64 bytes. In reality, the packet is longer than this as it contains other information. By the time it has been decoded and made available to the user's code, it is one byte longer than expected. This extra byte is included as the first byte of a HID report is always '0'.

Clone this wiki locally