xref: /btstack/src/btstack_hid.h (revision fe796163cf1ecb6bfabb8bf4cb51a6e5baea3f93)
13cbedd43SMatthias Ringwald /*
23cbedd43SMatthias Ringwald  * Copyright (C) 2021 BlueKitchen GmbH
33cbedd43SMatthias Ringwald  *
43cbedd43SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53cbedd43SMatthias Ringwald  * modification, are permitted provided that the following conditions
63cbedd43SMatthias Ringwald  * are met:
73cbedd43SMatthias Ringwald  *
83cbedd43SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103cbedd43SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123cbedd43SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133cbedd43SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143cbedd43SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153cbedd43SMatthias Ringwald  *    from this software without specific prior written permission.
163cbedd43SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173cbedd43SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183cbedd43SMatthias Ringwald  *    monetary gain.
193cbedd43SMatthias Ringwald  *
203cbedd43SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213cbedd43SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223cbedd43SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253cbedd43SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263cbedd43SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273cbedd43SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283cbedd43SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293cbedd43SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303cbedd43SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313cbedd43SMatthias Ringwald  * SUCH DAMAGE.
323cbedd43SMatthias Ringwald  *
333cbedd43SMatthias Ringwald  * Please inquire about commercial licensing options at
343cbedd43SMatthias Ringwald  * [email protected]
353cbedd43SMatthias Ringwald  *
363cbedd43SMatthias Ringwald  */
373cbedd43SMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title Human Interface Device (HID)
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
42fe5a6c4eSMilanka Ringwald 
433cbedd43SMatthias Ringwald #ifndef HID_H
443cbedd43SMatthias Ringwald #define HID_H
453cbedd43SMatthias Ringwald 
463cbedd43SMatthias Ringwald #if defined __cplusplus
473cbedd43SMatthias Ringwald extern "C" {
483cbedd43SMatthias Ringwald #endif
493cbedd43SMatthias Ringwald 
503cbedd43SMatthias Ringwald 
513cbedd43SMatthias Ringwald #include <stdint.h>
523cbedd43SMatthias Ringwald 
533cbedd43SMatthias Ringwald #define HID_BOOT_MODE_KEYBOARD_ID 1
543cbedd43SMatthias Ringwald #define HID_BOOT_MODE_MOUSE_ID    2
553cbedd43SMatthias Ringwald 
56279225e6SMatthias Ringwald // used to indicate that no 8-bit Report ID has been set / is used
57279225e6SMatthias Ringwald #define HID_REPORT_ID_UNDEFINED 0xffff
58279225e6SMatthias Ringwald 
593cbedd43SMatthias Ringwald typedef enum {
603cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HANDSHAKE = 0,
613cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HID_CONTROL,
623cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_2,
633cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_3,
643cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_REPORT,
653cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_REPORT,
663cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_PROTOCOL,
673cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_PROTOCOL,
683cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED,
693cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED,
703cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATA,
713cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATC_DEPRECATED
723cbedd43SMatthias Ringwald } hid_message_type_t;
733cbedd43SMatthias Ringwald 
743cbedd43SMatthias Ringwald typedef enum {
753cbedd43SMatthias Ringwald     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.
763cbedd43SMatthias Ringwald     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.
773cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID,    // Invalid report ID transmitted.
783cbedd43SMatthias Ringwald     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.
793cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER,    // A parameter value is out of range or inappropriate for the request.
803cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E,       // Device could not identify the error condition.
813cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_FATAL = 0x0F,         // Restart is essential to resume functionality
823cbedd43SMatthias Ringwald     // BTstack custom error codes
833cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_DISCONNECT
843cbedd43SMatthias Ringwald } hid_handshake_param_type_t;
853cbedd43SMatthias Ringwald 
863cbedd43SMatthias Ringwald typedef enum {
873cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_NOP_DEPRECATED = 0,              // Deprecated: No Operation.
883cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_HARD_RESET_DEPRECATED,           // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations.
893cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED,           // Deprecated: Device initializes all internal variables and initiates normal operations.
903cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SUSPEND = 0x03,                  // Go to reduced power mode.
913cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_EXIT_SUSPEND,                    // Exit reduced power mode.
923cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG
933cbedd43SMatthias Ringwald } hid_control_param_t;
943cbedd43SMatthias Ringwald 
953cbedd43SMatthias Ringwald typedef enum {
963cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_BOOT = 0,
973cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT,
983cbedd43SMatthias Ringwald 
993cbedd43SMatthias Ringwald     // the following item is only used for API calls in hid_host.h: hid_host_connect, hid_host_accept_connection
1003cbedd43SMatthias Ringwald     // in contrast to previous two enum items that will enforce given mode, this one enables fallback from report to boot mode
1013cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT
1023cbedd43SMatthias Ringwald } hid_protocol_mode_t;
1033cbedd43SMatthias Ringwald 
1043cbedd43SMatthias Ringwald typedef enum {
1053cbedd43SMatthias Ringwald     HID_REPORT_TYPE_RESERVED = 0,
1063cbedd43SMatthias Ringwald     HID_REPORT_TYPE_INPUT,
1073cbedd43SMatthias Ringwald     HID_REPORT_TYPE_OUTPUT,
1083cbedd43SMatthias Ringwald     HID_REPORT_TYPE_FEATURE
1093cbedd43SMatthias Ringwald } hid_report_type_t;
1103cbedd43SMatthias Ringwald 
1113cbedd43SMatthias Ringwald typedef enum {
1123cbedd43SMatthias Ringwald     HID_REPORT_ID_UNDECLARED,
1133cbedd43SMatthias Ringwald     HID_REPORT_ID_VALID,
1143cbedd43SMatthias Ringwald     HID_REPORT_ID_INVALID
1153cbedd43SMatthias Ringwald } hid_report_id_status_t;
1163cbedd43SMatthias Ringwald 
117*fe796163SMatthias Ringwald // HID Usage Pages
118*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_DESKTOP                   0x01
119*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_SIMULATE                  0x02
120*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_VIRTUAL_REALITY           0x03
121*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_SPORT                     0x04
122*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_GAME                      0x05
123*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_GENERIC_DEVICE            0x06
124*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_KEYBOARD                  0x07
125*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_LED                       0x08
126*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_BUTTON                    0x09
127*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_ORDINAL                   0x0a
128*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_TELEPHONY                 0x0b
129*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_CONSUMER                  0x0c
130*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_DIGITIZER                 0x0d
131*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_PID                       0x0f
132*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_UNICODE                   0x10
133*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_ALPHA_DISPLAY             0x14
134*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_MEDICAL                   0x40
135*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_LIGHTING_AND_ILLUMINATION 0x59
136*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_MONITOR                   0x80    // 0x80 - 0x83
137*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_POWER                     0x84    // 0x084 - 0x87
138*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_BARCODE_SCANNER           0x8c
139*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_SCALE                     0x8d
140*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_MSR                       0x8e
141*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_CAMERA                    0x90
142*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_ARCADE                    0x91
143*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_FIDO                      0xF1D0  // FIDO alliance
144*fe796163SMatthias Ringwald #define HID_USAGE_PAGE_VENDOR                    0xFF00  // 0xFF00 - 0xFFFF
145*fe796163SMatthias Ringwald 
146*fe796163SMatthias Ringwald // HID Usage Keyboard (partial) 0x0007
147*fe796163SMatthias Ringwald #define HID_USAGE_KEY_RESERVED                   0x00
148*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_CAPS_LOCK         0x39
149*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_SCROLL_LOCK       0x47
150*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYPAD_NUM_LOCK_AND_CLEAR  0x53
151*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_LEFTCONTROL       0xE0
152*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_LEFTSHIFT         0xE1
153*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_LEFTALT           0xE2
154*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_LEFT_GUI          0xE3
155*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_RIGHTCONTROL      0xE4
156*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_RIGHTSHIFT        0xE5
157*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_RIGHTALT          0xE6
158*fe796163SMatthias Ringwald #define HID_USAGE_KEY_KEYBOARD_RIGHT_GUI         0xE7
159*fe796163SMatthias Ringwald 
160*fe796163SMatthias Ringwald // HID Usage LED (partial) 0x0008
161*fe796163SMatthias Ringwald #define HID_USAGE_LED_NUM_LOCK                   0x01
162*fe796163SMatthias Ringwald #define HID_USAGE_LED_CAPS_LOCK                  0x02
163*fe796163SMatthias Ringwald #define HID_USAGE_LED_SCROLL_LOCK                0x03
164*fe796163SMatthias Ringwald #define HID_USAGE_LED_COMPOSE                    0x04
165*fe796163SMatthias Ringwald #define HID_USAGE_LED_KANA                       0x05
166*fe796163SMatthias Ringwald #define HID_USAGE_LED_POWER                      0x06
167*fe796163SMatthias Ringwald #define HID_USAGE_LED_SHIFT                      0x07
168*fe796163SMatthias Ringwald 
169*fe796163SMatthias Ringwald 
1703cbedd43SMatthias Ringwald /* API_START */
1713cbedd43SMatthias Ringwald 
1723cbedd43SMatthias Ringwald /*
1733cbedd43SMatthias Ringwald  * @brief Get boot descriptor data
1743cbedd43SMatthias Ringwald  * @result data
1753cbedd43SMatthias Ringwald  */
176e9933dfeSMatthias Ringwald const uint8_t * btstack_hid_get_boot_descriptor_data(void);
1773cbedd43SMatthias Ringwald 
1783cbedd43SMatthias Ringwald /*
1793cbedd43SMatthias Ringwald  * @brief Get boot descriptor length
1803cbedd43SMatthias Ringwald  * @result length
1813cbedd43SMatthias Ringwald  */
182e9933dfeSMatthias Ringwald uint16_t btstack_hid_get_boot_descriptor_len(void);
1833cbedd43SMatthias Ringwald 
1843cbedd43SMatthias Ringwald /* API_END */
1853cbedd43SMatthias Ringwald 
1863cbedd43SMatthias Ringwald #if defined __cplusplus
1873cbedd43SMatthias Ringwald }
1883cbedd43SMatthias Ringwald #endif
1893cbedd43SMatthias Ringwald 
1903cbedd43SMatthias Ringwald #endif
191