1 | /*
|
---|
2 | * Copyright (c) 1999 Lennart Augustsson <[email protected]>
|
---|
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 | * 1. Redistributions of source code must retain the above copyright
|
---|
9 | * notice, this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer in the
|
---|
12 | * documentation and/or other materials provided with the distribution.
|
---|
13 | *
|
---|
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
---|
15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
---|
18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
24 | * SUCH DAMAGE.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #define _DIAGASSERT(e) assert(e)
|
---|
28 |
|
---|
29 | typedef struct report_desc *report_desc_t;
|
---|
30 |
|
---|
31 | typedef struct hid_data *hid_data_t;
|
---|
32 |
|
---|
33 | typedef enum hid_kind {
|
---|
34 | hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
|
---|
35 | }hid_kind_t;
|
---|
36 |
|
---|
37 | typedef struct hid_item {
|
---|
38 | /* Global */
|
---|
39 | int _usage_page;
|
---|
40 | int logical_minimum;
|
---|
41 | int logical_maximum;
|
---|
42 | int physical_minimum;
|
---|
43 | int physical_maximum;
|
---|
44 | int unit_exponent;
|
---|
45 | int unit;
|
---|
46 | int report_size;
|
---|
47 | int report_ID;
|
---|
48 | int report_count;
|
---|
49 | /* Local */
|
---|
50 | unsigned int usage;
|
---|
51 | int usage_minimum;
|
---|
52 | int usage_maximum;
|
---|
53 | int designator_index;
|
---|
54 | int designator_minimum;
|
---|
55 | int designator_maximum;
|
---|
56 | int string_index;
|
---|
57 | int string_minimum;
|
---|
58 | int string_maximum;
|
---|
59 | int set_delimiter;
|
---|
60 | /* Misc */
|
---|
61 | int collection;
|
---|
62 | int collevel;
|
---|
63 | enum hid_kind kind;
|
---|
64 | unsigned int flags;
|
---|
65 | /* Absolute data position (bits) */
|
---|
66 | unsigned int pos;
|
---|
67 | /* */
|
---|
68 | struct hid_item *next;
|
---|
69 | } hid_item_t;
|
---|
70 |
|
---|
71 | #define HID_PAGE(u) ((u) >> 16)
|
---|
72 | #define HID_USAGE(u) ((u) & 0xffff)
|
---|
73 |
|
---|
74 | /* Obtaining a report descriptor, descr.c: */
|
---|
75 | report_desc_t hid_get_report_desc __P((int file));
|
---|
76 | void hid_dispose_report_desc __P((report_desc_t));
|
---|
77 |
|
---|
78 | /* Parsing of a HID report descriptor, parse.c: */
|
---|
79 | hid_data_t hid_start_parse __P((report_desc_t d, int kindset));
|
---|
80 | void hid_end_parse __P((hid_data_t s));
|
---|
81 | int hid_get_item __P((hid_data_t s, hid_item_t *h));
|
---|
82 | int hid_report_size __P((report_desc_t d, enum hid_kind k, int *idp));
|
---|
83 | int hid_locate __P((report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h));
|
---|
84 |
|
---|
85 | /* Conversion to/from usage names, usage.c: */
|
---|
86 | char *hid_usage_page __P((int i));
|
---|
87 | char *hid_usage_in_page __P((unsigned int u));
|
---|
88 | void hid_init __P((char *file));
|
---|
89 |
|
---|
90 | /* Extracting/insertion of data, data.c: */
|
---|
91 | int hid_get_data __P((void *p, hid_item_t *h));
|
---|
92 | void hid_set_data __P((void *p, hid_item_t *h, int data));
|
---|