USBIP C library 0.7.0
Virtual USB devices & host drivers over USB/IP
Loading...
Searching...
No Matches

USB HID (Human Interface Device) device class, HID 1.11. More...

#include "usb_class.h"

Data Structures

struct  hid_iface
 One generic HID interface: a single instance of the class on a device. More...
 
struct  usb_hid_descriptor
 The 9-byte HID descriptor that points at the Report descriptor (Sec.6.2.1). More...
 
struct  hid_opts
 Per-instance configuration for a generic HID interface. More...
 

Macros

#define HID_REPORT_INPUT
 Report types (high byte of wValue in Get/Set_Report), HID 1.11 Sec.7.2.1.
 
#define HID_REPORT_OUTPUT
 Output report (host -> device)
 
#define HID_REPORT_FEATURE
 Feature report (either direction, control only)
 
#define HID_SUBCLASS_NONE
 hid_opts::subclass - bInterfaceSubClass, HID 1.11 Sec.4.2.
 
#define HID_SUBCLASS_BOOT
 Boot interface: the fixed report layout a BIOS parses.
 
#define HID_PROTOCOL_NONE
 hid_opts::protocol - bInterfaceProtocol, HID 1.11 Sec.4.3.
 
#define HID_PROTOCOL_KEYBOARD
 Boot keyboard: 8-byte Input report.
 
#define HID_PROTOCOL_MOUSE
 Boot mouse: 3-byte Input report.
 
#define HID_BOOT_PROTOCOL
 hid_iface::protocol - Get/Set_Protocol values, HID 1.11 Sec.7.2.5.
 
#define HID_REPORT_PROTOCOL
 Host wants the Report descriptor's layout (default)
 
Report-descriptor item helpers (HID 1.11 Sec.6.2.2 short items)

Each macro expands to one short item (prefix byte + data byte(s)), so a Report descriptor reads like the spec when written as a static const uint8_t[]:

static const uint8_t mouse[] = {
HID_USAGE_PAGE(0x01), HID_USAGE(0x02),
...
};
#define HID_COLLECTION(x)
Main: open a collection - 0x00 Physical, 0x01 Application, 0x02 Logical (Sec.6.2.2....
Definition hid.h:143
#define HID_USAGE(x)
Local: Usage for the next Main item, within the current Usage Page - e.g.
Definition hid.h:112
#define HID_END_COLLECTION
Main: close the innermost open collection.
Definition hid.h:145
#define HID_USAGE_PAGE(x)
Global: Usage Page in force for the Usages that follow - 1-byte page id, e.g.
Definition hid.h:106

The three item classes behave differently, and mixing them up is the usual reason a descriptor parses but describes the wrong device:

  • Global (Usage Page, Logical Min/Max, Report Size/Count/ID) stays in force for every item that follows, until changed again.
  • Local (Usage, Usage Min/Max) applies only to the next Main item, then is discarded.
  • Main (Input, Output, Feature, Collection) is what actually declares fields in a report, out of the Global and Local state standing at that point.
#define HID_USAGE_PAGE(x)
 Global: Usage Page in force for the Usages that follow - 1-byte page id, e.g.
 
#define HID_USAGE_PAGE16(x)
 Global: HID_USAGE_PAGE with a 2-byte page id, for pages above 0xFF - notably the vendor-defined 0xFF00..0xFFFF range used by raw devices.
 
#define HID_USAGE(x)
 Local: Usage for the next Main item, within the current Usage Page - e.g.
 
#define HID_USAGE_MIN(x)
 Local: first Usage of a consecutive run applied to the next Main item.
 
#define HID_USAGE_MAX(x)
 Local: last Usage of that run - HID_USAGE_MIN(0xE0), HID_USAGE_MAX(0xE7) hands the eight keyboard modifier Usages to the eight fields of the next Main item, in order.
 
#define HID_LOGICAL_MIN(x)
 Global: smallest value a field may report, as one signed byte (-128..127).
 
#define HID_LOGICAL_MAX(x)
 Global: largest value a field may report, as one signed byte - so it tops out at.
 
#define HID_LOGICAL_MAX16(x)
 Global: HID_LOGICAL_MAX with 2 little-endian data bytes, for ranges a signed byte cannot hold - HID_LOGICAL_MAX16(255) for a byte-wide raw field, or a digitiser's absolute coordinate range.
 
#define HID_REPORT_SIZE(x)
 Global: width of one field, in bits (not bytes).
 
#define HID_REPORT_COUNT(x)
 Global: how many fields of that width the next Main item declares.
 
#define HID_REPORT_ID(x)
 Global: start a numbered report.
 
#define HID_COLLECTION(x)
 Main: open a collection - 0x00 Physical, 0x01 Application, 0x02 Logical (Sec.6.2.2.6).
 
#define HID_END_COLLECTION
 Main: close the innermost open collection.
 
#define HID_INPUT(x)
 Main: declare device -> host fields, sent on the interrupt IN pipe.
 
#define HID_OUTPUT(x)
 Main: declare host -> device fields, taken from the interrupt OUT pipe or a SET_REPORT(Output) - keyboard LEDs are the classic case.
 
#define HID_FEATURE(x)
 Main: declare fields the host reads and writes over EP0 only, with GET_REPORT/SET_REPORT(Feature) - configuration and state rather than live data.
 

Functions

hid_ifacehid_add (usbip_device *dev, const hid_opts *opts)
 Add a generic HID interface to a device.
 
int hid_send_report (hid_iface *iface, const void *data, int len)
 Send one Input report to the host on the interrupt-IN pipe (device -> host).
 

Variables

const usbip_device_class usbip_device_hid
 The HID class, for usbip_device_add_class()
 

Detailed Description

USB HID (Human Interface Device) device class, HID 1.11.

A generic HID interface: hand it any Report descriptor and it presents a proper HID device - keyboard, mouse, consumer control, or a vendor-defined raw device. It answers the full HID 1.11 request set on EP0 (GET/SET_REPORT, GET/SET_IDLE, GET/SET_PROTOCOL) plus the required interrupt IN and an optional interrupt OUT for Output reports (HID 1.11 Sec.4.4, Sec.7.2, Appendix G).

Built only on the public API (usbip_device.h). Mirrors python classes/device/hid.py.