2021-10-13 17:10:57 +08:00
/*
2025-02-25 15:17:49 +08:00
* SPDX - FileCopyrightText : 2015 - 2025 Espressif Systems ( Shanghai ) CO LTD
2021-10-13 17:10:57 +08:00
*
* SPDX - License - Identifier : Apache - 2.0
*/
2017-12-07 21:48:27 +08:00
# ifndef __ESP_BT_H__
# define __ESP_BT_H__
# include <stdint.h>
# include <stdbool.h>
# include "esp_err.h"
# include "sdkconfig.h"
# include "esp_task.h"
2022-10-13 12:01:27 +08:00
# include "esp_assert.h"
2017-12-07 21:48:27 +08:00
# ifdef __cplusplus
extern " C " {
# endif
2024-12-03 11:37:18 +08:00
/**
* @ brief Internal use only
*
* @ note Please do not modify this value
*/
2020-07-09 20:58:13 +08:00
# define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
2024-12-03 11:37:18 +08:00
/**
* @ brief Internal use only
*
* @ note Please do not modify this value
*/
2025-02-25 15:17:49 +08:00
# define ESP_BT_CTRL_CONFIG_VERSION 0x02502230
2020-07-09 20:58:13 +08:00
2024-12-03 11:37:18 +08:00
/**
* @ brief Internal use only
*
* @ note Please do not modify this value
*/
2020-07-09 20:58:13 +08:00
# define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
2024-12-03 11:37:18 +08:00
/**
* @ brief Internal use only
*
* @ note Please do not modify this value
*/
2020-07-09 20:58:13 +08:00
# define ESP_BT_HCI_TL_VERSION 0x00010000
2018-06-15 21:40:51 +08:00
2017-12-07 21:48:27 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth Controller mode
2017-12-07 21:48:27 +08:00
*/
2018-06-15 21:40:51 +08:00
typedef enum {
2024-12-03 11:37:18 +08:00
ESP_BT_MODE_IDLE = 0x00 , /*!< Bluetooth is not operating. */
ESP_BT_MODE_BLE = 0x01 , /*!< Bluetooth is operating in BLE mode. */
ESP_BT_MODE_CLASSIC_BT = 0x02 , /*!< Unsupported mode */
ESP_BT_MODE_BTDM = 0x03 , /*!< Unsupported mode */
2018-06-15 21:40:51 +08:00
} esp_bt_mode_t ;
2017-12-07 21:48:27 +08:00
2019-04-09 20:56:38 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief BLE Controller HCI transport layer type
2020-07-09 20:58:13 +08:00
*/
typedef enum {
ESP_BT_CTRL_HCI_TL_UART = 0 , /*!< HCI UART h4 transport layer */
2024-12-03 11:37:18 +08:00
ESP_BT_CTRL_HCI_TL_VHCI = 1 , /*!< Virtual HCI interface */
2020-07-09 20:58:13 +08:00
} esp_bt_ctrl_hci_tl_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief BLE connection event length computation type
2020-07-09 20:58:13 +08:00
*/
typedef enum {
ESP_BLE_CE_LEN_TYPE_ORIG = 0 , /*!< original */
2024-12-03 11:37:18 +08:00
ESP_BLE_CE_LEN_TYPE_CE = 1 , /*!< use `CE_LEN` parameter from HCI commands */
2020-07-09 20:58:13 +08:00
ESP_BLE_CE_LEN_TYPE_SD = 1 , /*!< Espressif vendor defined */
} esp_ble_ce_len_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth modem sleep mode
2020-07-09 20:58:13 +08:00
*/
typedef enum {
2024-12-03 11:37:18 +08:00
ESP_BT_SLEEP_MODE_NONE = 0 , /*!< Disable modem sleep */
ESP_BT_SLEEP_MODE_1 = 1 , /*!< Enable modem sleep */
2020-07-09 20:58:13 +08:00
} esp_bt_sleep_mode_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth modem sleep clock source
*
* @ note If the modem sleep mode is enabled , ` ESP_BT_SLEEP_CLOCK_MAIN_XTAL ` is the default option and
* ` ESP_BT_SLEEP_CLOCK_NONE ` will become an invalid option .
2020-07-09 20:58:13 +08:00
*/
2024-12-03 11:37:18 +08:00
2020-07-09 20:58:13 +08:00
typedef enum {
ESP_BT_SLEEP_CLOCK_NONE = 0 , /*!< Sleep clock not configured */
ESP_BT_SLEEP_CLOCK_MAIN_XTAL = 1 , /*!< SoC main crystal */
ESP_BT_SLEEP_CLOCK_EXT_32K_XTAL = 2 , /*!< External 32.768kHz crystal */
2023-02-21 14:47:41 +08:00
ESP_BT_SLEEP_CLOCK_RTC_SLOW = 3 , /*!< Internal 136kHz RC oscillator */
2021-01-28 22:28:04 +08:00
ESP_BT_SLEEP_CLOCK_FPGA_32K = 4 , /*!< Hardwired 32KHz clock temporarily used for FPGA */
2020-07-09 20:58:13 +08:00
} esp_bt_sleep_clock_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth antenna index
2019-04-09 20:56:38 +08:00
*/
enum {
2024-12-03 11:37:18 +08:00
ESP_BT_ANT_IDX_0 = 0 , /*!< Antenna NO 0 */
ESP_BT_ANT_IDX_1 = 1 , /*!< Antenna NO 1 */
2019-04-09 20:56:38 +08:00
} ;
2021-02-04 22:38:29 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Enable / disable the maximum TX / RX time limit for Coded - PHY connections in coexistence with Wi - Fi scenarios
2021-02-04 22:38:29 +08:00
*/
enum {
ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_DISABLE = 0 , /*!< Disable the limit */
2024-12-03 11:37:18 +08:00
ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_ENABLE , /*!< Enable the limit */
2021-02-04 22:38:29 +08:00
} ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
# define ESP_BT_HCI_TL_STATUS_OK (0) /*!< HCI_TL TX/RX operation status OK */
2021-04-30 18:19:35 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Callback function for HCI Transport Layer send / receive operations
2021-04-30 18:19:35 +08:00
*/
typedef void ( * esp_bt_hci_tl_callback_t ) ( void * arg , uint8_t status ) ;
2021-02-04 22:38:29 +08:00
# ifdef CONFIG_BT_ENABLED
2020-07-09 20:58:13 +08:00
# define BT_CTRL_BLE_MAX_ACT_LIMIT 10 //Maximum BLE activity limitation
2021-03-02 14:29:48 +08:00
# define SLAVE_CE_LEN_MIN_DEFAULT 5
2020-07-09 20:58:13 +08:00
# ifdef CONFIG_BT_CTRL_SCAN_DUPL_TYPE
# define SCAN_DUPLICATE_TYPE_VALUE CONFIG_BT_CTRL_SCAN_DUPL_TYPE
2018-08-20 15:04:37 +08:00
# else
# define SCAN_DUPLICATE_TYPE_VALUE 0
# endif
2018-05-03 20:22:08 +08:00
/* normal adv cache size */
2021-02-05 19:22:37 +08:00
# ifdef CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE
# define NORMAL_SCAN_DUPLICATE_CACHE_SIZE CONFIG_BT_CTRL_SCAN_DUPL_CACHE_SIZE
2018-05-03 20:22:08 +08:00
# else
2018-06-15 21:40:51 +08:00
# define NORMAL_SCAN_DUPLICATE_CACHE_SIZE 20
2018-05-03 20:22:08 +08:00
# endif
2020-07-09 20:58:13 +08:00
# ifndef CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN
# define CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN FALSE
2018-05-03 20:22:08 +08:00
# endif
2018-06-15 21:40:51 +08:00
# define SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY 0
# define SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV 1
2018-05-03 20:22:08 +08:00
2020-07-09 20:58:13 +08:00
# if CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN
2018-06-15 21:40:51 +08:00
# define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_MESH_ADV
2020-07-09 20:58:13 +08:00
# ifdef CONFIG_BT_CTRL_MESH_DUPL_SCAN_CACHE_SIZE
# define MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BT_CTRL_MESH_DUPL_SCAN_CACHE_SIZE
2018-05-03 20:22:08 +08:00
# else
2018-06-15 21:40:51 +08:00
# define MESH_DUPLICATE_SCAN_CACHE_SIZE 50
2018-05-03 20:22:08 +08:00
# endif
# else
# define SCAN_DUPLICATE_MODE SCAN_DUPLICATE_MODE_NORMAL_ADV_ONLY
2018-06-15 21:40:51 +08:00
# define MESH_DUPLICATE_SCAN_CACHE_SIZE 0
# endif
2022-12-13 16:51:51 +08:00
# ifndef CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
# define DUPL_SCAN_CACHE_REFRESH_PERIOD 0
# else
# define DUPL_SCAN_CACHE_REFRESH_PERIOD CONFIG_BT_CTRL_DUPL_SCAN_CACHE_REFRESH_PERIOD
# endif
2023-02-21 14:47:41 +08:00
# ifdef CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
# define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX CONFIG_BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
# else
# define BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX 0
# endif
2021-06-15 21:10:23 +08:00
# ifdef CONFIG_BT_CTRL_AGC_RECORRECT_EN
# define BT_CTRL_AGC_RECORRECT_EN CONFIG_BT_CTRL_AGC_RECORRECT_EN
2023-12-19 16:47:28 +08:00
// ESP32-S3
# if CONFIG_IDF_TARGET_ESP32S3
# define BT_CTRL_AGC_RECORRECT_NEW 1
# else
//Check if chip target is ESP32-C3 101
# if CONFIG_ESP32C3_REV_MIN_101
# define BT_CTRL_AGC_RECORRECT_NEW 1
# else
# define BT_CTRL_AGC_RECORRECT_NEW 0
# endif // CONFIG_ESP32C3_REV_MIN_101
# endif // CONFIG_IDF_TARGET_ESP32S3
2021-06-15 21:10:23 +08:00
# else
# define BT_CTRL_AGC_RECORRECT_EN 0
2023-12-19 16:47:28 +08:00
# define BT_CTRL_AGC_RECORRECT_NEW 0
2021-06-15 21:10:23 +08:00
# endif
# ifdef CONFIG_BT_CTRL_CODED_AGC_RECORRECT_EN
# define BT_CTRL_CODED_AGC_RECORRECT CONFIG_BT_CTRL_CODED_AGC_RECORRECT_EN
# else
# define BT_CTRL_CODED_AGC_RECORRECT 0
# endif
2023-01-14 16:53:18 +08:00
# if defined (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) || defined (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT)
# ifdef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
# define BT_CTRL_50_FEATURE_SUPPORT (CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
2023-04-20 14:46:05 +08:00
# endif // CONFIG_BT_BLE_50_FEATURES_SUPPORTED
2023-01-14 16:53:18 +08:00
# ifdef CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT
# define BT_CTRL_50_FEATURE_SUPPORT (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT)
2023-04-20 14:46:05 +08:00
# endif // CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT
# else
# if defined (CONFIG_BT_BLUEDROID_ENABLED) || defined (CONFIG_BT_NIMBLE_ENABLED)
# define BT_CTRL_50_FEATURE_SUPPORT (0)
2023-01-14 16:53:18 +08:00
# else
# define BT_CTRL_50_FEATURE_SUPPORT (1)
2023-04-20 14:46:05 +08:00
# endif // (CONFIG_BT_BLUEDROID_ENABLED) || (CONFIG_BT_NIMBLE_ENABLED)
# endif // (CONFIG_BT_BLE_50_FEATURES_SUPPORTED) || (CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT)
2023-01-14 16:53:18 +08:00
2023-07-07 19:50:24 +08:00
# if defined(CONFIG_BT_BLE_CCA_MODE)
# define BT_BLE_CCA_MODE (CONFIG_BT_BLE_CCA_MODE)
# else
# define BT_BLE_CCA_MODE (0)
# endif
2024-01-12 16:14:57 +08:00
# if defined(CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX)
# define BT_BLE_ADV_DATA_LENGTH_ZERO_AUX (CONFIG_BT_BLE_ADV_DATA_LENGTH_ZERO_AUX)
# else
# define BT_BLE_ADV_DATA_LENGTH_ZERO_AUX (0)
# endif
2024-04-02 15:15:33 +08:00
# if defined(CONFIG_BT_CTRL_CHAN_ASS_EN)
# define BT_CTRL_CHAN_ASS_EN (CONFIG_BT_CTRL_CHAN_ASS_EN)
# else
# define BT_CTRL_CHAN_ASS_EN (0)
# endif
# if defined(CONFIG_BT_CTRL_LE_PING_EN)
# define BT_CTRL_LE_PING_EN (CONFIG_BT_CTRL_LE_PING_EN)
# else
# define BT_CTRL_LE_PING_EN (0)
# endif
2023-12-19 16:47:28 +08:00
# define AGC_RECORRECT_EN ((BT_CTRL_AGC_RECORRECT_EN << 0) | (BT_CTRL_CODED_AGC_RECORRECT <<1) | (BT_CTRL_AGC_RECORRECT_NEW << 2))
2021-06-15 21:10:23 +08:00
2020-07-09 20:58:13 +08:00
# define CFG_MASK_BIT_SCAN_DUPLICATE_OPTION (1<<0)
2018-05-03 20:22:08 +08:00
2023-02-21 14:47:41 +08:00
# define CFG_MASK CFG_MASK_BIT_SCAN_DUPLICATE_OPTION
# if CONFIG_IDF_TARGET_ESP32C3
# define BLE_HW_TARGET_CODE_CHIP_ECO0 (0x01010000)
# else // CONFIG_IDF_TARGET_ESP32S3
# define BLE_HW_TARGET_CODE_CHIP_ECO0 (0x02010000)
# endif
2021-03-16 20:36:05 +08:00
2024-09-30 10:57:38 +08:00
# ifdef CONFIG_BT_CTRL_BLE_LLCP_CONN_UPDATE
# define BT_CTRL_BLE_LLCP_CONN_UPDATE (1<<0)
# else
# define BT_CTRL_BLE_LLCP_CONN_UPDATE (0<<0)
# endif
# ifdef CONFIG_BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE
# define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (1<<1)
# else
# define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (0<<1)
# endif
# ifdef CONFIG_BT_CTRL_BLE_LLCP_PHY_UPDATE
# define BT_CTRL_BLE_LLCP_PHY_UPDATE (1<<2)
# else
# define BT_CTRL_BLE_LLCP_PHY_UPDATE (0<<2)
# endif
# define BT_CTRL_BLE_LLCP_DISC_FLAG (BT_CTRL_BLE_LLCP_CONN_UPDATE | BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE | BT_CTRL_BLE_LLCP_PHY_UPDATE)
2024-08-26 20:04:00 +08:00
# if defined(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
# define BT_CTRL_RUN_IN_FLASH_ONLY CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
# else
# define BT_CTRL_RUN_IN_FLASH_ONLY (0)
# endif
# if (BT_CTRL_RUN_IN_FLASH_ONLY == 1)
# if defined(CONFIG_BT_CTRL_DTM_ENABLE)
# define BT_CTRL_DTM_ENABLE CONFIG_BT_CTRL_DTM_ENABLE
# else
# define BT_CTRL_DTM_ENABLE (0)
# endif
# if defined(CONFIG_BT_CTRL_BLE_MASTER)
# define BT_CTRL_BLE_MASTER CONFIG_BT_CTRL_BLE_MASTER
# else
# define BT_CTRL_BLE_MASTER (0)
# endif
# if defined(CONFIG_BT_CTRL_BLE_TEST)
# define BT_CTRL_BLE_TEST CONFIG_BT_CTRL_BLE_TEST
# else
# define BT_CTRL_BLE_TEST (0)
# endif
# if defined (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || defined (CONFIG_BT_BLE_SMP_ENABLE)
# ifdef CONFIG_BT_NIMBLE_SECURITY_ENABLE
# define BLE_SECURITY_ENABLE (CONFIG_BT_NIMBLE_SECURITY_ENABLE)
# endif //CONFIG_BT_NIMBLE_SECURITY_ENABLE
# ifdef CONFIG_BT_BLE_SMP_ENABLE
# define BLE_SECURITY_ENABLE (CONFIG_BT_BLE_SMP_ENABLE)
# endif //CONFIG_BT_BLE_SMP_ENABLE
# else
# if defined (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
# define BLE_SECURITY_ENABLE (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
# else
# define BLE_SECURITY_ENABLE (0)
# endif
# endif // (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || (CONFIG_BT_BLE_SMP_ENABLE)
# if defined (CONFIG_BT_CTRL_BLE_SCAN)
# define BT_CTRL_BLE_SCAN CONFIG_BT_CTRL_BLE_SCAN
# else
# define BT_CTRL_BLE_SCAN (0)
# endif
# else
# define BT_CTRL_BLE_MASTER (1)
# define BT_CTRL_DTM_ENABLE (1)
# define BT_CTRL_BLE_TEST (1)
# define BLE_SECURITY_ENABLE (1)
# define BT_CTRL_BLE_SCAN (1)
# endif // (BT_CTRL_RUN_IN_FLASH_ONLY == 1)
2024-09-30 10:57:38 +08:00
2024-11-27 17:08:24 +08:00
# ifdef CONFIG_BT_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
# define BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED CONFIG_BT_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
# else
# define BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED 0
# endif
2025-02-25 15:17:49 +08:00
# if defined(CONFIG_BT_CTRL_LE_LOG_EN)
# define BT_BLE_LOG_EN CONFIG_BT_CTRL_LE_LOG_EN
# else
# define BT_BLE_LOG_EN (0)
# endif
# if defined(CONFIG_BT_CTRL_LE_LOG_MODE_EN)
# define BLE_LOG_MODE_EN CONFIG_BT_CTRL_LE_LOG_MODE_EN
# else
# define BLE_LOG_MODE_EN (0)
# endif
# if defined(CONFIG_BT_CTRL_LE_LOG_LEVEL)
# define BLE_LOG_LEVEL CONFIG_BT_CTRL_LE_LOG_LEVEL
# else
# define BLE_LOG_LEVEL (0)
# endif
2018-06-15 21:40:51 +08:00
# define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
2020-07-09 20:58:13 +08:00
. magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL , \
. version = ESP_BT_CTRL_CONFIG_VERSION , \
2018-06-15 21:40:51 +08:00
. controller_task_stack_size = ESP_TASK_BT_CONTROLLER_STACK , \
. controller_task_prio = ESP_TASK_BT_CONTROLLER_PRIO , \
2020-07-09 20:58:13 +08:00
. controller_task_run_cpu = CONFIG_BT_CTRL_PINNED_TO_CORE , \
. bluetooth_mode = CONFIG_BT_CTRL_MODE_EFF , \
. ble_max_act = CONFIG_BT_CTRL_BLE_MAX_ACT_EFF , \
. sleep_mode = CONFIG_BT_CTRL_SLEEP_MODE_EFF , \
. sleep_clock = CONFIG_BT_CTRL_SLEEP_CLOCK_EFF , \
. ble_st_acl_tx_buf_nb = CONFIG_BT_CTRL_BLE_STATIC_ACL_TX_BUF_NB , \
. ble_hw_cca_check = CONFIG_BT_CTRL_HW_CCA_EFF , \
. ble_adv_dup_filt_max = CONFIG_BT_CTRL_ADV_DUP_FILT_MAX , \
2022-06-01 16:00:27 +08:00
. coex_param_en = false , \
2020-07-09 20:58:13 +08:00
. ce_len_type = CONFIG_BT_CTRL_CE_LENGTH_TYPE_EFF , \
2022-06-01 16:00:27 +08:00
. coex_use_hooks = false , \
2020-07-09 20:58:13 +08:00
. hci_tl_type = CONFIG_BT_CTRL_HCI_TL_EFF , \
. hci_tl_funcs = NULL , \
. txant_dft = CONFIG_BT_CTRL_TX_ANTENNA_INDEX_EFF , \
. rxant_dft = CONFIG_BT_CTRL_RX_ANTENNA_INDEX_EFF , \
. txpwr_dft = CONFIG_BT_CTRL_DFT_TX_POWER_LEVEL_EFF , \
2023-02-21 14:47:41 +08:00
. cfg_mask = CFG_MASK , \
2018-06-15 21:40:51 +08:00
. scan_duplicate_mode = SCAN_DUPLICATE_MODE , \
2019-04-09 20:56:38 +08:00
. scan_duplicate_type = SCAN_DUPLICATE_TYPE_VALUE , \
2018-06-15 21:40:51 +08:00
. normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE , \
. mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE , \
2021-02-04 22:38:29 +08:00
. coex_phy_coded_tx_rx_time_limit = CONFIG_BT_CTRL_COEX_PHY_CODED_TX_RX_TLIM_EFF , \
2023-02-21 14:47:41 +08:00
. hw_target_code = BLE_HW_TARGET_CODE_CHIP_ECO0 , \
2021-03-02 14:29:48 +08:00
. slave_ce_len_min = SLAVE_CE_LEN_MIN_DEFAULT , \
2021-06-15 21:10:23 +08:00
. hw_recorrect_en = AGC_RECORRECT_EN , \
2021-12-28 15:11:54 +08:00
. cca_thresh = CONFIG_BT_CTRL_HW_CCA_VAL , \
2022-10-13 15:50:51 +08:00
. scan_backoff_upperlimitmax = BT_CTRL_SCAN_BACKOFF_UPPERLIMITMAX , \
2022-12-13 16:51:51 +08:00
. dup_list_refresh_period = DUPL_SCAN_CACHE_REFRESH_PERIOD , \
2023-01-14 16:53:18 +08:00
. ble_50_feat_supp = BT_CTRL_50_FEATURE_SUPPORT , \
2023-07-07 19:50:24 +08:00
. ble_cca_mode = BT_BLE_CCA_MODE , \
2024-01-12 16:14:57 +08:00
. ble_data_lenth_zero_aux = BT_BLE_ADV_DATA_LENGTH_ZERO_AUX , \
2024-04-02 15:15:33 +08:00
. ble_chan_ass_en = BT_CTRL_CHAN_ASS_EN , \
. ble_ping_en = BT_CTRL_LE_PING_EN , \
2024-09-30 10:57:38 +08:00
. ble_llcp_disc_flag = BT_CTRL_BLE_LLCP_DISC_FLAG , \
2024-08-26 20:04:00 +08:00
. run_in_flash = BT_CTRL_RUN_IN_FLASH_ONLY , \
. dtm_en = BT_CTRL_DTM_ENABLE , \
. enc_en = BLE_SECURITY_ENABLE , \
. qa_test = BT_CTRL_BLE_TEST , \
. master_en = BT_CTRL_BLE_MASTER , \
. scan_en = BT_CTRL_BLE_SCAN , \
2024-11-27 17:08:24 +08:00
. ble_aa_check = BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED , \
2025-02-25 15:17:49 +08:00
. ble_log_mode_en = BLE_LOG_MODE_EN , \
. ble_log_level = BLE_LOG_LEVEL , \
2022-08-15 20:44:34 -03:00
}
2018-05-03 20:22:08 +08:00
2017-12-07 21:48:27 +08:00
# else
2022-10-13 12:01:27 +08:00
# define BT_CONTROLLER_INIT_CONFIG_DEFAULT() {0}; ESP_STATIC_ASSERT(0, "please enable bluetooth in menuconfig to use esp_bt.h");
2017-12-07 21:48:27 +08:00
# endif
2020-07-09 20:58:13 +08:00
/**
* @ brief Controller HCI transport layer function structure
2024-12-03 11:37:18 +08:00
*
* @ note This structure must be registered when HCI transport layer is UART
2020-07-09 20:58:13 +08:00
*/
typedef struct {
2023-07-18 21:13:29 +08:00
uint32_t _magic ; /*!< Magic number */
uint32_t _version ; /*!< Version number of the defined structure */
uint32_t _reserved ; /*!< Reserved for future use */
int ( * _open ) ( void ) ; /*!< HCI transport layer open function */
void ( * _close ) ( void ) ; /*!< HCI transport layer close function */
void ( * _finish_transfers ) ( void ) ; /*!< HCI transport layer finish transfers function */
void ( * _recv ) ( uint8_t * buf , uint32_t len , esp_bt_hci_tl_callback_t callback , void * arg ) ; /*!< HCI transport layer receive function */
void ( * _send ) ( uint8_t * buf , uint32_t len , esp_bt_hci_tl_callback_t callback , void * arg ) ; /*!< HCI transport layer send function */
bool ( * _flow_off ) ( void ) ; /*!< HCI transport layer flow off function */
void ( * _flow_on ) ( void ) ; /*!< HCI transport layer flow on function */
2020-07-09 20:58:13 +08:00
} esp_bt_hci_tl_t ;
2017-12-07 21:48:27 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth Controller config options
* @ note
* 1. For parameters configurable through menuconfig , it is recommended to adjust them via the menuconfig interface . Please refer to menuconfig for details on the range and default values .
* 2. It is not recommended to modify the values for parameters which are not configurable through menuconfig .
2017-12-07 21:48:27 +08:00
*/
2018-06-15 21:40:51 +08:00
typedef struct {
2020-07-09 20:58:13 +08:00
uint32_t magic ; /*!< Magic number */
uint32_t version ; /*!< version number of the defined structure */
2024-12-03 11:37:18 +08:00
uint16_t controller_task_stack_size ; /*!< Bluetooth Controller task stack size in bytes */
uint8_t controller_task_prio ; /*!< Bluetooth Controller task priority */
uint8_t controller_task_run_cpu ; /*!< CPU number that Bluetooth Controller task runs on. Configurable in menuconfig.
- 0 - CPU 0 ( default )
- 1 - CPU 1 */
uint8_t bluetooth_mode ; /*!< BLE mode */
uint8_t ble_max_act ; /*!< The maximum number of BLE instance. Configurable in menuconfig.
- Range : 1 - 10
- Default : 6 */
uint8_t sleep_mode ; /*!< Modem sleep mode. Configurable in menuconfig.
- 0 - Disable ( default )
- 1 - Enable */
uint8_t sleep_clock ; /*!< Modem sleep clock source. Configurable in menuconfig. */
uint8_t ble_st_acl_tx_buf_nb ; /*!< Static ACL TX buffer numbers. Configurable in menuconfig.
- Range : 0 - 12
- Default : 0 */
uint8_t ble_hw_cca_check ; /*!< Deprecated */
uint16_t ble_adv_dup_filt_max ; /*!< The maximum number of extended duplicate scan filter. Configurable in menuconfig.
- Range : 1 - 500
- Default : 30 */
bool coex_param_en ; /*!< Deprecated */
uint8_t ce_len_type ; /*!< Connection event length determination method. Configurable in menuconfig.
- 0 - Original ( default )
- 1 - use ` CE_LEN ` parameter from HCI commands
- 2 - Espressif vendor defined method */
bool coex_use_hooks ; /*!< Deprecated */
uint8_t hci_tl_type ; /*!< HCI transport layer type. Configurable in menuconfig.
- 0 - URAT
- 1 - Virtual HCI ( default ) */
esp_bt_hci_tl_t * hci_tl_funcs ; /*!< HCI transport functions used. It must be set when `hci_tl_type` is UART. */
uint8_t txant_dft ; /*!< Default TX antenna. Configurable in menuconfig.
- 0 - Antenna 0 ( default )
- 1 - Antenna 1 */
uint8_t rxant_dft ; /*!< Default RX antenna. Configurable in menuconfig.
- 0 - Antenna 0 ( default )
- 1 - Antenna 1 */
uint8_t txpwr_dft ; /*!< Default TX power. Please refer to `esp_power_level_t` for supported power level. Configurable in menuconfig.
- Default : ` ESP_PWR_LVL_P9 ` + 9 dBm . */
2023-07-18 21:13:29 +08:00
uint32_t cfg_mask ; /*!< Configuration mask to set specific options */
2024-12-03 11:37:18 +08:00
uint8_t scan_duplicate_mode ; /*!< Scan duplicate filtering mode. Configurable in menuconfig.
- 0 - Normal scan duplicate filtering mode ( default )
- 1 - Special scan duplicate filtering mode for BLE Mesh */
uint8_t scan_duplicate_type ; /*!< Scan duplicate filtering type. If `scan_duplicate_mode` is set to 1, this parameter will be ignored. Configurable in menuconfig.
- 0 - Filter scan duplicates by device address only ( default )
- 1 - Filter scan duplicates by advertising data only , even if they originate from different devices .
- 2 - Filter scan duplicated by device address and advertising data . */
uint16_t normal_adv_size ; /*!< Maximum number of devices in scan duplicate filtering list. Configurable in menuconfig.
- Range : 10 - 1000
- Default : 100 */
uint16_t mesh_adv_size ; /*!< Maximum number of Mesh advertising packets in scan duplicate filtering list. Configurable in menuconfig.
- Range : 10 - 1000
- Default : 100 */
uint8_t coex_phy_coded_tx_rx_time_limit ; /*!< Enable / disable the maximum TX/RX time limit for Coded-PHY connections in coexistence with Wi-Fi scenarios. Configurable in menuconfig.
- 0 - Disable ( default )
- 1 - Enable */
uint32_t hw_target_code ; /*!< Hardware target. Internal use only. Please do not modify this value. */
uint8_t slave_ce_len_min ; /*!< Slave minimum connection event length: 5 slots. Please do not modify this value. */
uint8_t hw_recorrect_en ; /*!< Enable / disable uncoded phy / coded phy hardware re-correction. Configurable in menuconfig. */
uint8_t cca_thresh ; /*!< Absolute value of hardware-triggered CCA threshold. The CCA threshold is always negative.
If the channel assessment result exceeds the CCA threshold ( e . g . - 75 dBm ) , indicating the channel is busy ,
the hardware will not transmit packets on that channel . Configurable in menuconfig .
- Range : 20 dBm - 100 dBm
- Default : 75 dBm */
uint16_t scan_backoff_upperlimitmax ; /*!< Enable / disable active scan backoff. Configurable in menuconfig.
- 0 - Disable ( default )
- 1 - Enable */
uint16_t dup_list_refresh_period ; /*!< Scan duplicate filtering list refresh period in seconds. Configurable in menuconfig
- Range : 0 - 100 seconds
- Default : 0 second */
bool ble_50_feat_supp ; /*!< True if BLE 5.0 features are enabled; false otherwise. This option depends on whether the Host enable the 5.0 features. */
uint8_t ble_cca_mode ; /*!< BLE CCA mode. Configurable in menuconfig
- 0 - Disable ( default )
- 1 - Hardware - triggered CCA
- 2 - Software - based CCA */
uint8_t ble_data_lenth_zero_aux ; /*!< Enable / disable auxiliary packets when the extended ADV data length is zero. Configurable in menuconfig.
- 0 - Disable ( default )
- 1 - Enable */
uint8_t ble_chan_ass_en ; /*!< Enable / disable BLE channel assessment. Configurable in menuconfig.
- 0 - Disable
- 1 - Enable ( default ) */
uint8_t ble_ping_en ; /*!< Enable / disable BLE ping procedure. Configurable in menuconfig.
- 0 - Disable
- 1 - Enable ( default ) */
uint8_t ble_llcp_disc_flag ; /*!< Flag indicating whether the Controller disconnects after Instant Passed (0x28) error occurs. Configurable in menuconfig.
- The Controller does not disconnect after Instant Passed ( 0x28 ) by default . */
bool run_in_flash ; /*!< True if the Controller code is in flash (flash model); false otherwise (default). Configurable in menuconfig. */
bool dtm_en ; /*!< In the flash mode, True if the DTM feature is enabled; false otherwise (default). Configurable in menuconfig. */
bool enc_en ; /*!< In the flash mode, True if the encryption feature is enabled (default); false otherwise. Configurable in menuconfig. */
bool qa_test ; /*!< In the flash mode, True if the QA test feature is enabled; false otherwise (default). Configurable in menuconfig.*/
bool master_en ; /*!< In the flash mode, True if the master feature is enabled (default); false otherwise. Configurable in menuconfig.*/
bool scan_en ; /*!< In the flash mode, True if the scan feature is enabled (default); false otherwise. Configurable in menuconfig.*/
2024-11-27 17:08:24 +08:00
bool ble_aa_check ; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */
2025-02-25 15:17:49 +08:00
uint32_t ble_log_mode_en ; /*!< BLE log mode enable */
uint8_t ble_log_level ; /*!< BLE log level */
2018-06-15 21:40:51 +08:00
} esp_bt_controller_config_t ;
2017-12-07 21:48:27 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth Controller status
2017-12-07 21:48:27 +08:00
*/
typedef enum {
2024-12-03 11:37:18 +08:00
ESP_BT_CONTROLLER_STATUS_IDLE = 0 , /*!< The Controller is not initialized or has been de-initialized. */
ESP_BT_CONTROLLER_STATUS_INITED , /*!< The Controller has been initialized, but not enabled or has been disabled. */
ESP_BT_CONTROLLER_STATUS_ENABLED , /*!< The Controller has been initialized and enabled. */
ESP_BT_CONTROLLER_STATUS_NUM , /*!< Number of Controller statuses */
2017-12-07 21:48:27 +08:00
} esp_bt_controller_status_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief BLE TX power type
*
* This TX power type is used for the API ` esp_ble_tx_power_set ( ) ` and ` esp_ble_tx_power_get ( ) ` .
*
* @ note
* 1. The connection TX power can only be set after the connection is established .
* After disconnecting , the corresponding TX power will not be affected .
* 2. ` ESP_BLE_PWR_TYPE_DEFAULT ` can be used to set the TX power for power types that have not been set before .
* It will not affect the TX power values which have been set for the ADV / SCAN / CONN0 - 8 power types .
* 3. If none of power type is set , the system will use ` ESP_PWR_LVL_P3 ` as default for all power types .
2017-12-07 21:48:27 +08:00
*/
typedef enum {
2024-12-03 11:37:18 +08:00
ESP_BLE_PWR_TYPE_CONN_HDL0 = 0 , /*!< TX power for Connection state handle 0 */
ESP_BLE_PWR_TYPE_CONN_HDL1 = 1 , /*!< TX power for Connection state handle 1 */
ESP_BLE_PWR_TYPE_CONN_HDL2 = 2 , /*!< TX power for Connection state handle 2 */
ESP_BLE_PWR_TYPE_CONN_HDL3 = 3 , /*!< TX power for Connection state handle 3 */
ESP_BLE_PWR_TYPE_CONN_HDL4 = 4 , /*!< TX power for Connection state handle 4 */
ESP_BLE_PWR_TYPE_CONN_HDL5 = 5 , /*!< TX power for Connection state handle 5 */
ESP_BLE_PWR_TYPE_CONN_HDL6 = 6 , /*!< TX power for Connection state handle 6 */
ESP_BLE_PWR_TYPE_CONN_HDL7 = 7 , /*!< TX power for Connection state handle 7 */
ESP_BLE_PWR_TYPE_CONN_HDL8 = 8 , /*!< TX power for Connection state handle 8 */
ESP_BLE_PWR_TYPE_ADV = 9 , /*!< TX power for Advertising state*/
ESP_BLE_PWR_TYPE_SCAN = 10 , /*!< TX power for Scanning state */
ESP_BLE_PWR_TYPE_DEFAULT = 11 , /*!< TX power for states that have not been set before */
ESP_BLE_PWR_TYPE_NUM = 12 , /*!< Reserved */
2017-12-07 21:48:27 +08:00
} esp_ble_power_type_t ;
/**
2024-12-03 11:37:18 +08:00
* @ brief The enhanced type of which TX power , could set Advertising / Connection / Default and etc .
*
* This TX power type is used for the API ` esp_ble_tx_power_set_enhanced ( ) ` and ` esp_ble_tx_power_get_enhanced ( ) ` .
*
* @ note
* 1. The connection TX power can only be set after the connection is established .
* After disconnecting , the corresponding TX power will not be affected .
* 2. ` ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT ` can be used to set the TX power for power types that have not been set before .
* It will not affect the TX power values which have been set for the ADV / SCAN / INIT / CONN power types .
* 3. If none of power type is set , the system will use ` ESP_PWR_LVL_P3 ` as default for all power types .
2024-07-23 16:22:26 +08:00
*/
typedef enum {
2024-12-03 11:37:18 +08:00
ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT = 0 , /*!< TX power for states that have not been set before */
ESP_BLE_ENHANCED_PWR_TYPE_ADV , /*!< TX power for Advertising state */
ESP_BLE_ENHANCED_PWR_TYPE_SCAN , /*!< TX power for Scanning state */
ESP_BLE_ENHANCED_PWR_TYPE_INIT , /*!< TX power for Initiating state */
ESP_BLE_ENHANCED_PWR_TYPE_CONN , /*!< TX power for Connection state */
ESP_BLE_ENHANCED_PWR_TYPE_MAX , /*!< Reserved */
2024-07-23 16:22:26 +08:00
} esp_ble_enhanced_power_type_t ;
2017-12-07 21:48:27 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Bluetooth TX power level ( index ) . Each index corresponds to a specific power value in dBm .
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
typedef enum {
ESP_PWR_LVL_N24 = 0 , /*!< Corresponding to -24 dBm */
ESP_PWR_LVL_N21 = 1 , /*!< Corresponding to -21 dBm */
ESP_PWR_LVL_N18 = 2 , /*!< Corresponding to -18 dBm */
ESP_PWR_LVL_N15 = 3 , /*!< Corresponding to -15 dBm */
ESP_PWR_LVL_N12 = 4 , /*!< Corresponding to -12 dBm */
ESP_PWR_LVL_N9 = 5 , /*!< Corresponding to -9 dBm */
ESP_PWR_LVL_N6 = 6 , /*!< Corresponding to -6 dBm */
ESP_PWR_LVL_N3 = 7 , /*!< Corresponding to -3 dBm */
ESP_PWR_LVL_N0 = 8 , /*!< Corresponding to 0 dBm */
ESP_PWR_LVL_P3 = 9 , /*!< Corresponding to +3 dBm */
ESP_PWR_LVL_P6 = 10 , /*!< Corresponding to +6 dBm */
ESP_PWR_LVL_P9 = 11 , /*!< Corresponding to +9 dBm */
ESP_PWR_LVL_P12 = 12 , /*!< Corresponding to +12 dBm */
ESP_PWR_LVL_P15 = 13 , /*!< Corresponding to +15 dBm */
ESP_PWR_LVL_P18 = 14 , /*!< Corresponding to +18 dBm */
ESP_PWR_LVL_P20 = 15 , /*!< Corresponding to +20 dBm */
ESP_PWR_LVL_P21 = 15 , /*!< Deprecated */
ESP_PWR_LVL_INVALID = 0xFF , /*!< Indicates an invalid value */
} esp_power_level_t ;
2024-07-23 16:22:26 +08:00
2017-12-07 21:48:27 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Initialize the Bluetooth Controller to allocate tasks and other resources
*
* @ note This function should be called only once , before any other Bluetooth functions .
*
* @ param [ in ] cfg Initial Bluetooth Controller configuration
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED : Invalid Bluetooth Controller mode
* - ESP_ERR_INVALID_ARG : Invalid arguments
* - ESP_ERR_NO_MEM : Out of memory
* - ESP_FAIL : Failure due to other reasons
*
2017-12-07 21:48:27 +08:00
*/
esp_err_t esp_bt_controller_init ( esp_bt_controller_config_t * cfg ) ;
/**
2024-12-03 11:37:18 +08:00
* @ brief De - initialize Bluetooth Controller to free resources and delete tasks
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. You should make sure that the Controller is in idle state before de - initializing it .
* 2. This function should be called only once , after any other Bluetooth functions .
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_ARG : Invalid arguments
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NO_MEM : Out of memory
2017-12-07 21:48:27 +08:00
*/
esp_err_t esp_bt_controller_deinit ( void ) ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Enable Bluetooth Controller
*
* @ note
* 1. Bluetooth Controller cannot be enabled in ` ESP_BT_CONTROLLER_STATUS_IDLE ` status . It has to be initialized first .
* 2. Due to a known issue , you cannot call ` esp_bt_controller_enable ( ) ` for the second time
* to change the Controller mode dynamically . To change the Controller mode , call
* ` esp_bt_controller_disable ( ) ` and then call ` esp_bt_controller_enable ( ) ` with the new mode .
*
* @ param [ in ] mode The Bluetooth Controller mode to enable
*
* For API compatibility , retain this argument . This mode must match the mode specified in the ` cfg ` of ` esp_bt_controller_init ( ) ` .
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_INVALID_ARG : Invalid arguments
2017-12-07 21:48:27 +08:00
*/
esp_err_t esp_bt_controller_enable ( esp_bt_mode_t mode ) ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Disable Bluetooth Controller
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
2017-12-07 21:48:27 +08:00
*/
esp_err_t esp_bt_controller_disable ( void ) ;
/**
2024-12-03 11:37:18 +08:00
* @ brief Get Bluetooth Controller status
*
* @ return
* - ESP_BT_CONTROLLER_STATUS_IDLE : The Controller is not initialized or has been de - initialized .
* - ESP_BT_CONTROLLER_STATUS_INITED : The Controller has been initialized , but not enabled or has been disabled .
* - ESP_BT_CONTROLLER_STATUS_ENABLED : The Controller has been initialized and enabled .
2017-12-07 21:48:27 +08:00
*/
esp_bt_controller_status_t esp_bt_controller_get_status ( void ) ;
2024-12-03 11:37:18 +08:00
/**
* @ brief Release the Controller memory as per the mode
*
* This function releases the BSS , data and other sections of the Controller to heap . The total size is about 70 KB .
*
* @ note
* 1. This function is optional and should be called only if you want to free up memory for other components .
* 2. This function should only be called when the Controller is in ` ESP_BT_CONTROLLER_STATUS_IDLE ` status .
* 3. Once Bluetooth Controller memory is released , the process cannot be reversed . This means you cannot use the Bluetooth Controller mode that you have released using this function .
* 4. If your firmware will upgrade the Bluetooth Controller mode later ( such as from disabled to enabled ) , then do not call this function .
*
* If you never intend to use Bluetooth in a current boot - up cycle , calling ` esp_bt_controller_mem_release ( ESP_BT_MODE_BLE ) ` could release the BSS and data consumed by BLE Controller to heap .
*
*
* @ param [ in ] mode The Bluetooth Controller mode
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NOT_FOUND : Requested resource not found
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_bt_controller_mem_release ( esp_bt_mode_t mode ) ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
/** @brief Release the Controller memory, BSS and data section of the BLE Host stack as per the mode
*
* @ note
* 1. This function is optional and should be called only if you want to free up memory for other components .
* 2. This function should only be called when the Controller is in ` ESP_BT_CONTROLLER_STATUS_IDLE ` status .
* 3. Once Bluetooth Controller memory is released , the process cannot be reversed . This means you cannot use the Bluetooth Controller mode that you have released using this function .
* 4. If your firmware will upgrade the Bluetooth Controller mode later ( such as from disabled to enabled ) , then do not call this function .
*
* This function first releases Controller memory by internally calling ` esp_bt_controller_mem_release ( ) ` , then releases Host memory .
*
* If you never intend to use Bluetooth in a current boot - up cycle , calling ` esp_bt_mem_release ( ESP_BT_MODE_BLE ) ` could release the BSS and data consumed by BLE stack to heap .
*
* For example , if you only use Bluetooth for setting the Wi - Fi configuration , and do not use Bluetooth in the rest of the product operation ,
* after receiving the Wi - Fi configuration , you can disable / de - init Bluetooth and release its memory .
* Below is the sequence of APIs to be called for such scenarios :
*
* esp_bluedroid_disable ( ) ;
* esp_bluedroid_deinit ( ) ;
* esp_bt_controller_disable ( ) ;
* esp_bt_controller_deinit ( ) ;
* esp_bt_mem_release ( ESP_BT_MODE_BLE ) ;
*
* @ param [ in ] mode The Bluetooth Controller mode
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NOT_FOUND : Requested resource not found
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_bt_mem_release ( esp_bt_mode_t mode ) ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
/**
* @ brief Enable Bluetooth modem sleep
*
* There are currently two options for Bluetooth modem sleep : ORIG mode and EVED mode . The latter is intended for BLE only .
* The modem sleep mode could be configured in menuconfig .
*
* In ORIG mode , if there is no event to process , the Bluetooth Controller will periodically switch off some components and pause operation , then wake up according to the scheduled interval and resume work .
* It can also wakeup earlier upon external request using function ` esp_bt_controller_wakeup_request ( ) ` .
2019-01-23 18:04:01 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note This function shall not be invoked before ` esp_bt_controller_enable ( ) ` .
2019-01-23 18:04:01 +08:00
*
2024-12-03 11:37:18 +08:00
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED : Operation or feature not supported
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_bt_sleep_enable ( void ) ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
/**
* @ brief Disable Bluetooth modem sleep
*
* @ note
* 1. Bluetooth Controller will not be allowed to enter modem sleep after calling this function .
* 2. In ORIG modem sleep mode , calling this function may not immediately wake up the Controller if it is currently dormant .
* In this case , ` esp_bt_controller_wakeup_request ( ) ` can be used to shorten the wake - up time .
* 3. This function shall not be invoked before ` esp_bt_controller_enable ( ) ` .
*
* @ return
* - ESP_OK : Success
* - ESP_ERR_INVALID_STATE : Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED : Operation or feature not supported
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_bt_sleep_disable ( void ) ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
/**
* @ brief Get the Bluetooth sleep clock source .
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* @ note This function shall not be invoked before ` esp_bt_controller_init ( ) ` .
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* @ return clock source used in Bluetooth low power mode
*/
esp_bt_sleep_clock_t esp_bt_get_lpclk_src ( void ) ;
/**
* @ brief Check if the Bluetooth Controller is currently in sleep mode when modem sleep is enabled .
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. This function shall not be invoked before ` esp_bt_controller_enable ( ) ` .
* 2. This function is supposed to be used ORIG mode of modem sleep .
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* @ return
* - True if the Controller is in modem sleep state ; false otherwise .
*/
bool esp_bt_controller_is_sleeping ( void ) ;
/**
* @ brief Request the Controller to wakeup from sleeping state during sleep mode
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* Profiling shows that it takes several milliseconds to wakeup from modem sleep after this request .
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* Generally it takes longer if 32 kHz XTAL is used than the main XTAL , due to the lower frequency of the former as the bluetooth low power clock source .
2017-12-07 21:48:27 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. This function shall not be invoked before ` esp_bt_controller_enable ( ) ` .
* 2. This function is supposed to be used ORIG mode of modem sleep .
* 3. After this request , the Bluetooth Controller can re - enter sleep as long as modem sleep remains enabled .
2017-12-07 21:48:27 +08:00
*/
2024-12-03 11:37:18 +08:00
void esp_bt_controller_wakeup_request ( void ) ;
2017-12-07 21:48:27 +08:00
2024-12-03 11:37:18 +08:00
/**
* @ brief Set BLE TX power for the specified power type
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* It is recommended to use ` esp_ble_tx_power_set_enhanced ` to set TX power for individual advertising and connection handle .
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* @ note Connection TX power should only be set after the connection is established .
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] power_type The type of TX power . It could be Advertising , Connection , or Default .
* @ param [ in ] power_level Power level ( index ) corresponding to the absolute value ( dBm )
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* @ return
* - ESP_OK : Success
* - ESP_ERR_NOT_SUPPORTED : Invalid TX power type
* - ESP_FAIL : Failure due to other reasons
*/
esp_err_t esp_ble_tx_power_set ( esp_ble_power_type_t power_type , esp_power_level_t power_level ) ;
/**
* @ brief Get BLE TX power of the specified power type
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* It is recommended to use ` esp_ble_tx_power_get_enhanced ` to get TX power of individual advertising and connection handle .
*
* @ note
* 1. Connection TX power should only be retrieved after the connection is established .
* 2. If an invalid power type is provided , this API returns ` ESP_PWR_LVL_INVALID ` .
2018-07-11 11:52:32 +05:30
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] power_type The type of TX power . It could be Advertising / Connection / Default and etc .
*
* @ return
* - Power level
2018-07-11 11:52:32 +05:30
*
*/
2024-12-03 11:37:18 +08:00
esp_power_level_t esp_ble_tx_power_get ( esp_ble_power_type_t power_type ) ;
2018-07-11 11:52:32 +05:30
2018-04-08 19:19:47 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Set BLE TX power for the specified Advertising or Connection handle
*
* For the TX power type : ` ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT ` , ` ESP_BLE_ENHANCED_PWR_TYPE_SCAN ` , ` ESP_BLE_ENHANCED_PWR_TYPE_INIT ` ,
* this API will ignore the input handle number , and set 0 internally .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* For the TX power type : ` ESP_BLE_ENHANCED_PWR_TYPE_ADV ` and ` ESP_BLE_ENHANCED_PWR_TYPE_CONN ` ,
* this API will set the TX power for the target handle .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. Connection TX power should only be set after connection created .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] power_type The type of TX power
* @ param [ in ] handle The handle of Advertising or Connection
* @ param [ in ] power_level Power level ( index ) corresponding to absolute value ( dBm )
2018-04-08 19:19:47 +08:00
*
* @ return
2024-12-03 11:37:18 +08:00
* - ESP_OK : Success
* - ESP_ERR_NOT_SUPPORTED : Invalid TX power type
* - ESP_FAIL : Failure due to other reasons
2018-04-08 19:19:47 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_ble_tx_power_set_enhanced ( esp_ble_enhanced_power_type_t power_type , uint16_t handle , esp_power_level_t power_level ) ;
2018-04-08 19:19:47 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Get BLE TX power of the specified Advertising or Connection handle
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* For the TX power type : ` ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT ` , ` ESP_BLE_ENHANCED_PWR_TYPE_SCAN ` , ` ESP_BLE_ENHANCED_PWR_TYPE_INIT ` ,
* this API will ignore the input handle number .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* For the TX power type : ` ESP_BLE_ENHANCED_PWR_TYPE_ADV ` and ` ESP_BLE_ENHANCED_PWR_TYPE_CONN ` ,
* this API will return the TX power of the target handle .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. Connection Tx power should only be get after connection created .
* 2. If an invalid power type is provided , this API returns ` ESP_PWR_LVL_INVALID ` .
2018-04-08 19:19:47 +08:00
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] power_type The type of TX power
* @ param [ in ] handle The handle of Advertising or Connection and the value 0 for other enhanced power types
*
* @ return Power level
2018-04-08 19:19:47 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_power_level_t esp_ble_tx_power_get_enhanced ( esp_ble_enhanced_power_type_t power_type , uint16_t handle ) ;
2018-04-08 19:19:47 +08:00
2018-08-20 15:04:37 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Notify Bluetooth Controller task to process the event upon TX or RX done
2019-01-23 18:04:01 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. This function shall not be invoked before ` esp_bt_controller_enable ( ) ` .
* 2. This function can be called in both ISR and non - ISR context .
* 3. This function ignored the passed ` event ` value currently
2020-07-09 20:58:13 +08:00
*/
2024-12-03 11:37:18 +08:00
int esp_bt_h4tl_eif_io_event_notify ( int event ) ;
2020-07-09 20:58:13 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Virtual HCI ( VHCI ) callback functions to notify the Host on the next operation
*/
typedef struct esp_vhci_host_callback {
void ( * notify_host_send_available ) ( void ) ; /*!< callback used to notify that the Host can send the HCI data to Controller */
int ( * notify_host_recv ) ( uint8_t * data , uint16_t len ) ; /*!< callback used to notify that the Controller has the HCI data to send to the Host */
} esp_vhci_host_callback_t ;
/**
* @ brief Check whether the Controller is ready to receive the HCI data
2019-01-23 18:04:01 +08:00
*
2024-12-03 11:37:18 +08:00
* If the return value is True , the Host can send the HCI data to the Controller .
2020-07-09 20:58:13 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note This function should be called before each ` esp_vhci_host_send_packet ( ) ` .
*
* @ return
* True if the Controller is ready to receive the HCI data ; false otherwise .
2018-08-20 15:04:37 +08:00
*/
2024-12-03 11:37:18 +08:00
bool esp_vhci_host_check_send_available ( void ) ;
2020-07-09 20:58:13 +08:00
2024-11-27 16:58:53 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Send the HCI data to the Controller
2024-11-27 16:58:53 +08:00
*
2024-12-03 11:37:18 +08:00
* @ note
* 1. This function shall not be called within a critical section or when the scheduler is suspended .
* 2. This function should be called only if ` esp_vhci_host_check_send_available ` returns True .
2024-11-27 16:58:53 +08:00
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] data Pointer to the HCI data
* @ param [ in ] len The HCI data length
2024-11-27 16:58:53 +08:00
*/
2024-12-03 11:37:18 +08:00
void esp_vhci_host_send_packet ( uint8_t * data , uint16_t len ) ;
2024-11-27 16:58:53 +08:00
2023-12-22 17:25:00 +08:00
/**
2024-12-03 11:37:18 +08:00
* @ brief Register the VHCI callback functions defined in ` esp_vhci_host_callback ` structure .
2023-12-22 17:25:00 +08:00
*
2024-12-03 11:37:18 +08:00
* @ param [ in ] callback ` esp_vhci_host_callback ` type variable
2023-12-22 17:25:00 +08:00
*
2024-12-03 11:37:18 +08:00
* @ return
* - ESP_OK : Success
* - ESP_FAIL : Failure
2023-12-22 17:25:00 +08:00
*/
2024-12-03 11:37:18 +08:00
esp_err_t esp_vhci_host_register_callback ( const esp_vhci_host_callback_t * callback ) ;
2023-12-22 17:25:00 +08:00
2025-02-25 15:17:49 +08:00
/**
* @ brief Select buffers
*/
typedef enum {
ESP_BLE_LOG_BUF_HCI = 0x02 ,
ESP_BLE_LOG_BUF_CONTROLLER = 0x05 ,
} esp_ble_log_buf_t ;
void esp_ble_controller_log_dump_all ( bool output ) ;
2017-12-07 21:48:27 +08:00
# ifdef __cplusplus
}
# endif
# endif /* __ESP_BT_H__ */