xref: /btstack/src/btstack_hid.h (revision ceed67ffe68ea5103bbc5647a2e000ed0e08b747)
1 /*
2  * Copyright (C) 2021 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /**
39  * @title Human Interface Device (HID)
40  *
41  */
42 
43 #ifndef HID_H
44 #define HID_H
45 
46 #if defined __cplusplus
47 extern "C" {
48 #endif
49 
50 
51 #include <stdint.h>
52 
53 #define HID_BOOT_MODE_KEYBOARD_ID 1
54 #define HID_BOOT_MODE_MOUSE_ID    2
55 
56 // used to indicate that no 8-bit Report ID has been set / is used
57 #define HID_REPORT_ID_UNDEFINED 0xffff
58 
59 typedef enum {
60     HID_MESSAGE_TYPE_HANDSHAKE = 0,
61     HID_MESSAGE_TYPE_HID_CONTROL,
62     HID_MESSAGE_TYPE_RESERVED_2,
63     HID_MESSAGE_TYPE_RESERVED_3,
64     HID_MESSAGE_TYPE_GET_REPORT,
65     HID_MESSAGE_TYPE_SET_REPORT,
66     HID_MESSAGE_TYPE_GET_PROTOCOL,
67     HID_MESSAGE_TYPE_SET_PROTOCOL,
68     HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED,
69     HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED,
70     HID_MESSAGE_TYPE_DATA,
71     HID_MESSAGE_TYPE_DATC_DEPRECATED
72 } hid_message_type_t;
73 
74 typedef enum {
75     HID_HANDSHAKE_PARAM_TYPE_SUCCESSFUL = 0x00,        // This code is used to acknowledge requests. A device that has correctly received SET_REPORT, SET_IDLE or SET_PROTOCOL payload transmits an acknowledgment to the host.
76     HID_HANDSHAKE_PARAM_TYPE_NOT_READY,                // This code indicates that a device is too busy to accept data. The Bluetooth HID Host should retransmit the data the next time it communicates with the device.
77     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID,    // Invalid report ID transmitted.
78     HID_HANDSHAKE_PARAM_TYPE_ERR_UNSUPPORTED_REQUEST,  // The device does not support the request. This result code shall be used if the HIDP message type is unsupported.
79     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER,    // A parameter value is out of range or inappropriate for the request.
80     HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E,       // Device could not identify the error condition.
81     HID_HANDSHAKE_PARAM_TYPE_ERR_FATAL = 0x0F,         // Restart is essential to resume functionality
82     // BTstack custom error codes
83     HID_HANDSHAKE_PARAM_TYPE_ERR_DISCONNECT
84 } hid_handshake_param_type_t;
85 
86 typedef enum {
87     HID_CONTROL_PARAM_NOP_DEPRECATED = 0,              // Deprecated: No Operation.
88     HID_CONTROL_PARAM_HARD_RESET_DEPRECATED,           // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations.
89     HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED,           // Deprecated: Device initializes all internal variables and initiates normal operations.
90     HID_CONTROL_PARAM_SUSPEND = 0x03,                  // Go to reduced power mode.
91     HID_CONTROL_PARAM_EXIT_SUSPEND,                    // Exit reduced power mode.
92     HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG
93 } hid_control_param_t;
94 
95 typedef enum {
96     HID_PROTOCOL_MODE_BOOT = 0,
97     HID_PROTOCOL_MODE_REPORT,
98 
99     // the following item is only used for API calls in hid_host.h: hid_host_connect, hid_host_accept_connection
100     // in contrast to previous two enum items that will enforce given mode, this one enables fallback from report to boot mode
101     HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT
102 } hid_protocol_mode_t;
103 
104 typedef enum {
105     HID_REPORT_TYPE_RESERVED = 0,
106     HID_REPORT_TYPE_INPUT,
107     HID_REPORT_TYPE_OUTPUT,
108     HID_REPORT_TYPE_FEATURE
109 } hid_report_type_t;
110 
111 typedef enum {
112     HID_REPORT_ID_UNDECLARED,
113     HID_REPORT_ID_VALID,
114     HID_REPORT_ID_INVALID
115 } hid_report_id_status_t;
116 
117 // HID Usage Pages
118 #define HID_USAGE_PAGE_DESKTOP                   0x01
119 #define HID_USAGE_PAGE_SIMULATE                  0x02
120 #define HID_USAGE_PAGE_VIRTUAL_REALITY           0x03
121 #define HID_USAGE_PAGE_SPORT                     0x04
122 #define HID_USAGE_PAGE_GAME                      0x05
123 #define HID_USAGE_PAGE_GENERIC_DEVICE            0x06
124 #define HID_USAGE_PAGE_KEYBOARD                  0x07
125 #define HID_USAGE_PAGE_LED                       0x08
126 #define HID_USAGE_PAGE_BUTTON                    0x09
127 #define HID_USAGE_PAGE_ORDINAL                   0x0a
128 #define HID_USAGE_PAGE_TELEPHONY                 0x0b
129 #define HID_USAGE_PAGE_CONSUMER                  0x0c
130 #define HID_USAGE_PAGE_DIGITIZER                 0x0d
131 #define HID_USAGE_PAGE_PID                       0x0f
132 #define HID_USAGE_PAGE_UNICODE                   0x10
133 #define HID_USAGE_PAGE_ALPHA_DISPLAY             0x14
134 #define HID_USAGE_PAGE_MEDICAL                   0x40
135 #define HID_USAGE_PAGE_LIGHTING_AND_ILLUMINATION 0x59
136 #define HID_USAGE_PAGE_MONITOR                   0x80    // 0x80 - 0x83
137 #define HID_USAGE_PAGE_POWER                     0x84    // 0x084 - 0x87
138 #define HID_USAGE_PAGE_BARCODE_SCANNER           0x8c
139 #define HID_USAGE_PAGE_SCALE                     0x8d
140 #define HID_USAGE_PAGE_MSR                       0x8e
141 #define HID_USAGE_PAGE_CAMERA                    0x90
142 #define HID_USAGE_PAGE_ARCADE                    0x91
143 #define HID_USAGE_PAGE_FIDO                      0xF1D0  // FIDO alliance
144 #define HID_USAGE_PAGE_VENDOR                    0xFF00  // 0xFF00 - 0xFFFF
145 
146 // HID Usage Keyboard (partial) 0x0007
147 #define HID_USAGE_KEY_RESERVED                   0x00
148 #define HID_USAGE_KEY_KEYBOARD_CAPS_LOCK         0x39
149 #define HID_USAGE_KEY_KEYBOARD_SCROLL_LOCK       0x47
150 #define HID_USAGE_KEY_KEYPAD_NUM_LOCK_AND_CLEAR  0x53
151 #define HID_USAGE_KEY_KEYBOARD_LEFTCONTROL       0xE0
152 #define HID_USAGE_KEY_KEYBOARD_LEFTSHIFT         0xE1
153 #define HID_USAGE_KEY_KEYBOARD_LEFTALT           0xE2
154 #define HID_USAGE_KEY_KEYBOARD_LEFT_GUI          0xE3
155 #define HID_USAGE_KEY_KEYBOARD_RIGHTCONTROL      0xE4
156 #define HID_USAGE_KEY_KEYBOARD_RIGHTSHIFT        0xE5
157 #define HID_USAGE_KEY_KEYBOARD_RIGHTALT          0xE6
158 #define HID_USAGE_KEY_KEYBOARD_RIGHT_GUI         0xE7
159 
160 // HID Usage LED (partial) 0x0008
161 #define HID_USAGE_LED_NUM_LOCK                   0x01
162 #define HID_USAGE_LED_CAPS_LOCK                  0x02
163 #define HID_USAGE_LED_SCROLL_LOCK                0x03
164 #define HID_USAGE_LED_COMPOSE                    0x04
165 #define HID_USAGE_LED_KANA                       0x05
166 #define HID_USAGE_LED_POWER                      0x06
167 #define HID_USAGE_LED_SHIFT                      0x07
168 
169 
170 /* API_START */
171 
172 /*
173  * @brief Get boot descriptor data
174  * @result data
175  */
176 const uint8_t * btstack_hid_get_boot_descriptor_data(void);
177 
178 /*
179  * @brief Get boot descriptor length
180  * @result length
181  */
182 uint16_t btstack_hid_get_boot_descriptor_len(void);
183 
184 /* API_END */
185 
186 #if defined __cplusplus
187 }
188 #endif
189 
190 #endif
191