xref: /btstack/src/btstack_hid.h (revision 3cbedd4337c5f865d4c28535558ba1f75f168a17)
1*3cbedd43SMatthias Ringwald /*
2*3cbedd43SMatthias Ringwald  * Copyright (C) 2021 BlueKitchen GmbH
3*3cbedd43SMatthias Ringwald  *
4*3cbedd43SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*3cbedd43SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*3cbedd43SMatthias Ringwald  * are met:
7*3cbedd43SMatthias Ringwald  *
8*3cbedd43SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*3cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*3cbedd43SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*3cbedd43SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*3cbedd43SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*3cbedd43SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*3cbedd43SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*3cbedd43SMatthias Ringwald  *    from this software without specific prior written permission.
16*3cbedd43SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*3cbedd43SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*3cbedd43SMatthias Ringwald  *    monetary gain.
19*3cbedd43SMatthias Ringwald  *
20*3cbedd43SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*3cbedd43SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*3cbedd43SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*3cbedd43SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*3cbedd43SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*3cbedd43SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*3cbedd43SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*3cbedd43SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*3cbedd43SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*3cbedd43SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*3cbedd43SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*3cbedd43SMatthias Ringwald  * SUCH DAMAGE.
32*3cbedd43SMatthias Ringwald  *
33*3cbedd43SMatthias Ringwald  * Please inquire about commercial licensing options at
34*3cbedd43SMatthias Ringwald  * [email protected]
35*3cbedd43SMatthias Ringwald  *
36*3cbedd43SMatthias Ringwald  */
37*3cbedd43SMatthias Ringwald 
38*3cbedd43SMatthias Ringwald #ifndef HID_H
39*3cbedd43SMatthias Ringwald #define HID_H
40*3cbedd43SMatthias Ringwald 
41*3cbedd43SMatthias Ringwald #if defined __cplusplus
42*3cbedd43SMatthias Ringwald extern "C" {
43*3cbedd43SMatthias Ringwald #endif
44*3cbedd43SMatthias Ringwald 
45*3cbedd43SMatthias Ringwald 
46*3cbedd43SMatthias Ringwald #include <stdint.h>
47*3cbedd43SMatthias Ringwald 
48*3cbedd43SMatthias Ringwald #define HID_BOOT_MODE_KEYBOARD_ID 1
49*3cbedd43SMatthias Ringwald #define HID_BOOT_MODE_MOUSE_ID    2
50*3cbedd43SMatthias Ringwald 
51*3cbedd43SMatthias Ringwald typedef enum {
52*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HANDSHAKE = 0,
53*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_HID_CONTROL,
54*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_2,
55*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_RESERVED_3,
56*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_REPORT,
57*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_REPORT,
58*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_PROTOCOL,
59*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_PROTOCOL,
60*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED,
61*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED,
62*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATA,
63*3cbedd43SMatthias Ringwald     HID_MESSAGE_TYPE_DATC_DEPRECATED
64*3cbedd43SMatthias Ringwald } hid_message_type_t;
65*3cbedd43SMatthias Ringwald 
66*3cbedd43SMatthias Ringwald typedef enum {
67*3cbedd43SMatthias 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.
68*3cbedd43SMatthias 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.
69*3cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID,    // Invalid report ID transmitted.
70*3cbedd43SMatthias 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.
71*3cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER,    // A parameter value is out of range or inappropriate for the request.
72*3cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E,       // Device could not identify the error condition.
73*3cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_FATAL = 0x0F,         // Restart is essential to resume functionality
74*3cbedd43SMatthias Ringwald     // BTstack custom error codes
75*3cbedd43SMatthias Ringwald     HID_HANDSHAKE_PARAM_TYPE_ERR_DISCONNECT
76*3cbedd43SMatthias Ringwald } hid_handshake_param_type_t;
77*3cbedd43SMatthias Ringwald 
78*3cbedd43SMatthias Ringwald typedef enum {
79*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_NOP_DEPRECATED = 0,              // Deprecated: No Operation.
80*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_HARD_RESET_DEPRECATED,           // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations.
81*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED,           // Deprecated: Device initializes all internal variables and initiates normal operations.
82*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_SUSPEND = 0x03,                  // Go to reduced power mode.
83*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_EXIT_SUSPEND,                    // Exit reduced power mode.
84*3cbedd43SMatthias Ringwald     HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG
85*3cbedd43SMatthias Ringwald } hid_control_param_t;
86*3cbedd43SMatthias Ringwald 
87*3cbedd43SMatthias Ringwald typedef enum {
88*3cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_BOOT = 0,
89*3cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT,
90*3cbedd43SMatthias Ringwald 
91*3cbedd43SMatthias Ringwald     // the following item is only used for API calls in hid_host.h: hid_host_connect, hid_host_accept_connection
92*3cbedd43SMatthias Ringwald     // in contrast to previous two enum items that will enforce given mode, this one enables fallback from report to boot mode
93*3cbedd43SMatthias Ringwald     HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT
94*3cbedd43SMatthias Ringwald } hid_protocol_mode_t;
95*3cbedd43SMatthias Ringwald 
96*3cbedd43SMatthias Ringwald typedef enum {
97*3cbedd43SMatthias Ringwald     HID_REPORT_TYPE_RESERVED = 0,
98*3cbedd43SMatthias Ringwald     HID_REPORT_TYPE_INPUT,
99*3cbedd43SMatthias Ringwald     HID_REPORT_TYPE_OUTPUT,
100*3cbedd43SMatthias Ringwald     HID_REPORT_TYPE_FEATURE
101*3cbedd43SMatthias Ringwald } hid_report_type_t;
102*3cbedd43SMatthias Ringwald 
103*3cbedd43SMatthias Ringwald typedef enum {
104*3cbedd43SMatthias Ringwald     HID_REPORT_ID_UNDECLARED,
105*3cbedd43SMatthias Ringwald     HID_REPORT_ID_VALID,
106*3cbedd43SMatthias Ringwald     HID_REPORT_ID_INVALID
107*3cbedd43SMatthias Ringwald } hid_report_id_status_t;
108*3cbedd43SMatthias Ringwald 
109*3cbedd43SMatthias Ringwald /* API_START */
110*3cbedd43SMatthias Ringwald 
111*3cbedd43SMatthias Ringwald /*
112*3cbedd43SMatthias Ringwald  * @brief Get boot descriptor data
113*3cbedd43SMatthias Ringwald  * @result data
114*3cbedd43SMatthias Ringwald  */
115*3cbedd43SMatthias Ringwald const uint8_t * hid_get_boot_descriptor_data(void);
116*3cbedd43SMatthias Ringwald 
117*3cbedd43SMatthias Ringwald /*
118*3cbedd43SMatthias Ringwald  * @brief Get boot descriptor length
119*3cbedd43SMatthias Ringwald  * @result length
120*3cbedd43SMatthias Ringwald  */
121*3cbedd43SMatthias Ringwald uint16_t hid_get_boot_descriptor_len(void);
122*3cbedd43SMatthias Ringwald 
123*3cbedd43SMatthias Ringwald /* API_END */
124*3cbedd43SMatthias Ringwald 
125*3cbedd43SMatthias Ringwald #if defined __cplusplus
126*3cbedd43SMatthias Ringwald }
127*3cbedd43SMatthias Ringwald #endif
128*3cbedd43SMatthias Ringwald 
129*3cbedd43SMatthias Ringwald #endif
130