esp_bt.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_BT_H__
  14. #define __ESP_BT_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "sdkconfig.h"
  19. #include "esp_task.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL 0x20200622
  24. /**
  25. * @brief Bluetooth mode for controller enable/disable
  26. */
  27. typedef enum {
  28. ESP_BT_MODE_IDLE = 0x00, /*!< Bluetooth is not running */
  29. ESP_BT_MODE_BLE = 0x01, /*!< Run BLE mode */
  30. ESP_BT_MODE_CLASSIC_BT = 0x02, /*!< Run Classic BT mode */
  31. ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */
  32. } esp_bt_mode_t;
  33. /**
  34. * @brief BLE sleep clock accuracy(SCA), values for ble_sca field in esp_bt_controller_config_t,
  35. * currently only ESP_BLE_SCA_500PPM and ESP_BLE_SCA_250PPM are supported
  36. */
  37. enum {
  38. ESP_BLE_SCA_500PPM = 0, /*!< BLE SCA at 500ppm */
  39. ESP_BLE_SCA_250PPM, /*!< BLE SCA at 250ppm */
  40. ESP_BLE_SCA_150PPM, /*!< BLE SCA at 150ppm */
  41. ESP_BLE_SCA_100PPM, /*!< BLE SCA at 100ppm */
  42. ESP_BLE_SCA_75PPM, /*!< BLE SCA at 75ppm */
  43. ESP_BLE_SCA_50PPM, /*!< BLE SCA at 50ppm */
  44. ESP_BLE_SCA_30PPM, /*!< BLE SCA at 30ppm */
  45. ESP_BLE_SCA_20PPM, /*!< BLE SCA at 20ppm */
  46. };
  47. #ifdef CONFIG_BT_ENABLED
  48. /* While scanning, if the free memory value in controller is less than SCAN_SEND_ADV_RESERVED_SIZE,
  49. the adv packet will be discarded until the memory is restored. */
  50. #define SCAN_SEND_ADV_RESERVED_SIZE 1000
  51. /* enable controller log debug when adv lost */
  52. #define CONTROLLER_ADV_LOST_DEBUG_BIT (0<<0)
  53. #ifdef CONFIG_BT_HCI_UART_NO
  54. #define BT_HCI_UART_NO_DEFAULT CONFIG_BT_HCI_UART_NO
  55. #else
  56. #define BT_HCI_UART_NO_DEFAULT 1
  57. #endif /* BT_HCI_UART_NO_DEFAULT */
  58. #ifdef CONFIG_BT_HCI_UART_BAUDRATE
  59. #define BT_HCI_UART_BAUDRATE_DEFAULT CONFIG_BT_HCI_UART_BAUDRATE
  60. #else
  61. #define BT_HCI_UART_BAUDRATE_DEFAULT 921600
  62. #endif /* BT_HCI_UART_BAUDRATE_DEFAULT */
  63. #ifdef CONFIG_BTDM_SCAN_DUPL_TYPE
  64. #define SCAN_DUPLICATE_TYPE_VALUE CONFIG_BTDM_SCAN_DUPL_TYPE
  65. #else
  66. #define SCAN_DUPLICATE_TYPE_VALUE 0
  67. #endif
  68. /* normal adv cache size */
  69. #ifdef CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE
  70. #define NORMAL_SCAN_DUPLICATE_CACHE_SIZE CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE
  71. #else
  72. #define NORMAL_SCAN_DUPLICATE_CACHE_SIZE 20
  73. #endif
  74. #ifndef CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN
  75. #define CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN FALSE
  76. #endif
  77. #define SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY 0
  78. #define SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV 1
  79. #if CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN
  80. #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV
  81. #ifdef CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE
  82. #define MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE
  83. #else
  84. #define MESH_DUPLICATE_SCAN_CACHE_SIZE 50
  85. #endif
  86. #else
  87. #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY
  88. #define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
  89. #endif
  90. #if defined(CONFIG_BTDM_CTRL_MODE_BLE_ONLY)
  91. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_BLE
  92. #elif defined(CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY)
  93. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_CLASSIC_BT
  94. #else
  95. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_BTDM
  96. #endif
  97. #ifdef CONFIG_BTDM_CTRL_AUTO_LATENCY_EFF
  98. #define BTDM_CTRL_AUTO_LATENCY_EFF CONFIG_BTDM_CTRL_AUTO_LATENCY_EFF
  99. #else
  100. #define BTDM_CTRL_AUTO_LATENCY_EFF false
  101. #endif
  102. #ifdef CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF
  103. #define BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF CONFIG_BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF
  104. #else
  105. #define BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF false
  106. #endif
  107. #define BTDM_CONTROLLER_BLE_MAX_CONN_LIMIT 9 //Maximum BLE connection limitation
  108. #define BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_LIMIT 7 //Maximum ACL connection limitation
  109. #define BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_LIMIT 3 //Maximum SCO/eSCO connection limitation
  110. #define BTDM_CONTROLLER_SCO_DATA_PATH_HCI 0 // SCO data is routed to HCI
  111. #define BTDM_CONTROLLER_SCO_DATA_PATH_PCM 1 // SCO data path is PCM
  112. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
  113. .controller_task_stack_size = ESP_TASK_BT_CONTROLLER_STACK, \
  114. .controller_task_prio = ESP_TASK_BT_CONTROLLER_PRIO, \
  115. .hci_uart_no = BT_HCI_UART_NO_DEFAULT, \
  116. .hci_uart_baudrate = BT_HCI_UART_BAUDRATE_DEFAULT, \
  117. .scan_duplicate_mode = SCAN_DUPLICATE_MODE, \
  118. .scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \
  119. .normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE, \
  120. .mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE, \
  121. .send_adv_reserved_size = SCAN_SEND_ADV_RESERVED_SIZE, \
  122. .controller_debug_flag = CONTROLLER_ADV_LOST_DEBUG_BIT, \
  123. .mode = BTDM_CONTROLLER_MODE_EFF, \
  124. .ble_max_conn = CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF, \
  125. .bt_max_acl_conn = CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF, \
  126. .bt_sco_datapath = CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF, \
  127. .auto_latency = BTDM_CTRL_AUTO_LATENCY_EFF, \
  128. .bt_legacy_auth_vs_evt = BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF, \
  129. .bt_max_sync_conn = CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF, \
  130. .ble_sca = CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF, \
  131. .pcm_role = CONFIG_BTDM_CTRL_PCM_ROLE_EFF, \
  132. .pcm_polar = CONFIG_BTDM_CTRL_PCM_POLAR_EFF, \
  133. .magic = ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL, \
  134. };
  135. #else
  136. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; _Static_assert(0, "please enable bluetooth in menuconfig to use bt.h");
  137. #endif
  138. /**
  139. * @brief Controller config options, depend on config mask.
  140. * Config mask indicate which functions enabled, this means
  141. * some options or parameters of some functions enabled by config mask.
  142. */
  143. typedef struct {
  144. /*
  145. * Following parameters can be configured runtime, when call esp_bt_controller_init()
  146. */
  147. uint16_t controller_task_stack_size; /*!< Bluetooth controller task stack size */
  148. uint8_t controller_task_prio; /*!< Bluetooth controller task priority */
  149. uint8_t hci_uart_no; /*!< If use UART1/2 as HCI IO interface, indicate UART number */
  150. uint32_t hci_uart_baudrate; /*!< If use UART1/2 as HCI IO interface, indicate UART baudrate */
  151. uint8_t scan_duplicate_mode; /*!< scan duplicate mode */
  152. uint8_t scan_duplicate_type; /*!< scan duplicate type */
  153. uint16_t normal_adv_size; /*!< Normal adv size for scan duplicate */
  154. uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */
  155. uint16_t send_adv_reserved_size; /*!< Controller minimum memory value */
  156. uint32_t controller_debug_flag; /*!< Controller debug log flag */
  157. uint8_t mode; /*!< Controller mode: BR/EDR, BLE or Dual Mode */
  158. uint8_t ble_max_conn; /*!< BLE maximum connection numbers */
  159. uint8_t bt_max_acl_conn; /*!< BR/EDR maximum ACL connection numbers */
  160. uint8_t bt_sco_datapath; /*!< SCO data path, i.e. HCI or PCM module */
  161. bool auto_latency; /*!< BLE auto latency, used to enhance classic BT performance */
  162. bool bt_legacy_auth_vs_evt; /*!< BR/EDR Legacy auth complete event required to protect from BIAS attack */
  163. /*
  164. * Following parameters can not be configured runtime when call esp_bt_controller_init()
  165. * It will be overwrite with a constant value which in menuconfig or from a macro.
  166. * So, do not modify the value when esp_bt_controller_init()
  167. */
  168. uint8_t bt_max_sync_conn; /*!< BR/EDR maximum ACL connection numbers. Effective in menuconfig */
  169. uint8_t ble_sca; /*!< BLE low power crystal accuracy index */
  170. uint8_t pcm_role; /*!< PCM role (master & slave)*/
  171. uint8_t pcm_polar; /*!< PCM polar trig (falling clk edge & rising clk edge) */
  172. uint32_t magic; /*!< Magic number */
  173. } esp_bt_controller_config_t;
  174. /**
  175. * @brief Bluetooth controller enable/disable/initialised/de-initialised status
  176. */
  177. typedef enum {
  178. ESP_BT_CONTROLLER_STATUS_IDLE = 0,
  179. ESP_BT_CONTROLLER_STATUS_INITED,
  180. ESP_BT_CONTROLLER_STATUS_ENABLED,
  181. ESP_BT_CONTROLLER_STATUS_NUM,
  182. } esp_bt_controller_status_t;
  183. /**
  184. * @brief BLE tx power type
  185. * ESP_BLE_PWR_TYPE_CONN_HDL0-8: for each connection, and only be set after connection completed.
  186. * when disconnect, the correspond TX power is not effected.
  187. * ESP_BLE_PWR_TYPE_ADV : for advertising/scan response.
  188. * ESP_BLE_PWR_TYPE_SCAN : for scan.
  189. * ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value.
  190. * if neither in scan mode nor in adv mode, it will use this default value.
  191. * If none of power type is set, system will use ESP_PWR_LVL_P3 as default for ADV/SCAN/CONN0-9.
  192. */
  193. typedef enum {
  194. ESP_BLE_PWR_TYPE_CONN_HDL0 = 0, /*!< For connection handle 0 */
  195. ESP_BLE_PWR_TYPE_CONN_HDL1 = 1, /*!< For connection handle 1 */
  196. ESP_BLE_PWR_TYPE_CONN_HDL2 = 2, /*!< For connection handle 2 */
  197. ESP_BLE_PWR_TYPE_CONN_HDL3 = 3, /*!< For connection handle 3 */
  198. ESP_BLE_PWR_TYPE_CONN_HDL4 = 4, /*!< For connection handle 4 */
  199. ESP_BLE_PWR_TYPE_CONN_HDL5 = 5, /*!< For connection handle 5 */
  200. ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */
  201. ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */
  202. ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */
  203. ESP_BLE_PWR_TYPE_ADV = 9, /*!< For advertising */
  204. ESP_BLE_PWR_TYPE_SCAN = 10, /*!< For scan */
  205. ESP_BLE_PWR_TYPE_DEFAULT = 11, /*!< For default, if not set other, it will use default value */
  206. ESP_BLE_PWR_TYPE_NUM = 12, /*!< TYPE numbers */
  207. } esp_ble_power_type_t;
  208. /**
  209. * @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm).
  210. */
  211. typedef enum {
  212. ESP_PWR_LVL_N12 = 0, /*!< Corresponding to -12dbm */
  213. ESP_PWR_LVL_N9 = 1, /*!< Corresponding to -9dbm */
  214. ESP_PWR_LVL_N6 = 2, /*!< Corresponding to -6dbm */
  215. ESP_PWR_LVL_N3 = 3, /*!< Corresponding to -3dbm */
  216. ESP_PWR_LVL_N0 = 4, /*!< Corresponding to 0dbm */
  217. ESP_PWR_LVL_P3 = 5, /*!< Corresponding to +3dbm */
  218. ESP_PWR_LVL_P6 = 6, /*!< Corresponding to +6dbm */
  219. ESP_PWR_LVL_P9 = 7, /*!< Corresponding to +9dbm */
  220. ESP_PWR_LVL_N14 = ESP_PWR_LVL_N12, /*!< Backward compatibility! Setting to -14dbm will actually result to -12dbm */
  221. ESP_PWR_LVL_N11 = ESP_PWR_LVL_N9, /*!< Backward compatibility! Setting to -11dbm will actually result to -9dbm */
  222. ESP_PWR_LVL_N8 = ESP_PWR_LVL_N6, /*!< Backward compatibility! Setting to -8dbm will actually result to -6dbm */
  223. ESP_PWR_LVL_N5 = ESP_PWR_LVL_N3, /*!< Backward compatibility! Setting to -5dbm will actually result to -3dbm */
  224. ESP_PWR_LVL_N2 = ESP_PWR_LVL_N0, /*!< Backward compatibility! Setting to -2dbm will actually result to 0dbm */
  225. ESP_PWR_LVL_P1 = ESP_PWR_LVL_P3, /*!< Backward compatibility! Setting to +1dbm will actually result to +3dbm */
  226. ESP_PWR_LVL_P4 = ESP_PWR_LVL_P6, /*!< Backward compatibility! Setting to +4dbm will actually result to +6dbm */
  227. ESP_PWR_LVL_P7 = ESP_PWR_LVL_P9, /*!< Backward compatibility! Setting to +7dbm will actually result to +9dbm */
  228. } esp_power_level_t;
  229. /**
  230. * @brief Bluetooth audio data transport path
  231. */
  232. typedef enum {
  233. ESP_SCO_DATA_PATH_HCI = 0, /*!< data over HCI transport */
  234. ESP_SCO_DATA_PATH_PCM = 1, /*!< data over PCM interface */
  235. } esp_sco_data_path_t;
  236. /**
  237. * @brief Set BLE TX power
  238. * Connection Tx power should only be set after connection created.
  239. * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
  240. * @param power_level: Power level(index) corresponding to absolute value(dbm)
  241. * @return ESP_OK - success, other - failed
  242. */
  243. esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level);
  244. /**
  245. * @brief Get BLE TX power
  246. * Connection Tx power should only be get after connection created.
  247. * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
  248. * @return >= 0 - Power level, < 0 - Invalid
  249. */
  250. esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
  251. /**
  252. * @brief Set BR/EDR TX power
  253. * BR/EDR power control will use the power in range of minimum value and maximum value.
  254. * The power level will effect the global BR/EDR TX power, such inquire, page, connection and so on.
  255. * Please call the function after esp_bt_controller_enable and before any function which cause RF do TX.
  256. * So you can call the function before doing discovery, profile init and so on.
  257. * For example, if you want BR/EDR use the new TX power to do inquire, you should call
  258. * this function before inquire. Another word, If call this function when BR/EDR is in inquire(ING),
  259. * please do inquire again after call this function.
  260. * Default minimum power level is ESP_PWR_LVL_N0, and maximum power level is ESP_PWR_LVL_P3.
  261. * @param min_power_level: The minimum power level
  262. * @param max_power_level: The maximum power level
  263. * @return ESP_OK - success, other - failed
  264. */
  265. esp_err_t esp_bredr_tx_power_set(esp_power_level_t min_power_level, esp_power_level_t max_power_level);
  266. /**
  267. * @brief Get BR/EDR TX power
  268. * If the argument is not NULL, then store the corresponding value.
  269. * @param min_power_level: The minimum power level
  270. * @param max_power_level: The maximum power level
  271. * @return ESP_OK - success, other - failed
  272. */
  273. esp_err_t esp_bredr_tx_power_get(esp_power_level_t *min_power_level, esp_power_level_t *max_power_level);
  274. /**
  275. * @brief set default SCO data path
  276. * Should be called after controller is enabled, and before (e)SCO link is established
  277. * @param data_path: SCO data path
  278. * @return ESP_OK - success, other - failed
  279. */
  280. esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path);
  281. /**
  282. * @brief Initialize BT controller to allocate task and other resource.
  283. * This function should be called only once, before any other BT functions are called.
  284. * @param cfg: Initial configuration of BT controller. Different from previous version, there's a mode and some
  285. * connection configuration in "cfg" to configure controller work mode and allocate the resource which is needed.
  286. * @return ESP_OK - success, other - failed
  287. */
  288. esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
  289. /**
  290. * @brief De-initialize BT controller to free resource and delete task.
  291. *
  292. * This function should be called only once, after any other BT functions are called.
  293. * @return ESP_OK - success, other - failed
  294. */
  295. esp_err_t esp_bt_controller_deinit(void);
  296. /**
  297. * @brief Enable BT controller.
  298. * Due to a known issue, you cannot call esp_bt_controller_enable() a second time
  299. * to change the controller mode dynamically. To change controller mode, call
  300. * esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode.
  301. * @param mode : the mode(BLE/BT/BTDM) to enable. For compatible of API, retain this argument. This mode must be
  302. * equal as the mode in "cfg" of esp_bt_controller_init().
  303. * @return ESP_OK - success, other - failed
  304. */
  305. esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
  306. /**
  307. * @brief Disable BT controller
  308. * @return ESP_OK - success, other - failed
  309. */
  310. esp_err_t esp_bt_controller_disable(void);
  311. /**
  312. * @brief Get BT controller is initialised/de-initialised/enabled/disabled
  313. * @return status value
  314. */
  315. esp_bt_controller_status_t esp_bt_controller_get_status(void);
  316. /**
  317. * @brief Get BT MAC address.
  318. * @return Array pointer of length 6 storing MAC address value.
  319. */
  320. uint8_t* esp_bt_get_mac(void);
  321. /** @brief esp_vhci_host_callback
  322. * used for vhci call host function to notify what host need to do
  323. */
  324. typedef struct esp_vhci_host_callback {
  325. void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
  326. int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< callback used to notify that the controller has a packet to send to the host*/
  327. } esp_vhci_host_callback_t;
  328. /** @brief esp_vhci_host_check_send_available
  329. * used for check actively if the host can send packet to controller or not.
  330. * @return true for ready to send, false means cannot send packet
  331. */
  332. bool esp_vhci_host_check_send_available(void);
  333. /** @brief esp_vhci_host_send_packet
  334. * host send packet to controller
  335. *
  336. * Should not call this function from within a critical section
  337. * or when the scheduler is suspended.
  338. *
  339. * @param data the packet point
  340. * @param len the packet length
  341. */
  342. void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
  343. /** @brief esp_vhci_host_register_callback
  344. * register the vhci reference callback
  345. * struct defined by vhci_host_callback structure.
  346. * @param callback esp_vhci_host_callback type variable
  347. * @return ESP_OK - success, ESP_FAIL - failed
  348. */
  349. esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
  350. /** @brief esp_bt_controller_mem_release
  351. * release the controller memory as per the mode
  352. *
  353. * This function releases the BSS, data and other sections of the controller to heap. The total size is about 70k bytes.
  354. *
  355. * esp_bt_controller_mem_release(mode) should be called only before esp_bt_controller_init()
  356. * or after esp_bt_controller_deinit().
  357. *
  358. * Note that once BT controller memory is released, the process cannot be reversed. It means you cannot use the bluetooth
  359. * mode which you have released by this function.
  360. *
  361. * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
  362. * then do not call this function.
  363. *
  364. * If the app calls esp_bt_controller_enable(ESP_BT_MODE_BLE) to use BLE only then it is safe to call
  365. * esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) at initialization time to free unused BT Classic memory.
  366. *
  367. * If the mode is ESP_BT_MODE_BTDM, then it may be useful to call API esp_bt_mem_release(ESP_BT_MODE_BTDM) instead,
  368. * which internally calls esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) and additionally releases the BSS and data
  369. * consumed by the BT/BLE host stack to heap. For more details about usage please refer to the documentation of
  370. * esp_bt_mem_release() function
  371. *
  372. * @param mode : the mode want to release memory
  373. * @return ESP_OK - success, other - failed
  374. */
  375. esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode);
  376. /** @brief esp_bt_mem_release
  377. * release controller memory and BSS and data section of the BT/BLE host stack as per the mode
  378. *
  379. * This function first releases controller memory by internally calling esp_bt_controller_mem_release().
  380. * Additionally, if the mode is set to ESP_BT_MODE_BTDM, it also releases the BSS and data consumed by the BT/BLE host stack to heap
  381. *
  382. * Note that once BT memory is released, the process cannot be reversed. It means you cannot use the bluetooth
  383. * mode which you have released by this function.
  384. *
  385. * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
  386. * then do not call this function.
  387. *
  388. * If you never intend to use bluetooth in a current boot-up cycle, you can call esp_bt_mem_release(ESP_BT_MODE_BTDM)
  389. * before esp_bt_controller_init or after esp_bt_controller_deinit.
  390. *
  391. * For example, if a user only uses bluetooth for setting the WiFi configuration, and does not use bluetooth in the rest of the product operation".
  392. * In such cases, after receiving the WiFi configuration, you can disable/deinit bluetooth and release its memory.
  393. * Below is the sequence of APIs to be called for such scenarios:
  394. *
  395. * esp_bluedroid_disable();
  396. * esp_bluedroid_deinit();
  397. * esp_bt_controller_disable();
  398. * esp_bt_controller_deinit();
  399. * esp_bt_mem_release(ESP_BT_MODE_BTDM);
  400. *
  401. * @note In case of NimBLE host, to release BSS and data memory to heap, the mode needs to be
  402. * set to ESP_BT_MODE_BTDM as controller is dual mode.
  403. * @param mode : the mode whose memory is to be released
  404. * @return ESP_OK - success, other - failed
  405. */
  406. esp_err_t esp_bt_mem_release(esp_bt_mode_t mode);
  407. /**
  408. * @brief enable bluetooth to enter modem sleep
  409. *
  410. * Note that this function shall not be invoked before esp_bt_controller_enable()
  411. *
  412. * There are currently two options for bluetooth modem sleep, one is ORIG mode, and another is EVED Mode. EVED Mode is intended for BLE only.
  413. *
  414. * For ORIG mode:
  415. * Bluetooth modem sleep is enabled in controller start up by default if CONFIG_BTDM_MODEM_SLEEP is set and "ORIG mode" is selected. In ORIG modem sleep mode, bluetooth controller will switch off some components and pause to work every now and then, if there is no event to process; and wakeup according to the scheduled interval and resume the work. It can also wakeup earlier upon external request using function "esp_bt_controller_wakeup_request".
  416. *
  417. * @return
  418. * - ESP_OK : success
  419. * - other : failed
  420. */
  421. esp_err_t esp_bt_sleep_enable(void);
  422. /**
  423. * @brief disable bluetooth modem sleep
  424. *
  425. * Note that this function shall not be invoked before esp_bt_controller_enable()
  426. *
  427. * If esp_bt_sleep_disable() is called, bluetooth controller will not be allowed to enter modem sleep;
  428. *
  429. * If ORIG modem sleep mode is in use, if this function is called, bluetooth controller may not immediately wake up if it is dormant then.
  430. * In this case, esp_bt_controller_wakeup_request() can be used to shorten the time for wakeup.
  431. *
  432. * @return
  433. * - ESP_OK : success
  434. * - other : failed
  435. */
  436. esp_err_t esp_bt_sleep_disable(void);
  437. /**
  438. * @brief Manually clear scan duplicate list
  439. *
  440. * Note that scan duplicate list will be automatically cleared when the maximum amount of device in the filter is reached
  441. * the amount of device in the filter can be configured in menuconfig.
  442. *
  443. * @note This function name is incorrectly spelled, it will be fixed in release 5.x version.
  444. *
  445. * @return
  446. * - ESP_OK : success
  447. * - other : failed
  448. */
  449. esp_err_t esp_ble_scan_dupilcate_list_flush(void);
  450. #ifdef __cplusplus
  451. }
  452. #endif
  453. #endif /* __ESP_BT_H__ */