1/* @title: USB HID */
2
3/*
4 * USB Human Interface Device (HID) class definitions
5 * Spec: USB HID 1.11
6 */
7#pragma once
8
9/* HID subclasses */
10#define USB_HID_SUBCLASS_NONE 0x00
11#define USB_HID_SUBCLASS_BOOT 0x01
12
13/* HID protocols (only meaningful for BOOT subclass) */
14#define USB_HID_PROTOCOL_NONE 0x00
15#define USB_HID_PROTOCOL_KEYBOARD 0x01
16#define USB_HID_PROTOCOL_MOUSE 0x02
17
18/* ================================
19 * Descriptor types
20 * ================================ */
21#define USB_HID_DESC_TYPE_HID 0x21
22#define USB_HID_DESC_TYPE_REPORT 0x22
23#define USB_HID_DESC_TYPE_PHYSICAL 0x23
24
25/* ================================
26 * HID class-specific requests
27 * ================================ */
28#define USB_HID_REQ_GET_REPORT 0x01
29#define USB_HID_REQ_GET_IDLE 0x02
30#define USB_HID_REQ_GET_PROTOCOL 0x03
31#define USB_HID_REQ_SET_REPORT 0x09
32#define USB_HID_REQ_SET_IDLE 0x0A
33#define USB_HID_REQ_SET_PROTOCOL 0x0B
34
35/* ================================
36 * Report types (wValue high byte)
37 * ================================ */
38#define USB_HID_REPORT_INPUT 0x01
39#define USB_HID_REPORT_OUTPUT 0x02
40#define USB_HID_REPORT_FEATURE 0x03
41
42/* ================================
43 * Protocol values (SET_PROTOCOL)
44 * ================================ */
45#define USB_HID_PROTOCOL_BOOT 0x00
46#define USB_HID_PROTOCOL_REPORT 0x01
47
48/* ================================
49 * Country codes (HID descriptor)
50 * ================================ */
51#define USB_HID_COUNTRY_NONE 0x00
52#define USB_HID_COUNTRY_ARABIC 0x01
53#define USB_HID_COUNTRY_BELGIAN 0x02
54#define USB_HID_COUNTRY_CANADIAN_BI 0x03
55#define USB_HID_COUNTRY_CANADIAN_FR 0x04
56#define USB_HID_COUNTRY_CZECH 0x05
57#define USB_HID_COUNTRY_DANISH 0x06
58#define USB_HID_COUNTRY_FINNISH 0x07
59#define USB_HID_COUNTRY_FRENCH 0x08
60#define USB_HID_COUNTRY_GERMAN 0x09
61#define USB_HID_COUNTRY_GREEK 0x0A
62#define USB_HID_COUNTRY_HEBREW 0x0B
63#define USB_HID_COUNTRY_HUNGARY 0x0C
64#define USB_HID_COUNTRY_INTL_ISO 0x0D
65#define USB_HID_COUNTRY_ITALIAN 0x0E
66#define USB_HID_COUNTRY_JAPAN_KATA 0x0F
67#define USB_HID_COUNTRY_KOREAN 0x10
68#define USB_HID_COUNTRY_LATIN_AMER 0x11
69#define USB_HID_COUNTRY_NETHERLANDS 0x12
70#define USB_HID_COUNTRY_NORWEGIAN 0x13
71#define USB_HID_COUNTRY_PERSIAN 0x14
72#define USB_HID_COUNTRY_POLAND 0x15
73#define USB_HID_COUNTRY_PORTUGUESE 0x16
74#define USB_HID_COUNTRY_RUSSIA 0x17
75#define USB_HID_COUNTRY_SLOVAKIA 0x18
76#define USB_HID_COUNTRY_SPANISH 0x19
77#define USB_HID_COUNTRY_SWEDISH 0x1A
78#define USB_HID_COUNTRY_SWISS_FR 0x1B
79#define USB_HID_COUNTRY_SWISS_DE 0x1C
80#define USB_HID_COUNTRY_SWITZ_FR 0x1D
81#define USB_HID_COUNTRY_TAIWAN 0x1E
82#define USB_HID_COUNTRY_TURKISH_Q 0x1F
83#define USB_HID_COUNTRY_UK 0x20
84#define USB_HID_COUNTRY_US 0x21
85#define USB_HID_COUNTRY_YUGOSLAVIA 0x22
86#define USB_HID_COUNTRY_TURKISH_F 0x23
87
88/* ================================
89 * Boot keyboard definitions
90 * ================================ */
91
92/* Modifier byte bits */
93#define USB_HID_MODIFIER_BASE 0xE0
94
95#define USB_HID_MOD_LCTRL 0x01
96#define USB_HID_MOD_LSHIFT 0x02
97#define USB_HID_MOD_LALT 0x04
98#define USB_HID_MOD_LGUI 0x08
99#define USB_HID_MOD_RCTRL 0x10
100#define USB_HID_MOD_RSHIFT 0x20
101#define USB_HID_MOD_RALT 0x40
102#define USB_HID_MOD_RGUI 0x80
103
104/* LED output report bits */
105#define USB_HID_LED_NUM_LOCK 0x01
106#define USB_HID_LED_CAPS_LOCK 0x02
107#define USB_HID_LED_SCROLL_LOCK 0x04
108#define USB_HID_LED_COMPOSE 0x08
109#define USB_HID_LED_KANA 0x10
110
111/* ================================
112 * Boot mouse definitions
113 * ================================ */
114
115#define USB_HID_MOUSE_BTN_LEFT 0x01
116#define USB_HID_MOUSE_BTN_RIGHT 0x02
117#define USB_HID_MOUSE_BTN_MIDDLE 0x04
118#define USB_HID_MOUSE_BTN_BACK 0x08
119#define USB_HID_MOUSE_BTN_FORWARD 0x10
120
121/* ================================
122 * Interface class-specific bmRequestType
123 * ================================ */
124
125#define USB_HID_REQTYPE_IN 0xA1 /* Class | Interface | IN */
126#define USB_HID_REQTYPE_OUT 0x21 /* Class | Interface | OUT */
127
128/* ================================
129 * Common HID interface expectations
130 * ================================ */
131
132/*
133 * - Interrupt IN endpoint mandatory
134 * - Interrupt OUT optional
135 * - No bulk or isochronous endpoints
136 * - Control endpoint used for reports & protocol
137 */
138