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

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

Buffer length of parsed input report

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