b371e689d5722518dbe3318d7ff5a58001d6d2a6
[dragonfly.git] / lib / libusbhid / libusbhid.h
1 /*      $NetBSD: usb.h,v 1.8 2000/08/13 22:22:02 augustss Exp $ */
2
3 /*
4  * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD: src/lib/libusbhid/libusbhid.h,v 1.7.2.1 2002/04/03 15:54:00 joe Exp $
29  * $DragonFly: src/lib/libusbhid/Attic/libusbhid.h,v 1.2 2003/06/17 04:26:51 dillon Exp $
30  *
31  */
32
33 #include <sys/cdefs.h>
34
35 typedef struct report_desc *report_desc_t;
36
37 typedef struct hid_data *hid_data_t;
38
39 typedef enum hid_kind {
40         hid_input, hid_output, hid_feature, hid_collection, hid_endcollection
41 } hid_kind_t;
42
43 typedef struct hid_item {
44         /* Global */
45         int _usage_page;
46         int logical_minimum;
47         int logical_maximum;
48         int physical_minimum;
49         int physical_maximum;
50         int unit_exponent;
51         int unit;
52         int report_size;
53         int report_ID;
54 #define NO_REPORT_ID 0
55         int report_count;
56         /* Local */
57         unsigned int usage;
58         int usage_minimum;
59         int usage_maximum;
60         int designator_index;
61         int designator_minimum;
62         int designator_maximum;
63         int string_index;
64         int string_minimum;
65         int string_maximum;
66         int set_delimiter;
67         /* Misc */
68         int collection;
69         int collevel;
70         enum hid_kind kind;
71         unsigned int flags;
72         /* Absolute data position (bits) */
73         unsigned int pos;
74         /* */
75         struct hid_item *next;
76 } hid_item_t;
77
78 #define HID_PAGE(u) (((u) >> 16) & 0xffff)
79 #define HID_USAGE(u) ((u) & 0xffff)
80
81 /* Obtaining a report descriptor, descr.c: */
82 report_desc_t hid_get_report_desc(int file);
83 report_desc_t hid_use_report_desc(unsigned char *data, unsigned int size);
84 void hid_dispose_report_desc(report_desc_t);
85
86 /* Parsing of a HID report descriptor, parse.c: */
87 hid_data_t hid_start_parse(report_desc_t d, int kindset);
88 void hid_end_parse(hid_data_t s);
89 int hid_get_item(hid_data_t s, hid_item_t *h);
90 int hid_report_size(report_desc_t d, unsigned int id, enum hid_kind k);
91 int hid_locate(report_desc_t d, unsigned int usage, enum hid_kind k, hid_item_t *h);
92
93 /* Conversion to/from usage names, usage.c: */
94 int hid_parse_usage_page(const char *name);
95 int hid_parse_usage_in_page(const char *name);
96 const char *hid_usage_page(int i);
97 const char *hid_usage_in_page(unsigned int u);
98 void hid_init(const char *file);
99
100 /* Extracting/insertion of data, data.c: */
101 int hid_get_data(const void *p, const hid_item_t *h);
102 void hid_set_data(void *p, const hid_item_t *h, int data);