1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 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 16 /** 17 * @file wm_bt.h 18 * 19 * @brief Bluetooth API 20 * 21 * @author WinnerMicro 22 * 23 * Copyright (c) 2020 Winner Microelectronics Co., Ltd. 24 */ 25 #ifndef WM_BT_H 26 #define WM_BT_H 27 28 #include "wm_bt_def.h" 29 30 /** 31 * @defgroup BT_APIs Bluetooth APIs 32 * @brief Bluetooth related APIs 33 */ 34 35 /** 36 * @addtogroup BT_APIs 37 * @{ 38 */ 39 40 /** 41 * @defgroup BT_Host_APIs BT Host APIs 42 * @brief BT Host APIs 43 */ 44 45 /** 46 * @addtogroup BT_Host_APIs 47 * @{ 48 */ 49 50 /** 51 * @brief reply the pin request 52 * 53 * @param[in] *bd_addr remote device address 54 * @param[in] accept 55 * @param[in] pin_len 56 * @param[in] *pin_code 57 * 58 * @return @ref tls_bt_status_t 59 60 * 61 * @note None 62 */ 63 64 tls_bt_status_t tls_bt_pin_reply(const tls_bt_addr_t *bd_addr, uint8_t accept, 65 uint8_t pin_len, tls_bt_pin_code_t *pin_code); 66 67 /** 68 * @brief reply the ssp request 69 * 70 * @param[in] *bd_addr remote device address 71 * @param[in] variant @ref tls_bt_ssp_variant_t 72 * @param[in] accept 73 * @param[in] passkey 74 * 75 * @return @ref tls_bt_status_t 76 * 77 * @note None 78 */ 79 80 tls_bt_status_t tls_bt_ssp_reply(const tls_bt_addr_t *bd_addr, tls_bt_ssp_variant_t variant, 81 uint8_t accept, uint32_t passkey); 82 83 /** 84 * @brief set the adapter property 85 * 86 * @param[in] *property remote device address 87 * @param[in] update_to_flash save the property to flash or not 88 * 89 * @return @ref tls_bt_status_t 90 * 91 * @note None 92 */ 93 tls_bt_status_t tls_bt_set_adapter_property(const tls_bt_property_t *property, uint8_t update_to_flash); 94 95 /** 96 * @brief get the adapter property 97 * 98 * @param[in] type @ref tls_bt_property_type_t 99 * 100 * @return @ref tls_bt_status_t 101 * 102 * @note None 103 */ 104 tls_bt_status_t tls_bt_get_adapter_property(tls_bt_property_type_t type); 105 106 /** 107 * @brief 108 * 109 * @param None 110 * 111 * @return @ref tls_bt_status_t 112 * 113 * @note None 114 */ 115 tls_bt_status_t tls_bt_start_discovery(void); 116 117 /** 118 * @brief 119 * 120 * @param None 121 * 122 * @return @ref tls_bt_status_t 123 * 124 * @note None 125 */ 126 tls_bt_status_t tls_bt_cancel_discovery(void); 127 128 /** 129 * @brief 130 * 131 * @param[in] *bd_addr 132 * @param[in] transport 133 * 134 * @return @ref tls_bt_status_t 135 * 136 * @note None 137 */ 138 tls_bt_status_t tls_bt_create_bond(const tls_bt_addr_t *bd_addr, int transport); 139 140 /** 141 * @brief 142 * 143 * @param[in] *bd_addr 144 * 145 * @return @ref tls_bt_status_t 146 * 147 * @note None 148 */ 149 tls_bt_status_t tls_bt_cancel_bond(const tls_bt_addr_t *bd_addr); 150 151 /** 152 * @brief 153 * 154 * @param[in] *bd_addr 155 * 156 * @return @ref tls_bt_status_t 157 * 158 * @note None 159 */ 160 tls_bt_status_t tls_bt_remove_bond(const tls_bt_addr_t *bd_addr); 161 162 /** 163 * @brief 164 * 165 * @param None 166 * 167 * @return @ref tls_bt_status_t 168 * 169 * @note None 170 */ 171 tls_bt_status_t tls_bt_host_cleanup(void); 172 173 /** 174 * @brief 175 * 176 * @param[in] callback 177 * @param[in] *p_hci_if 178 * @param[in] log_level 179 * 180 * @return @ref tls_bt_status_t 181 * 182 * @note None 183 */ 184 tls_bt_status_t tls_bt_enable(tls_bt_host_callback_t callback, tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level); 185 186 /** 187 * @brief 188 * 189 * @param None 190 * 191 * @return @ref tls_bt_status_t 192 * 193 * @note None 194 */ 195 tls_bt_status_t tls_bt_disable(void); 196 197 /** 198 * @} 199 */ 200 201 /** 202 * @defgroup BT_Controller_APIs BT Controller APIs 203 * @brief BT Controller APIs 204 */ 205 206 /** 207 * @addtogroup BT_Controller_APIs 208 * @{ 209 */ 210 211 /** 212 * @brief enable the bluetooth controller stack 213 * 214 * @param[in] *p_hci_if pointer on uart property 215 * @param[in] log_level @ref tls_bt_log_level_t 216 * 217 * @retval @ref tls_bt_status_t 218 * 219 * @note None 220 */ 221 tls_bt_status_t tls_bt_ctrl_enable(tls_bt_hci_if_t *p_hci_if, tls_bt_log_level_t log_level); 222 223 /** 224 * @brief disable the bluetooth controller stack 225 * 226 * @param None 227 * 228 * @return @ref tls_bt_status_t 229 * 230 * @note None 231 */ 232 tls_bt_status_t tls_bt_ctrl_disable(void); 233 234 /** 235 * @brief configure the ble emit power of different ble handle type 236 * 237 * @param[in] power_type @ref tls_ble_power_type_t 238 * @param[in] power_level_index [1,2,3,4,5] map to[1,4,7,10,13]dBm 239 * 240 * @retval @ref tls_bt_status_t 241 * 242 * @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only. 243 */ 244 tls_bt_status_t tls_ble_set_tx_power(tls_ble_power_type_t power_type, int8_t power_level_index); 245 246 /** 247 * @brief get the ble emit power of different ble handle type 248 * 249 * @param[in] power_type @ref tls_ble_power_type_t 250 * 251 * @retval power value db 252 * 253 * @note power_type, supports TLS_BLE_PWR_TYPE_DEFAULT only. 254 */ 255 int8_t tls_ble_get_tx_power(tls_ble_power_type_t power_type); 256 257 /** 258 * @brief configure the classic/enhanced bluetooth transmit power 259 * 260 * @param[in] min_power_level power level[1,13]dBm 261 * @param[in] max_power_level power level[1,13]dBm 262 * 263 * @retval @ref tls_bt_status_t 264 * 265 * @note None 266 */ 267 tls_bt_status_t tls_bredr_set_tx_power(int8_t min_power_level, int8_t max_power_level); 268 269 /** 270 * @brief get the classic/enhanced bluetooth transmit power level 271 * 272 * @param[in] *min_power_level pointer on min_power_level 273 * @param[in] *max_power_level pointer on max_power_level 274 * 275 * @retval @ref tls_bt_status_t 276 * 277 * @note None 278 */ 279 tls_bt_status_t tls_bredr_get_tx_power(int8_t* min_power_level, int8_t* max_power_level); 280 281 /** 282 * @brief configure the voice output path 283 * 284 * @param[in] data_path @ref tls_sco_data_path_t 285 * 286 * @retval @ref tls_bt_status_t 287 * 288 * @note None 289 */ 290 tls_bt_status_t tls_bredr_sco_datapath_set(tls_sco_data_path_t data_path); 291 292 /** 293 * @brief get controller stack status 294 * 295 * @param None 296 * 297 * @retval @ref tls_bt_ctrl_status_t 298 * 299 * @note None 300 */ 301 tls_bt_ctrl_status_t tls_bt_controller_get_status(void); 302 303 /** 304 * @brief this function receive the hci message from host hci_h4 inteface 305 * 306 * @param[in] *data hci formated message 307 * @param[in] len command length 308 * 309 * @retval @ref tls_bt_ctrl_status_t 310 * 311 * @note None 312 */ 313 tls_bt_status_t tls_bt_vuart_host_send_packet(uint8_t *data, uint16_t len); 314 315 /** 316 * @brief this function register the host stack receive message function 317 * and indication the controller receive hci command avaiable 318 * 319 * @param[in] *p_host_if @ref tls_bt_host_if_t 320 * 321 * @retval @ref tls_bt_ctrl_status_t 322 * 323 * @note None 324 */ 325 tls_bt_status_t tls_bt_ctrl_if_register(const tls_bt_host_if_t *p_host_if); 326 327 /** 328 * @brief this function unregister the host stack receive message function 329 * and indication the controller receive hci command avaiable 330 * 331 * @param None 332 * 333 * @retval @ref tls_bt_ctrl_status_t 334 * 335 * @note None 336 */ 337 tls_bt_status_t tls_bt_ctrl_if_unregister(void); 338 339 /** 340 * @brief this function configure the controller enter into sleep mode when controller 341 * is in idle mode 342 * 343 * @param[in] enable TRUE: enable 344 * FALSE: didsable 345 * 346 * @retval @ref tls_bt_ctrl_status_t 347 * 348 * @note None 349 */ 350 tls_bt_status_t tls_bt_ctrl_sleep(bool enable); 351 352 /** 353 * @brief this function look up the controller is in sleep mode or not 354 * 355 * @param None 356 * 357 * @retval TRUE: sleep mode 358 * FALSE: not sleep mode 359 * 360 * @note None 361 */ 362 bool tls_bt_ctrl_is_sleep(void); 363 364 /** 365 * @brief this function wake up the controller, in other words exit sleep mode 366 * 367 * @param None 368 * 369 * @retval @ref tls_bt_ctrl_status_t 370 * 371 * @note None 372 */ 373 tls_bt_status_t tls_bt_ctrl_wakeup(void); 374 375 /** 376 * @brief this function check controller can handle hci commands yes or no 377 * 378 * @param None 379 * 380 * @retval @ref bool TRUE or FALSE 381 * 382 * @note None 383 */ 384 385 bool tls_bt_vuart_host_check_send_available(void); 386 387 /** 388 * @brief this function exit bluetooth test mode 389 * 390 * @param None 391 * 392 * @retval @ref tls_bt_ctrl_status_t 393 * 394 * @note None 395 */ 396 tls_bt_status_t exit_bt_test_mode(void); 397 398 /** 399 * @brief this function enable bluetooth test mode 400 * 401 * @param[in] p_hci_if, specific the uart port property 402 * 403 * @retval @ref tls_bt_ctrl_status_t 404 * 405 * @note None 406 */ 407 408 tls_bt_status_t enable_bt_test_mode(tls_bt_hci_if_t *p_hci_if); 409 410 /** 411 * @brief this function enable rf to bluetooth mode 412 * 413 * @param[in] 1, bluetooth mode, 0 wifi/bluetooth mode 414 * 415 * @retval None 416 * 417 * @note None 418 */ 419 420 void tls_rf_bt_mode(uint8_t enable); 421 422 /** 423 * @} 424 */ 425 426 /** 427 * @} 428 */ 429 430 #endif /* WM_BT_H */ 431 432