blob: 9265a2ede765f26f34ac7fb51bc593add32d1ea6 [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27/** \ingroup group_class
28 * \defgroup ClassDriver_HID Human Interface Device (HID)
29 * @{ */
30
31#ifndef _TUSB_HID_H_
32#define _TUSB_HID_H_
33
34#include "common/tusb_common.h"
35
36#ifdef __cplusplus
37 extern "C" {
38#endif
39
40//--------------------------------------------------------------------+
41// Common Definitions
42//--------------------------------------------------------------------+
43/** \defgroup ClassDriver_HID_Common Common Definitions
44 * @{ */
45
46 /// USB HID Descriptor
47typedef struct TU_ATTR_PACKED
48{
49 uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
50 uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
51
52 uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
53 uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
54 uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
55
56 uint8_t bReportType; /**< Type of HID class report. */
57 uint16_t wReportLength; /**< the total size of the Report descriptor. */
58} tusb_hid_descriptor_hid_t;
59
60/// HID Subclass
61typedef enum
62{
63 HID_SUBCLASS_NONE = 0, ///< No Subclass
64 HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass
65}hid_subclass_enum_t;
66
67/// HID Interface Protocol
68typedef enum
69{
70 HID_ITF_PROTOCOL_NONE = 0, ///< None
71 HID_ITF_PROTOCOL_KEYBOARD = 1, ///< Keyboard
72 HID_ITF_PROTOCOL_MOUSE = 2 ///< Mouse
73}hid_interface_protocol_enum_t;
74
75/// HID Descriptor Type
76typedef enum
77{
78 HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor
79 HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor
80 HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor
81}hid_descriptor_enum_t;
82
83/// HID Request Report Type
84typedef enum
85{
86 HID_REPORT_TYPE_INVALID = 0,
87 HID_REPORT_TYPE_INPUT, ///< Input
88 HID_REPORT_TYPE_OUTPUT, ///< Output
89 HID_REPORT_TYPE_FEATURE ///< Feature
90}hid_report_type_t;
91
92/// HID Class Specific Control Request
93typedef enum
94{
95 HID_REQ_CONTROL_GET_REPORT = 0x01, ///< Get Report
96 HID_REQ_CONTROL_GET_IDLE = 0x02, ///< Get Idle
97 HID_REQ_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
98 HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report
99 HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
100 HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
101}hid_request_enum_t;
102
103/// HID Local Code
104typedef enum
105{
106 HID_LOCAL_NotSupported = 0 , ///< NotSupported
107 HID_LOCAL_Arabic , ///< Arabic
108 HID_LOCAL_Belgian , ///< Belgian
109 HID_LOCAL_Canadian_Bilingual , ///< Canadian_Bilingual
110 HID_LOCAL_Canadian_French , ///< Canadian_French
111 HID_LOCAL_Czech_Republic , ///< Czech_Republic
112 HID_LOCAL_Danish , ///< Danish
113 HID_LOCAL_Finnish , ///< Finnish
114 HID_LOCAL_French , ///< French
115 HID_LOCAL_German , ///< German
116 HID_LOCAL_Greek , ///< Greek
117 HID_LOCAL_Hebrew , ///< Hebrew
118 HID_LOCAL_Hungary , ///< Hungary
119 HID_LOCAL_International , ///< International
120 HID_LOCAL_Italian , ///< Italian
121 HID_LOCAL_Japan_Katakana , ///< Japan_Katakana
122 HID_LOCAL_Korean , ///< Korean
123 HID_LOCAL_Latin_American , ///< Latin_American
124 HID_LOCAL_Netherlands_Dutch , ///< Netherlands/Dutch
125 HID_LOCAL_Norwegian , ///< Norwegian
126 HID_LOCAL_Persian_Farsi , ///< Persian (Farsi)
127 HID_LOCAL_Poland , ///< Poland
128 HID_LOCAL_Portuguese , ///< Portuguese
129 HID_LOCAL_Russia , ///< Russia
130 HID_LOCAL_Slovakia , ///< Slovakia
131 HID_LOCAL_Spanish , ///< Spanish
132 HID_LOCAL_Swedish , ///< Swedish
133 HID_LOCAL_Swiss_French , ///< Swiss/French
134 HID_LOCAL_Swiss_German , ///< Swiss/German
135 HID_LOCAL_Switzerland , ///< Switzerland
136 HID_LOCAL_Taiwan , ///< Taiwan
137 HID_LOCAL_Turkish_Q , ///< Turkish-Q
138 HID_LOCAL_UK , ///< UK
139 HID_LOCAL_US , ///< US
140 HID_LOCAL_Yugoslavia , ///< Yugoslavia
141 HID_LOCAL_Turkish_F ///< Turkish-F
142} hid_local_enum_t;
143
144// HID protocol value used by GetProtocol / SetProtocol
145typedef enum
146{
147 HID_PROTOCOL_BOOT = 0,
148 HID_PROTOCOL_REPORT = 1
149} hid_protocol_mode_enum_t;
150
151/** @} */
152
153//--------------------------------------------------------------------+
154// GAMEPAD
155//--------------------------------------------------------------------+
156/** \addtogroup ClassDriver_HID_Gamepad Gamepad
157 * @{ */
158
159/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
160 ____________________________ __
161 / [__ZL__] [__ZR__] \ |
162 / [__ TL __] [__ TR __] \ | Front Triggers
163 __/________________________________\__ __|
164 / _ \ |
165 / /\ __ (N) \ |
166 / || __ |MO| __ _ _ \ | Main Pad
167 | <===DP===> |SE| |ST| (W) -|- (E) | |
168 \ || ___ ___ _ / |
169 /\ \/ / \ / \ (S) /\ __|
170 / \________ | LS | ____ | RS | ________/ \ |
171| / \ \___/ / \ \___/ / \ | | Control Sticks
172| / \_____/ \_____/ \ | __|
173| / \ |
174 \_____/ \_____/
175
176 |________|______| |______|___________|
177 D-Pad Left Right Action Pad
178 Stick Stick
179
180 |_____________|
181 Menu Pad
182
183 Most gamepads have the following features:
184 - Action-Pad 4 buttons in diamonds-shape (on the right side) NORTH, SOUTH, WEST and EAST.
185 - D-Pad (Direction-pad) 4 buttons (on the left side) that point up, down, left and right.
186 - Menu-Pad Different constellations, but most-times 2 buttons: SELECT - START.
187 - Analog-Sticks provide freely moveable sticks to control directions, Analog-sticks may also
188 provide a digital button if you press them.
189 - Triggers are located on the upper-side of the pad in vertical direction. The upper buttons
190 are normally named Left- and Right-Triggers, the lower buttons Z-Left and Z-Right.
191 - Rumble Many devices provide force-feedback features. But are mostly just simple rumble motors.
192 */
193
194/// HID Gamepad Protocol Report.
195typedef struct TU_ATTR_PACKED
196{
197 int8_t x; ///< Delta x movement of left analog-stick
198 int8_t y; ///< Delta y movement of left analog-stick
199 int8_t z; ///< Delta z movement of right analog-joystick
200 int8_t rz; ///< Delta Rz movement of right analog-joystick
201 int8_t rx; ///< Delta Rx movement of analog left trigger
202 int8_t ry; ///< Delta Ry movement of analog right trigger
203 uint8_t hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
204 uint32_t buttons; ///< Buttons mask for currently pressed buttons
205}hid_gamepad_report_t;
206
207/// Standard Gamepad Buttons Bitmap
208typedef enum
209{
210 GAMEPAD_BUTTON_0 = TU_BIT(0),
211 GAMEPAD_BUTTON_1 = TU_BIT(1),
212 GAMEPAD_BUTTON_2 = TU_BIT(2),
213 GAMEPAD_BUTTON_3 = TU_BIT(3),
214 GAMEPAD_BUTTON_4 = TU_BIT(4),
215 GAMEPAD_BUTTON_5 = TU_BIT(5),
216 GAMEPAD_BUTTON_6 = TU_BIT(6),
217 GAMEPAD_BUTTON_7 = TU_BIT(7),
218 GAMEPAD_BUTTON_8 = TU_BIT(8),
219 GAMEPAD_BUTTON_9 = TU_BIT(9),
220 GAMEPAD_BUTTON_10 = TU_BIT(10),
221 GAMEPAD_BUTTON_11 = TU_BIT(11),
222 GAMEPAD_BUTTON_12 = TU_BIT(12),
223 GAMEPAD_BUTTON_13 = TU_BIT(13),
224 GAMEPAD_BUTTON_14 = TU_BIT(14),
225 GAMEPAD_BUTTON_15 = TU_BIT(15),
226 GAMEPAD_BUTTON_16 = TU_BIT(16),
227 GAMEPAD_BUTTON_17 = TU_BIT(17),
228 GAMEPAD_BUTTON_18 = TU_BIT(18),
229 GAMEPAD_BUTTON_19 = TU_BIT(19),
230 GAMEPAD_BUTTON_20 = TU_BIT(20),
231 GAMEPAD_BUTTON_21 = TU_BIT(21),
232 GAMEPAD_BUTTON_22 = TU_BIT(22),
233 GAMEPAD_BUTTON_23 = TU_BIT(23),
234 GAMEPAD_BUTTON_24 = TU_BIT(24),
235 GAMEPAD_BUTTON_25 = TU_BIT(25),
236 GAMEPAD_BUTTON_26 = TU_BIT(26),
237 GAMEPAD_BUTTON_27 = TU_BIT(27),
238 GAMEPAD_BUTTON_28 = TU_BIT(28),
239 GAMEPAD_BUTTON_29 = TU_BIT(29),
240 GAMEPAD_BUTTON_30 = TU_BIT(30),
241 GAMEPAD_BUTTON_31 = TU_BIT(31),
242}hid_gamepad_button_bm_t;
243
244/// Standard Gamepad Buttons Naming from Linux input event codes
245/// https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h
246#define GAMEPAD_BUTTON_A GAMEPAD_BUTTON_0
247#define GAMEPAD_BUTTON_SOUTH GAMEPAD_BUTTON_0
248
249#define GAMEPAD_BUTTON_B GAMEPAD_BUTTON_1
250#define GAMEPAD_BUTTON_EAST GAMEPAD_BUTTON_1
251
252#define GAMEPAD_BUTTON_C GAMEPAD_BUTTON_2
253
254#define GAMEPAD_BUTTON_X GAMEPAD_BUTTON_3
255#define GAMEPAD_BUTTON_NORTH GAMEPAD_BUTTON_3
256
257#define GAMEPAD_BUTTON_Y GAMEPAD_BUTTON_4
258#define GAMEPAD_BUTTON_WEST GAMEPAD_BUTTON_4
259
260#define GAMEPAD_BUTTON_Z GAMEPAD_BUTTON_5
261#define GAMEPAD_BUTTON_TL GAMEPAD_BUTTON_6
262#define GAMEPAD_BUTTON_TR GAMEPAD_BUTTON_7
263#define GAMEPAD_BUTTON_TL2 GAMEPAD_BUTTON_8
264#define GAMEPAD_BUTTON_TR2 GAMEPAD_BUTTON_9
265#define GAMEPAD_BUTTON_SELECT GAMEPAD_BUTTON_10
266#define GAMEPAD_BUTTON_START GAMEPAD_BUTTON_11
267#define GAMEPAD_BUTTON_MODE GAMEPAD_BUTTON_12
268#define GAMEPAD_BUTTON_THUMBL GAMEPAD_BUTTON_13
269#define GAMEPAD_BUTTON_THUMBR GAMEPAD_BUTTON_14
270
271/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes)
272typedef enum
273{
274 GAMEPAD_HAT_CENTERED = 0, ///< DPAD_CENTERED
275 GAMEPAD_HAT_UP = 1, ///< DPAD_UP
276 GAMEPAD_HAT_UP_RIGHT = 2, ///< DPAD_UP_RIGHT
277 GAMEPAD_HAT_RIGHT = 3, ///< DPAD_RIGHT
278 GAMEPAD_HAT_DOWN_RIGHT = 4, ///< DPAD_DOWN_RIGHT
279 GAMEPAD_HAT_DOWN = 5, ///< DPAD_DOWN
280 GAMEPAD_HAT_DOWN_LEFT = 6, ///< DPAD_DOWN_LEFT
281 GAMEPAD_HAT_LEFT = 7, ///< DPAD_LEFT
282 GAMEPAD_HAT_UP_LEFT = 8, ///< DPAD_UP_LEFT
283}hid_gamepad_hat_t;
284
285/// @}
286
287//--------------------------------------------------------------------+
288// MOUSE
289//--------------------------------------------------------------------+
290/** \addtogroup ClassDriver_HID_Mouse Mouse
291 * @{ */
292
293/// Standard HID Boot Protocol Mouse Report.
294typedef struct TU_ATTR_PACKED
295{
296 uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
297 int8_t x; /**< Current delta x movement of the mouse. */
298 int8_t y; /**< Current delta y movement on the mouse. */
299 int8_t wheel; /**< Current delta wheel movement on the mouse. */
300 int8_t pan; // using AC Pan
301} hid_mouse_report_t;
302
303/// Standard Mouse Buttons Bitmap
304typedef enum
305{
306 MOUSE_BUTTON_LEFT = TU_BIT(0), ///< Left button
307 MOUSE_BUTTON_RIGHT = TU_BIT(1), ///< Right button
308 MOUSE_BUTTON_MIDDLE = TU_BIT(2), ///< Middle button
309 MOUSE_BUTTON_BACKWARD = TU_BIT(3), ///< Backward button,
310 MOUSE_BUTTON_FORWARD = TU_BIT(4), ///< Forward button,
311}hid_mouse_button_bm_t;
312
313/// @}
314
315//--------------------------------------------------------------------+
316// Keyboard
317//--------------------------------------------------------------------+
318/** \addtogroup ClassDriver_HID_Keyboard Keyboard
319 * @{ */
320
321/// Standard HID Boot Protocol Keyboard Report.
322typedef struct TU_ATTR_PACKED
323{
324 uint8_t modifier; /**< Keyboard modifier (KEYBOARD_MODIFIER_* masks). */
325 uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
326 uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
327} hid_keyboard_report_t;
328
329/// Keyboard modifier codes bitmap
330typedef enum
331{
332 KEYBOARD_MODIFIER_LEFTCTRL = TU_BIT(0), ///< Left Control
333 KEYBOARD_MODIFIER_LEFTSHIFT = TU_BIT(1), ///< Left Shift
334 KEYBOARD_MODIFIER_LEFTALT = TU_BIT(2), ///< Left Alt
335 KEYBOARD_MODIFIER_LEFTGUI = TU_BIT(3), ///< Left Window
336 KEYBOARD_MODIFIER_RIGHTCTRL = TU_BIT(4), ///< Right Control
337 KEYBOARD_MODIFIER_RIGHTSHIFT = TU_BIT(5), ///< Right Shift
338 KEYBOARD_MODIFIER_RIGHTALT = TU_BIT(6), ///< Right Alt
339 KEYBOARD_MODIFIER_RIGHTGUI = TU_BIT(7) ///< Right Window
340}hid_keyboard_modifier_bm_t;
341
342typedef enum
343{
344 KEYBOARD_LED_NUMLOCK = TU_BIT(0), ///< Num Lock LED
345 KEYBOARD_LED_CAPSLOCK = TU_BIT(1), ///< Caps Lock LED
346 KEYBOARD_LED_SCROLLLOCK = TU_BIT(2), ///< Scroll Lock LED
347 KEYBOARD_LED_COMPOSE = TU_BIT(3), ///< Composition Mode
348 KEYBOARD_LED_KANA = TU_BIT(4) ///< Kana mode
349}hid_keyboard_led_bm_t;
350
351/// @}
352
353//--------------------------------------------------------------------+
354// HID KEYCODE
355//--------------------------------------------------------------------+
356#define HID_KEY_NONE 0x00
357#define HID_KEY_A 0x04
358#define HID_KEY_B 0x05
359#define HID_KEY_C 0x06
360#define HID_KEY_D 0x07
361#define HID_KEY_E 0x08
362#define HID_KEY_F 0x09
363#define HID_KEY_G 0x0A
364#define HID_KEY_H 0x0B
365#define HID_KEY_I 0x0C
366#define HID_KEY_J 0x0D
367#define HID_KEY_K 0x0E
368#define HID_KEY_L 0x0F
369#define HID_KEY_M 0x10
370#define HID_KEY_N 0x11
371#define HID_KEY_O 0x12
372#define HID_KEY_P 0x13
373#define HID_KEY_Q 0x14
374#define HID_KEY_R 0x15
375#define HID_KEY_S 0x16
376#define HID_KEY_T 0x17
377#define HID_KEY_U 0x18
378#define HID_KEY_V 0x19
379#define HID_KEY_W 0x1A
380#define HID_KEY_X 0x1B
381#define HID_KEY_Y 0x1C
382#define HID_KEY_Z 0x1D
383#define HID_KEY_1 0x1E
384#define HID_KEY_2 0x1F
385#define HID_KEY_3 0x20
386#define HID_KEY_4 0x21
387#define HID_KEY_5 0x22
388#define HID_KEY_6 0x23
389#define HID_KEY_7 0x24
390#define HID_KEY_8 0x25
391#define HID_KEY_9 0x26
392#define HID_KEY_0 0x27
393#define HID_KEY_ENTER 0x28
394#define HID_KEY_ESCAPE 0x29
395#define HID_KEY_BACKSPACE 0x2A
396#define HID_KEY_TAB 0x2B
397#define HID_KEY_SPACE 0x2C
398#define HID_KEY_MINUS 0x2D
399#define HID_KEY_EQUAL 0x2E
400#define HID_KEY_BRACKET_LEFT 0x2F
401#define HID_KEY_BRACKET_RIGHT 0x30
402#define HID_KEY_BACKSLASH 0x31
403#define HID_KEY_EUROPE_1 0x32
404#define HID_KEY_SEMICOLON 0x33
405#define HID_KEY_APOSTROPHE 0x34
406#define HID_KEY_GRAVE 0x35
407#define HID_KEY_COMMA 0x36
408#define HID_KEY_PERIOD 0x37
409#define HID_KEY_SLASH 0x38
410#define HID_KEY_CAPS_LOCK 0x39
411#define HID_KEY_F1 0x3A
412#define HID_KEY_F2 0x3B
413#define HID_KEY_F3 0x3C
414#define HID_KEY_F4 0x3D
415#define HID_KEY_F5 0x3E
416#define HID_KEY_F6 0x3F
417#define HID_KEY_F7 0x40
418#define HID_KEY_F8 0x41
419#define HID_KEY_F9 0x42
420#define HID_KEY_F10 0x43
421#define HID_KEY_F11 0x44
422#define HID_KEY_F12 0x45
423#define HID_KEY_PRINT_SCREEN 0x46
424#define HID_KEY_SCROLL_LOCK 0x47
425#define HID_KEY_PAUSE 0x48
426#define HID_KEY_INSERT 0x49
427#define HID_KEY_HOME 0x4A
428#define HID_KEY_PAGE_UP 0x4B
429#define HID_KEY_DELETE 0x4C
430#define HID_KEY_END 0x4D
431#define HID_KEY_PAGE_DOWN 0x4E
432#define HID_KEY_ARROW_RIGHT 0x4F
433#define HID_KEY_ARROW_LEFT 0x50
434#define HID_KEY_ARROW_DOWN 0x51
435#define HID_KEY_ARROW_UP 0x52
436#define HID_KEY_NUM_LOCK 0x53
437#define HID_KEY_KEYPAD_DIVIDE 0x54
438#define HID_KEY_KEYPAD_MULTIPLY 0x55
439#define HID_KEY_KEYPAD_SUBTRACT 0x56
440#define HID_KEY_KEYPAD_ADD 0x57
441#define HID_KEY_KEYPAD_ENTER 0x58
442#define HID_KEY_KEYPAD_1 0x59
443#define HID_KEY_KEYPAD_2 0x5A
444#define HID_KEY_KEYPAD_3 0x5B
445#define HID_KEY_KEYPAD_4 0x5C
446#define HID_KEY_KEYPAD_5 0x5D
447#define HID_KEY_KEYPAD_6 0x5E
448#define HID_KEY_KEYPAD_7 0x5F
449#define HID_KEY_KEYPAD_8 0x60
450#define HID_KEY_KEYPAD_9 0x61
451#define HID_KEY_KEYPAD_0 0x62
452#define HID_KEY_KEYPAD_DECIMAL 0x63
453#define HID_KEY_EUROPE_2 0x64
454#define HID_KEY_APPLICATION 0x65
455#define HID_KEY_POWER 0x66
456#define HID_KEY_KEYPAD_EQUAL 0x67
457#define HID_KEY_F13 0x68
458#define HID_KEY_F14 0x69
459#define HID_KEY_F15 0x6A
460#define HID_KEY_F16 0x6B
461#define HID_KEY_F17 0x6C
462#define HID_KEY_F18 0x6D
463#define HID_KEY_F19 0x6E
464#define HID_KEY_F20 0x6F
465#define HID_KEY_F21 0x70
466#define HID_KEY_F22 0x71
467#define HID_KEY_F23 0x72
468#define HID_KEY_F24 0x73
469#define HID_KEY_EXECUTE 0x74
470#define HID_KEY_HELP 0x75
471#define HID_KEY_MENU 0x76
472#define HID_KEY_SELECT 0x77
473#define HID_KEY_STOP 0x78
474#define HID_KEY_AGAIN 0x79
475#define HID_KEY_UNDO 0x7A
476#define HID_KEY_CUT 0x7B
477#define HID_KEY_COPY 0x7C
478#define HID_KEY_PASTE 0x7D
479#define HID_KEY_FIND 0x7E
480#define HID_KEY_MUTE 0x7F
481#define HID_KEY_VOLUME_UP 0x80
482#define HID_KEY_VOLUME_DOWN 0x81
483#define HID_KEY_LOCKING_CAPS_LOCK 0x82
484#define HID_KEY_LOCKING_NUM_LOCK 0x83
485#define HID_KEY_LOCKING_SCROLL_LOCK 0x84
486#define HID_KEY_KEYPAD_COMMA 0x85
487#define HID_KEY_KEYPAD_EQUAL_SIGN 0x86
488#define HID_KEY_KANJI1 0x87
489#define HID_KEY_KANJI2 0x88
490#define HID_KEY_KANJI3 0x89
491#define HID_KEY_KANJI4 0x8A
492#define HID_KEY_KANJI5 0x8B
493#define HID_KEY_KANJI6 0x8C
494#define HID_KEY_KANJI7 0x8D
495#define HID_KEY_KANJI8 0x8E
496#define HID_KEY_KANJI9 0x8F
497#define HID_KEY_LANG1 0x90
498#define HID_KEY_LANG2 0x91
499#define HID_KEY_LANG3 0x92
500#define HID_KEY_LANG4 0x93
501#define HID_KEY_LANG5 0x94
502#define HID_KEY_LANG6 0x95
503#define HID_KEY_LANG7 0x96
504#define HID_KEY_LANG8 0x97
505#define HID_KEY_LANG9 0x98
506#define HID_KEY_ALTERNATE_ERASE 0x99
507#define HID_KEY_SYSREQ_ATTENTION 0x9A
508#define HID_KEY_CANCEL 0x9B
509#define HID_KEY_CLEAR 0x9C
510#define HID_KEY_PRIOR 0x9D
511#define HID_KEY_RETURN 0x9E
512#define HID_KEY_SEPARATOR 0x9F
513#define HID_KEY_OUT 0xA0
514#define HID_KEY_OPER 0xA1
515#define HID_KEY_CLEAR_AGAIN 0xA2
516#define HID_KEY_CRSEL_PROPS 0xA3
517#define HID_KEY_EXSEL 0xA4
518// RESERVED 0xA5-DF
519#define HID_KEY_CONTROL_LEFT 0xE0
520#define HID_KEY_SHIFT_LEFT 0xE1
521#define HID_KEY_ALT_LEFT 0xE2
522#define HID_KEY_GUI_LEFT 0xE3
523#define HID_KEY_CONTROL_RIGHT 0xE4
524#define HID_KEY_SHIFT_RIGHT 0xE5
525#define HID_KEY_ALT_RIGHT 0xE6
526#define HID_KEY_GUI_RIGHT 0xE7
527
528
529//--------------------------------------------------------------------+
530// REPORT DESCRIPTOR
531//--------------------------------------------------------------------+
532
533//------------- ITEM & TAG -------------//
534#define HID_REPORT_DATA_0(data)
535#define HID_REPORT_DATA_1(data) , data
536#define HID_REPORT_DATA_2(data) , U16_TO_U8S_LE(data)
537#define HID_REPORT_DATA_3(data) , U32_TO_U8S_LE(data)
538
539#define HID_REPORT_ITEM(data, tag, type, size) \
540 (((tag) << 4) | ((type) << 2) | (size)) HID_REPORT_DATA_##size(data)
541
542// Report Item Types
543enum {
544 RI_TYPE_MAIN = 0,
545 RI_TYPE_GLOBAL = 1,
546 RI_TYPE_LOCAL = 2
547};
548
549//------------- Main Items - HID 1.11 section 6.2.2.4 -------------//
550
551// Report Item Main group
552enum {
553 RI_MAIN_INPUT = 8,
554 RI_MAIN_OUTPUT = 9,
555 RI_MAIN_COLLECTION = 10,
556 RI_MAIN_FEATURE = 11,
557 RI_MAIN_COLLECTION_END = 12
558};
559
560#define HID_INPUT(x) HID_REPORT_ITEM(x, RI_MAIN_INPUT , RI_TYPE_MAIN, 1)
561#define HID_OUTPUT(x) HID_REPORT_ITEM(x, RI_MAIN_OUTPUT , RI_TYPE_MAIN, 1)
562#define HID_COLLECTION(x) HID_REPORT_ITEM(x, RI_MAIN_COLLECTION , RI_TYPE_MAIN, 1)
563#define HID_FEATURE(x) HID_REPORT_ITEM(x, RI_MAIN_FEATURE , RI_TYPE_MAIN, 1)
564#define HID_COLLECTION_END HID_REPORT_ITEM(x, RI_MAIN_COLLECTION_END, RI_TYPE_MAIN, 0)
565
566//------------- Input, Output, Feature - HID 1.11 section 6.2.2.5 -------------//
567#define HID_DATA (0<<0)
568#define HID_CONSTANT (1<<0)
569
570#define HID_ARRAY (0<<1)
571#define HID_VARIABLE (1<<1)
572
573#define HID_ABSOLUTE (0<<2)
574#define HID_RELATIVE (1<<2)
575
576#define HID_WRAP_NO (0<<3)
577#define HID_WRAP (1<<3)
578
579#define HID_LINEAR (0<<4)
580#define HID_NONLINEAR (1<<4)
581
582#define HID_PREFERRED_STATE (0<<5)
583#define HID_PREFERRED_NO (1<<5)
584
585#define HID_NO_NULL_POSITION (0<<6)
586#define HID_NULL_STATE (1<<6)
587
588#define HID_NON_VOLATILE (0<<7)
589#define HID_VOLATILE (1<<7)
590
591#define HID_BITFIELD (0<<8)
592#define HID_BUFFERED_BYTES (1<<8)
593
594//------------- Collection Item - HID 1.11 section 6.2.2.6 -------------//
595enum {
596 HID_COLLECTION_PHYSICAL = 0,
597 HID_COLLECTION_APPLICATION,
598 HID_COLLECTION_LOGICAL,
599 HID_COLLECTION_REPORT,
600 HID_COLLECTION_NAMED_ARRAY,
601 HID_COLLECTION_USAGE_SWITCH,
602 HID_COLLECTION_USAGE_MODIFIER
603};
604
605//------------- Global Items - HID 1.11 section 6.2.2.7 -------------//
606
607// Report Item Global group
608enum {
609 RI_GLOBAL_USAGE_PAGE = 0,
610 RI_GLOBAL_LOGICAL_MIN = 1,
611 RI_GLOBAL_LOGICAL_MAX = 2,
612 RI_GLOBAL_PHYSICAL_MIN = 3,
613 RI_GLOBAL_PHYSICAL_MAX = 4,
614 RI_GLOBAL_UNIT_EXPONENT = 5,
615 RI_GLOBAL_UNIT = 6,
616 RI_GLOBAL_REPORT_SIZE = 7,
617 RI_GLOBAL_REPORT_ID = 8,
618 RI_GLOBAL_REPORT_COUNT = 9,
619 RI_GLOBAL_PUSH = 10,
620 RI_GLOBAL_POP = 11
621};
622
623#define HID_USAGE_PAGE(x) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, 1)
624#define HID_USAGE_PAGE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_USAGE_PAGE, RI_TYPE_GLOBAL, n)
625
626#define HID_LOGICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, 1)
627#define HID_LOGICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MIN, RI_TYPE_GLOBAL, n)
628
629#define HID_LOGICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, 1)
630#define HID_LOGICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_LOGICAL_MAX, RI_TYPE_GLOBAL, n)
631
632#define HID_PHYSICAL_MIN(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, 1)
633#define HID_PHYSICAL_MIN_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MIN, RI_TYPE_GLOBAL, n)
634
635#define HID_PHYSICAL_MAX(x) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, 1)
636#define HID_PHYSICAL_MAX_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_PHYSICAL_MAX, RI_TYPE_GLOBAL, n)
637
638#define HID_UNIT_EXPONENT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, 1)
639#define HID_UNIT_EXPONENT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT_EXPONENT, RI_TYPE_GLOBAL, n)
640
641#define HID_UNIT(x) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, 1)
642#define HID_UNIT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_UNIT, RI_TYPE_GLOBAL, n)
643
644#define HID_REPORT_SIZE(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, 1)
645#define HID_REPORT_SIZE_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_SIZE, RI_TYPE_GLOBAL, n)
646
647#define HID_REPORT_ID(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, 1),
648#define HID_REPORT_ID_N(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_ID, RI_TYPE_GLOBAL, n),
649
650#define HID_REPORT_COUNT(x) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, 1)
651#define HID_REPORT_COUNT_N(x, n) HID_REPORT_ITEM(x, RI_GLOBAL_REPORT_COUNT, RI_TYPE_GLOBAL, n)
652
653#define HID_PUSH HID_REPORT_ITEM(x, RI_GLOBAL_PUSH, RI_TYPE_GLOBAL, 0)
654#define HID_POP HID_REPORT_ITEM(x, RI_GLOBAL_POP, RI_TYPE_GLOBAL, 0)
655
656//------------- LOCAL ITEMS 6.2.2.8 -------------//
657
658enum {
659 RI_LOCAL_USAGE = 0,
660 RI_LOCAL_USAGE_MIN = 1,
661 RI_LOCAL_USAGE_MAX = 2,
662 RI_LOCAL_DESIGNATOR_INDEX = 3,
663 RI_LOCAL_DESIGNATOR_MIN = 4,
664 RI_LOCAL_DESIGNATOR_MAX = 5,
665 // 6 is reserved
666 RI_LOCAL_STRING_INDEX = 7,
667 RI_LOCAL_STRING_MIN = 8,
668 RI_LOCAL_STRING_MAX = 9,
669 RI_LOCAL_DELIMITER = 10,
670};
671
672#define HID_USAGE(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, 1)
673#define HID_USAGE_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE, RI_TYPE_LOCAL, n)
674
675#define HID_USAGE_MIN(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, 1)
676#define HID_USAGE_MIN_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MIN, RI_TYPE_LOCAL, n)
677
678#define HID_USAGE_MAX(x) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, 1)
679#define HID_USAGE_MAX_N(x, n) HID_REPORT_ITEM(x, RI_LOCAL_USAGE_MAX, RI_TYPE_LOCAL, n)
680
681//--------------------------------------------------------------------+
682// Usage Table
683//--------------------------------------------------------------------+
684
685/// HID Usage Table - Table 1: Usage Page Summary
686enum {
687 HID_USAGE_PAGE_DESKTOP = 0x01,
688 HID_USAGE_PAGE_SIMULATE = 0x02,
689 HID_USAGE_PAGE_VIRTUAL_REALITY = 0x03,
690 HID_USAGE_PAGE_SPORT = 0x04,
691 HID_USAGE_PAGE_GAME = 0x05,
692 HID_USAGE_PAGE_GENERIC_DEVICE = 0x06,
693 HID_USAGE_PAGE_KEYBOARD = 0x07,
694 HID_USAGE_PAGE_LED = 0x08,
695 HID_USAGE_PAGE_BUTTON = 0x09,
696 HID_USAGE_PAGE_ORDINAL = 0x0a,
697 HID_USAGE_PAGE_TELEPHONY = 0x0b,
698 HID_USAGE_PAGE_CONSUMER = 0x0c,
699 HID_USAGE_PAGE_DIGITIZER = 0x0d,
700 HID_USAGE_PAGE_PID = 0x0f,
701 HID_USAGE_PAGE_UNICODE = 0x10,
702 HID_USAGE_PAGE_ALPHA_DISPLAY = 0x14,
703 HID_USAGE_PAGE_MEDICAL = 0x40,
704 HID_USAGE_PAGE_MONITOR = 0x80, //0x80 - 0x83
705 HID_USAGE_PAGE_POWER = 0x84, // 0x084 - 0x87
706 HID_USAGE_PAGE_BARCODE_SCANNER = 0x8c,
707 HID_USAGE_PAGE_SCALE = 0x8d,
708 HID_USAGE_PAGE_MSR = 0x8e,
709 HID_USAGE_PAGE_CAMERA = 0x90,
710 HID_USAGE_PAGE_ARCADE = 0x91,
711 HID_USAGE_PAGE_VENDOR = 0xFF00 // 0xFF00 - 0xFFFF
712};
713
714/// HID Usage Table - Table 6: Generic Desktop Page
715enum {
716 HID_USAGE_DESKTOP_POINTER = 0x01,
717 HID_USAGE_DESKTOP_MOUSE = 0x02,
718 HID_USAGE_DESKTOP_JOYSTICK = 0x04,
719 HID_USAGE_DESKTOP_GAMEPAD = 0x05,
720 HID_USAGE_DESKTOP_KEYBOARD = 0x06,
721 HID_USAGE_DESKTOP_KEYPAD = 0x07,
722 HID_USAGE_DESKTOP_MULTI_AXIS_CONTROLLER = 0x08,
723 HID_USAGE_DESKTOP_TABLET_PC_SYSTEM = 0x09,
724 HID_USAGE_DESKTOP_X = 0x30,
725 HID_USAGE_DESKTOP_Y = 0x31,
726 HID_USAGE_DESKTOP_Z = 0x32,
727 HID_USAGE_DESKTOP_RX = 0x33,
728 HID_USAGE_DESKTOP_RY = 0x34,
729 HID_USAGE_DESKTOP_RZ = 0x35,
730 HID_USAGE_DESKTOP_SLIDER = 0x36,
731 HID_USAGE_DESKTOP_DIAL = 0x37,
732 HID_USAGE_DESKTOP_WHEEL = 0x38,
733 HID_USAGE_DESKTOP_HAT_SWITCH = 0x39,
734 HID_USAGE_DESKTOP_COUNTED_BUFFER = 0x3a,
735 HID_USAGE_DESKTOP_BYTE_COUNT = 0x3b,
736 HID_USAGE_DESKTOP_MOTION_WAKEUP = 0x3c,
737 HID_USAGE_DESKTOP_START = 0x3d,
738 HID_USAGE_DESKTOP_SELECT = 0x3e,
739 HID_USAGE_DESKTOP_VX = 0x40,
740 HID_USAGE_DESKTOP_VY = 0x41,
741 HID_USAGE_DESKTOP_VZ = 0x42,
742 HID_USAGE_DESKTOP_VBRX = 0x43,
743 HID_USAGE_DESKTOP_VBRY = 0x44,
744 HID_USAGE_DESKTOP_VBRZ = 0x45,
745 HID_USAGE_DESKTOP_VNO = 0x46,
746 HID_USAGE_DESKTOP_FEATURE_NOTIFICATION = 0x47,
747 HID_USAGE_DESKTOP_RESOLUTION_MULTIPLIER = 0x48,
748 HID_USAGE_DESKTOP_SYSTEM_CONTROL = 0x80,
749 HID_USAGE_DESKTOP_SYSTEM_POWER_DOWN = 0x81,
750 HID_USAGE_DESKTOP_SYSTEM_SLEEP = 0x82,
751 HID_USAGE_DESKTOP_SYSTEM_WAKE_UP = 0x83,
752 HID_USAGE_DESKTOP_SYSTEM_CONTEXT_MENU = 0x84,
753 HID_USAGE_DESKTOP_SYSTEM_MAIN_MENU = 0x85,
754 HID_USAGE_DESKTOP_SYSTEM_APP_MENU = 0x86,
755 HID_USAGE_DESKTOP_SYSTEM_MENU_HELP = 0x87,
756 HID_USAGE_DESKTOP_SYSTEM_MENU_EXIT = 0x88,
757 HID_USAGE_DESKTOP_SYSTEM_MENU_SELECT = 0x89,
758 HID_USAGE_DESKTOP_SYSTEM_MENU_RIGHT = 0x8A,
759 HID_USAGE_DESKTOP_SYSTEM_MENU_LEFT = 0x8B,
760 HID_USAGE_DESKTOP_SYSTEM_MENU_UP = 0x8C,
761 HID_USAGE_DESKTOP_SYSTEM_MENU_DOWN = 0x8D,
762 HID_USAGE_DESKTOP_SYSTEM_COLD_RESTART = 0x8E,
763 HID_USAGE_DESKTOP_SYSTEM_WARM_RESTART = 0x8F,
764 HID_USAGE_DESKTOP_DPAD_UP = 0x90,
765 HID_USAGE_DESKTOP_DPAD_DOWN = 0x91,
766 HID_USAGE_DESKTOP_DPAD_RIGHT = 0x92,
767 HID_USAGE_DESKTOP_DPAD_LEFT = 0x93,
768 HID_USAGE_DESKTOP_SYSTEM_DOCK = 0xA0,
769 HID_USAGE_DESKTOP_SYSTEM_UNDOCK = 0xA1,
770 HID_USAGE_DESKTOP_SYSTEM_SETUP = 0xA2,
771 HID_USAGE_DESKTOP_SYSTEM_BREAK = 0xA3,
772 HID_USAGE_DESKTOP_SYSTEM_DEBUGGER_BREAK = 0xA4,
773 HID_USAGE_DESKTOP_APPLICATION_BREAK = 0xA5,
774 HID_USAGE_DESKTOP_APPLICATION_DEBUGGER_BREAK = 0xA6,
775 HID_USAGE_DESKTOP_SYSTEM_SPEAKER_MUTE = 0xA7,
776 HID_USAGE_DESKTOP_SYSTEM_HIBERNATE = 0xA8,
777 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INVERT = 0xB0,
778 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_INTERNAL = 0xB1,
779 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_EXTERNAL = 0xB2,
780 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_BOTH = 0xB3,
781 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_DUAL = 0xB4,
782 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_TOGGLE_INT_EXT = 0xB5,
783 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_SWAP_PRIMARY_SECONDARY = 0xB6,
784 HID_USAGE_DESKTOP_SYSTEM_DISPLAY_LCD_AUTOSCALE = 0xB7
785};
786
787
788/// HID Usage Table: Consumer Page (0x0C)
789/// Only contains controls that supported by Windows (whole list is too long)
790enum
791{
792 // Generic Control
793 HID_USAGE_CONSUMER_CONTROL = 0x0001,
794
795 // Power Control
796 HID_USAGE_CONSUMER_POWER = 0x0030,
797 HID_USAGE_CONSUMER_RESET = 0x0031,
798 HID_USAGE_CONSUMER_SLEEP = 0x0032,
799
800 // Screen Brightness
801 HID_USAGE_CONSUMER_BRIGHTNESS_INCREMENT = 0x006F,
802 HID_USAGE_CONSUMER_BRIGHTNESS_DECREMENT = 0x0070,
803
804 // These HID usages operate only on mobile systems (battery powered) and
805 // require Windows 8 (build 8302 or greater).
806 HID_USAGE_CONSUMER_WIRELESS_RADIO_CONTROLS = 0x000C,
807 HID_USAGE_CONSUMER_WIRELESS_RADIO_BUTTONS = 0x00C6,
808 HID_USAGE_CONSUMER_WIRELESS_RADIO_LED = 0x00C7,
809 HID_USAGE_CONSUMER_WIRELESS_RADIO_SLIDER_SWITCH = 0x00C8,
810
811 // Media Control
812 HID_USAGE_CONSUMER_PLAY_PAUSE = 0x00CD,
813 HID_USAGE_CONSUMER_SCAN_NEXT = 0x00B5,
814 HID_USAGE_CONSUMER_SCAN_PREVIOUS = 0x00B6,
815 HID_USAGE_CONSUMER_STOP = 0x00B7,
816 HID_USAGE_CONSUMER_VOLUME = 0x00E0,
817 HID_USAGE_CONSUMER_MUTE = 0x00E2,
818 HID_USAGE_CONSUMER_BASS = 0x00E3,
819 HID_USAGE_CONSUMER_TREBLE = 0x00E4,
820 HID_USAGE_CONSUMER_BASS_BOOST = 0x00E5,
821 HID_USAGE_CONSUMER_VOLUME_INCREMENT = 0x00E9,
822 HID_USAGE_CONSUMER_VOLUME_DECREMENT = 0x00EA,
823 HID_USAGE_CONSUMER_BASS_INCREMENT = 0x0152,
824 HID_USAGE_CONSUMER_BASS_DECREMENT = 0x0153,
825 HID_USAGE_CONSUMER_TREBLE_INCREMENT = 0x0154,
826 HID_USAGE_CONSUMER_TREBLE_DECREMENT = 0x0155,
827
828 // Application Launcher
829 HID_USAGE_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION = 0x0183,
830 HID_USAGE_CONSUMER_AL_EMAIL_READER = 0x018A,
831 HID_USAGE_CONSUMER_AL_CALCULATOR = 0x0192,
832 HID_USAGE_CONSUMER_AL_LOCAL_BROWSER = 0x0194,
833
834 // Browser/Explorer Specific
835 HID_USAGE_CONSUMER_AC_SEARCH = 0x0221,
836 HID_USAGE_CONSUMER_AC_HOME = 0x0223,
837 HID_USAGE_CONSUMER_AC_BACK = 0x0224,
838 HID_USAGE_CONSUMER_AC_FORWARD = 0x0225,
839 HID_USAGE_CONSUMER_AC_STOP = 0x0226,
840 HID_USAGE_CONSUMER_AC_REFRESH = 0x0227,
841 HID_USAGE_CONSUMER_AC_BOOKMARKS = 0x022A,
842
843 // Mouse Horizontal scroll
844 HID_USAGE_CONSUMER_AC_PAN = 0x0238,
845};
846
847/*--------------------------------------------------------------------
848 * ASCII to KEYCODE Conversion
849 * Expand to array of [128][2] (shift, keycode)
850 *
851 * Usage: example to convert input chr into keyboard report (modifier + keycode)
852 *
853 * uint8_t const conv_table[128][2] = { HID_ASCII_TO_KEYCODE };
854 *
855 * uint8_t keycode[6] = { 0 };
856 * uint8_t modifier = 0;
857 *
858 * if ( conv_table[chr][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
859 * keycode[0] = conv_table[chr][1];
860 * tud_hid_keyboard_report(report_id, modifier, keycode);
861 *
862 *--------------------------------------------------------------------*/
863#define HID_ASCII_TO_KEYCODE \
864 {0, 0 }, /* 0x00 Null */ \
865 {0, 0 }, /* 0x01 */ \
866 {0, 0 }, /* 0x02 */ \
867 {0, 0 }, /* 0x03 */ \
868 {0, 0 }, /* 0x04 */ \
869 {0, 0 }, /* 0x05 */ \
870 {0, 0 }, /* 0x06 */ \
871 {0, 0 }, /* 0x07 */ \
872 {0, HID_KEY_BACKSPACE }, /* 0x08 Backspace */ \
873 {0, HID_KEY_TAB }, /* 0x09 Tab */ \
874 {0, HID_KEY_ENTER }, /* 0x0A Line Feed */ \
875 {0, 0 }, /* 0x0B */ \
876 {0, 0 }, /* 0x0C */ \
877 {0, HID_KEY_ENTER }, /* 0x0D CR */ \
878 {0, 0 }, /* 0x0E */ \
879 {0, 0 }, /* 0x0F */ \
880 {0, 0 }, /* 0x10 */ \
881 {0, 0 }, /* 0x11 */ \
882 {0, 0 }, /* 0x12 */ \
883 {0, 0 }, /* 0x13 */ \
884 {0, 0 }, /* 0x14 */ \
885 {0, 0 }, /* 0x15 */ \
886 {0, 0 }, /* 0x16 */ \
887 {0, 0 }, /* 0x17 */ \
888 {0, 0 }, /* 0x18 */ \
889 {0, 0 }, /* 0x19 */ \
890 {0, 0 }, /* 0x1A */ \
891 {0, HID_KEY_ESCAPE }, /* 0x1B Escape */ \
892 {0, 0 }, /* 0x1C */ \
893 {0, 0 }, /* 0x1D */ \
894 {0, 0 }, /* 0x1E */ \
895 {0, 0 }, /* 0x1F */ \
896 \
897 {0, HID_KEY_SPACE }, /* 0x20 */ \
898 {1, HID_KEY_1 }, /* 0x21 ! */ \
899 {1, HID_KEY_APOSTROPHE }, /* 0x22 " */ \
900 {1, HID_KEY_3 }, /* 0x23 # */ \
901 {1, HID_KEY_4 }, /* 0x24 $ */ \
902 {1, HID_KEY_5 }, /* 0x25 % */ \
903 {1, HID_KEY_7 }, /* 0x26 & */ \
904 {0, HID_KEY_APOSTROPHE }, /* 0x27 ' */ \
905 {1, HID_KEY_9 }, /* 0x28 ( */ \
906 {1, HID_KEY_0 }, /* 0x29 ) */ \
907 {1, HID_KEY_8 }, /* 0x2A * */ \
908 {1, HID_KEY_EQUAL }, /* 0x2B + */ \
909 {0, HID_KEY_COMMA }, /* 0x2C , */ \
910 {0, HID_KEY_MINUS }, /* 0x2D - */ \
911 {0, HID_KEY_PERIOD }, /* 0x2E . */ \
912 {0, HID_KEY_SLASH }, /* 0x2F / */ \
913 {0, HID_KEY_0 }, /* 0x30 0 */ \
914 {0, HID_KEY_1 }, /* 0x31 1 */ \
915 {0, HID_KEY_2 }, /* 0x32 2 */ \
916 {0, HID_KEY_3 }, /* 0x33 3 */ \
917 {0, HID_KEY_4 }, /* 0x34 4 */ \
918 {0, HID_KEY_5 }, /* 0x35 5 */ \
919 {0, HID_KEY_6 }, /* 0x36 6 */ \
920 {0, HID_KEY_7 }, /* 0x37 7 */ \
921 {0, HID_KEY_8 }, /* 0x38 8 */ \
922 {0, HID_KEY_9 }, /* 0x39 9 */ \
923 {1, HID_KEY_SEMICOLON }, /* 0x3A : */ \
924 {0, HID_KEY_SEMICOLON }, /* 0x3B ; */ \
925 {1, HID_KEY_COMMA }, /* 0x3C < */ \
926 {0, HID_KEY_EQUAL }, /* 0x3D = */ \
927 {1, HID_KEY_PERIOD }, /* 0x3E > */ \
928 {1, HID_KEY_SLASH }, /* 0x3F ? */ \
929 \
930 {1, HID_KEY_2 }, /* 0x40 @ */ \
931 {1, HID_KEY_A }, /* 0x41 A */ \
932 {1, HID_KEY_B }, /* 0x42 B */ \
933 {1, HID_KEY_C }, /* 0x43 C */ \
934 {1, HID_KEY_D }, /* 0x44 D */ \
935 {1, HID_KEY_E }, /* 0x45 E */ \
936 {1, HID_KEY_F }, /* 0x46 F */ \
937 {1, HID_KEY_G }, /* 0x47 G */ \
938 {1, HID_KEY_H }, /* 0x48 H */ \
939 {1, HID_KEY_I }, /* 0x49 I */ \
940 {1, HID_KEY_J }, /* 0x4A J */ \
941 {1, HID_KEY_K }, /* 0x4B K */ \
942 {1, HID_KEY_L }, /* 0x4C L */ \
943 {1, HID_KEY_M }, /* 0x4D M */ \
944 {1, HID_KEY_N }, /* 0x4E N */ \
945 {1, HID_KEY_O }, /* 0x4F O */ \
946 {1, HID_KEY_P }, /* 0x50 P */ \
947 {1, HID_KEY_Q }, /* 0x51 Q */ \
948 {1, HID_KEY_R }, /* 0x52 R */ \
949 {1, HID_KEY_S }, /* 0x53 S */ \
950 {1, HID_KEY_T }, /* 0x55 T */ \
951 {1, HID_KEY_U }, /* 0x55 U */ \
952 {1, HID_KEY_V }, /* 0x56 V */ \
953 {1, HID_KEY_W }, /* 0x57 W */ \
954 {1, HID_KEY_X }, /* 0x58 X */ \
955 {1, HID_KEY_Y }, /* 0x59 Y */ \
956 {1, HID_KEY_Z }, /* 0x5A Z */ \
957 {0, HID_KEY_BRACKET_LEFT }, /* 0x5B [ */ \
958 {0, HID_KEY_BACKSLASH }, /* 0x5C '\' */ \
959 {0, HID_KEY_BRACKET_RIGHT }, /* 0x5D ] */ \
960 {1, HID_KEY_6 }, /* 0x5E ^ */ \
961 {1, HID_KEY_MINUS }, /* 0x5F _ */ \
962 \
963 {0, HID_KEY_GRAVE }, /* 0x60 ` */ \
964 {0, HID_KEY_A }, /* 0x61 a */ \
965 {0, HID_KEY_B }, /* 0x62 b */ \
966 {0, HID_KEY_C }, /* 0x63 c */ \
967 {0, HID_KEY_D }, /* 0x66 d */ \
968 {0, HID_KEY_E }, /* 0x65 e */ \
969 {0, HID_KEY_F }, /* 0x66 f */ \
970 {0, HID_KEY_G }, /* 0x67 g */ \
971 {0, HID_KEY_H }, /* 0x68 h */ \
972 {0, HID_KEY_I }, /* 0x69 i */ \
973 {0, HID_KEY_J }, /* 0x6A j */ \
974 {0, HID_KEY_K }, /* 0x6B k */ \
975 {0, HID_KEY_L }, /* 0x6C l */ \
976 {0, HID_KEY_M }, /* 0x6D m */ \
977 {0, HID_KEY_N }, /* 0x6E n */ \
978 {0, HID_KEY_O }, /* 0x6F o */ \
979 {0, HID_KEY_P }, /* 0x70 p */ \
980 {0, HID_KEY_Q }, /* 0x71 q */ \
981 {0, HID_KEY_R }, /* 0x72 r */ \
982 {0, HID_KEY_S }, /* 0x73 s */ \
983 {0, HID_KEY_T }, /* 0x75 t */ \
984 {0, HID_KEY_U }, /* 0x75 u */ \
985 {0, HID_KEY_V }, /* 0x76 v */ \
986 {0, HID_KEY_W }, /* 0x77 w */ \
987 {0, HID_KEY_X }, /* 0x78 x */ \
988 {0, HID_KEY_Y }, /* 0x79 y */ \
989 {0, HID_KEY_Z }, /* 0x7A z */ \
990 {1, HID_KEY_BRACKET_LEFT }, /* 0x7B { */ \
991 {1, HID_KEY_BACKSLASH }, /* 0x7C | */ \
992 {1, HID_KEY_BRACKET_RIGHT }, /* 0x7D } */ \
993 {1, HID_KEY_GRAVE }, /* 0x7E ~ */ \
994 {0, HID_KEY_DELETE } /* 0x7F Delete */ \
995
996/*--------------------------------------------------------------------
997 * KEYCODE to Ascii Conversion
998 * Expand to array of [128][2] (ascii without shift, ascii with shift)
999 *
1000 * Usage: example to convert ascii from keycode (key) and shift modifier (shift).
1001 * Here we assume key < 128 ( printable )
1002 *
1003 * uint8_t const conv_table[128][2] = { HID_KEYCODE_TO_ASCII };
1004 * char ch = shift ? conv_table[chr][1] : conv_table[chr][0];
1005 *
1006 *--------------------------------------------------------------------*/
1007#define HID_KEYCODE_TO_ASCII \
1008 {0 , 0 }, /* 0x00 */ \
1009 {0 , 0 }, /* 0x01 */ \
1010 {0 , 0 }, /* 0x02 */ \
1011 {0 , 0 }, /* 0x03 */ \
1012 {'a' , 'A' }, /* 0x04 */ \
1013 {'b' , 'B' }, /* 0x05 */ \
1014 {'c' , 'C' }, /* 0x06 */ \
1015 {'d' , 'D' }, /* 0x07 */ \
1016 {'e' , 'E' }, /* 0x08 */ \
1017 {'f' , 'F' }, /* 0x09 */ \
1018 {'g' , 'G' }, /* 0x0a */ \
1019 {'h' , 'H' }, /* 0x0b */ \
1020 {'i' , 'I' }, /* 0x0c */ \
1021 {'j' , 'J' }, /* 0x0d */ \
1022 {'k' , 'K' }, /* 0x0e */ \
1023 {'l' , 'L' }, /* 0x0f */ \
1024 {'m' , 'M' }, /* 0x10 */ \
1025 {'n' , 'N' }, /* 0x11 */ \
1026 {'o' , 'O' }, /* 0x12 */ \
1027 {'p' , 'P' }, /* 0x13 */ \
1028 {'q' , 'Q' }, /* 0x14 */ \
1029 {'r' , 'R' }, /* 0x15 */ \
1030 {'s' , 'S' }, /* 0x16 */ \
1031 {'t' , 'T' }, /* 0x17 */ \
1032 {'u' , 'U' }, /* 0x18 */ \
1033 {'v' , 'V' }, /* 0x19 */ \
1034 {'w' , 'W' }, /* 0x1a */ \
1035 {'x' , 'X' }, /* 0x1b */ \
1036 {'y' , 'Y' }, /* 0x1c */ \
1037 {'z' , 'Z' }, /* 0x1d */ \
1038 {'1' , '!' }, /* 0x1e */ \
1039 {'2' , '@' }, /* 0x1f */ \
1040 {'3' , '#' }, /* 0x20 */ \
1041 {'4' , '$' }, /* 0x21 */ \
1042 {'5' , '%' }, /* 0x22 */ \
1043 {'6' , '^' }, /* 0x23 */ \
1044 {'7' , '&' }, /* 0x24 */ \
1045 {'8' , '*' }, /* 0x25 */ \
1046 {'9' , '(' }, /* 0x26 */ \
1047 {'0' , ')' }, /* 0x27 */ \
1048 {'\r' , '\r' }, /* 0x28 */ \
1049 {'\x1b', '\x1b' }, /* 0x29 */ \
1050 {'\b' , '\b' }, /* 0x2a */ \
1051 {'\t' , '\t' }, /* 0x2b */ \
1052 {' ' , ' ' }, /* 0x2c */ \
1053 {'-' , '_' }, /* 0x2d */ \
1054 {'=' , '+' }, /* 0x2e */ \
1055 {'[' , '{' }, /* 0x2f */ \
1056 {']' , '}' }, /* 0x30 */ \
1057 {'\\' , '|' }, /* 0x31 */ \
1058 {'#' , '~' }, /* 0x32 */ \
1059 {';' , ':' }, /* 0x33 */ \
1060 {'\'' , '\"' }, /* 0x34 */ \
1061 {'`' , '~' }, /* 0x35 */ \
1062 {',' , '<' }, /* 0x36 */ \
1063 {'.' , '>' }, /* 0x37 */ \
1064 {'/' , '?' }, /* 0x38 */ \
1065 \
1066 {0 , 0 }, /* 0x39 */ \
1067 {0 , 0 }, /* 0x3a */ \
1068 {0 , 0 }, /* 0x3b */ \
1069 {0 , 0 }, /* 0x3c */ \
1070 {0 , 0 }, /* 0x3d */ \
1071 {0 , 0 }, /* 0x3e */ \
1072 {0 , 0 }, /* 0x3f */ \
1073 {0 , 0 }, /* 0x40 */ \
1074 {0 , 0 }, /* 0x41 */ \
1075 {0 , 0 }, /* 0x42 */ \
1076 {0 , 0 }, /* 0x43 */ \
1077 {0 , 0 }, /* 0x44 */ \
1078 {0 , 0 }, /* 0x45 */ \
1079 {0 , 0 }, /* 0x46 */ \
1080 {0 , 0 }, /* 0x47 */ \
1081 {0 , 0 }, /* 0x48 */ \
1082 {0 , 0 }, /* 0x49 */ \
1083 {0 , 0 }, /* 0x4a */ \
1084 {0 , 0 }, /* 0x4b */ \
1085 {0 , 0 }, /* 0x4c */ \
1086 {0 , 0 }, /* 0x4d */ \
1087 {0 , 0 }, /* 0x4e */ \
1088 {0 , 0 }, /* 0x4f */ \
1089 {0 , 0 }, /* 0x50 */ \
1090 {0 , 0 }, /* 0x51 */ \
1091 {0 , 0 }, /* 0x52 */ \
1092 {0 , 0 }, /* 0x53 */ \
1093 \
1094 {'/' , '/' }, /* 0x54 */ \
1095 {'*' , '*' }, /* 0x55 */ \
1096 {'-' , '-' }, /* 0x56 */ \
1097 {'+' , '+' }, /* 0x57 */ \
1098 {'\r' , '\r' }, /* 0x58 */ \
1099 {'1' , 0 }, /* 0x59 */ \
1100 {'2' , 0 }, /* 0x5a */ \
1101 {'3' , 0 }, /* 0x5b */ \
1102 {'4' , 0 }, /* 0x5c */ \
1103 {'5' , '5' }, /* 0x5d */ \
1104 {'6' , 0 }, /* 0x5e */ \
1105 {'7' , 0 }, /* 0x5f */ \
1106 {'8' , 0 }, /* 0x60 */ \
1107 {'9' , 0 }, /* 0x61 */ \
1108 {'0' , 0 }, /* 0x62 */ \
1109 {'0' , 0 }, /* 0x63 */ \
1110 {'=' , '=' }, /* 0x67 */ \
1111
1112
1113#ifdef __cplusplus
1114 }
1115#endif
1116
1117#endif /* _TUSB_HID_H__ */
1118
1119/// @}