1 .\" $NetBSD: usb.3,v 1.13 2000/09/24 02:17:52 augustss Exp $
3 .\" Copyright (c) 1999, 2001 Lennart Augustsson <augustss@NetBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" $FreeBSD: head/lib/libusbhid/usbhid.3 240762 2012-09-20 18:56:27Z mav $
34 .Nm hid_get_report_desc ,
35 .Nm hid_get_report_id ,
36 .Nm hid_use_report_desc ,
37 .Nm hid_dispose_report_desc ,
44 .Nm hid_usage_in_page ,
50 .Nd USB HID access routines
56 .Fn hid_get_report_desc "int file"
58 .Fn hid_get_report_id "int file"
60 .Fn hid_set_immed "int fd" "int enable"
62 .Fn hid_use_report_desc "unsigned char *data" "unsigned int size"
64 .Fn hid_dispose_report_desc "report_desc_t d"
66 .Fn hid_start_parse "report_desc_t d" "int kindset" "int id"
68 .Fn hid_end_parse "hid_data_t s"
70 .Fn hid_get_item "hid_data_t s" "hid_item_t *h"
72 .Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int id"
74 .Fn hid_locate "report_desc_t d" "unsigned int usage" "hid_kind_t k" "hid_item_t *h" "int id"
76 .Fn hid_usage_page "int i"
78 .Fn hid_usage_in_page "unsigned int u"
80 .Fn hid_parse_usage_page "const char *"
82 .Fn hid_parse_usage_in_page "const char *"
84 .Fn hid_init "const char *file"
86 .Fn hid_get_data "const void *data" "const hid_item_t *h"
88 .Fn hid_set_data "void *buf" "const hid_item_t *h" "int data"
90 .Fn hid_get_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
92 .Fn hid_set_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
96 library provides routines to extract data from USB Human Interface Devices.
98 USB HID devices send and receive data laid out in a device dependent way.
101 library contains routines to extract the
102 .Em "report descriptor"
103 which contains the data layout information and then use this information.
105 The routines can be divided into four parts: extraction of the descriptor,
106 parsing of the descriptor, translating to/from symbolic names, and
108 .Ss Synchronous HID operation
109 Synchronous HID operation can be enabled or disabled by a call to
111 If the second argument is zero synchronous HID operation is disabled.
112 Else synchronous HID operation is enabled.
113 The function returns a negative value on failure.
118 functions allow to synchronously get and set specific report if device
120 For devices with multiple report IDs, wanted ID should be provided in the
121 first byte of the buffer for both get and set.
122 .Ss Descriptor Functions
123 The report descriptor ID can be obtained by calling
124 .Fn hid_get_report_id .
125 A report descriptor can be obtained by calling
126 .Fn hid_get_report_desc
127 with a file descriptor obtained by opening a
130 Alternatively a data buffer containing the report descriptor can be
132 .Fn hid_use_report_desc .
133 The data is copied into an internal structure.
134 When the report descriptor
135 is no longer needed it should be freed by calling
136 .Fn hid_dispose_report_desc .
139 is opaque and should be used when calling the parsing functions.
141 .Fn hid_dispose_report_desc
144 .Ss Descriptor Parsing Functions
145 To parse the report descriptor the
147 function should be called with a report descriptor, a set that
148 describes which items that are interesting, and the desired report
149 ID (or -1 to obtain items of all report IDs).
150 The set is obtained by OR-ing together values
158 if the initialization fails, otherwise an opaque value to be used
162 function should be called to free internal data structures.
164 To iterate through all the items in the report descriptor
166 should be called while it returns a value greater than 0.
167 When the report descriptor ends it will returns 0; a syntax
168 error within the report descriptor will cause a return value less
170 The struct pointed to by
172 will be filled with the relevant data for the item.
177 and the meaning of the components in the USB HID documentation.
179 Data should be read/written to the device in the size of
181 The size of a report (of a certain kind) can be computed by the
184 If the report is prefixed by an ID byte it is given by
187 To locate a single item the
189 function can be used.
190 It should be given the usage code of
191 the item and its kind and it will fill the item and return
192 non-zero if the item was found.
193 .Ss Name Translation Functions
196 will return the symbolic name of a usage page, and the function
197 .Fn hid_usage_in_page
198 will return the symbolic name of the usage within the page.
199 Both these functions may return a pointer to static data.
202 .Fn hid_parse_usage_page
204 .Fn hid_parse_usage_in_page
208 .Fn hid_usage_in_page .
209 They take a usage string and return the number of the usage, or \-1
210 if it cannot be found.
212 Before any of these functions can be called the usage table
213 must be parsed, this is done by calling
215 with the name of the table.
218 to this function will cause it to use the default table.
219 .Ss Data Extraction Functions
220 Given the data obtained from a HID device and an item in the
221 report descriptor the
223 function extracts the value of the item.
226 can be used to put data into a report (which must be zeroed first).
228 .Bl -tag -width ".Pa /usr/share/misc/usb_hid_usages"
229 .It Pa /usr/share/misc/usb_hid_usages
230 The default HID usage table.
237 specifications can be found at
238 .Pa http://www.usb.org/developers/docs/ .
245 library first appeared in
248 This man page is woefully incomplete.