source: mainline/uspace/lib/usb/include/usb/classes/hidtypes.h@ 9d05599

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

usages order fixed

  • Property mode set to 100644
File size: 4.7 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 * USB HID report descriptor and report data parser
34 */
35#ifndef LIBUSB_HIDTYPES_H_
36#define LIBUSB_HIDTYPES_H_
37
38#include <stdint.h>
39#include <adt/list.h>
40
41#define USB_HID_MAX_USAGES 20
42
43#define USB_HID_UINT32_TO_INT32(x, size) ((((x) & (1 << ((size) - 1))) != 0) ? -(~(x - 1) & ((1 << size) - 1)) : (x)) //(-(~((x) - 1)))
44#define USB_HID_INT32_TO_UINT32(x, size) (((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
45
46
47typedef enum {
48 USB_HID_REPORT_TYPE_INPUT = 1,
49 USB_HID_REPORT_TYPE_OUTPUT = 2,
50 USB_HID_REPORT_TYPE_FEATURE = 3
51} usb_hid_report_type_t;
52
53
54typedef struct {
55 /** */
56 int report_count;
57 link_t reports; /** list of usb_hid_report_description_t */
58
59 link_t collection_paths;
60 int collection_paths_count;
61
62 int use_report_ids;
63 uint8_t last_report_id;
64
65} usb_hid_report_t;
66
67typedef struct {
68 uint8_t report_id;
69 usb_hid_report_type_t type;
70
71 size_t bit_length;
72 size_t item_length;
73
74 link_t report_items; /** list of report items (fields) */
75
76 link_t link;
77} usb_hid_report_description_t;
78
79typedef struct {
80
81 int offset;
82 size_t size;
83
84 uint16_t usage_page;
85 uint16_t usage;
86
87 uint8_t item_flags;
88 usb_hid_report_path_t *collection_path;
89
90 int32_t logical_minimum;
91 int32_t logical_maximum;
92 int32_t physical_minimum;
93 int32_t physical_maximum;
94 uint32_t usage_minimum;
95 uint32_t usage_maximum;
96 uint32_t unit;
97 uint32_t unit_exponent;
98
99
100 int32_t value;
101
102 link_t link;
103} usb_hid_report_field_t;
104
105
106
107/**
108 * state table
109 */
110typedef struct {
111 /** report id */
112 int32_t id;
113
114 /** */
115 uint16_t extended_usage_page;
116 uint32_t usages[USB_HID_MAX_USAGES];
117 int usages_count;
118
119 /** */
120 uint32_t usage_page;
121
122 /** */
123 uint32_t usage_minimum;
124 /** */
125 uint32_t usage_maximum;
126 /** */
127 int32_t logical_minimum;
128 /** */
129 int32_t logical_maximum;
130 /** */
131 int32_t size;
132 /** */
133 int32_t count;
134 /** */
135 size_t offset;
136 /** */
137 int32_t unit_exponent;
138 /** */
139 int32_t unit;
140
141 /** */
142 uint32_t string_index;
143 /** */
144 uint32_t string_minimum;
145 /** */
146 uint32_t string_maximum;
147 /** */
148 uint32_t designator_index;
149 /** */
150 uint32_t designator_minimum;
151 /** */
152 uint32_t designator_maximum;
153 /** */
154 int32_t physical_minimum;
155 /** */
156 int32_t physical_maximum;
157
158 /** */
159 uint8_t item_flags;
160
161 usb_hid_report_type_t type;
162
163 /** current collection path*/
164 usb_hid_report_path_t *usage_path;
165 /** */
166 link_t link;
167} usb_hid_report_item_t;
168
169/** HID parser callbacks for IN items. */
170typedef struct {
171 /** Callback for keyboard.
172 *
173 * @param key_codes Array of pressed key (including modifiers).
174 * @param count Length of @p key_codes.
175 * @param arg Custom argument.
176 */
177 void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t report_id, void *arg);
178} usb_hid_report_in_callbacks_t;
179
180
181typedef enum {
182 USB_HID_MOD_LCTRL = 0x01,
183 USB_HID_MOD_LSHIFT = 0x02,
184 USB_HID_MOD_LALT = 0x04,
185 USB_HID_MOD_LGUI = 0x08,
186 USB_HID_MOD_RCTRL = 0x10,
187 USB_HID_MOD_RSHIFT = 0x20,
188 USB_HID_MOD_RALT = 0x40,
189 USB_HID_MOD_RGUI = 0x80,
190 USB_HID_MOD_COUNT = 8
191} usb_hid_modifiers_t;
192
193static const usb_hid_modifiers_t
194 usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
195 USB_HID_MOD_LCTRL,
196 USB_HID_MOD_LSHIFT,
197 USB_HID_MOD_LALT,
198 USB_HID_MOD_LGUI,
199 USB_HID_MOD_RCTRL,
200 USB_HID_MOD_RSHIFT,
201 USB_HID_MOD_RALT,
202 USB_HID_MOD_RGUI
203};
204
205#endif
206/**
207 * @}
208 */
Note: See TracBrowser for help on using the repository browser.