b7402ade3491b203332602ab71761b069e5b8bad
[dragonfly.git] / lib / libusbhid / usbhid.3
1 .\"     $NetBSD: usb.3,v 1.13 2000/09/24 02:17:52 augustss Exp $
2 .\"     $FreeBSD: src/lib/libusbhid/usbhid.3,v 1.11.2.1 2002/04/03 15:54:00 joe Exp $
3 .\"     $DragonFly: src/lib/libusbhid/usbhid.3,v 1.8 2008/09/07 08:21:57 swildner Exp $
4 .\"
5 .\" Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
6 .\" All rights reserved.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .Dd May 11, 1999
30 .Dt USBHID 3
31 .Os
32 .Sh NAME
33 .Nm usbhid ,
34 .Nm hid_get_report_desc ,
35 .Nm hid_use_report_desc ,
36 .Nm hid_dispose_report_desc ,
37 .Nm hid_start_parse ,
38 .Nm hid_end_parse ,
39 .Nm hid_get_item ,
40 .Nm hid_report_size ,
41 .Nm hid_locate ,
42 .Nm hid_usage_page ,
43 .Nm hid_usage_in_page ,
44 .Nm hid_parse_usage_page ,
45 .Nm hid_parse_usage_in_page ,
46 .Nm hid_init ,
47 .Nm hid_get_data ,
48 .Nm hid_set_data
49 .Nd USB HID access routines
50 .Sh LIBRARY
51 .Lb libusbhid
52 .Sh SYNOPSIS
53 .In libusbhid.h
54 .Ft report_desc_t
55 .Fn hid_get_report_desc "int file"
56 .Ft report_desc_t
57 .Fn hid_use_report_desc "unsigned char *data" "unsigned int size"
58 .Ft void
59 .Fn hid_dispose_report_desc "report_desc_t d"
60 .Ft hid_data_t
61 .Fn hid_start_parse "report_desc_t d" "int kindset"
62 .Ft void
63 .Fn hid_end_parse "hid_data_t s"
64 .Ft int
65 .Fn hid_get_item "hid_data_t s" "hid_item_t *h"
66 .Ft int
67 .Fn hid_report_size "report_desc_t d" "unsigned int id" "hid_kind_t k"
68 .Ft int
69 .Fn hid_locate "report_desc_t d" "unsigned int usage" "hid_kind_t k" "hid_item_t *h"
70 .Ft const char *
71 .Fn hid_usage_page "int i"
72 .Ft const char *
73 .Fn hid_usage_in_page "unsigned int u"
74 .Ft int
75 .Fn hid_parse_usage_page "const char *name"
76 .Ft int
77 .Fn hid_parse_usage_in_page "const char *name"
78 .Ft void
79 .Fn hid_init "const char *file"
80 .Ft int
81 .Fn hid_get_data "const void *data" "const hid_item_t *h"
82 .Ft void
83 .Fn hid_set_data "void *p" "const hid_item_t *h" "int data"
84 .Sh DESCRIPTION
85 The
86 .Nm
87 library provides routines to extract data from USB Human Interface Devices.
88 .Ss INTRODUCTION
89 USB HID devices send and receive data laid out in a device dependent
90 way.  The
91 .Nm
92 library contains routines to extract the
93 .Em report descriptor
94 which contains the data layout information and then use this information.
95 .Pp
96 The routines can be divided into four parts: extraction of the descriptor,
97 parsing of the descriptor, translating to/from symbolic names, and
98 data manipulation.
99 .Ss DESCRIPTOR FUNCTIONS
100 A report descriptor can be obtained by calling
101 .Fn hid_get_report_desc
102 with a file descriptor obtained by opening a
103 .Xr uhid 4
104 device. Alternatively a data buffer containing the report descriptor can be
105 passed into
106 .Fn hid_use_report_desc .
107 The data is copied into an internal structure. When the report descriptor
108 is no longer needed it should be freed by calling
109 .Fn hid_dispose_report_desc .
110 The type
111 .Fa report_desc_t
112 is opaque and should be used when calling the parsing functions.
113 If
114 .Fn hid_dispose_report_desc
115 fails it will return
116 .Fa NULL .
117 .Ss DESCRIPTOR PARSING FUNCTIONS
118 To parse the report descriptor the
119 .Fn hid_start_parse
120 function should be called with a report descriptor and a set that
121 describes which items that are interesting.  The set is obtained
122 by or-ing together values
123 .Fa "(1 << k)"
124 where
125 .Fa k
126 is an item of type
127 .Fa hid_kind_t .
128 The function returns
129 .Fa NULL
130 if the initialization fails, otherwise an opaque value to be used
131 in subsequent calls.
132 After parsing the
133 .Fn hid_end_parse
134 function should be called to free internal data structures.
135 .Pp
136 To iterate through all the items in the report descriptor
137 .Fn hid_get_item
138 should be called while it returns a value greater than 0.
139 When the report descriptor ends it will returns 0; a syntax
140 error within the report descriptor will cause a return value less
141 than 0.
142 The struct pointed to by
143 .Fa h
144 will be filled with the relevant data for the item.
145 The definition of
146 .Fa hid_item_t
147 can be found in
148 .In libusbhid.h
149 and the meaning of the components in the USB HID documentation.
150 .Pp
151 Data should be read/written to the device in the size of
152 the report.  The size of a report (of a certain kind) can be
153 computed by the
154 .Fn hid_report_size
155 function.
156 .Pp
157 To locate a single item the
158 .Fn hid_locate
159 function can be used.  It should be given the usage code of
160 the item and its kind and it will fill the item and return
161 non-zero if the item was found.
162 .Ss NAME TRANSLATION FUNCTIONS
163 The function
164 .Fn hid_usage_page
165 will return the symbolic name of a usage page, and the function
166 .Fn hid_usage_in_page
167 will return the symbolic name of the usage within the page.
168 Both these functions may return a pointer to static data.
169 .Pp
170 The functions
171 .Fn hid_parse_usage_page
172 and
173 .Fn hid_parse_usage_in_page
174 are the inverses of
175 .Fn hid_usage_page
176 and
177 .Fn hid_usage_in_page .
178 They take a usage string and return the number of the usage, or -1
179 if it cannot be found.
180 .Pp
181 Before any of these functions can be called the usage table
182 must be parsed, this is done by calling
183 .Fn hid_init
184 with the name of the table.  Passing
185 .Fa NULL
186 to this function will cause it to use the default table.
187 .Ss DATA EXTRACTION FUNCTIONS
188 Given the data obtained from a HID device and an item in the
189 report descriptor the
190 .Fn hid_get_data
191 function extracts the value of the item.
192 Conversely
193 .Fn hid_set_data
194 can be used to put data into a report (which must be zeroed first).
195 .Sh FILES
196 .Pa /usr/share/misc/usb_hid_usages
197 The default HID usage table.
198 .Sh EXAMPLES
199 Not yet.
200 .Sh SEE ALSO
201 The
202 .Tn USB
203 specifications can be found at
204 .Pa http://www.usb.org/developers/docs.htm .
205 .Pp
206 .Xr uhid 4 ,
207 .Xr usb 4
208 .Sh HISTORY
209 The
210 .Nm
211 library first appeared in
212 .Nx 1.5 .
213 .Sh BUGS
214 This man page is woefully incomplete.