1 /*	$NetBSD: usbhid.h,v 1.16 2016/04/23 10:15:32 skrll Exp $	*/
2 /*	$FreeBSD: src/sys/dev/usb/usbhid.h,v 1.7 1999/11/17 22:33:51 n_hibma Exp $ */
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Lennart Augustsson (lennart@augustsson.net) at
10  * Carlstedt Research & Technology.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 #ifndef _DEV_USB_USBHID_H_
36 #define _DEV_USB_USBHID_H_
37 
38 #define UR_GET_HID_DESCRIPTOR	0x06
39 #define  UDESC_HID		0x21
40 #define  UDESC_REPORT		0x22
41 #define  UDESC_PHYSICAL		0x23
42 #define UR_SET_HID_DESCRIPTOR	0x07
43 #define UR_GET_REPORT		0x01
44 #define UR_SET_REPORT		0x09
45 #define UR_GET_IDLE		0x02
46 #define UR_SET_IDLE		0x0a
47 #define UR_GET_PROTOCOL		0x03
48 #define UR_SET_PROTOCOL		0x0b
49 
50 typedef struct usb_hid_descriptor {
51 	uByte		bLength;
52 	uByte		bDescriptorType;
53 	uWord		bcdHID;
54 	uByte		bCountryCode;
55 	uByte		bNumDescriptors;
56 	struct {
57 		uByte		bDescriptorType;
58 		uWord		wDescriptorLength;
59 	} descrs[1];
60 } UPACKED usb_hid_descriptor_t;
61 #define USB_HID_DESCRIPTOR_SIZE(n) (9+(n)*3)
62 
63 /* Usage pages */
64 #define HUP_UNDEFINED		0x0000
65 #define HUP_GENERIC_DESKTOP	0x0001
66 #define HUP_SIMULATION		0x0002
67 #define HUP_VR_CONTROLS		0x0003
68 #define HUP_SPORTS_CONTROLS	0x0004
69 #define HUP_GAMING_CONTROLS	0x0005
70 #define HUP_KEYBOARD		0x0007
71 #define HUP_LEDS		0x0008
72 #define HUP_BUTTON		0x0009
73 #define HUP_ORDINALS		0x000a
74 #define HUP_TELEPHONY		0x000b
75 #define HUP_CONSUMER		0x000c
76 #define HUP_DIGITIZERS		0x000d
77 #define HUP_PHYSICAL_IFACE	0x000e
78 #define HUP_UNICODE		0x0010
79 #define HUP_ALPHANUM_DISPLAY	0x0014
80 #define HUP_MONITOR		0x0080
81 #define HUP_MONITOR_ENUM_VAL	0x0081
82 #define HUP_VESA_VC		0x0082
83 #define HUP_VESA_CMD		0x0083
84 #define HUP_POWER		0x0084
85 #define HUP_BATTERY_SYSTEM	0x0085
86 #define HUP_BARCODE_SCANNER	0x008b
87 #define HUP_SCALE		0x008c
88 #define HUP_CAMERA_CONTROL	0x0090
89 #define HUP_ARCADE		0x0091
90 #define HUP_MICROSOFT		0xff00
91 
92 /* Usages, generic desktop */
93 #define HUG_POINTER		0x0001
94 #define HUG_MOUSE		0x0002
95 #define HUG_JOYSTICK		0x0004
96 #define HUG_GAME_PAD		0x0005
97 #define HUG_KEYBOARD		0x0006
98 #define HUG_KEYPAD		0x0007
99 #define HUG_X			0x0030
100 #define HUG_Y			0x0031
101 #define HUG_Z			0x0032
102 #define HUG_RX			0x0033
103 #define HUG_RY			0x0034
104 #define HUG_RZ			0x0035
105 #define HUG_SLIDER		0x0036
106 #define HUG_DIAL		0x0037
107 #define HUG_WHEEL		0x0038
108 #define HUG_HAT_SWITCH		0x0039
109 #define HUG_COUNTED_BUFFER	0x003a
110 #define HUG_BYTE_COUNT		0x003b
111 #define HUG_MOTION_WAKEUP	0x003c
112 #define HUG_VX			0x0040
113 #define HUG_VY			0x0041
114 #define HUG_VZ			0x0042
115 #define HUG_VBRX		0x0043
116 #define HUG_VBRY		0x0044
117 #define HUG_VBRZ		0x0045
118 #define HUG_VNO			0x0046
119 #define HUG_SYSTEM_CONTROL	0x0080
120 #define HUG_SYSTEM_POWER_DOWN	0x0081
121 #define HUG_SYSTEM_SLEEP	0x0082
122 #define HUG_SYSTEM_WAKEUP	0x0083
123 #define HUG_SYSTEM_CONTEXT_MENU	0x0084
124 #define HUG_SYSTEM_MAIN_MENU	0x0085
125 #define HUG_SYSTEM_APP_MENU	0x0086
126 #define HUG_SYSTEM_MENU_HELP	0x0087
127 #define HUG_SYSTEM_MENU_EXIT	0x0088
128 #define HUG_SYSTEM_MENU_SELECT	0x0089
129 #define HUG_SYSTEM_MENU_RIGHT	0x008a
130 #define HUG_SYSTEM_MENU_LEFT	0x008b
131 #define HUG_SYSTEM_MENU_UP	0x008c
132 #define HUG_SYSTEM_MENU_DOWN	0x008d
133 
134 /* Usages Digitizers */
135 #define HUD_UNDEFINED		0x0000
136 #define HUD_TOUCH_SCREEN	0x0004
137 #define HUD_FINGER		0x0022
138 #define HUD_TIP_PRESSURE	0x0030
139 #define HUD_BARREL_PRESSURE	0x0031
140 #define HUD_IN_RANGE		0x0032
141 #define HUD_TOUCH		0x0033
142 #define HUD_UNTOUCH		0x0034
143 #define HUD_TAP			0x0035
144 #define HUD_QUALITY		0x0036
145 #define HUD_DATA_VALID		0x0037
146 #define HUD_TRANSDUCER_INDEX	0x0038
147 #define HUD_TABLET_FKEYS	0x0039
148 #define HUD_PROGRAM_CHANGE_KEYS	0x003a
149 #define HUD_BATTERY_STRENGTH	0x003b
150 #define HUD_INVERT		0x003c
151 #define HUD_X_TILT		0x003d
152 #define HUD_Y_TILT		0x003e
153 #define HUD_AZIMUTH		0x003f
154 #define HUD_ALTITUDE		0x0040
155 #define HUD_TWIST		0x0041
156 #define HUD_TIP_SWITCH		0x0042
157 #define HUD_SEC_TIP_SWITCH	0x0043
158 #define HUD_BARREL_SWITCH	0x0044
159 #define HUD_ERASER		0x0045
160 #define HUD_TABLET_PICK		0x0046
161 
162 /* Usages LEDs */
163 #define HUD_LED_NUM_LOCK	0x0001
164 #define HUD_LED_CAPS_LOCK	0x0002
165 #define HUD_LED_SCROLL_LOCK	0x0003
166 #define HUD_LED_COMPOSE		0x0004
167 #define HUD_LED_KANA		0x0005
168 
169 /* Usages, Consumer */
170 #define HUC_AC_PAN		0x0238
171 
172 #define HID_USAGE2(p, u) (((p) << 16) | u)
173 #define HID_GET_USAGE(u) ((u) & 0xffff)
174 #define HID_GET_USAGE_PAGE(u) (((u) >> 16) & 0xffff)
175 
176 #define UHID_INPUT_REPORT 0x01
177 #define UHID_OUTPUT_REPORT 0x02
178 #define UHID_FEATURE_REPORT 0x03
179 
180 #define HCOLL_PHYSICAL		0
181 #define HCOLL_APPLICATION	1
182 #define HCOLL_LOGICAL		2
183 
184 /* Bits in the input/output/feature items */
185 #define HIO_CONST	0x001
186 #define HIO_VARIABLE	0x002
187 #define HIO_RELATIVE	0x004
188 #define HIO_WRAP	0x008
189 #define HIO_NONLINEAR	0x010
190 #define HIO_NOPREF	0x020
191 #define HIO_NULLSTATE	0x040
192 #define HIO_VOLATILE	0x080
193 #define HIO_BUFBYTES	0x100
194 
195 #endif /* _DEV_USB_USBHID_H_ */
196