Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
hid.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 * Copyright (c) 2018,2021 Nordic Semiconductor ASA
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
16#ifndef ZEPHYR_INCLUDE_USB_CLASS_HID_H_
17#define ZEPHYR_INCLUDE_USB_CLASS_HID_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
36#define USB_HID_VERSION 0x0111
37
39#define USB_DESC_HID 0x21
41#define USB_DESC_HID_REPORT 0x22
43#define USB_DESC_HID_PHYSICAL 0x23
44
46#define USB_HID_GET_REPORT 0x01
48#define USB_HID_GET_IDLE 0x02
50#define USB_HID_GET_PROTOCOL 0x03
52#define USB_HID_SET_REPORT 0x09
54#define USB_HID_SET_IDLE 0x0A
56#define USB_HID_SET_PROTOCOL 0x0B
57
59#define HID_BOOT_IFACE_CODE_NONE 0
61#define HID_BOOT_IFACE_CODE_KEYBOARD 1
63#define HID_BOOT_IFACE_CODE_MOUSE 2
64
66#define HID_PROTOCOL_BOOT 0
68#define HID_PROTOCOL_REPORT 1
69
71#define HID_ITEM_TYPE_MAIN 0x0
73#define HID_ITEM_TYPE_GLOBAL 0x1
75#define HID_ITEM_TYPE_LOCAL 0x2
76
78#define HID_ITEM_TAG_INPUT 0x8
80#define HID_ITEM_TAG_OUTPUT 0x9
82#define HID_ITEM_TAG_COLLECTION 0xA
84#define HID_ITEM_TAG_FEATURE 0xB
86#define HID_ITEM_TAG_COLLECTION_END 0xC
87
89#define HID_ITEM_TAG_USAGE_PAGE 0x0
91#define HID_ITEM_TAG_LOGICAL_MIN 0x1
93#define HID_ITEM_TAG_LOGICAL_MAX 0x2
95#define HID_ITEM_TAG_PHYSICAL_MIN 0x3
97#define HID_ITEM_TAG_PHYSICAL_MAX 0x4
99#define HID_ITEM_TAG_UNIT_EXPONENT 0x5
101#define HID_ITEM_TAG_UNIT 0x6
103#define HID_ITEM_TAG_REPORT_SIZE 0x7
105#define HID_ITEM_TAG_REPORT_ID 0x8
107#define HID_ITEM_TAG_REPORT_COUNT 0x9
108
110#define HID_ITEM_TAG_USAGE 0x0
112#define HID_ITEM_TAG_USAGE_MIN 0x1
114#define HID_ITEM_TAG_USAGE_MAX 0x2
115
117#define HID_COLLECTION_PHYSICAL 0x00
119#define HID_COLLECTION_APPLICATION 0x01
121#define HID_COLLECTION_LOGICAL 0x02
123#define HID_COLLECTION_REPORT 0x03
125#define HID_COLLECTION_NAMED_ARRAY 0x04
127#define HID_COLLECTION_USAGE_SWITCH 0x05
129#define HID_COLLECTION_MODIFIER 0x06
130
131
132/* Usage page and IDs from Universal Serial Bus HID Usage Tables */
133
135#define HID_USAGE_GEN_DESKTOP 0x01
137#define HID_USAGE_GEN_KEYBOARD 0x07
139#define HID_USAGE_GEN_LEDS 0x08
141#define HID_USAGE_GEN_BUTTON 0x09
142
144#define HID_USAGE_GEN_DESKTOP_UNDEFINED 0x00
146#define HID_USAGE_GEN_DESKTOP_POINTER 0x01
148#define HID_USAGE_GEN_DESKTOP_MOUSE 0x02
150#define HID_USAGE_GEN_DESKTOP_JOYSTICK 0x04
152#define HID_USAGE_GEN_DESKTOP_GAMEPAD 0x05
154#define HID_USAGE_GEN_DESKTOP_KEYBOARD 0x06
156#define HID_USAGE_GEN_DESKTOP_KEYPAD 0x07
158#define HID_USAGE_GEN_DESKTOP_X 0x30
160#define HID_USAGE_GEN_DESKTOP_Y 0x31
162#define HID_USAGE_GEN_DESKTOP_WHEEL 0x38
163
181#define HID_ITEM(bTag, bType, bSize) (((bTag & 0xF) << 4) | \
182 ((bType & 0x3) << 2) | (bSize & 0x3))
183
193#define HID_INPUT(a) \
194 HID_ITEM(HID_ITEM_TAG_INPUT, HID_ITEM_TYPE_MAIN, 1), a
195
204#define HID_OUTPUT(a) \
205 HID_ITEM(HID_ITEM_TAG_OUTPUT, HID_ITEM_TYPE_MAIN, 1), a
206
213#define HID_FEATURE(a) \
214 HID_ITEM(HID_ITEM_TAG_FEATURE, HID_ITEM_TYPE_MAIN, 1), a
215
225#define HID_COLLECTION(a) \
226 HID_ITEM(HID_ITEM_TAG_COLLECTION, HID_ITEM_TYPE_MAIN, 1), a
227
236#define HID_END_COLLECTION \
237 HID_ITEM(HID_ITEM_TAG_COLLECTION_END, HID_ITEM_TYPE_MAIN, 0)
238
248#define HID_USAGE_PAGE(page) \
249 HID_ITEM(HID_ITEM_TAG_USAGE_PAGE, HID_ITEM_TYPE_GLOBAL, 1), page
250
260#define HID_LOGICAL_MIN8(a) \
261 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 1), a
262
272#define HID_LOGICAL_MAX8(a) \
273 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 1), a
274
282#define HID_LOGICAL_MIN16(a, b) \
283 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 2), a, b
284
292#define HID_LOGICAL_MAX16(a, b) \
293 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 2), a, b
294
304#define HID_LOGICAL_MIN32(a, b, c, d) \
305 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
306
316#define HID_LOGICAL_MAX32(a, b, c, d) \
317 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
318
328#define HID_REPORT_SIZE(size) \
329 HID_ITEM(HID_ITEM_TAG_REPORT_SIZE, HID_ITEM_TYPE_GLOBAL, 1), size
330
337#define HID_REPORT_ID(id) \
338 HID_ITEM(HID_ITEM_TAG_REPORT_ID, HID_ITEM_TYPE_GLOBAL, 1), id
339
349#define HID_REPORT_COUNT(count) \
350 HID_ITEM(HID_ITEM_TAG_REPORT_COUNT, HID_ITEM_TYPE_GLOBAL, 1), count
351
361#define HID_USAGE(idx) \
362 HID_ITEM(HID_ITEM_TAG_USAGE, HID_ITEM_TYPE_LOCAL, 1), idx
363
373#define HID_USAGE_MIN8(a) \
374 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 1), a
375
385#define HID_USAGE_MAX8(a) \
386 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 1), a
387
398#define HID_USAGE_MIN16(a, b) \
399 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 2), a, b
400
411#define HID_USAGE_MAX16(a, b) \
412 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 2), a, b
413
428#define HID_MOUSE_REPORT_DESC(bcnt) { \
429 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
430 HID_USAGE(HID_USAGE_GEN_DESKTOP_MOUSE), \
431 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
432 HID_USAGE(HID_USAGE_GEN_DESKTOP_POINTER), \
433 HID_COLLECTION(HID_COLLECTION_PHYSICAL), \
434 /* Bits used for button signalling */ \
435 HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON), \
436 HID_USAGE_MIN8(1), \
437 HID_USAGE_MAX8(bcnt), \
438 HID_LOGICAL_MIN8(0), \
439 HID_LOGICAL_MAX8(1), \
440 HID_REPORT_SIZE(1), \
441 HID_REPORT_COUNT(bcnt), \
442 /* HID_INPUT (Data,Var,Abs) */ \
443 HID_INPUT(0x02), \
444 /* Unused bits */ \
445 HID_REPORT_SIZE(8 - bcnt), \
446 HID_REPORT_COUNT(1), \
447 /* HID_INPUT (Cnst,Ary,Abs) */ \
448 HID_INPUT(1), \
449 /* X and Y axis, scroll */ \
450 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
451 HID_USAGE(HID_USAGE_GEN_DESKTOP_X), \
452 HID_USAGE(HID_USAGE_GEN_DESKTOP_Y), \
453 HID_USAGE(HID_USAGE_GEN_DESKTOP_WHEEL), \
454 HID_LOGICAL_MIN8(-127), \
455 HID_LOGICAL_MAX8(127), \
456 HID_REPORT_SIZE(8), \
457 HID_REPORT_COUNT(3), \
458 /* HID_INPUT (Data,Var,Rel) */ \
459 HID_INPUT(0x06), \
460 HID_END_COLLECTION, \
461 HID_END_COLLECTION, \
462}
463
467#define HID_KEYBOARD_REPORT_DESC() { \
468 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
469 HID_USAGE(HID_USAGE_GEN_DESKTOP_KEYBOARD), \
470 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
471 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
472 /* HID_USAGE_MINIMUM(Keyboard LeftControl) */ \
473 HID_USAGE_MIN8(0xE0), \
474 /* HID_USAGE_MAXIMUM(Keyboard Right GUI) */ \
475 HID_USAGE_MAX8(0xE7), \
476 HID_LOGICAL_MIN8(0), \
477 HID_LOGICAL_MAX8(1), \
478 HID_REPORT_SIZE(1), \
479 HID_REPORT_COUNT(8), \
480 /* HID_INPUT(Data,Var,Abs) */ \
481 HID_INPUT(0x02), \
482 HID_REPORT_SIZE(8), \
483 HID_REPORT_COUNT(1), \
484 /* HID_INPUT(Cnst,Var,Abs) */ \
485 HID_INPUT(0x03), \
486 HID_REPORT_SIZE(1), \
487 HID_REPORT_COUNT(5), \
488 HID_USAGE_PAGE(HID_USAGE_GEN_LEDS), \
489 /* HID_USAGE_MINIMUM(Num Lock) */ \
490 HID_USAGE_MIN8(1), \
491 /* HID_USAGE_MAXIMUM(Kana) */ \
492 HID_USAGE_MAX8(5), \
493 /* HID_OUTPUT(Data,Var,Abs) */ \
494 HID_OUTPUT(0x02), \
495 HID_REPORT_SIZE(3), \
496 HID_REPORT_COUNT(1), \
497 /* HID_OUTPUT(Cnst,Var,Abs) */ \
498 HID_OUTPUT(0x03), \
499 HID_REPORT_SIZE(8), \
500 HID_REPORT_COUNT(6), \
501 HID_LOGICAL_MIN8(0), \
502 HID_LOGICAL_MAX8(101), \
503 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
504 /* HID_USAGE_MIN8(Reserved) */ \
505 HID_USAGE_MIN8(0), \
506 /* HID_USAGE_MAX8(Keyboard Application) */ \
507 HID_USAGE_MAX8(101), \
508 /* HID_INPUT (Data,Ary,Abs) */ \
509 HID_INPUT(0x00), \
510 HID_END_COLLECTION, \
511}
512
563 HID_KEY_HASH = 50, /* Non-US # and ~ */
583 HID_KEY_SYSRQ = 70, /* PRINTSCREEN */
597 HID_KEY_KPSLASH = 84, /* NUMPAD DIVIDE */
598 HID_KEY_KPASTERISK = 85, /* NUMPAD MULTIPLY */
612};
613
628
639
648#ifdef __cplusplus
649}
650#endif
651
652#endif /* ZEPHYR_INCLUDE_USB_CLASS_HID_H_ */
hid_kbd_modifier
HID keyboard modifiers.
Definition hid.h:617
hid_kbd_code
HID keyboard button codes.
Definition hid.h:516
hid_kbd_led
HID keyboard LEDs.
Definition hid.h:632
@ HID_KBD_MODIFIER_RIGHT_UI
Definition hid.h:626
@ HID_KBD_MODIFIER_LEFT_CTRL
Definition hid.h:619
@ HID_KBD_MODIFIER_LEFT_UI
Definition hid.h:622
@ HID_KBD_MODIFIER_NONE
Definition hid.h:618
@ HID_KBD_MODIFIER_LEFT_ALT
Definition hid.h:621
@ HID_KBD_MODIFIER_RIGHT_ALT
Definition hid.h:625
@ HID_KBD_MODIFIER_RIGHT_CTRL
Definition hid.h:623
@ HID_KBD_MODIFIER_LEFT_SHIFT
Definition hid.h:620
@ HID_KBD_MODIFIER_RIGHT_SHIFT
Definition hid.h:624
@ HID_KEY_V
Definition hid.h:538
@ HID_KEY_R
Definition hid.h:534
@ HID_KEY_1
Definition hid.h:543
@ HID_KEY_Q
Definition hid.h:533
@ HID_KEY_HASH
Definition hid.h:563
@ HID_KEY_4
Definition hid.h:546
@ HID_KEY_8
Definition hid.h:550
@ HID_KEY_PAUSE
Definition hid.h:585
@ HID_KEY_KP_5
Definition hid.h:606
@ HID_KEY_KP_7
Definition hid.h:608
@ HID_KEY_INSERT
Definition hid.h:586
@ HID_KEY_F7
Definition hid.h:577
@ HID_KEY_G
Definition hid.h:523
@ HID_KEY_PAGEUP
Definition hid.h:588
@ HID_KEY_SLASH
Definition hid.h:569
@ HID_KEY_BACKSLASH
Definition hid.h:562
@ HID_KEY_J
Definition hid.h:526
@ HID_KEY_KPPLUS
Definition hid.h:600
@ HID_KEY_SEMICOLON
Definition hid.h:564
@ HID_KEY_DOT
Definition hid.h:568
@ HID_KEY_KP_3
Definition hid.h:604
@ HID_KEY_KPSLASH
Definition hid.h:597
@ HID_KEY_KP_4
Definition hid.h:605
@ HID_KEY_KP_0
Definition hid.h:611
@ HID_KEY_H
Definition hid.h:524
@ HID_KEY_RIGHT
Definition hid.h:592
@ HID_KEY_Y
Definition hid.h:541
@ HID_KEY_K
Definition hid.h:527
@ HID_KEY_CAPSLOCK
Definition hid.h:570
@ HID_KEY_M
Definition hid.h:529
@ HID_KEY_F8
Definition hid.h:578
@ HID_KEY_A
Definition hid.h:517
@ HID_KEY_7
Definition hid.h:549
@ HID_KEY_F9
Definition hid.h:579
@ HID_KEY_TAB
Definition hid.h:556
@ HID_KEY_HOME
Definition hid.h:587
@ HID_KEY_KP_2
Definition hid.h:603
@ HID_KEY_KPMINUS
Definition hid.h:599
@ HID_KEY_APOSTROPHE
Definition hid.h:565
@ HID_KEY_9
Definition hid.h:551
@ HID_KEY_ESC
Definition hid.h:554
@ HID_KEY_F3
Definition hid.h:573
@ HID_KEY_F11
Definition hid.h:581
@ HID_KEY_KP_1
Definition hid.h:602
@ HID_KEY_0
Definition hid.h:552
@ HID_KEY_T
Definition hid.h:536
@ HID_KEY_GRAVE
Definition hid.h:566
@ HID_KEY_END
Definition hid.h:590
@ HID_KEY_KP_6
Definition hid.h:607
@ HID_KEY_C
Definition hid.h:519
@ HID_KEY_F1
Definition hid.h:571
@ HID_KEY_F2
Definition hid.h:572
@ HID_KEY_DOWN
Definition hid.h:594
@ HID_KEY_X
Definition hid.h:540
@ HID_KEY_MINUS
Definition hid.h:558
@ HID_KEY_Z
Definition hid.h:542
@ HID_KEY_COMMA
Definition hid.h:567
@ HID_KEY_F4
Definition hid.h:574
@ HID_KEY_U
Definition hid.h:537
@ HID_KEY_F12
Definition hid.h:582
@ HID_KEY_N
Definition hid.h:530
@ HID_KEY_KPENTER
Definition hid.h:601
@ HID_KEY_B
Definition hid.h:518
@ HID_KEY_D
Definition hid.h:520
@ HID_KEY_F6
Definition hid.h:576
@ HID_KEY_LEFTBRACE
Definition hid.h:560
@ HID_KEY_F10
Definition hid.h:580
@ HID_KEY_EQUAL
Definition hid.h:559
@ HID_KEY_P
Definition hid.h:532
@ HID_KEY_F
Definition hid.h:522
@ HID_KEY_KP_9
Definition hid.h:610
@ HID_KEY_F5
Definition hid.h:575
@ HID_KEY_O
Definition hid.h:531
@ HID_KEY_KP_8
Definition hid.h:609
@ HID_KEY_W
Definition hid.h:539
@ HID_KEY_6
Definition hid.h:548
@ HID_KEY_SCROLLLOCK
Definition hid.h:584
@ HID_KEY_SYSRQ
Definition hid.h:583
@ HID_KEY_S
Definition hid.h:535
@ HID_KEY_DELETE
Definition hid.h:589
@ HID_KEY_2
Definition hid.h:544
@ HID_KEY_ENTER
Definition hid.h:553
@ HID_KEY_RIGHTBRACE
Definition hid.h:561
@ HID_KEY_5
Definition hid.h:547
@ HID_KEY_SPACE
Definition hid.h:557
@ HID_KEY_3
Definition hid.h:545
@ HID_KEY_L
Definition hid.h:528
@ HID_KEY_UP
Definition hid.h:595
@ HID_KEY_PAGEDOWN
Definition hid.h:591
@ HID_KEY_LEFT
Definition hid.h:593
@ HID_KEY_I
Definition hid.h:525
@ HID_KEY_BACKSPACE
Definition hid.h:555
@ HID_KEY_NUMLOCK
Definition hid.h:596
@ HID_KEY_KPASTERISK
Definition hid.h:598
@ HID_KEY_E
Definition hid.h:521
@ HID_KBD_LED_NUM_LOCK
Definition hid.h:633
@ HID_KBD_LED_SCROLL_LOCK
Definition hid.h:635
@ HID_KBD_LED_CAPS_LOCK
Definition hid.h:634
@ HID_KBD_LED_COMPOSE
Definition hid.h:636
@ HID_KBD_LED_KANA
Definition hid.h:637