- USB HID access routines
#include <usbhid.h> report_desc_t
hid_get_report_desc (int file); report_desc_t
hid_use_report_desc (unsigned char *data unsigned int size); void
hid_dispose_report_desc (report_desc_t d); hid_data_t
hid_start_parse (report_desc_t d int kindset int id); void
hid_end_parse (hid_data_t s); int
hid_get_item (hid_data_t s hid_item_t *h); int
hid_report_size (report_desc_t d hid_kind_t k int id); int
hid_locate (report_desc_t d u_int usage hid_kind_t k hid_item_t *h int id); const char *
hid_usage_page (int i); const char *
hid_usage_in_page (u_int u); int
hid_parse_usage_page (const char *); int
hid_parse_usage_in_page (const char *); void
hid_init (const char *file); int
hid_get_data (const void *data const hid_item_t *h); void
hid_set_data (void *buf const hid_item_t *h int data);
library provides routines to extract data from USB Human Interface Devices.
USB HID devices send and receive data layed out in a device dependent way.
library contains routines to extract the
which contains the data layout information and then use this information.
The routines can be divided into four parts: extraction of the descriptor,
parsing of the descriptor, translating to/from symbolic names, and
A report descriptor can be obtained by calling
with a file descriptor obtained by opening a
Alternatively a data buffer containing the report descriptor can be
The data is copied into an internal structure.
When the report descriptor
is no longer needed it should be freed by calling
is opaque and should be used when calling the parsing functions.
fails it will return
Descriptor Parsing Functions
To parse the report descriptor the
function should be called with a report descriptor and a set that
describes which items that are interesting.
The set is obtained by OR-ing together values
Fa (1 << k)
is an item of type
Vt hid_kind_t .
The report ID (if present) is given by
Fa id .
The function returns
if the initialization fails, otherwise an opaque value to be used
in subsequent calls.
After parsing the
function should be called to free internal data structures.
To iterate through all the items in the report descriptor
should be called while it returns a value greater than 0.
When the report descriptor ends it will returns 0; a syntax
error within the report descriptor will cause a return value less
The struct pointed to by
will be filled with the relevant data for the item.
The definition of
can be found in
and the meaning of the components in the USB HID documentation.
Data should be read/written to the device in the size of
The size of a report (of a certain kind) can be computed by the
If the report is prefixed by an ID byte it is given by
Fa id .
To locate a single item the
function can be used.
It should be given the usage code of
the item and its kind and it will fill the item and return
non-zero if the item was found.
Name Translation Functions
will return the symbolic name of a usage page, and the function
will return the symbolic name of the usage within the page.
Both these functions may return a pointer to static data.
are the inverses of
They take a usage string and return the number of the usage, or -1
if it cannot be found.
Before any of these functions can be called the usage table
must be parsed, this is done by calling
with the name of the table.
to this function will cause it to use the default table.
Data Extraction Functions
Given the data obtained from a HID device and an item in the
report descriptor the
function extracts the value of the item.
can be used to put data into a report (which must be zeroed first).