hammer2 - Messaging layer separation work part 5
[dragonfly.git] / lib / libu4bhid / usbhid.3
1 .\"     $NetBSD: usb.3,v 1.13 2000/09/24 02:17:52 augustss Exp $
2 .\"
3 .\" Copyright (c) 1999, 2001 Lennart Augustsson <augustss@NetBSD.org>
4 .\" All rights reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
14 .\"
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
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .Dd January 27, 2009
30 .Dt USBHID 3
31 .Os
32 .Sh NAME
33 .Nm usbhid ,
34 .Nm hid_get_report_desc ,
35 .Nm hid_get_report_id ,
36 .Nm hid_use_report_desc ,
37 .Nm hid_dispose_report_desc ,
38 .Nm hid_start_parse ,
39 .Nm hid_end_parse ,
40 .Nm hid_get_item ,
41 .Nm hid_report_size ,
42 .Nm hid_locate ,
43 .Nm hid_usage_page ,
44 .Nm hid_usage_in_page ,
45 .Nm hid_init ,
46 .Nm hid_get_data ,
47 .Nm hid_set_data ,
48 .Nm hid_get_report ,
49 .Nm hid_set_report
50 .Nd USB HID access routines
51 .Sh LIBRARY
52 .Lb libusbhid
53 .Sh SYNOPSIS
54 .In usbhid.h
55 .Ft report_desc_t
56 .Fn hid_get_report_desc "int file"
57 .Ft int
58 .Fn hid_get_report_id "int file"
59 .Ft int
60 .Fn hid_set_immed "int fd" "int enable"
61 .Ft report_desc_t
62 .Fn hid_use_report_desc "unsigned char *data" "unsigned int size"
63 .Ft void
64 .Fn hid_dispose_report_desc "report_desc_t d"
65 .Ft hid_data_t
66 .Fn hid_start_parse "report_desc_t d" "int kindset" "int id"
67 .Ft void
68 .Fn hid_end_parse "hid_data_t s"
69 .Ft int
70 .Fn hid_get_item "hid_data_t s" "hid_item_t *h"
71 .Ft int
72 .Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int id"
73 .Ft int
74 .Fn hid_locate "report_desc_t d" "u_int usage" "hid_kind_t k" "hid_item_t *h" "int id"
75 .Ft "const char *"
76 .Fn hid_usage_page "int i"
77 .Ft "const char *"
78 .Fn hid_usage_in_page "u_int u"
79 .Ft int
80 .Fn hid_parse_usage_page "const char *"
81 .Ft int
82 .Fn hid_parse_usage_in_page "const char *"
83 .Ft void
84 .Fn hid_init "const char *file"
85 .Ft int
86 .Fn hid_get_data "const void *data" "const hid_item_t *h"
87 .Ft void
88 .Fn hid_set_data "void *buf" "const hid_item_t *h" "int data"
89 .Ft int
90 .Fn hid_get_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
91 .Ft int
92 .Fn hid_set_report "int fd" "enum hid_kind k" "unsigned char *data" "unsigned int size"
93 .Sh DESCRIPTION
94 The
95 .Nm
96 library provides routines to extract data from USB Human Interface Devices.
97 .Ss Introduction
98 USB HID devices send and receive data layed out in a device dependent way.
99 The
100 .Nm
101 library contains routines to extract the
102 .Em "report descriptor"
103 which contains the data layout information and then use this information.
104 .Pp
105 The routines can be divided into four parts: extraction of the descriptor,
106 parsing of the descriptor, translating to/from symbolic names, and
107 data manipulation.
108 .Ss Synchronous HID operation
109 Synchronous HID operation can be enabled or disabled by a call to
110 .Fn hid_set_immed .
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.
114 .Pp
115 .Fn hid_get_report
116 and
117 .Fn hid_set_report
118 functions allow to synchronously get and set specific report if device
119 supports it.
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
128 .Xr uhid 4
129 device.
130 Alternatively a data buffer containing the report descriptor can be
131 passed into
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 .
137 The type
138 .Vt report_desc_t
139 is opaque and should be used when calling the parsing functions.
140 If
141 .Fn hid_dispose_report_desc
142 fails it will return
143 .Dv NULL .
144 .Ss Descriptor Parsing Functions
145 To parse the report descriptor the
146 .Fn hid_start_parse
147 function should be called with a report descriptor and a set that
148 describes which items that are interesting.
149 The set is obtained by OR-ing together values
150 .Fa "(1 << k)"
151 where
152 .Fa k
153 is an item of type
154 .Vt hid_kind_t .
155 The report ID (if present) is given by
156 .Fa id .
157 The function returns
158 .Dv NULL
159 if the initialization fails, otherwise an opaque value to be used
160 in subsequent calls.
161 After parsing the
162 .Fn hid_end_parse
163 function should be called to free internal data structures.
164 .Pp
165 To iterate through all the items in the report descriptor
166 .Fn hid_get_item
167 should be called while it returns a value greater than 0.
168 When the report descriptor ends it will returns 0; a syntax
169 error within the report descriptor will cause a return value less
170 than 0.
171 The struct pointed to by
172 .Fa h
173 will be filled with the relevant data for the item.
174 The definition of
175 .Vt hid_item_t
176 can be found in
177 .In usbhid.h
178 and the meaning of the components in the USB HID documentation.
179 .Pp
180 Data should be read/written to the device in the size of
181 the report.
182 The size of a report (of a certain kind) can be computed by the
183 .Fn hid_report_size
184 function.
185 If the report is prefixed by an ID byte it is given by
186 .Fa id .
187 .Pp
188 To locate a single item the
189 .Fn hid_locate
190 function can be used.
191 It should be given the usage code of
192 the item and its kind and it will fill the item and return
193 non-zero if the item was found.
194 .Ss Name Translation Functions
195 The function
196 .Fn hid_usage_page
197 will return the symbolic name of a usage page, and the function
198 .Fn hid_usage_in_page
199 will return the symbolic name of the usage within the page.
200 Both these functions may return a pointer to static data.
201 .Pp
202 The functions
203 .Fn hid_parse_usage_page
204 and
205 .Fn hid_parse_usage_in_page
206 are the inverses of
207 .Fn hid_usage_page
208 and
209 .Fn hid_usage_in_page .
210 They take a usage string and return the number of the usage, or \-1
211 if it cannot be found.
212 .Pp
213 Before any of these functions can be called the usage table
214 must be parsed, this is done by calling
215 .Fn hid_init
216 with the name of the table.
217 Passing
218 .Dv NULL
219 to this function will cause it to use the default table.
220 .Ss Data Extraction Functions
221 Given the data obtained from a HID device and an item in the
222 report descriptor the
223 .Fn hid_get_data
224 function extracts the value of the item.
225 Conversely
226 .Fn hid_set_data
227 can be used to put data into a report (which must be zeroed first).
228 .Sh FILES
229 .Bl -tag -width ".Pa /usr/share/misc/usb_hid_usages"
230 .It Pa /usr/share/misc/usb_hid_usages
231 The default HID usage table.
232 .El
233 .Sh EXAMPLES
234 Not yet.
235 .Sh SEE ALSO
236 The
237 .Tn USB
238 specifications can be found at
239 .Pa http://www.usb.org/developers/docs/ .
240 .Pp
241 .Xr uhid 4 ,
242 .Xr usb 4
243 .Sh HISTORY
244 The
245 .Nm
246 library first appeared in
247 .Nx 1.5 .
248 .Sh BUGS
249 This man page is woefully incomplete.