16#ifndef ZEPHYR_INCLUDE_USB_CLASS_HID_H_
17#define ZEPHYR_INCLUDE_USB_CLASS_HID_H_
38#define USB_HID_VERSION 0x0111
41#define USB_DESC_HID 0x21
43#define USB_DESC_HID_REPORT 0x22
45#define USB_DESC_HID_PHYSICAL 0x23
48#define USB_HID_GET_REPORT 0x01
50#define USB_HID_GET_IDLE 0x02
52#define USB_HID_GET_PROTOCOL 0x03
54#define USB_HID_SET_REPORT 0x09
56#define USB_HID_SET_IDLE 0x0A
58#define USB_HID_SET_PROTOCOL 0x0B
61#define HID_BOOT_IFACE_CODE_NONE 0
63#define HID_BOOT_IFACE_CODE_KEYBOARD 1
65#define HID_BOOT_IFACE_CODE_MOUSE 2
68#define HID_PROTOCOL_BOOT 0
70#define HID_PROTOCOL_REPORT 1
73#define HID_ITEM_TYPE_MAIN 0x0
75#define HID_ITEM_TYPE_GLOBAL 0x1
77#define HID_ITEM_TYPE_LOCAL 0x2
80#define HID_ITEM_TAG_INPUT 0x8
82#define HID_ITEM_TAG_OUTPUT 0x9
84#define HID_ITEM_TAG_COLLECTION 0xA
86#define HID_ITEM_TAG_FEATURE 0xB
88#define HID_ITEM_TAG_COLLECTION_END 0xC
91#define HID_ITEM_TAG_USAGE_PAGE 0x0
93#define HID_ITEM_TAG_LOGICAL_MIN 0x1
95#define HID_ITEM_TAG_LOGICAL_MAX 0x2
97#define HID_ITEM_TAG_PHYSICAL_MIN 0x3
99#define HID_ITEM_TAG_PHYSICAL_MAX 0x4
101#define HID_ITEM_TAG_UNIT_EXPONENT 0x5
103#define HID_ITEM_TAG_UNIT 0x6
105#define HID_ITEM_TAG_REPORT_SIZE 0x7
107#define HID_ITEM_TAG_REPORT_ID 0x8
109#define HID_ITEM_TAG_REPORT_COUNT 0x9
112#define HID_ITEM_TAG_USAGE 0x0
114#define HID_ITEM_TAG_USAGE_MIN 0x1
116#define HID_ITEM_TAG_USAGE_MAX 0x2
119#define HID_COLLECTION_PHYSICAL 0x00
121#define HID_COLLECTION_APPLICATION 0x01
123#define HID_COLLECTION_LOGICAL 0x02
125#define HID_COLLECTION_REPORT 0x03
127#define HID_COLLECTION_NAMED_ARRAY 0x04
129#define HID_COLLECTION_USAGE_SWITCH 0x05
131#define HID_COLLECTION_MODIFIER 0x06
137#define HID_USAGE_GEN_DESKTOP 0x01
139#define HID_USAGE_GEN_KEYBOARD 0x07
141#define HID_USAGE_GEN_LEDS 0x08
143#define HID_USAGE_GEN_BUTTON 0x09
146#define HID_USAGE_GEN_DESKTOP_UNDEFINED 0x00
148#define HID_USAGE_GEN_DESKTOP_POINTER 0x01
150#define HID_USAGE_GEN_DESKTOP_MOUSE 0x02
152#define HID_USAGE_GEN_DESKTOP_JOYSTICK 0x04
154#define HID_USAGE_GEN_DESKTOP_GAMEPAD 0x05
156#define HID_USAGE_GEN_DESKTOP_KEYBOARD 0x06
158#define HID_USAGE_GEN_DESKTOP_KEYPAD 0x07
160#define HID_USAGE_GEN_DESKTOP_X 0x30
162#define HID_USAGE_GEN_DESKTOP_Y 0x31
164#define HID_USAGE_GEN_DESKTOP_WHEEL 0x38
183#define HID_ITEM(bTag, bType, bSize) (((bTag & 0xF) << 4) | \
184 ((bType & 0x3) << 2) | (bSize & 0x3))
195#define HID_INPUT(a) \
196 HID_ITEM(HID_ITEM_TAG_INPUT, HID_ITEM_TYPE_MAIN, 1), a
206#define HID_OUTPUT(a) \
207 HID_ITEM(HID_ITEM_TAG_OUTPUT, HID_ITEM_TYPE_MAIN, 1), a
215#define HID_FEATURE(a) \
216 HID_ITEM(HID_ITEM_TAG_FEATURE, HID_ITEM_TYPE_MAIN, 1), a
227#define HID_COLLECTION(a) \
228 HID_ITEM(HID_ITEM_TAG_COLLECTION, HID_ITEM_TYPE_MAIN, 1), a
238#define HID_END_COLLECTION \
239 HID_ITEM(HID_ITEM_TAG_COLLECTION_END, HID_ITEM_TYPE_MAIN, 0)
250#define HID_USAGE_PAGE(page) \
251 HID_ITEM(HID_ITEM_TAG_USAGE_PAGE, HID_ITEM_TYPE_GLOBAL, 1), page
262#define HID_LOGICAL_MIN8(a) \
263 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 1), a
274#define HID_LOGICAL_MAX8(a) \
275 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 1), a
284#define HID_LOGICAL_MIN16(a, b) \
285 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 2), a, b
294#define HID_LOGICAL_MAX16(a, b) \
295 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 2), a, b
306#define HID_LOGICAL_MIN32(a, b, c, d) \
307 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
318#define HID_LOGICAL_MAX32(a, b, c, d) \
319 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
330#define HID_REPORT_SIZE(size) \
331 HID_ITEM(HID_ITEM_TAG_REPORT_SIZE, HID_ITEM_TYPE_GLOBAL, 1), size
339#define HID_REPORT_ID(id) \
340 HID_ITEM(HID_ITEM_TAG_REPORT_ID, HID_ITEM_TYPE_GLOBAL, 1), id
351#define HID_REPORT_COUNT(count) \
352 HID_ITEM(HID_ITEM_TAG_REPORT_COUNT, HID_ITEM_TYPE_GLOBAL, 1), count
363#define HID_USAGE(idx) \
364 HID_ITEM(HID_ITEM_TAG_USAGE, HID_ITEM_TYPE_LOCAL, 1), idx
375#define HID_USAGE_MIN8(a) \
376 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 1), a
387#define HID_USAGE_MAX8(a) \
388 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 1), a
400#define HID_USAGE_MIN16(a, b) \
401 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 2), a, b
413#define HID_USAGE_MAX16(a, b) \
414 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 2), a, b
430#define HID_MOUSE_REPORT_DESC(bcnt) { \
431 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
432 HID_USAGE(HID_USAGE_GEN_DESKTOP_MOUSE), \
433 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
434 HID_USAGE(HID_USAGE_GEN_DESKTOP_POINTER), \
435 HID_COLLECTION(HID_COLLECTION_PHYSICAL), \
437 HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON), \
439 HID_USAGE_MAX8(bcnt), \
440 HID_LOGICAL_MIN8(0), \
441 HID_LOGICAL_MAX8(1), \
442 HID_REPORT_SIZE(1), \
443 HID_REPORT_COUNT(bcnt), \
447 HID_REPORT_SIZE(8 - bcnt), \
448 HID_REPORT_COUNT(1), \
452 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
453 HID_USAGE(HID_USAGE_GEN_DESKTOP_X), \
454 HID_USAGE(HID_USAGE_GEN_DESKTOP_Y), \
455 HID_USAGE(HID_USAGE_GEN_DESKTOP_WHEEL), \
456 HID_LOGICAL_MIN8(-127), \
457 HID_LOGICAL_MAX8(127), \
458 HID_REPORT_SIZE(8), \
459 HID_REPORT_COUNT(3), \
462 HID_END_COLLECTION, \
463 HID_END_COLLECTION, \
469#define HID_KEYBOARD_REPORT_DESC() { \
470 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
471 HID_USAGE(HID_USAGE_GEN_DESKTOP_KEYBOARD), \
472 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
473 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
475 HID_USAGE_MIN8(0xE0), \
477 HID_USAGE_MAX8(0xE7), \
478 HID_LOGICAL_MIN8(0), \
479 HID_LOGICAL_MAX8(1), \
480 HID_REPORT_SIZE(1), \
481 HID_REPORT_COUNT(8), \
484 HID_REPORT_SIZE(8), \
485 HID_REPORT_COUNT(1), \
488 HID_REPORT_SIZE(1), \
489 HID_REPORT_COUNT(5), \
490 HID_USAGE_PAGE(HID_USAGE_GEN_LEDS), \
497 HID_REPORT_SIZE(3), \
498 HID_REPORT_COUNT(1), \
501 HID_REPORT_SIZE(8), \
502 HID_REPORT_COUNT(6), \
503 HID_LOGICAL_MIN8(0), \
504 HID_LOGICAL_MAX8(101), \
505 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
509 HID_USAGE_MAX8(101), \
512 HID_END_COLLECTION, \
hid_kbd_modifier
HID keyboard modifiers.
Definition hid.h:619
hid_kbd_code
HID keyboard button codes.
Definition hid.h:518
hid_kbd_led
HID keyboard LEDs.
Definition hid.h:634
@ HID_KBD_MODIFIER_RIGHT_UI
Definition hid.h:628
@ HID_KBD_MODIFIER_LEFT_CTRL
Definition hid.h:621
@ HID_KBD_MODIFIER_LEFT_UI
Definition hid.h:624
@ HID_KBD_MODIFIER_NONE
Definition hid.h:620
@ HID_KBD_MODIFIER_LEFT_ALT
Definition hid.h:623
@ HID_KBD_MODIFIER_RIGHT_ALT
Definition hid.h:627
@ HID_KBD_MODIFIER_RIGHT_CTRL
Definition hid.h:625
@ HID_KBD_MODIFIER_LEFT_SHIFT
Definition hid.h:622
@ HID_KBD_MODIFIER_RIGHT_SHIFT
Definition hid.h:626
@ HID_KEY_V
Definition hid.h:540
@ HID_KEY_R
Definition hid.h:536
@ HID_KEY_1
Definition hid.h:545
@ HID_KEY_Q
Definition hid.h:535
@ HID_KEY_HASH
Definition hid.h:565
@ HID_KEY_4
Definition hid.h:548
@ HID_KEY_8
Definition hid.h:552
@ HID_KEY_PAUSE
Definition hid.h:587
@ HID_KEY_KP_5
Definition hid.h:608
@ HID_KEY_KP_7
Definition hid.h:610
@ HID_KEY_INSERT
Definition hid.h:588
@ HID_KEY_F7
Definition hid.h:579
@ HID_KEY_G
Definition hid.h:525
@ HID_KEY_PAGEUP
Definition hid.h:590
@ HID_KEY_SLASH
Definition hid.h:571
@ HID_KEY_BACKSLASH
Definition hid.h:564
@ HID_KEY_J
Definition hid.h:528
@ HID_KEY_KPPLUS
Definition hid.h:602
@ HID_KEY_SEMICOLON
Definition hid.h:566
@ HID_KEY_DOT
Definition hid.h:570
@ HID_KEY_KP_3
Definition hid.h:606
@ HID_KEY_KPSLASH
Definition hid.h:599
@ HID_KEY_KP_4
Definition hid.h:607
@ HID_KEY_KP_0
Definition hid.h:613
@ HID_KEY_H
Definition hid.h:526
@ HID_KEY_RIGHT
Definition hid.h:594
@ HID_KEY_Y
Definition hid.h:543
@ HID_KEY_K
Definition hid.h:529
@ HID_KEY_CAPSLOCK
Definition hid.h:572
@ HID_KEY_M
Definition hid.h:531
@ HID_KEY_F8
Definition hid.h:580
@ HID_KEY_A
Definition hid.h:519
@ HID_KEY_7
Definition hid.h:551
@ HID_KEY_F9
Definition hid.h:581
@ HID_KEY_TAB
Definition hid.h:558
@ HID_KEY_HOME
Definition hid.h:589
@ HID_KEY_KP_2
Definition hid.h:605
@ HID_KEY_KPMINUS
Definition hid.h:601
@ HID_KEY_APOSTROPHE
Definition hid.h:567
@ HID_KEY_9
Definition hid.h:553
@ HID_KEY_ESC
Definition hid.h:556
@ HID_KEY_F3
Definition hid.h:575
@ HID_KEY_F11
Definition hid.h:583
@ HID_KEY_KP_1
Definition hid.h:604
@ HID_KEY_0
Definition hid.h:554
@ HID_KEY_T
Definition hid.h:538
@ HID_KEY_GRAVE
Definition hid.h:568
@ HID_KEY_END
Definition hid.h:592
@ HID_KEY_KP_6
Definition hid.h:609
@ HID_KEY_C
Definition hid.h:521
@ HID_KEY_F1
Definition hid.h:573
@ HID_KEY_F2
Definition hid.h:574
@ HID_KEY_DOWN
Definition hid.h:596
@ HID_KEY_X
Definition hid.h:542
@ HID_KEY_MINUS
Definition hid.h:560
@ HID_KEY_Z
Definition hid.h:544
@ HID_KEY_COMMA
Definition hid.h:569
@ HID_KEY_F4
Definition hid.h:576
@ HID_KEY_U
Definition hid.h:539
@ HID_KEY_F12
Definition hid.h:584
@ HID_KEY_N
Definition hid.h:532
@ HID_KEY_KPENTER
Definition hid.h:603
@ HID_KEY_B
Definition hid.h:520
@ HID_KEY_D
Definition hid.h:522
@ HID_KEY_F6
Definition hid.h:578
@ HID_KEY_LEFTBRACE
Definition hid.h:562
@ HID_KEY_F10
Definition hid.h:582
@ HID_KEY_EQUAL
Definition hid.h:561
@ HID_KEY_P
Definition hid.h:534
@ HID_KEY_F
Definition hid.h:524
@ HID_KEY_KP_9
Definition hid.h:612
@ HID_KEY_F5
Definition hid.h:577
@ HID_KEY_O
Definition hid.h:533
@ HID_KEY_KP_8
Definition hid.h:611
@ HID_KEY_W
Definition hid.h:541
@ HID_KEY_6
Definition hid.h:550
@ HID_KEY_SCROLLLOCK
Definition hid.h:586
@ HID_KEY_SYSRQ
Definition hid.h:585
@ HID_KEY_S
Definition hid.h:537
@ HID_KEY_DELETE
Definition hid.h:591
@ HID_KEY_2
Definition hid.h:546
@ HID_KEY_ENTER
Definition hid.h:555
@ HID_KEY_RIGHTBRACE
Definition hid.h:563
@ HID_KEY_5
Definition hid.h:549
@ HID_KEY_SPACE
Definition hid.h:559
@ HID_KEY_3
Definition hid.h:547
@ HID_KEY_L
Definition hid.h:530
@ HID_KEY_UP
Definition hid.h:597
@ HID_KEY_PAGEDOWN
Definition hid.h:593
@ HID_KEY_LEFT
Definition hid.h:595
@ HID_KEY_I
Definition hid.h:527
@ HID_KEY_BACKSPACE
Definition hid.h:557
@ HID_KEY_NUMLOCK
Definition hid.h:598
@ HID_KEY_KPASTERISK
Definition hid.h:600
@ HID_KEY_E
Definition hid.h:523
@ HID_KBD_LED_NUM_LOCK
Definition hid.h:635
@ HID_KBD_LED_SCROLL_LOCK
Definition hid.h:637
@ HID_KBD_LED_CAPS_LOCK
Definition hid.h:636
@ HID_KBD_LED_COMPOSE
Definition hid.h:638
@ HID_KBD_LED_KANA
Definition hid.h:639