Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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
37#define USB_DESC_HID 0x21
39#define USB_DESC_HID_REPORT 0x22
41#define USB_DESC_HID_PHYSICAL 0x23
42
44#define USB_HID_GET_REPORT 0x01
46#define USB_HID_GET_IDLE 0x02
48#define USB_HID_GET_PROTOCOL 0x03
50#define USB_HID_SET_REPORT 0x09
52#define USB_HID_SET_IDLE 0x0A
54#define USB_HID_SET_PROTOCOL 0x0B
55
57#define HID_BOOT_IFACE_CODE_NONE 0
59#define HID_BOOT_IFACE_CODE_KEYBOARD 1
61#define HID_BOOT_IFACE_CODE_MOUSE 2
62
64#define HID_PROTOCOL_BOOT 0
66#define HID_PROTOCOL_REPORT 1
67
69#define HID_ITEM_TYPE_MAIN 0x0
71#define HID_ITEM_TYPE_GLOBAL 0x1
73#define HID_ITEM_TYPE_LOCAL 0x2
74
76#define HID_ITEM_TAG_INPUT 0x8
78#define HID_ITEM_TAG_OUTPUT 0x9
80#define HID_ITEM_TAG_COLLECTION 0xA
82#define HID_ITEM_TAG_FEATURE 0xB
84#define HID_ITEM_TAG_COLLECTION_END 0xC
85
87#define HID_ITEM_TAG_USAGE_PAGE 0x0
89#define HID_ITEM_TAG_LOGICAL_MIN 0x1
91#define HID_ITEM_TAG_LOGICAL_MAX 0x2
93#define HID_ITEM_TAG_PHYSICAL_MIN 0x3
95#define HID_ITEM_TAG_PHYSICAL_MAX 0x4
97#define HID_ITEM_TAG_UNIT_EXPONENT 0x5
99#define HID_ITEM_TAG_UNIT 0x6
101#define HID_ITEM_TAG_REPORT_SIZE 0x7
103#define HID_ITEM_TAG_REPORT_ID 0x8
105#define HID_ITEM_TAG_REPORT_COUNT 0x9
106
108#define HID_ITEM_TAG_USAGE 0x0
110#define HID_ITEM_TAG_USAGE_MIN 0x1
112#define HID_ITEM_TAG_USAGE_MAX 0x2
113
115#define HID_COLLECTION_PHYSICAL 0x00
117#define HID_COLLECTION_APPLICATION 0x01
118
119/* Usage page and IDs from Universal Serial Bus HID Usage Tables */
120
122#define HID_USAGE_GEN_DESKTOP 0x01
124#define HID_USAGE_GEN_KEYBOARD 0x07
126#define HID_USAGE_GEN_LEDS 0x08
128#define HID_USAGE_GEN_BUTTON 0x09
129
131#define HID_USAGE_GEN_DESKTOP_UNDEFINED 0x00
133#define HID_USAGE_GEN_DESKTOP_POINTER 0x01
135#define HID_USAGE_GEN_DESKTOP_MOUSE 0x02
137#define HID_USAGE_GEN_DESKTOP_JOYSTICK 0x04
139#define HID_USAGE_GEN_DESKTOP_GAMEPAD 0x05
141#define HID_USAGE_GEN_DESKTOP_KEYBOARD 0x06
143#define HID_USAGE_GEN_DESKTOP_KEYPAD 0x07
145#define HID_USAGE_GEN_DESKTOP_X 0x30
147#define HID_USAGE_GEN_DESKTOP_Y 0x31
149#define HID_USAGE_GEN_DESKTOP_WHEEL 0x38
150
169#define HID_ITEM(bTag, bType, bSize) (((bTag & 0xF) << 4) | \
170 ((bType & 0x3) << 2) | (bSize & 0x3))
171
181#define HID_INPUT(a) \
182 HID_ITEM(HID_ITEM_TAG_INPUT, HID_ITEM_TYPE_MAIN, 1), a
183
192#define HID_OUTPUT(a) \
193 HID_ITEM(HID_ITEM_TAG_OUTPUT, HID_ITEM_TYPE_MAIN, 1), a
194
201#define HID_FEATURE(a) \
202 HID_ITEM(HID_ITEM_TAG_OUTPUT, HID_ITEM_TYPE_MAIN, 1), a
203
213#define HID_COLLECTION(a) \
214 HID_ITEM(HID_ITEM_TAG_COLLECTION, HID_ITEM_TYPE_MAIN, 1), a
215
224#define HID_END_COLLECTION \
225 HID_ITEM(HID_ITEM_TAG_COLLECTION_END, HID_ITEM_TYPE_MAIN, 0)
226
236#define HID_USAGE_PAGE(page) \
237 HID_ITEM(HID_ITEM_TAG_USAGE_PAGE, HID_ITEM_TYPE_GLOBAL, 1), page
238
248#define HID_LOGICAL_MIN8(a) \
249 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 1), a
250
260#define HID_LOGICAL_MAX8(a) \
261 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 1), a
262
270#define HID_LOGICAL_MIN16(a, b) \
271 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 2), a, b
272
280#define HID_LOGICAL_MAX16(a, b) \
281 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 2), a, b
282
292#define HID_LOGICAL_MIN32(a, b, c, d) \
293 HID_ITEM(HID_ITEM_TAG_LOGICAL_MIN, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
294
304#define HID_LOGICAL_MAX32(a, b, c, d) \
305 HID_ITEM(HID_ITEM_TAG_LOGICAL_MAX, HID_ITEM_TYPE_GLOBAL, 3), a, b, c, d
306
316#define HID_REPORT_SIZE(size) \
317 HID_ITEM(HID_ITEM_TAG_REPORT_SIZE, HID_ITEM_TYPE_GLOBAL, 1), size
318
325#define HID_REPORT_ID(id) \
326 HID_ITEM(HID_ITEM_TAG_REPORT_ID, HID_ITEM_TYPE_GLOBAL, 1), id
327
337#define HID_REPORT_COUNT(count) \
338 HID_ITEM(HID_ITEM_TAG_REPORT_COUNT, HID_ITEM_TYPE_GLOBAL, 1), count
339
349#define HID_USAGE(idx) \
350 HID_ITEM(HID_ITEM_TAG_USAGE, HID_ITEM_TYPE_LOCAL, 1), idx
351
361#define HID_USAGE_MIN8(a) \
362 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 1), a
363
373#define HID_USAGE_MAX8(a) \
374 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 1), a
375
386#define HID_USAGE_MIN16(a, b) \
387 HID_ITEM(HID_ITEM_TAG_USAGE_MIN, HID_ITEM_TYPE_LOCAL, 2), a, b
388
399#define HID_USAGE_MAX16(a, b) \
400 HID_ITEM(HID_ITEM_TAG_USAGE_MAX, HID_ITEM_TYPE_LOCAL, 2), a, b
401
417#define HID_MOUSE_REPORT_DESC(bcnt) { \
418 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
419 HID_USAGE(HID_USAGE_GEN_DESKTOP_MOUSE), \
420 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
421 HID_USAGE(HID_USAGE_GEN_DESKTOP_POINTER), \
422 HID_COLLECTION(HID_COLLECTION_PHYSICAL), \
423 /* Bits used for button signalling */ \
424 HID_USAGE_PAGE(HID_USAGE_GEN_BUTTON), \
425 HID_USAGE_MIN8(1), \
426 HID_USAGE_MAX8(bcnt), \
427 HID_LOGICAL_MIN8(0), \
428 HID_LOGICAL_MAX8(1), \
429 HID_REPORT_SIZE(1), \
430 HID_REPORT_COUNT(bcnt), \
431 /* HID_INPUT (Data,Var,Abs) */ \
432 HID_INPUT(0x02), \
433 /* Unused bits */ \
434 HID_REPORT_SIZE(8 - bcnt), \
435 HID_REPORT_COUNT(1), \
436 /* HID_INPUT (Cnst,Ary,Abs) */ \
437 HID_INPUT(1), \
438 /* X and Y axis, scroll */ \
439 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
440 HID_USAGE(HID_USAGE_GEN_DESKTOP_X), \
441 HID_USAGE(HID_USAGE_GEN_DESKTOP_Y), \
442 HID_USAGE(HID_USAGE_GEN_DESKTOP_WHEEL), \
443 HID_LOGICAL_MIN8(-127), \
444 HID_LOGICAL_MAX8(127), \
445 HID_REPORT_SIZE(8), \
446 HID_REPORT_COUNT(3), \
447 /* HID_INPUT (Data,Var,Rel) */ \
448 HID_INPUT(0x06), \
449 HID_END_COLLECTION, \
450 HID_END_COLLECTION, \
451}
452
456#define HID_KEYBOARD_REPORT_DESC() { \
457 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), \
458 HID_USAGE(HID_USAGE_GEN_DESKTOP_KEYBOARD), \
459 HID_COLLECTION(HID_COLLECTION_APPLICATION), \
460 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
461 /* HID_USAGE_MINIMUM(Keyboard LeftControl) */ \
462 HID_USAGE_MIN8(0xE0), \
463 /* HID_USAGE_MAXIMUM(Keyboard Right GUI) */ \
464 HID_USAGE_MAX8(0xE7), \
465 HID_LOGICAL_MIN8(0), \
466 HID_LOGICAL_MAX8(1), \
467 HID_REPORT_SIZE(1), \
468 HID_REPORT_COUNT(8), \
469 /* HID_INPUT(Data,Var,Abs) */ \
470 HID_INPUT(0x02), \
471 HID_REPORT_SIZE(8), \
472 HID_REPORT_COUNT(1), \
473 /* HID_INPUT(Cnst,Var,Abs) */ \
474 HID_INPUT(0x03), \
475 HID_REPORT_SIZE(1), \
476 HID_REPORT_COUNT(5), \
477 HID_USAGE_PAGE(HID_USAGE_GEN_LEDS), \
478 /* HID_USAGE_MINIMUM(Num Lock) */ \
479 HID_USAGE_MIN8(1), \
480 /* HID_USAGE_MAXIMUM(Kana) */ \
481 HID_USAGE_MAX8(5), \
482 /* HID_OUTPUT(Data,Var,Abs) */ \
483 HID_OUTPUT(0x02), \
484 HID_REPORT_SIZE(3), \
485 HID_REPORT_COUNT(1), \
486 /* HID_OUTPUT(Cnst,Var,Abs) */ \
487 HID_OUTPUT(0x03), \
488 HID_REPORT_SIZE(8), \
489 HID_REPORT_COUNT(6), \
490 HID_LOGICAL_MIN8(0), \
491 HID_LOGICAL_MAX8(101), \
492 HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP_KEYPAD), \
493 /* HID_USAGE_MIN8(Reserved) */ \
494 HID_USAGE_MIN8(0), \
495 /* HID_USAGE_MAX8(Keyboard Application) */ \
496 HID_USAGE_MAX8(101), \
497 /* HID_INPUT (Data,Ary,Abs) */ \
498 HID_INPUT(0x00), \
499 HID_END_COLLECTION, \
500}
501
552 HID_KEY_HASH = 50, /* Non-US # and ~ */
572 HID_KEY_SYSRQ = 70, /* PRINTSCREEN */
586 HID_KEY_KPSLASH = 84, /* NUMPAD DIVIDE */
587 HID_KEY_KPASTERISK = 85, /* NUMPAD MULTIPLY */
601};
602
616};
617
627};
628
633#ifdef __cplusplus
634}
635#endif
636
637#endif /* ZEPHYR_INCLUDE_USB_CLASS_HID_H_ */
hid_kbd_modifier
HID keyboard modifiers.
Definition: hid.h:606
hid_kbd_code
HID keyboard button codes.
Definition: hid.h:505
hid_kbd_led
HID keyboard LEDs.
Definition: hid.h:621
@ HID_KBD_MODIFIER_RIGHT_UI
Definition: hid.h:615
@ HID_KBD_MODIFIER_LEFT_CTRL
Definition: hid.h:608
@ HID_KBD_MODIFIER_LEFT_UI
Definition: hid.h:611
@ HID_KBD_MODIFIER_NONE
Definition: hid.h:607
@ HID_KBD_MODIFIER_LEFT_ALT
Definition: hid.h:610
@ HID_KBD_MODIFIER_RIGHT_ALT
Definition: hid.h:614
@ HID_KBD_MODIFIER_RIGHT_CTRL
Definition: hid.h:612
@ HID_KBD_MODIFIER_LEFT_SHIFT
Definition: hid.h:609
@ HID_KBD_MODIFIER_RIGHT_SHIFT
Definition: hid.h:613
@ HID_KEY_V
Definition: hid.h:527
@ HID_KEY_R
Definition: hid.h:523
@ HID_KEY_1
Definition: hid.h:532
@ HID_KEY_Q
Definition: hid.h:522
@ HID_KEY_HASH
Definition: hid.h:552
@ HID_KEY_4
Definition: hid.h:535
@ HID_KEY_8
Definition: hid.h:539
@ HID_KEY_PAUSE
Definition: hid.h:574
@ HID_KEY_KP_5
Definition: hid.h:595
@ HID_KEY_KP_7
Definition: hid.h:597
@ HID_KEY_INSERT
Definition: hid.h:575
@ HID_KEY_F7
Definition: hid.h:566
@ HID_KEY_G
Definition: hid.h:512
@ HID_KEY_PAGEUP
Definition: hid.h:577
@ HID_KEY_SLASH
Definition: hid.h:558
@ HID_KEY_BACKSLASH
Definition: hid.h:551
@ HID_KEY_J
Definition: hid.h:515
@ HID_KEY_KPPLUS
Definition: hid.h:589
@ HID_KEY_SEMICOLON
Definition: hid.h:553
@ HID_KEY_DOT
Definition: hid.h:557
@ HID_KEY_KP_3
Definition: hid.h:593
@ HID_KEY_KPSLASH
Definition: hid.h:586
@ HID_KEY_KP_4
Definition: hid.h:594
@ HID_KEY_KP_0
Definition: hid.h:600
@ HID_KEY_H
Definition: hid.h:513
@ HID_KEY_RIGHT
Definition: hid.h:581
@ HID_KEY_Y
Definition: hid.h:530
@ HID_KEY_K
Definition: hid.h:516
@ HID_KEY_CAPSLOCK
Definition: hid.h:559
@ HID_KEY_M
Definition: hid.h:518
@ HID_KEY_F8
Definition: hid.h:567
@ HID_KEY_A
Definition: hid.h:506
@ HID_KEY_7
Definition: hid.h:538
@ HID_KEY_F9
Definition: hid.h:568
@ HID_KEY_TAB
Definition: hid.h:545
@ HID_KEY_HOME
Definition: hid.h:576
@ HID_KEY_KP_2
Definition: hid.h:592
@ HID_KEY_KPMINUS
Definition: hid.h:588
@ HID_KEY_APOSTROPHE
Definition: hid.h:554
@ HID_KEY_9
Definition: hid.h:540
@ HID_KEY_ESC
Definition: hid.h:543
@ HID_KEY_F3
Definition: hid.h:562
@ HID_KEY_F11
Definition: hid.h:570
@ HID_KEY_KP_1
Definition: hid.h:591
@ HID_KEY_0
Definition: hid.h:541
@ HID_KEY_T
Definition: hid.h:525
@ HID_KEY_GRAVE
Definition: hid.h:555
@ HID_KEY_END
Definition: hid.h:579
@ HID_KEY_KP_6
Definition: hid.h:596
@ HID_KEY_C
Definition: hid.h:508
@ HID_KEY_F1
Definition: hid.h:560
@ HID_KEY_F2
Definition: hid.h:561
@ HID_KEY_DOWN
Definition: hid.h:583
@ HID_KEY_X
Definition: hid.h:529
@ HID_KEY_MINUS
Definition: hid.h:547
@ HID_KEY_Z
Definition: hid.h:531
@ HID_KEY_COMMA
Definition: hid.h:556
@ HID_KEY_F4
Definition: hid.h:563
@ HID_KEY_U
Definition: hid.h:526
@ HID_KEY_F12
Definition: hid.h:571
@ HID_KEY_N
Definition: hid.h:519
@ HID_KEY_KPENTER
Definition: hid.h:590
@ HID_KEY_B
Definition: hid.h:507
@ HID_KEY_D
Definition: hid.h:509
@ HID_KEY_F6
Definition: hid.h:565
@ HID_KEY_LEFTBRACE
Definition: hid.h:549
@ HID_KEY_F10
Definition: hid.h:569
@ HID_KEY_EQUAL
Definition: hid.h:548
@ HID_KEY_P
Definition: hid.h:521
@ HID_KEY_F
Definition: hid.h:511
@ HID_KEY_KP_9
Definition: hid.h:599
@ HID_KEY_F5
Definition: hid.h:564
@ HID_KEY_O
Definition: hid.h:520
@ HID_KEY_KP_8
Definition: hid.h:598
@ HID_KEY_W
Definition: hid.h:528
@ HID_KEY_6
Definition: hid.h:537
@ HID_KEY_SCROLLLOCK
Definition: hid.h:573
@ HID_KEY_SYSRQ
Definition: hid.h:572
@ HID_KEY_S
Definition: hid.h:524
@ HID_KEY_DELETE
Definition: hid.h:578
@ HID_KEY_2
Definition: hid.h:533
@ HID_KEY_ENTER
Definition: hid.h:542
@ HID_KEY_RIGHTBRACE
Definition: hid.h:550
@ HID_KEY_5
Definition: hid.h:536
@ HID_KEY_SPACE
Definition: hid.h:546
@ HID_KEY_3
Definition: hid.h:534
@ HID_KEY_L
Definition: hid.h:517
@ HID_KEY_UP
Definition: hid.h:584
@ HID_KEY_PAGEDOWN
Definition: hid.h:580
@ HID_KEY_LEFT
Definition: hid.h:582
@ HID_KEY_I
Definition: hid.h:514
@ HID_KEY_BACKSPACE
Definition: hid.h:544
@ HID_KEY_NUMLOCK
Definition: hid.h:585
@ HID_KEY_KPASTERISK
Definition: hid.h:587
@ HID_KEY_E
Definition: hid.h:510
@ HID_KBD_LED_NUM_LOCK
Definition: hid.h:622
@ HID_KBD_LED_SCROLL_LOCK
Definition: hid.h:624
@ HID_KBD_LED_CAPS_LOCK
Definition: hid.h:623
@ HID_KBD_LED_COMPOSE
Definition: hid.h:625
@ HID_KBD_LED_KANA
Definition: hid.h:626