xref: /btstack/src/btstack_hid.h (revision 2c4f9bbb6d93b3f1a90ed62ac67e4cd019f0736a)
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 MATTHIAS
24  * RINGWALD 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 #ifndef HID_H
39 #define HID_H
40 
41 #if defined __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 #include <stdint.h>
47 
48 #define HID_BOOT_MODE_KEYBOARD_ID 1
49 #define HID_BOOT_MODE_MOUSE_ID    2
50 
51 typedef enum {
52     HID_MESSAGE_TYPE_HANDSHAKE = 0,
53     HID_MESSAGE_TYPE_HID_CONTROL,
54     HID_MESSAGE_TYPE_RESERVED_2,
55     HID_MESSAGE_TYPE_RESERVED_3,
56     HID_MESSAGE_TYPE_GET_REPORT,
57     HID_MESSAGE_TYPE_SET_REPORT,
58     HID_MESSAGE_TYPE_GET_PROTOCOL,
59     HID_MESSAGE_TYPE_SET_PROTOCOL,
60     HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED,
61     HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED,
62     HID_MESSAGE_TYPE_DATA,
63     HID_MESSAGE_TYPE_DATC_DEPRECATED
64 } hid_message_type_t;
65 
66 typedef enum {
67     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     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     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID,    // Invalid report ID transmitted.
70     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     HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER,    // A parameter value is out of range or inappropriate for the request.
72     HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E,       // Device could not identify the error condition.
73     HID_HANDSHAKE_PARAM_TYPE_ERR_FATAL = 0x0F,         // Restart is essential to resume functionality
74     // BTstack custom error codes
75     HID_HANDSHAKE_PARAM_TYPE_ERR_DISCONNECT
76 } hid_handshake_param_type_t;
77 
78 typedef enum {
79     HID_CONTROL_PARAM_NOP_DEPRECATED = 0,              // Deprecated: No Operation.
80     HID_CONTROL_PARAM_HARD_RESET_DEPRECATED,           // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations.
81     HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED,           // Deprecated: Device initializes all internal variables and initiates normal operations.
82     HID_CONTROL_PARAM_SUSPEND = 0x03,                  // Go to reduced power mode.
83     HID_CONTROL_PARAM_EXIT_SUSPEND,                    // Exit reduced power mode.
84     HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG
85 } hid_control_param_t;
86 
87 typedef enum {
88     HID_PROTOCOL_MODE_BOOT = 0,
89     HID_PROTOCOL_MODE_REPORT,
90 
91     // the following item is only used for API calls in hid_host.h: hid_host_connect, hid_host_accept_connection
92     // in contrast to previous two enum items that will enforce given mode, this one enables fallback from report to boot mode
93     HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT
94 } hid_protocol_mode_t;
95 
96 typedef enum {
97     HID_REPORT_TYPE_RESERVED = 0,
98     HID_REPORT_TYPE_INPUT,
99     HID_REPORT_TYPE_OUTPUT,
100     HID_REPORT_TYPE_FEATURE
101 } hid_report_type_t;
102 
103 typedef enum {
104     HID_REPORT_ID_UNDECLARED,
105     HID_REPORT_ID_VALID,
106     HID_REPORT_ID_INVALID
107 } hid_report_id_status_t;
108 
109 /* API_START */
110 
111 /*
112  * @brief Get boot descriptor data
113  * @result data
114  */
115 const uint8_t * hid_get_boot_descriptor_data(void);
116 
117 /*
118  * @brief Get boot descriptor length
119  * @result length
120  */
121 uint16_t hid_get_boot_descriptor_len(void);
122 
123 /* API_END */
124 
125 #if defined __cplusplus
126 }
127 #endif
128 
129 #endif
130