source: mainline/uspace/lib/usbhid/include/usb/hid/hidtypes.h@ 74b1e40

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 74b1e40 was 74b1e40, checked in by Matej Klonfar <maklf@…>, 15 years ago

hid parser header's doxygen doc

  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 * Copyright (c) 2011 Matej Klonfar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - 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 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libusb
30 * @{
31 */
32/** @file
33 * Basic data structures for USB HID Report descriptor and report parser.
34 */
35#ifndef LIBUSB_HIDTYPES_H_
36#define LIBUSB_HIDTYPES_H_
37
38#include <stdint.h>
39#include <adt/list.h>
40
41/*---------------------------------------------------------------------------*/
42
43/**
44 * Maximum amount of specified usages for one report item
45 */
46#define USB_HID_MAX_USAGES 0xffff
47
48/**
49 * Converts integer from unsigned two's complement format format to signed
50 * one.
51 *
52 * @param x Number to convert
53 * @param size Length of the unsigned number in bites
54 * @return signed int
55 */
56#define USB_HID_UINT32_TO_INT32(x, size) \
57 ((((x) & (1 << ((size) - 1))) != 0) ? \
58 -(~((x) - 1) & ((1 << size) - 1)) : (x))
59
60/**
61 * Convert integer from signed format to unsigned. If number is negative the
62 * two's complement format is used.
63 *
64 * @param x Number to convert
65 * @param size Length of result number in bites
66 * @return unsigned int
67 */
68#define USB_HID_INT32_TO_UINT32(x, size) \
69 (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
70
71/*---------------------------------------------------------------------------*/
72
73/**
74 * Report type
75 */
76typedef enum {
77 USB_HID_REPORT_TYPE_INPUT = 1,
78 USB_HID_REPORT_TYPE_OUTPUT = 2,
79 USB_HID_REPORT_TYPE_FEATURE = 3
80} usb_hid_report_type_t;
81
82/*---------------------------------------------------------------------------*/
83
84/**
85 * Description of all reports described in one report descriptor.
86 */
87typedef struct {
88 /** Count of available reports. */
89 int report_count;
90
91 /** Head of linked list of description of reports. */
92 link_t reports;
93
94 /** Head of linked list of all used usage/collection paths. */
95 link_t collection_paths;
96
97 /** Length of list of usage paths. */
98 int collection_paths_count;
99
100 /** Flag whether report ids are used. */
101 int use_report_ids;
102
103 /** Report id of last parsed report. */
104 uint8_t last_report_id;
105
106} usb_hid_report_t;
107/*---------------------------------------------------------------------------*/
108
109/**
110 * Description of one concrete report
111 */
112typedef struct {
113 /** Report id. Zero when no report id is used. */
114 uint8_t report_id;
115
116 /** Type of report */
117 usb_hid_report_type_t type;
118
119 /** Bit length of the report */
120 size_t bit_length;
121
122 /** Number of items in report */
123 size_t item_length;
124
125 /** Linked list of report items in report */
126 link_t report_items;
127
128 /** Linked list of descriptions. */
129 link_t link;
130} usb_hid_report_description_t;
131/*---------------------------------------------------------------------------*/
132
133/**
134 * Description of one field/item in report
135 */
136typedef struct {
137 /** Bit offset of the field */
138 int offset;
139
140 /** Bit size of the field */
141 size_t size;
142
143 /** Usage page. Zero when usage page can be changed. */
144 uint16_t usage_page;
145
146 /** Usage. Zero when usage can be changed. */
147 uint16_t usage;
148
149 /** Item's attributes */
150 uint8_t item_flags;
151
152 /** Usage/Collection path of the field. */
153 usb_hid_report_path_t *collection_path;
154
155 /**
156 * The lowest valid logical value (value with the device operates)
157 */
158 int32_t logical_minimum;
159
160 /**
161 * The greatest valid logical value
162 */
163 int32_t logical_maximum;
164
165 /**
166 * The lowest valid physical value (value with the system operates)
167 */
168 int32_t physical_minimum;
169
170 /** The greatest valid physical value */
171 int32_t physical_maximum;
172
173 /** The lowest valid usage index */
174 int32_t usage_minimum;
175
176 /** The greatest valid usage index */
177 int32_t usage_maximum;
178
179 /** Unit of the value */
180 uint32_t unit;
181
182 /** Unit exponent */
183 uint32_t unit_exponent;
184
185 /** Array of possible usages */
186 uint32_t *usages;
187
188 /** Size of the array of usages */
189 size_t usages_count;
190
191 /** Parsed value */
192 int32_t value;
193
194 /** List to another report items */
195 link_t link;
196} usb_hid_report_field_t;
197
198/*---------------------------------------------------------------------------*/
199
200/**
201 * State table for report descriptor parsing
202 */
203typedef struct {
204 /** report id */
205 int32_t id;
206
207 /** Extended usage page */
208 uint16_t extended_usage_page;
209
210 /** Array of usages specified for this item */
211 uint32_t usages[USB_HID_MAX_USAGES];
212
213 /** Length of usages array */
214 int usages_count;
215
216 /** Usage page*/
217 uint32_t usage_page;
218
219 /** Minimum valid usage index */
220 int32_t usage_minimum;
221
222 /** Maximum valid usage index */
223 int32_t usage_maximum;
224
225 /** Minimum valid logical value */
226 int32_t logical_minimum;
227
228 /** Maximum valid logical value */
229 int32_t logical_maximum;
230
231 /** Length of the items in bits*/
232 int32_t size;
233
234 /** COunt of items*/
235 int32_t count;
236
237 /** Bit offset of the item in report */
238 size_t offset;
239
240 /** Unit exponent */
241 int32_t unit_exponent;
242 /** Unit of the value */
243 int32_t unit;
244
245 /** String index */
246 uint32_t string_index;
247
248 /** Minimum valid string index */
249 uint32_t string_minimum;
250
251 /** Maximum valid string index */
252 uint32_t string_maximum;
253
254 /** The designator index */
255 uint32_t designator_index;
256
257 /** Minimum valid designator value*/
258 uint32_t designator_minimum;
259
260 /** Maximum valid designator value*/
261 uint32_t designator_maximum;
262
263 /** Minimal valid physical value*/
264 int32_t physical_minimum;
265
266 /** Maximal valid physical value */
267 int32_t physical_maximum;
268
269 /** Items attributes*/
270 uint8_t item_flags;
271
272 /** Report type */
273 usb_hid_report_type_t type;
274
275 /** current collection path*/
276 usb_hid_report_path_t *usage_path;
277
278 /** Unused*/
279 link_t link;
280
281 int in_delimiter;
282} usb_hid_report_item_t;
283/*---------------------------------------------------------------------------*/
284/**
285 * Enum of the keyboard modifiers
286 */
287typedef enum {
288 USB_HID_MOD_LCTRL = 0x01,
289 USB_HID_MOD_LSHIFT = 0x02,
290 USB_HID_MOD_LALT = 0x04,
291 USB_HID_MOD_LGUI = 0x08,
292 USB_HID_MOD_RCTRL = 0x10,
293 USB_HID_MOD_RSHIFT = 0x20,
294 USB_HID_MOD_RALT = 0x40,
295 USB_HID_MOD_RGUI = 0x80,
296 USB_HID_MOD_COUNT = 8
297} usb_hid_modifiers_t;
298
299static const usb_hid_modifiers_t
300 usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
301 USB_HID_MOD_LCTRL,
302 USB_HID_MOD_LSHIFT,
303 USB_HID_MOD_LALT,
304 USB_HID_MOD_LGUI,
305 USB_HID_MOD_RCTRL,
306 USB_HID_MOD_RSHIFT,
307 USB_HID_MOD_RALT,
308 USB_HID_MOD_RGUI
309};
310/*---------------------------------------------------------------------------*/
311
312
313#endif
314/**
315 * @}
316 */
Note: See TracBrowser for help on using the repository browser.