source: mainline/uspace/lib/usb/include/usb/classes/hidparser.h@ c32688d

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

bitmap translation

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
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 * @brief USB HID parser.
34 */
35#ifndef LIBUSB_HIDPARSER_H_
36#define LIBUSB_HIDPARSER_H_
37
38#include <stdint.h>
39#include <adt/list.h>
40#include <usb/classes/hid_report_items.h>
41
42/**
43 * Item prefix
44 */
45#define USB_HID_ITEM_SIZE(data) ((uint8_t)(data & 0x3))
46#define USB_HID_ITEM_TAG(data) ((uint8_t)((data & 0xF0) >> 4))
47#define USB_HID_ITEM_TAG_CLASS(data) ((uint8_t)((data & 0xC) >> 2))
48#define USB_HID_ITEM_IS_LONG(data) (data == 0xFE)
49
50
51/**
52 * Input/Output/Feature Item flags
53 */
54/** Constant (1) / Variable (0) */
55#define USB_HID_ITEM_FLAG_CONSTANT(flags) ((flags & 0x1) == 0x1)
56/** Variable (1) / Array (0) */
57#define USB_HID_ITEM_FLAG_VARIABLE(flags) ((flags & 0x2) == 0x2)
58/** Absolute / Relative*/
59#define USB_HID_ITEM_FLAG_RELATIVE(flags) ((flags & 0x4) == 0x4)
60/** Wrap / No Wrap */
61#define USB_HID_ITEM_FLAG_WRAP(flags) ((flags & 0x8) == 0x8)
62#define USB_HID_ITEM_FLAG_LINEAR(flags) ((flags & 0x10) == 0x10)
63#define USB_HID_ITEM_FLAG_PREFERRED(flags) ((flags & 0x20) == 0x20)
64#define USB_HID_ITEM_FLAG_POSITION(flags) ((flags & 0x40) == 0x40)
65#define USB_HID_ITEM_FLAG_VOLATILE(flags) ((flags & 0x80) == 0x80)
66#define USB_HID_ITEM_FLAG_BUFFERED(flags) ((flags & 0x100) == 0x100)
67
68
69/**
70 * Description of path of usage pages and usages in report descriptor
71 */
72typedef struct {
73 int32_t usage_page;
74} usb_hid_report_path_t;
75
76/**
77 * Description of report items
78 */
79typedef struct {
80 int32_t id;
81 int32_t usage_page;
82 int32_t usage;
83 int32_t usage_minimum;
84 int32_t usage_maximum;
85 int32_t logical_minimum;
86 int32_t logical_maximum;
87 int32_t size;
88 int32_t count;
89 size_t offset;
90 int32_t delimiter;
91
92 int32_t unit_exponent;
93 int32_t unit;
94
95 /*
96 * some not yet used fields
97 */
98 int32_t string_index;
99 int32_t string_minimum;
100 int32_t string_maximum;
101 int32_t designator_index;
102 int32_t designator_minimum;
103 int32_t designator_maximum;
104 int32_t physical_minimum;
105 int32_t physical_maximum;
106
107 uint8_t item_flags;
108
109 link_t link;
110} usb_hid_report_item_t;
111
112
113/** HID report parser structure. */
114typedef struct {
115 link_t input;
116 link_t output;
117 link_t feature;
118} usb_hid_report_parser_t;
119
120
121
122/** HID parser callbacks for IN items. */
123typedef struct {
124 /** Callback for keyboard.
125 *
126 * @param key_codes Array of pressed key (including modifiers).
127 * @param count Length of @p key_codes.
128 * @param arg Custom argument.
129 */
130 void (*keyboard)(const uint8_t *key_codes, size_t count, const uint8_t modifiers, void *arg);
131} usb_hid_report_in_callbacks_t;
132
133
134typedef enum {
135 USB_HID_MOD_LCTRL = 0x01,
136 USB_HID_MOD_LSHIFT = 0x02,
137 USB_HID_MOD_LALT = 0x04,
138 USB_HID_MOD_LGUI = 0x08,
139 USB_HID_MOD_RCTRL = 0x10,
140 USB_HID_MOD_RSHIFT = 0x20,
141 USB_HID_MOD_RALT = 0x40,
142 USB_HID_MOD_RGUI = 0x80,
143 USB_HID_MOD_COUNT = 8
144} usb_hid_modifiers_t;
145
146typedef enum {
147 USB_HID_LED_NUM_LOCK = 0x1,
148 USB_HID_LED_CAPS_LOCK = 0x2,
149 USB_HID_LED_SCROLL_LOCK = 0x4,
150 USB_HID_LED_COMPOSE = 0x8,
151 USB_HID_LED_KANA = 0x10,
152 USB_HID_LED_COUNT = 5
153} usb_hid_led_t;
154
155static const usb_hid_modifiers_t
156 usb_hid_modifiers_consts[USB_HID_MOD_COUNT] = {
157 USB_HID_MOD_LCTRL,
158 USB_HID_MOD_LSHIFT,
159 USB_HID_MOD_LALT,
160 USB_HID_MOD_LGUI,
161 USB_HID_MOD_RCTRL,
162 USB_HID_MOD_RSHIFT,
163 USB_HID_MOD_RALT,
164 USB_HID_MOD_RGUI
165};
166
167//static const usb_hid_led_t usb_hid_led_consts[USB_HID_LED_COUNT] = {
168// USB_HID_LED_NUM_LOCK,
169// USB_HID_LED_CAPS_LOCK,
170// USB_HID_LED_SCROLL_LOCK,
171// USB_HID_LED_COMPOSE,
172// USB_HID_LED_KANA
173//};
174
175//#define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01
176//#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02
177//#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04
178//#define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08
179//#define USB_HID_BOOT_KEYBOARD_KANA 0x10
180
181/*
182 * modifiers definitions
183 */
184
185int usb_hid_boot_keyboard_input_report(const uint8_t *data, size_t size,
186 const usb_hid_report_in_callbacks_t *callbacks, void *arg);
187
188int usb_hid_boot_keyboard_output_report(uint8_t leds, uint8_t *data, size_t size);
189
190int usb_hid_parser_init(usb_hid_report_parser_t *parser);
191int usb_hid_parse_report_descriptor(usb_hid_report_parser_t *parser,
192 const uint8_t *data, size_t size);
193
194int usb_hid_parse_report(const usb_hid_report_parser_t *parser,
195 const uint8_t *data, size_t size,
196 const usb_hid_report_in_callbacks_t *callbacks, void *arg);
197
198int usb_hid_report_input_length(const usb_hid_report_parser_t *parser,
199 const usb_hid_report_path_t *path);
200
201
202void usb_hid_free_report_parser(usb_hid_report_parser_t *parser);
203
204void usb_hid_descriptor_print(usb_hid_report_parser_t *parser);
205
206#endif
207/**
208 * @}
209 */
Note: See TracBrowser for help on using the repository browser.