1 // Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __ESP_HIDD_API_H__
16 #define __ESP_HIDD_API_H__
17 
18 #include "esp_bt_defs.h"
19 #include "esp_gatt_defs.h"
20 #include "esp_err.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 typedef enum {
27     ESP_HIDD_EVENT_REG_FINISH = 0,
28     ESP_BAT_EVENT_REG,
29     ESP_HIDD_EVENT_DEINIT_FINISH,
30     ESP_HIDD_EVENT_BLE_CONNECT,
31     ESP_HIDD_EVENT_BLE_DISCONNECT,
32     ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT,
33 } esp_hidd_cb_event_t;
34 
35 /// HID config status
36 typedef enum {
37     ESP_HIDD_STA_CONN_SUCCESS = 0x00,
38     ESP_HIDD_STA_CONN_FAIL    = 0x01,
39 } esp_hidd_sta_conn_state_t;
40 
41 /// HID init status
42 typedef enum {
43     ESP_HIDD_INIT_OK = 0,
44     ESP_HIDD_INIT_FAILED = 1,
45 } esp_hidd_init_state_t;
46 
47 /// HID deinit status
48 typedef enum {
49     ESP_HIDD_DEINIT_OK = 0,
50     ESP_HIDD_DEINIT_FAILED = 0,
51 } esp_hidd_deinit_state_t;
52 
53 #define LEFT_CONTROL_KEY_MASK        (1 << 0)
54 #define LEFT_SHIFT_KEY_MASK          (1 << 1)
55 #define LEFT_ALT_KEY_MASK            (1 << 2)
56 #define LEFT_GUI_KEY_MASK            (1 << 3)
57 #define RIGHT_CONTROL_KEY_MASK       (1 << 4)
58 #define RIGHT_SHIFT_KEY_MASK         (1 << 5)
59 #define RIGHT_ALT_KEY_MASK           (1 << 6)
60 #define RIGHT_GUI_KEY_MASK           (1 << 7)
61 
62 typedef uint8_t key_mask_t;
63 /**
64  * @brief HIDD callback parameters union
65  */
66 typedef union {
67     /**
68 	 * @brief ESP_HIDD_EVENT_INIT_FINISH
69 	 */
70     struct hidd_init_finish_evt_param {
71         esp_hidd_init_state_t state;				/*!< Initial status */
72         esp_gatt_if_t gatts_if;
73     } init_finish;							      /*!< HID callback param of ESP_HIDD_EVENT_INIT_FINISH */
74 
75     /**
76 	 * @brief ESP_HIDD_EVENT_DEINIT_FINISH
77 	 */
78     struct hidd_deinit_finish_evt_param {
79         esp_hidd_deinit_state_t state;				/*!< De-initial status */
80     } deinit_finish;								/*!< HID callback param of ESP_HIDD_EVENT_DEINIT_FINISH */
81 
82     /**
83      * @brief ESP_HIDD_EVENT_CONNECT
84 	 */
85     struct hidd_connect_evt_param {
86         uint16_t conn_id;
87         esp_bd_addr_t remote_bda;                   /*!< HID Remote bluetooth connection index */
88     } connect;									    /*!< HID callback param of ESP_HIDD_EVENT_CONNECT */
89 
90     /**
91      * @brief ESP_HIDD_EVENT_DISCONNECT
92 	 */
93     struct hidd_disconnect_evt_param {
94         esp_bd_addr_t remote_bda;                   /*!< HID Remote bluetooth device address */
95     } disconnect;									/*!< HID callback param of ESP_HIDD_EVENT_DISCONNECT */
96 
97     /**
98      * @brief ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT
99 	 */
100     struct hidd_vendor_write_evt_param {
101         uint16_t conn_id;                           /*!< HID connection index */
102         uint16_t report_id;                         /*!< HID report index */
103         uint16_t length;                            /*!< data length */
104         uint8_t  *data;                             /*!< The pointer to the data */
105     } vendor_write;									/*!< HID callback param of ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT */
106 
107 } esp_hidd_cb_param_t;
108 
109 
110 /**
111  * @brief HID device event callback function type
112  * @param event : Event type
113  * @param param : Point to callback parameter, currently is union type
114  */
115 typedef void (*esp_hidd_event_cb_t) (esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param);
116 
117 
118 
119 /**
120  *
121  * @brief           This function is called to receive hid device callback event
122  *
123  * @param[in]    callbacks: callback functions
124  *
125  * @return         ESP_OK - success, other - failed
126  *
127  */
128 esp_err_t esp_hidd_register_callbacks(esp_hidd_event_cb_t callbacks);
129 
130 /**
131  *
132  * @brief           This function is called to initialize hid device profile
133  *
134  * @return          ESP_OK - success, other - failed
135  *
136  */
137 esp_err_t esp_hidd_profile_init(void);
138 
139 /**
140  *
141  * @brief           This function is called to de-initialize hid device profile
142  *
143  * @return          ESP_OK - success, other - failed
144  *
145  */
146 esp_err_t esp_hidd_profile_deinit(void);
147 
148 /**
149  *
150  * @brief           Get hidd profile version
151  *
152  * @return          Most 8bit significant is Great version, Least 8bit is Sub version
153  *
154  */
155 uint16_t esp_hidd_get_version(void);
156 
157 void esp_hidd_send_consumer_value(uint16_t conn_id, uint8_t key_cmd, bool key_pressed);
158 
159 void esp_hidd_send_keyboard_value(uint16_t conn_id, key_mask_t special_key_mask, uint8_t *keyboard_cmd, uint8_t num_key);
160 
161 void esp_hidd_send_mouse_value(uint16_t conn_id, uint8_t mouse_button, int8_t mickeys_x, int8_t mickeys_y);
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* __ESP_HIDD_API_H__ */
168