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