]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libusbhid/usbhid.3
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libusbhid / 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 December 29, 2001
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_init ,
45 .Nm hid_get_data ,
46 .Nm hid_set_data
47 .Nd USB HID access routines
48 .Sh LIBRARY
49 .Lb libusbhid
50 .Sh SYNOPSIS
51 .In usbhid.h
52 .Ft report_desc_t
53 .Fn hid_get_report_desc "int file"
54 .Ft report_desc_t
55 .Fn hid_use_report_desc "unsigned char *data" "unsigned int size"
56 .Ft void
57 .Fn hid_dispose_report_desc "report_desc_t d"
58 .Ft hid_data_t
59 .Fn hid_start_parse "report_desc_t d" "int kindset" "int id"
60 .Ft void
61 .Fn hid_end_parse "hid_data_t s"
62 .Ft int
63 .Fn hid_get_item "hid_data_t s" "hid_item_t *h"
64 .Ft int
65 .Fn hid_report_size "report_desc_t d" "hid_kind_t k" "int id"
66 .Ft int
67 .Fn hid_locate "report_desc_t d" "u_int usage" "hid_kind_t k" "hid_item_t *h" "int id"
68 .Ft "const char *"
69 .Fn hid_usage_page "int i"
70 .Ft "const char *"
71 .Fn hid_usage_in_page "u_int u"
72 .Ft int
73 .Fn hid_parse_usage_page "const char *"
74 .Ft int
75 .Fn hid_parse_usage_in_page "const char *"
76 .Ft void
77 .Fn hid_init "const char *file"
78 .Ft int
79 .Fn hid_get_data "const void *data" "const hid_item_t *h"
80 .Ft void
81 .Fn hid_set_data "void *buf" "const hid_item_t *h" "int data"
82 .Sh DESCRIPTION
83 The
84 .Nm
85 library provides routines to extract data from USB Human Interface Devices.
86 .Ss Introduction
87 USB HID devices send and receive data layed out in a device dependent way.
88 The
89 .Nm
90 library contains routines to extract the
91 .Em "report descriptor"
92 which contains the data layout information and then use this information.
93 .Pp
94 The routines can be divided into four parts: extraction of the descriptor,
95 parsing of the descriptor, translating to/from symbolic names, and
96 data manipulation.
97 .Ss Descriptor Functions
98 A report descriptor can be obtained by calling
99 .Fn hid_get_report_desc
100 with a file descriptor obtained by opening a
101 .Xr uhid 4
102 device.
103 Alternatively a data buffer containing the report descriptor can be
104 passed into
105 .Fn hid_use_report_desc .
106 The data is copied into an internal structure.
107 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 .Vt 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 .Dv 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.
122 The set is obtained by OR-ing together values
123 .Fa "(1 << k)"
124 where
125 .Fa k
126 is an item of type
127 .Vt hid_kind_t .
128 The report ID (if present) is given by
129 .Fa id .
130 The function returns
131 .Dv NULL
132 if the initialization fails, otherwise an opaque value to be used
133 in subsequent calls.
134 After parsing the
135 .Fn hid_end_parse
136 function should be called to free internal data structures.
137 .Pp
138 To iterate through all the items in the report descriptor
139 .Fn hid_get_item
140 should be called while it returns a value greater than 0.
141 When the report descriptor ends it will returns 0; a syntax
142 error within the report descriptor will cause a return value less
143 than 0.
144 The struct pointed to by
145 .Fa h
146 will be filled with the relevant data for the item.
147 The definition of
148 .Vt hid_item_t
149 can be found in
150 .In usbhid.h
151 and the meaning of the components in the USB HID documentation.
152 .Pp
153 Data should be read/written to the device in the size of
154 the report.
155 The size of a report (of a certain kind) can be computed by the
156 .Fn hid_report_size
157 function.
158 If the report is prefixed by an ID byte it is given by
159 .Fa id .
160 .Pp
161 To locate a single item the
162 .Fn hid_locate
163 function can be used.
164 It should be given the usage code of
165 the item and its kind and it will fill the item and return
166 non-zero if the item was found.
167 .Ss Name Translation Functions
168 The function
169 .Fn hid_usage_page
170 will return the symbolic name of a usage page, and the function
171 .Fn hid_usage_in_page
172 will return the symbolic name of the usage within the page.
173 Both these functions may return a pointer to static data.
174 .Pp
175 The functions
176 .Fn hid_parse_usage_page
177 and
178 .Fn hid_parse_usage_in_page
179 are the inverses of
180 .Fn hid_usage_page
181 and
182 .Fn hid_usage_in_page .
183 They take a usage string and return the number of the usage, or \-1
184 if it cannot be found.
185 .Pp
186 Before any of these functions can be called the usage table
187 must be parsed, this is done by calling
188 .Fn hid_init
189 with the name of the table.
190 Passing
191 .Dv NULL
192 to this function will cause it to use the default table.
193 .Ss Data Extraction Functions
194 Given the data obtained from a HID device and an item in the
195 report descriptor the
196 .Fn hid_get_data
197 function extracts the value of the item.
198 Conversely
199 .Fn hid_set_data
200 can be used to put data into a report (which must be zeroed first).
201 .Sh FILES
202 .Bl -tag -width ".Pa /usr/share/misc/usb_hid_usages"
203 .It Pa /usr/share/misc/usb_hid_usages
204 The default HID usage table.
205 .El
206 .Sh EXAMPLES
207 Not yet.
208 .Sh SEE ALSO
209 The
210 .Tn USB
211 specifications can be found at
212 .Pa http://www.usb.org/developers/docs/ .
213 .Pp
214 .Xr uhid 4 ,
215 .Xr usb 4
216 .Sh HISTORY
217 The
218 .Nm
219 library first appeared in
220 .Nx 1.5 .
221 .Sh BUGS
222 This man page is woefully incomplete.