esp_bt.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 0x5A5AA5A5
  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. #ifdef CONFIG_BT_ENABLED
  34. /* While scanning, if the free memory value in controller is less than SCAN_SEND_ADV_RESERVED_SIZE,
  35. the adv packet will be discarded until the memory is restored. */
  36. #define SCAN_SEND_ADV_RESERVED_SIZE 1000
  37. /* enable controller log debug when adv lost */
  38. #define CONTROLLER_ADV_LOST_DEBUG_BIT (0<<0)
  39. #ifdef CONFIG_BT_HCI_UART_NO
  40. #define BT_HCI_UART_NO_DEFAULT CONFIG_BT_HCI_UART_NO
  41. #else
  42. #define BT_HCI_UART_NO_DEFAULT 1
  43. #endif /* BT_HCI_UART_NO_DEFAULT */
  44. #ifdef CONFIG_BT_HCI_UART_BAUDRATE
  45. #define BT_HCI_UART_BAUDRATE_DEFAULT CONFIG_BT_HCI_UART_BAUDRATE
  46. #else
  47. #define BT_HCI_UART_BAUDRATE_DEFAULT 921600
  48. #endif /* BT_HCI_UART_BAUDRATE_DEFAULT */
  49. #ifdef CONFIG_SCAN_DUPLICATE_TYPE
  50. #define SCAN_DUPLICATE_TYPE_VALUE CONFIG_SCAN_DUPLICATE_TYPE
  51. #else
  52. #define SCAN_DUPLICATE_TYPE_VALUE 0
  53. #endif
  54. /* normal adv cache size */
  55. #ifdef CONFIG_DUPLICATE_SCAN_CACHE_SIZE
  56. #define NORMAL_SCAN_DUPLICATE_CACHE_SIZE CONFIG_DUPLICATE_SCAN_CACHE_SIZE
  57. #else
  58. #define NORMAL_SCAN_DUPLICATE_CACHE_SIZE 20
  59. #endif
  60. #ifndef CONFIG_BLE_MESH_SCAN_DUPLICATE_EN
  61. #define CONFIG_BLE_MESH_SCAN_DUPLICATE_EN FALSE
  62. #endif
  63. #define SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY 0
  64. #define SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV 1
  65. #if CONFIG_BLE_MESH_SCAN_DUPLICATE_EN
  66. #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV
  67. #ifdef CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE
  68. #define MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE
  69. #else
  70. #define MESH_DUPLICATE_SCAN_CACHE_SIZE 50
  71. #endif
  72. #else
  73. #define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY
  74. #define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
  75. #endif
  76. #if defined(CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY)
  77. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_BLE
  78. #elif defined(CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY)
  79. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_CLASSIC_BT
  80. #else
  81. #define BTDM_CONTROLLER_MODE_EFF ESP_BT_MODE_BTDM
  82. #endif
  83. #define BTDM_CONTROLLER_BLE_MAX_CONN_LIMIT 9 //Maximum BLE connection limitation
  84. #define BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_LIMIT 7 //Maximum ACL connection limitation
  85. #define BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_LIMIT 3 //Maximum SCO/eSCO connection limitation
  86. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
  87. .controller_task_stack_size = ESP_TASK_BT_CONTROLLER_STACK, \
  88. .controller_task_prio = ESP_TASK_BT_CONTROLLER_PRIO, \
  89. .hci_uart_no = BT_HCI_UART_NO_DEFAULT, \
  90. .hci_uart_baudrate = BT_HCI_UART_BAUDRATE_DEFAULT, \
  91. .scan_duplicate_mode = SCAN_DUPLICATE_MODE, \
  92. .scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE, \
  93. .normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE, \
  94. .mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE, \
  95. .send_adv_reserved_size = SCAN_SEND_ADV_RESERVED_SIZE, \
  96. .controller_debug_flag = CONTROLLER_ADV_LOST_DEBUG_BIT, \
  97. .mode = BTDM_CONTROLLER_MODE_EFF, \
  98. .ble_max_conn = CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF, \
  99. .bt_max_acl_conn = CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_ACL_CONN_EFF, \
  100. .bt_max_sync_conn = CONFIG_BTDM_CONTROLLER_BR_EDR_MAX_SYNC_CONN_EFF, \
  101. .magic = ESP_BT_CONTROLLER_CONFIG_MAGIC_VAL, \
  102. };
  103. #else
  104. #define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; _Static_assert(0, "please enable bluetooth in menuconfig to use bt.h");
  105. #endif
  106. /**
  107. * @brief Controller config options, depend on config mask.
  108. * Config mask indicate which functions enabled, this means
  109. * some options or parameters of some functions enabled by config mask.
  110. */
  111. typedef struct {
  112. /*
  113. * Following parameters can be configured runtime, when call esp_bt_controller_init()
  114. */
  115. uint16_t controller_task_stack_size; /*!< Bluetooth controller task stack size */
  116. uint8_t controller_task_prio; /*!< Bluetooth controller task priority */
  117. uint8_t hci_uart_no; /*!< If use UART1/2 as HCI IO interface, indicate UART number */
  118. uint32_t hci_uart_baudrate; /*!< If use UART1/2 as HCI IO interface, indicate UART baudrate */
  119. uint8_t scan_duplicate_mode; /*!< scan duplicate mode */
  120. uint8_t scan_duplicate_type; /*!< scan duplicate type */
  121. uint16_t normal_adv_size; /*!< Normal adv size for scan duplicate */
  122. uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */
  123. uint16_t send_adv_reserved_size; /*!< Controller minimum memory value */
  124. uint32_t controller_debug_flag; /*!< Controller debug log flag */
  125. uint8_t mode; /*!< Controller mode: BR/EDR, BLE or Dual Mode */
  126. uint8_t ble_max_conn; /*!< BLE maximum connection numbers */
  127. uint8_t bt_max_acl_conn; /*!< BR/EDR maximum ACL connection numbers */
  128. /*
  129. * Following parameters can not be configured runtime when call esp_bt_controller_init()
  130. * It will be overwrite with a constant value which in menuconfig or from a macro.
  131. * So, do not modify the value when esp_bt_controller_init()
  132. */
  133. uint8_t bt_max_sync_conn; /*!< BR/EDR maximum ACL connection numbers. Effective in menuconfig */
  134. uint32_t magic; /*!< Magic number */
  135. } esp_bt_controller_config_t;
  136. /**
  137. * @brief Bluetooth controller enable/disable/initialised/de-initialised status
  138. */
  139. typedef enum {
  140. ESP_BT_CONTROLLER_STATUS_IDLE = 0,
  141. ESP_BT_CONTROLLER_STATUS_INITED,
  142. ESP_BT_CONTROLLER_STATUS_ENABLED,
  143. ESP_BT_CONTROLLER_STATUS_NUM,
  144. } esp_bt_controller_status_t;
  145. /**
  146. * @brief BLE tx power type
  147. * ESP_BLE_PWR_TYPE_CONN_HDL0-8: for each connection, and only be set after connection completed.
  148. * when disconnect, the correspond TX power is not effected.
  149. * ESP_BLE_PWR_TYPE_ADV : for advertising/scan response.
  150. * ESP_BLE_PWR_TYPE_SCAN : for scan.
  151. * ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value.
  152. * if neither in scan mode nor in adv mode, it will use this default value.
  153. * If none of power type is set, system will use ESP_PWR_LVL_P3 as default for ADV/SCAN/CONN0-9.
  154. */
  155. typedef enum {
  156. ESP_BLE_PWR_TYPE_CONN_HDL0 = 0, /*!< For connection handle 0 */
  157. ESP_BLE_PWR_TYPE_CONN_HDL1 = 1, /*!< For connection handle 1 */
  158. ESP_BLE_PWR_TYPE_CONN_HDL2 = 2, /*!< For connection handle 2 */
  159. ESP_BLE_PWR_TYPE_CONN_HDL3 = 3, /*!< For connection handle 3 */
  160. ESP_BLE_PWR_TYPE_CONN_HDL4 = 4, /*!< For connection handle 4 */
  161. ESP_BLE_PWR_TYPE_CONN_HDL5 = 5, /*!< For connection handle 5 */
  162. ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */
  163. ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */
  164. ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */
  165. ESP_BLE_PWR_TYPE_ADV = 9, /*!< For advertising */
  166. ESP_BLE_PWR_TYPE_SCAN = 10, /*!< For scan */
  167. ESP_BLE_PWR_TYPE_DEFAULT = 11, /*!< For default, if not set other, it will use default value */
  168. ESP_BLE_PWR_TYPE_NUM = 12, /*!< TYPE numbers */
  169. } esp_ble_power_type_t;
  170. /**
  171. * @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm).
  172. */
  173. typedef enum {
  174. ESP_PWR_LVL_N12 = 0, /*!< Corresponding to -12dbm */
  175. ESP_PWR_LVL_N9 = 1, /*!< Corresponding to -9dbm */
  176. ESP_PWR_LVL_N6 = 2, /*!< Corresponding to -6dbm */
  177. ESP_PWR_LVL_N3 = 3, /*!< Corresponding to -3dbm */
  178. ESP_PWR_LVL_N0 = 4, /*!< Corresponding to 0dbm */
  179. ESP_PWR_LVL_P3 = 5, /*!< Corresponding to +3dbm */
  180. ESP_PWR_LVL_P6 = 6, /*!< Corresponding to +6dbm */
  181. ESP_PWR_LVL_P9 = 7, /*!< Corresponding to +9dbm */
  182. ESP_PWR_LVL_N14 = ESP_PWR_LVL_N12, /*!< Backward compatibility! Setting to -14dbm will actually result to -12dbm */
  183. ESP_PWR_LVL_N11 = ESP_PWR_LVL_N9, /*!< Backward compatibility! Setting to -11dbm will actually result to -9dbm */
  184. ESP_PWR_LVL_N8 = ESP_PWR_LVL_N6, /*!< Backward compatibility! Setting to -8dbm will actually result to -6dbm */
  185. ESP_PWR_LVL_N5 = ESP_PWR_LVL_N3, /*!< Backward compatibility! Setting to -5dbm will actually result to -3dbm */
  186. ESP_PWR_LVL_N2 = ESP_PWR_LVL_N0, /*!< Backward compatibility! Setting to -2dbm will actually result to 0dbm */
  187. ESP_PWR_LVL_P1 = ESP_PWR_LVL_P3, /*!< Backward compatibility! Setting to +1dbm will actually result to +3dbm */
  188. ESP_PWR_LVL_P4 = ESP_PWR_LVL_P6, /*!< Backward compatibility! Setting to +4dbm will actually result to +6dbm */
  189. ESP_PWR_LVL_P7 = ESP_PWR_LVL_P9, /*!< Backward compatibility! Setting to +7dbm will actually result to +9dbm */
  190. } esp_power_level_t;
  191. /**
  192. * @brief Bluetooth audio data transport path
  193. */
  194. typedef enum {
  195. ESP_SCO_DATA_PATH_HCI = 0, /*!< data over HCI transport */
  196. ESP_SCO_DATA_PATH_PCM = 1, /*!< data over PCM interface */
  197. } esp_sco_data_path_t;
  198. /**
  199. * @brief Set BLE TX power
  200. * Connection Tx power should only be set after connection created.
  201. * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
  202. * @param power_level: Power level(index) corresponding to absolute value(dbm)
  203. * @return ESP_OK - success, other - failed
  204. */
  205. esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level);
  206. /**
  207. * @brief Get BLE TX power
  208. * Connection Tx power should only be get after connection created.
  209. * @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
  210. * @return >= 0 - Power level, < 0 - Invalid
  211. */
  212. esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
  213. /**
  214. * @brief Set BR/EDR TX power
  215. * BR/EDR power control will use the power in range of minimum value and maximum value.
  216. * The power level will effect the global BR/EDR TX power, such inquire, page, connection and so on.
  217. * Please call the function after esp_bt_controller_enable and before any function which cause RF do TX.
  218. * So you can call the function before doing discovery, profile init and so on.
  219. * For example, if you want BR/EDR use the new TX power to do inquire, you should call
  220. * this function before inquire. Another word, If call this function when BR/EDR is in inquire(ING),
  221. * please do inquire again after call this function.
  222. * Default minimum power level is ESP_PWR_LVL_N0, and maximum power level is ESP_PWR_LVL_P3.
  223. * @param min_power_level: The minimum power level
  224. * @param max_power_level: The maximum power level
  225. * @return ESP_OK - success, other - failed
  226. */
  227. esp_err_t esp_bredr_tx_power_set(esp_power_level_t min_power_level, esp_power_level_t max_power_level);
  228. /**
  229. * @brief Get BR/EDR TX power
  230. * If the argument is not NULL, then store the corresponding value.
  231. * @param min_power_level: The minimum power level
  232. * @param max_power_level: The maximum power level
  233. * @return ESP_OK - success, other - failed
  234. */
  235. esp_err_t esp_bredr_tx_power_get(esp_power_level_t *min_power_level, esp_power_level_t *max_power_level);
  236. /**
  237. * @brief set default SCO data path
  238. * Should be called after controller is enabled, and before (e)SCO link is established
  239. * @param data_path: SCO data path
  240. * @return ESP_OK - success, other - failed
  241. */
  242. esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path);
  243. /**
  244. * @brief Initialize BT controller to allocate task and other resource.
  245. * This function should be called only once, before any other BT functions are called.
  246. * @param cfg: Initial configuration of BT controller. Different from previous version, there's a mode and some
  247. * connection configuration in "cfg" to configure controller work mode and allocate the resource which is needed.
  248. * @return ESP_OK - success, other - failed
  249. */
  250. esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
  251. /**
  252. * @brief De-initialize BT controller to free resource and delete task.
  253. *
  254. * This function should be called only once, after any other BT functions are called.
  255. * This function is not whole completed, esp_bt_controller_init cannot called after this function.
  256. * @return ESP_OK - success, other - failed
  257. */
  258. esp_err_t esp_bt_controller_deinit(void);
  259. /**
  260. * @brief Enable BT controller.
  261. * Due to a known issue, you cannot call esp_bt_controller_enable() a second time
  262. * to change the controller mode dynamically. To change controller mode, call
  263. * esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode.
  264. * @param mode : the mode(BLE/BT/BTDM) to enable. For compatible of API, retain this argument. This mode must be
  265. * equal as the mode in "cfg" of esp_bt_controller_init().
  266. * @return ESP_OK - success, other - failed
  267. */
  268. esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
  269. /**
  270. * @brief Disable BT controller
  271. * @return ESP_OK - success, other - failed
  272. */
  273. esp_err_t esp_bt_controller_disable(void);
  274. /**
  275. * @brief Get BT controller is initialised/de-initialised/enabled/disabled
  276. * @return status value
  277. */
  278. esp_bt_controller_status_t esp_bt_controller_get_status(void);
  279. /** @brief esp_vhci_host_callback
  280. * used for vhci call host function to notify what host need to do
  281. */
  282. typedef struct esp_vhci_host_callback {
  283. void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
  284. 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*/
  285. } esp_vhci_host_callback_t;
  286. /** @brief esp_vhci_host_check_send_available
  287. * used for check actively if the host can send packet to controller or not.
  288. * @return true for ready to send, false means cannot send packet
  289. */
  290. bool esp_vhci_host_check_send_available(void);
  291. /** @brief esp_vhci_host_send_packet
  292. * host send packet to controller
  293. *
  294. * Should not call this function from within a critical section
  295. * or when the scheduler is suspended.
  296. *
  297. * @param data the packet point
  298. * @param len the packet length
  299. */
  300. void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
  301. /** @brief esp_vhci_host_register_callback
  302. * register the vhci reference callback
  303. * struct defined by vhci_host_callback structure.
  304. * @param callback esp_vhci_host_callback type variable
  305. * @return ESP_OK - success, ESP_FAIL - failed
  306. */
  307. esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
  308. /** @brief esp_bt_controller_mem_release
  309. * release the controller memory as per the mode
  310. *
  311. * This function releases the BSS, data and other sections of the controller to heap. The total size is about 70k bytes.
  312. *
  313. * esp_bt_controller_mem_release(mode) should be called only before esp_bt_controller_init()
  314. * or after esp_bt_controller_deinit().
  315. *
  316. * Note that once BT controller memory is released, the process cannot be reversed. It means you cannot use the bluetooth
  317. * mode which you have released by this function.
  318. *
  319. * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
  320. * then do not call this function.
  321. *
  322. * If the app calls esp_bt_controller_enable(ESP_BT_MODE_BLE) to use BLE only then it is safe to call
  323. * esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) at initialization time to free unused BT Classic memory.
  324. *
  325. * 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,
  326. * which internally calls esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) and additionally releases the BSS and data
  327. * consumed by the BT/BLE host stack to heap. For more details about usage please refer to the documentation of
  328. * esp_bt_mem_release() function
  329. *
  330. * @param mode : the mode want to release memory
  331. * @return ESP_OK - success, other - failed
  332. */
  333. esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode);
  334. /** @brief esp_bt_mem_release
  335. * release controller memory and BSS and data section of the BT/BLE host stack as per the mode
  336. *
  337. * This function first releases controller memory by internally calling esp_bt_controller_mem_release().
  338. * 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
  339. *
  340. * Note that once BT memory is released, the process cannot be reversed. It means you cannot use the bluetooth
  341. * mode which you have released by this function.
  342. *
  343. * If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
  344. * then do not call this function.
  345. *
  346. * If you never intend to use bluetooth in a current boot-up cycle, you can call esp_bt_mem_release(ESP_BT_MODE_BTDM)
  347. * before esp_bt_controller_init or after esp_bt_controller_deinit.
  348. *
  349. * 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".
  350. * In such cases, after receiving the WiFi configuration, you can disable/deinit bluetooth and release its memory.
  351. * Below is the sequence of APIs to be called for such scenarios:
  352. *
  353. * esp_bluedroid_disable();
  354. * esp_bluedroid_deinit();
  355. * esp_bt_controller_disable();
  356. * esp_bt_controller_deinit();
  357. * esp_bt_mem_release(ESP_BT_MODE_BTDM);
  358. *
  359. * @param mode : the mode whose memory is to be released
  360. * @return ESP_OK - success, other - failed
  361. */
  362. esp_err_t esp_bt_mem_release(esp_bt_mode_t mode);
  363. /**
  364. * @brief enable bluetooth to enter modem sleep
  365. *
  366. * Note that this function shall not be invoked before esp_bt_controller_enable()
  367. *
  368. * 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.
  369. *
  370. * For ORIG mode:
  371. * Bluetooth modem sleep is enabled in controller start up by default if CONFIG_BTDM_CONTROLLER_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".
  372. *
  373. * @return
  374. * - ESP_OK : success
  375. * - other : failed
  376. */
  377. esp_err_t esp_bt_sleep_enable(void);
  378. /**
  379. * @brief disable bluetooth modem sleep
  380. *
  381. * Note that this function shall not be invoked before esp_bt_controller_enable()
  382. *
  383. * If esp_bt_sleep_disable() is called, bluetooth controller will not be allowed to enter modem sleep;
  384. *
  385. * 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.
  386. * In this case, esp_bt_controller_wakeup_request() can be used to shorten the time for wakeup.
  387. *
  388. * @return
  389. * - ESP_OK : success
  390. * - other : failed
  391. */
  392. esp_err_t esp_bt_sleep_disable(void);
  393. /**
  394. * @brief to check whether bluetooth controller is sleeping at the instant, if modem sleep is enabled
  395. *
  396. * Note that this function shall not be invoked before esp_bt_controller_enable()
  397. * This function is supposed to be used ORIG mode of modem sleep
  398. *
  399. * @return true if in modem sleep state, false otherwise
  400. */
  401. bool esp_bt_controller_is_sleeping(void);
  402. /**
  403. * @brief request controller to wakeup from sleeping state during sleep mode
  404. *
  405. * Note that this function shall not be invoked before esp_bt_controller_enable()
  406. * Note that this function is supposed to be used ORIG mode of modem sleep
  407. * Note that after this request, bluetooth controller may again enter sleep as long as the modem sleep is enabled
  408. *
  409. * Profiling shows that it takes several milliseconds to wakeup from modem sleep after this request.
  410. * Generally it takes longer if 32kHz XTAL is used than the main XTAL, due to the lower frequency of the former as the bluetooth low power clock source.
  411. */
  412. void esp_bt_controller_wakeup_request(void);
  413. /**
  414. * @brief Manually clear scan duplicate list
  415. *
  416. * Note that scan duplicate list will be automatically cleared when the maximum amount of device in the filter is reached
  417. * the amount of device in the filter can be configured in menuconfig.
  418. *
  419. *
  420. * @return
  421. * - ESP_OK : success
  422. * - other : failed
  423. */
  424. esp_err_t esp_ble_scan_dupilcate_list_flush(void);
  425. #ifdef __cplusplus
  426. }
  427. #endif
  428. #endif /* __ESP_BT_H__ */