Merge branch 'docs/refactor_ceva_bt_controller_api_v5.0' into 'release/v5.0'

docs(ble): Refactored the API reference for esp32/c3/s3 BT controller (v5.0)

See merge request espressif/esp-idf!35349
This commit is contained in:
Wang Meng Yang 2025-02-08 11:05:55 +08:00
commit 90e98f1dbc
2 changed files with 680 additions and 485 deletions

View File

@ -242,47 +242,73 @@ the adv packet will be discarded until the memory is restored. */
/**
* @brief Bluetooth Controller config options
* @note
* 1. For parameters configurable in menuconfig, please refer to menuconfig for details on range and default values.
* 2. It is not recommended to modify the default values of `controller_task_stack_size`, `controller_task_prio`.
* 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.
*/
typedef struct {
uint16_t controller_task_stack_size; /*!< Bluetooth Controller task stack size in bytes */
uint8_t controller_task_prio; /*!< Bluetooth Controller task priority */
uint8_t hci_uart_no; /*!< Indicates UART number if using UART1/2 as HCI I/O interface. Configurable in menuconfig. */
uint32_t hci_uart_baudrate; /*!< Indicates UART baudrate if using UART1/2 as HCI I/O interface. Configurable in menuconfig. */
uint8_t scan_duplicate_mode; /*!< Scan duplicate filtering mode. Configurable in menuconfig. */
uint8_t scan_duplicate_type; /*!< Scan duplicate filtering type. Configurable in menuconfig. */
uint16_t normal_adv_size; /*!< Maximum number of devices in scan duplicate filtering list. Configurable in menuconfig. */
uint16_t mesh_adv_size; /*!< Maximum number of Mesh ADV packets in scan duplicate filtering list. Configurable in menuconfig. */
uint8_t hci_uart_no; /*!< UART number as HCI I/O interface. Configurable in menuconfig.
- 1 - URAT 1 (default)
- 2 - URAT 2 */
uint32_t hci_uart_baudrate; /*!< UART baudrate. Configurable in menuconfig.
- Range: 115200 - 921600
- Default: 921600 */
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 */
uint16_t send_adv_reserved_size; /*!< Controller minimum memory value in bytes. Internal use only */
uint32_t controller_debug_flag; /*!< Controller debug log flag. Internal use only */
uint8_t mode; /*!< Controller mode:
1: BLE mode
2: Classic Bluetooth mode
3: Dual mode
Others: Invalid
Configurable in menuconfig
*/
uint8_t ble_max_conn; /*!< Maximum number of BLE connections. Configurable in menuconfig. */
uint8_t bt_max_acl_conn; /*!< Maximum number of BR/EDR ACL connections. Configurable in menuconfig. */
uint8_t bt_sco_datapath; /*!< SCO data path, i.e. HCI or PCM module. Configurable in menuconfig. */
bool auto_latency; /*!< True if BLE auto latency is enabled, used to enhance Classic Bluetooth performance; false otherwise. Configurable in menuconfig.*/
bool bt_legacy_auth_vs_evt; /*!< True if BR/EDR Legacy Authentication Vendor Specific Event is enabled, which is required to protect from BIAS attack; false otherwise. Configurable in menuconfig. */
uint8_t bt_max_sync_conn; /*!< Maximum number of BR/EDR synchronous connections. Configurable in menuconfig. */
uint8_t ble_sca; /*!< BLE low power crystal accuracy index. Configurable in menuconfig. */
uint8_t pcm_role; /*!< PCM role (master & slave). Configurable in menuconfig.*/
uint8_t pcm_polar; /*!< PCM polar trig (falling clk edge & rising clk edge). Configurable in menuconfig. */
uint8_t pcm_fsyncshp; /*!< Physical shape of the PCM Frame Synchronization signal (stereo mode & mono mode). Configurable in menuconfig */
bool hli; /*!< True if using high level interrupt; false otherwise. Configurable in menuconfig. */
uint16_t dup_list_refresh_period; /*!< Scan duplicate filtering list refresh period in seconds. Configurable in menuconfig.*/
bool ble_scan_backoff; /*!< True if BLE scan backoff is enabled; false otherwise. Configurable in menuconfig.*/
uint8_t ble_llcp_disc_flag; /*!< BLE disconnect flag when instant passed. Configurable in menuconfig. */
bool ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig. */
uint8_t mode; /*!< Controller mode. Configurable in menuconfig
- 1 - BLE mode
- 2 - Classic Bluetooth mode
- 3 - Dual mode
- 4 - Others: Invalid */
uint8_t ble_max_conn; /*!< Maximum number of BLE connections. Configurable in menuconfig
- Range: 1 - 9
- Default: 3 */
uint8_t bt_max_acl_conn; /*!< Maximum number of BR/EDR ACL connections. Configurable in menuconfig
- Range: 1 - 7
- Default: 2 */
uint8_t bt_sco_datapath; /*!< SCO data path. Configurable in menuconfig
- 0 - HCI module (default)
- 1 - PCM module */
bool auto_latency; /*!< True if BLE auto latency is enabled, used to enhance Classic Bluetooth performance in the Dual mode; false otherwise (default). Configurable in menuconfig */
bool bt_legacy_auth_vs_evt; /*!< True if BR/EDR Legacy Authentication Vendor Specific Event is enabled (default in the classic bluetooth or Dual mode), which is required to protect from BIAS attack; false otherwise. Configurable in menuconfig */
uint8_t bt_max_sync_conn; /*!< Maximum number of BR/EDR synchronous connections. Configurable in menuconfig
- Range: 0 - 3
- Default: 0 */
uint8_t ble_sca; /*!< BLE low power crystal accuracy index. Configurable in menuconfig
- 0 - `BTDM_BLE_DEFAULT_SCA_500PPM`
- 1 - `BTDM_BLE_DEFAULT_SCA_250PPM` (default) */
uint8_t pcm_role; /*!< PCM role. Configurable in menuconfig
- 0 - PCM master (default)
- 1 - PCM slave (default) */
uint8_t pcm_polar; /*!< PCM polarity (falling clk edge & rising clk edge). Configurable in menuconfig
- 0 - Falling Edge (default)
- 1 - Rising Edge */
uint8_t pcm_fsyncshp; /*!< Physical shape of the PCM Frame Synchronization signal. Configurable in menuconfig
- 0 - Stereo Mode (default)
- 1 - Mono Mode 1
- 2 - Mono Mode 2 */
bool hli; /*!< True if using high-level (level 4) interrupt (default); false otherwise. Configurable in menuconfig */
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_scan_backoff; /*!< True if BLE scan backoff is enabled; false otherwise (default). Configurable in menuconfig */
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 ble_aa_check; /*!< True if adds a verification step for the Access Address within the `CONNECT_IND` PDU; false otherwise (default). Configurable in menuconfig */
uint32_t magic; /*!< Magic number */
} esp_bt_controller_config_t;
@ -351,82 +377,6 @@ typedef enum {
ESP_SCO_DATA_PATH_PCM = 1, /*!< data over PCM interface */
} esp_sco_data_path_t;
/**
* @brief Set BLE TX power
*
* @note Connection TX power should only be set after the connection is established.
*
* @param[in] power_type The type of TX power. It could be Advertising, Connection, Default, etc.
* @param[in] power_level Power level (index) corresponding to the absolute value (dBm)
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
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
*
* @note Connection TX power should only be retrieved after the connection is established.
*
* @param[in] power_type The type of TX power. It could be Advertising/Connection/Default and etc.
*
* @return
* - Power level
*
*/
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
/**
* @brief Set BR/EDR TX power
*
* BR/EDR power control will use the power within the range of minimum value and maximum value.
* The power level will affect the global BR/EDR TX power for operations such as inquiry, page, and connection.
*
* @note
* 1. Please call this function after `esp_bt_controller_enable()` and before any functions that cause RF transmission,
* such as performing discovery, profile initialization, and so on.
* 2. For BR/EDR to use the new TX power for inquiry, call this function before starting an inquiry.
* If BR/EDR is already inquiring, restart the inquiry after calling this function.
*
* @param[in] min_power_level The minimum power level. The default value is `ESP_PWR_LVL_N0`.
* @param[in] max_power_level The maximum power level. The default value is `ESP_PWR_LVL_P3`.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_bredr_tx_power_set(esp_power_level_t min_power_level, esp_power_level_t max_power_level);
/**
* @brief Get BR/EDR TX power
*
* The corresponding power levels will be stored into the arguments.
*
* @param[out] min_power_level Pointer to store the minimum power level
* @param[out] max_power_level The maximum power level
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
esp_err_t esp_bredr_tx_power_get(esp_power_level_t *min_power_level, esp_power_level_t *max_power_level);
/**
* @brief Set default SCO data path
*
* @note This function should be called after the Controller is enabled, and before (e)SCO link is established.
*
* @param[in] data_path SCO data path
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path);
/**
* @brief Initialize the Bluetooth Controller to allocate tasks and other resources
*
@ -437,6 +387,8 @@ esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path);
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_INVALID_ARG: Invalid arguments
* - ESP_ERR_NO_MEM: Out of memory
*/
esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
@ -445,13 +397,12 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
*
* @note
* 1. You should stop advertising and scanning, and disconnect all existing connections before de-initializing Bluetooth Controller.
* 2. This function should be called only once, after any other Bluetooth functions.
* 2. This function should be called after `esp_bt_controller_disable` if the Controller was enabled before.
* 3. This function should be called only once, after any other Bluetooth functions.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_NO_MEM: Out of memory
*/
esp_err_t esp_bt_controller_deinit(void);
@ -471,6 +422,7 @@ esp_err_t esp_bt_controller_deinit(void);
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_INVALID_ARG: Invalid arguments
*/
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
@ -493,49 +445,6 @@ esp_err_t esp_bt_controller_disable(void);
*/
esp_bt_controller_status_t esp_bt_controller_get_status(void);
/**
* @brief Vendor 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 to notify the Host that the Controller is ready to receive the packet */
int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< Callback to notify the Host that the Controller has a packet to send */
} esp_vhci_host_callback_t;
/**
* @brief Check whether the Controller is ready to receive the packet
*
* If the return value is True, the Host can send the packet to the Controller.
*
* @note This function should be called before each `esp_vhci_host_send_packet()`.
*
* @return
* True if the Controller is ready to receive packets; false otherwise
*/
bool esp_vhci_host_check_send_available(void);
/**
* @brief Send the packet to the Controller
*
* @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.
*
* @param[in] data Pointer to the packet data
* @param[in] len The packet length
*/
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
/**
* @brief Register the VHCI callback funations defined in `esp_vhci_host_callback` structure.
*
* @param[in] callback `esp_vhci_host_callback` type variable
*
* @return
* - ESP_OK: Success
* - ESP_FAIL: Failure
*/
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
/**
* @brief Release the Controller memory as per the mode
*
@ -543,7 +452,7 @@ esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callba
*
* @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.
* 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 switching from BLE to Classic Bluetooth or from disabled to enabled), then do not call this function.
*
@ -553,6 +462,7 @@ esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callba
*
* If you intend to use Classic Bluetooth only, calling `esp_bt_controller_mem_release(ESP_BT_MODE_BLE)` could release the BSS and data consumed by BLE Controller. You can then continue using Classic Bluetooth.
*
*
* @param[in] mode The Bluetooth Controller mode
*
* @return
@ -562,12 +472,11 @@ esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callba
*/
esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode);
/**
* @brief Release the Controller memory, BSS and data section of the Classic Bluetooth/BLE Host stack as per the mode
/** @brief Release the Controller memory, BSS and data section of the Classic Bluetooth/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.
* 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 switching from BLE to Classic Bluetooth or from disabled to enabled), then do not call this function.
*
@ -616,7 +525,6 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode);
*/
esp_err_t esp_bt_sleep_enable(void);
/**
* @brief Disable Bluetooth modem sleep
*
@ -629,35 +537,155 @@ esp_err_t esp_bt_sleep_enable(void);
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED: Operation or feature not supported
* - ESP_ERR_NOT_SUPPORTED: The modem sleep mode is not supported
*/
esp_err_t esp_bt_sleep_disable(void);
/**
* @brief Manually clear the scan duplicate list
* @brief Set BLE TX power
*
* @note Connection TX power should only be set after the connection is established.
*
* @param[in] power_type The type of TX power. It could be Advertising, Connection, Default, etc.
* @param[in] power_level Power level (index) corresponding to the absolute value (dBm)
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
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
*
* @note Connection TX power should only be retrieved after the connection is established.
*
* @param[in] power_type The type of TX power. It could be Advertising/Connection/Default and etc.
*
* @return
* - Power level
*
*/
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
/**
* @brief Manually clear the BLE scan duplicate list
*
* @note
* The scan duplicate list will be automatically cleared when the maximum amount of devices in the filter is reached. The amount of devices in the filter can be configured in menuconfig.
* 1. This function name is incorrectly spelled, it will be fixed in release 5.x version.
* 2. The scan duplicate list will be automatically cleared when the maximum amount of devices in the filter is reached.
* The amount of devices in the filter can be configured in menuconfig.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_ble_scan_duplicate_list_flush(void);
esp_err_t esp_ble_scan_dupilcate_list_flush(void);
/**
* @brief Power on Bluetooth Wi-Fi power domain
* @brief Set BR/EDR TX power
*
* @note This function is not recommended to use due to potential risk.
* BR/EDR power control will use the power within the range of minimum value and maximum value.
* The power level will affect the global BR/EDR TX power for operations such as inquiry, page, and connection.
*
* @note
* 1. Please call this function after `esp_bt_controller_enable()` and before any functions that cause RF transmission,
* such as performing discovery, profile initialization, and so on.
* 2. For BR/EDR to use the new TX power for inquiry, call this function before starting an inquiry.
* If BR/EDR is already inquiring, restart the inquiry after calling this function.
*
* @param[in] min_power_level The minimum power level. The default value is `ESP_PWR_LVL_N0`.
* @param[in] max_power_level The maximum power level. The default value is `ESP_PWR_LVL_P3`.
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_bredr_tx_power_set(esp_power_level_t min_power_level, esp_power_level_t max_power_level);
/**
* @brief Get BR/EDR TX power
*
* The corresponding power levels will be stored into the arguments.
*
* @param[out] min_power_level Pointer to store the minimum power level
* @param[out] max_power_level The maximum power level
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_ARG: Invalid argument
*/
esp_err_t esp_bredr_tx_power_get(esp_power_level_t *min_power_level, esp_power_level_t *max_power_level);
/**
* @brief Set BR/EDR default SCO data path
*
* @note This function should be called after the Controller is enabled, and before (e)SCO link is established.
*
* @param[in] data_path SCO data path
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path);
/**
* @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 to notify the Host that the Controller is ready to receive the HCI data */
int (*notify_host_recv)(uint8_t *data, uint16_t len); /*!< Callback to notify the Host that the Controller has the HCI data to send */
} esp_vhci_host_callback_t;
/**
* @brief Check whether the Controller is ready to receive the HCI data from the Host
*
* If the return value is True, the Host can send the HCI data to the Controller.
*
* @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
*/
bool esp_vhci_host_check_send_available(void);
/**
* @brief Send the HCI data to the Controller
*
* @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.
*
* @param[in] data Pointer to the HCI data
* @param[in] len The HCI data length
*/
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
/**
* @brief Register the VHCI callback functions defined in `esp_vhci_host_callback` structure
*
* @param[in] callback `esp_vhci_host_callback` type variable
*
* @return
* - ESP_OK: Success
* - ESP_FAIL: Failure
*/
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
/**
* @brief Power on Bluetooth Wi-Fi power domain
*
* @note This function is not recommended to use due to potential risk.
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief Power off Bluetooth Wi-Fi power domain
*
* @note This function is not recommended to use due to potential risk.
* @brief Power off Bluetooth Wi-Fi power domain
*
* @note This function is not recommended to use due to potential risk.
*/
void esp_wifi_bt_power_domain_off(void);

View File

@ -18,50 +18,76 @@
extern "C" {
#endif
/**
* @brief Internal use only
*
* @note Please do not modify this value
*/
#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
/**
* @brief Internal use only
*
* @note Please do not modify this value
*/
#define ESP_BT_CTRL_CONFIG_VERSION 0x02410230
/**
* @brief Internal use only
*
* @note Please do not modify this value
*/
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
/**
* @brief Internal use only
*
* @note Please do not modify this value
*/
#define ESP_BT_HCI_TL_VERSION 0x00010000
/**
* @brief Bluetooth mode for controller enable/disable
* @brief Bluetooth Controller mode
*/
typedef enum {
ESP_BT_MODE_IDLE = 0x00, /*!< Bluetooth is not running */
ESP_BT_MODE_BLE = 0x01, /*!< Run BLE mode */
ESP_BT_MODE_CLASSIC_BT = 0x02, /*!< Run Classic BT mode */
ESP_BT_MODE_BTDM = 0x03, /*!< Run dual mode */
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 */
} esp_bt_mode_t;
/**
* @brief Type of controller HCI transport layer
* @brief BLE Controller HCI transport layer type
*/
typedef enum {
ESP_BT_CTRL_HCI_TL_UART = 0, /*!< HCI UART h4 transport layer */
ESP_BT_CTRL_HCI_TL_VHCI = 1, /*!< VHCI interface */
ESP_BT_CTRL_HCI_TL_VHCI = 1, /*!< Virtual HCI interface */
} esp_bt_ctrl_hci_tl_t;
/**
* @brief type of BLE connection event length computation
* @brief BLE connection event length computation type
*/
typedef enum {
ESP_BLE_CE_LEN_TYPE_ORIG = 0, /*!< original */
ESP_BLE_CE_LEN_TYPE_CE = 1, /*!< use CE_LEN parameter from HCI commands */
ESP_BLE_CE_LEN_TYPE_CE = 1, /*!< use `CE_LEN` parameter from HCI commands */
ESP_BLE_CE_LEN_TYPE_SD = 1, /*!< Espressif vendor defined */
} esp_ble_ce_len_t;
/**
* @brief Bluetooth sleep mode
* @brief Bluetooth modem sleep mode
*/
typedef enum {
ESP_BT_SLEEP_MODE_NONE = 0, /*!< Bluetooth sleep mode disabled */
ESP_BT_SLEEP_MODE_1 = 1, /*!< Bluetooth sleep mode 1 */
ESP_BT_SLEEP_MODE_NONE = 0, /*!< Disable modem sleep */
ESP_BT_SLEEP_MODE_1 = 1, /*!< Enable modem sleep */
} esp_bt_sleep_mode_t;
/**
* @brief Bluetooth sleep clock
* @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.
*/
typedef enum {
ESP_BT_SLEEP_CLOCK_NONE = 0, /*!< Sleep clock not configured */
ESP_BT_SLEEP_CLOCK_MAIN_XTAL = 1, /*!< SoC main crystal */
@ -71,19 +97,19 @@ typedef enum {
} esp_bt_sleep_clock_t;
/**
* @brief antenna index used for bluetooth
* @brief Bluetooth antenna index
*/
enum {
ESP_BT_ANT_IDX_0 = 0, /*!< anntena NO 0 */
ESP_BT_ANT_IDX_1 = 1, /*!< anntena NO 1 */
ESP_BT_ANT_IDX_0 = 0, /*!< Antenna NO 0 */
ESP_BT_ANT_IDX_1 = 1, /*!< Antenna NO 1 */
};
/**
* @brief Maximum Tx/Rx time limit on Coded-PHY connection
* @brief Enable / disable the maximum TX/RX time limit for Coded-PHY connections in coexistence with Wi-Fi scenarios
*/
enum {
ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_DISABLE = 0, /*!< Disable the limit */
ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_ENABLE, /*!< Always Enable the limit */
ESP_BT_COEX_PHY_CODED_TX_RX_TIME_LIMIT_FORCE_ENABLE, /*!< Enable the limit */
};
#define ESP_BT_HCI_TL_STATUS_OK (0) /*!< HCI_TL Tx/Rx operation status OK */
@ -347,7 +373,8 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
/**
* @brief Controller HCI transport layer function structure
* This structure shall be registered when HCI transport layer is UART
*
* @note This structure must be registered when HCI transport layer is UART
*/
typedef struct {
uint32_t _magic; /*!< Magic number */
@ -363,390 +390,530 @@ typedef struct {
} esp_bt_hci_tl_t;
/**
* @brief Controller config options, depend on config mask.
* Config mask indicate which functions enabled, this means
* some options or parameters of some functions enabled by config mask.
* @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.
*/
typedef struct {
/*
* Following parameters can not be configured runtime when call esp_bt_controller_init()
* They will be overwritten by constant values from menuconfig options or from macros.
* So, do not modify the value when esp_bt_controller_init()
*/
uint32_t magic; /*!< Magic number */
uint32_t version; /*!< version number of the defined structure */
/*
* Following parameters can be configured runtime, when call esp_bt_controller_init()
*/
uint16_t controller_task_stack_size; /*!< Bluetooth controller task stack size */
uint8_t controller_task_prio; /*!< Bluetooth controller task priority */
uint8_t controller_task_run_cpu; /*!< CPU num that Bluetooth controller task runs on */
uint8_t bluetooth_mode; /*!< Controller mode: BR/EDR, BLE or Dual Mode */
uint8_t ble_max_act; /*!< BLE maximum number of air activities */
uint8_t sleep_mode; /*!< controller sleep mode */
uint8_t sleep_clock; /*!< controller sleep clock */
uint8_t ble_st_acl_tx_buf_nb; /*!< controller static ACL TX BUFFER number */
uint8_t ble_hw_cca_check; /*!< controller hardware triggered CCA check */
uint16_t ble_adv_dup_filt_max; /*!< maximum number of duplicate scan filter */
bool coex_param_en; /*!< deprecated */
uint8_t ce_len_type; /*!< connection event length computation method */
bool coex_use_hooks; /*!< deprecated */
uint8_t hci_tl_type; /*!< HCI transport layer, UART, VHCI, etc */
esp_bt_hci_tl_t *hci_tl_funcs; /*!< hci transport functions used, must be set when hci_tl_type is UART */
uint8_t txant_dft; /*!< default Tx antenna */
uint8_t rxant_dft; /*!< default Rx antenna */
uint8_t txpwr_dft; /*!< default Tx power */
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. */
uint32_t cfg_mask; /*!< Configuration mask to set specific options */
uint8_t scan_duplicate_mode; /*!< scan duplicate mode */
uint8_t scan_duplicate_type; /*!< scan duplicate type */
uint16_t normal_adv_size; /*!< Normal adv size for scan duplicate */
uint16_t mesh_adv_size; /*!< Mesh adv size for scan duplicate */
uint8_t coex_phy_coded_tx_rx_time_limit; /*!< limit on max tx/rx time in case of connection using CODED-PHY with Wi-Fi coexistence */
uint32_t hw_target_code; /*!< hardware target */
uint8_t slave_ce_len_min; /*!< slave minimum ce length*/
uint8_t hw_recorrect_en; /*!< Hardware re-correction enabled */
uint8_t cca_thresh; /*!< cca threshold*/
uint16_t scan_backoff_upperlimitmax; /*!< scan backoff upperlimitmax value */
uint16_t dup_list_refresh_period; /*!< duplicate scan list refresh time */
bool ble_50_feat_supp; /*!< BLE 5.0 feature support */
uint8_t ble_cca_mode; /*!< BLE CCA mode */
uint8_t ble_data_lenth_zero_aux; /*!< Config ext adv aux option */
uint8_t ble_chan_ass_en; /*!< BLE channel assessment enable */
uint8_t ble_ping_en; /*!< BLE ping procedure enable */
uint8_t ble_llcp_disc_flag; /*!< BLE disconnect flag when instant passed */
bool run_in_flash; /*!< Check if controller code is in flash */
bool dtm_en; /*!< Controller DTM feature is enabled or not */
bool enc_en; /*!< Controller encryption feature is enabled or not */
bool qa_test; /*!< Controller QA test feature is enabled or not */
bool master_en; /*!< Controller master feature is enabled or not */
bool scan_en; /*!< Controller scan feature is enabled or not */
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.*/
bool ble_aa_check; /*!< True if adds a verification step for the Access Address within the CONNECT_IND PDU; false otherwise. Configurable in menuconfig */
} esp_bt_controller_config_t;
/**
* @brief Bluetooth controller enable/disable/initialised/de-initialised status
* @brief Bluetooth Controller status
*/
typedef enum {
ESP_BT_CONTROLLER_STATUS_IDLE = 0,
ESP_BT_CONTROLLER_STATUS_INITED,
ESP_BT_CONTROLLER_STATUS_ENABLED,
ESP_BT_CONTROLLER_STATUS_NUM,
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 */
} esp_bt_controller_status_t;
/**
* @brief BLE tx power type
* ESP_BLE_PWR_TYPE_CONN_HDL0-8: for each connection, and only be set after connection completed.
* when disconnect, the correspond TX power is not effected.
* ESP_BLE_PWR_TYPE_ADV : for advertising/scan response.
* ESP_BLE_PWR_TYPE_SCAN : for scan.
* ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value.
* if neither in scan mode nor in adv mode, it will use this default value.
* If none of power type is set, system will use ESP_PWR_LVL_P3 as default for ADV/SCAN/CONN0-9.
* @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.
*/
typedef enum {
ESP_BLE_PWR_TYPE_CONN_HDL0 = 0, /*!< For connection handle 0 */
ESP_BLE_PWR_TYPE_CONN_HDL1 = 1, /*!< For connection handle 1 */
ESP_BLE_PWR_TYPE_CONN_HDL2 = 2, /*!< For connection handle 2 */
ESP_BLE_PWR_TYPE_CONN_HDL3 = 3, /*!< For connection handle 3 */
ESP_BLE_PWR_TYPE_CONN_HDL4 = 4, /*!< For connection handle 4 */
ESP_BLE_PWR_TYPE_CONN_HDL5 = 5, /*!< For connection handle 5 */
ESP_BLE_PWR_TYPE_CONN_HDL6 = 6, /*!< For connection handle 6 */
ESP_BLE_PWR_TYPE_CONN_HDL7 = 7, /*!< For connection handle 7 */
ESP_BLE_PWR_TYPE_CONN_HDL8 = 8, /*!< For connection handle 8 */
ESP_BLE_PWR_TYPE_ADV = 9, /*!< For advertising */
ESP_BLE_PWR_TYPE_SCAN = 10, /*!< For scan */
ESP_BLE_PWR_TYPE_DEFAULT = 11, /*!< For default, if not set other, it will use default value */
ESP_BLE_PWR_TYPE_NUM = 12, /*!< TYPE numbers */
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 */
} esp_ble_power_type_t;
/**
* @brief Bluetooth TX power level(index), it's just a index corresponding to power(dbm).
* @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.
*/
typedef enum {
ESP_PWR_LVL_N24 = 0, /*!< Corresponding to -24dbm */
ESP_PWR_LVL_N21 = 1, /*!< Corresponding to -21dbm */
ESP_PWR_LVL_N18 = 2, /*!< Corresponding to -18dbm */
ESP_PWR_LVL_N15 = 3, /*!< Corresponding to -15dbm */
ESP_PWR_LVL_N12 = 4, /*!< Corresponding to -12dbm */
ESP_PWR_LVL_N9 = 5, /*!< Corresponding to -9dbm */
ESP_PWR_LVL_N6 = 6, /*!< Corresponding to -6dbm */
ESP_PWR_LVL_N3 = 7, /*!< Corresponding to -3dbm */
ESP_PWR_LVL_N0 = 8, /*!< Corresponding to 0dbm */
ESP_PWR_LVL_P3 = 9, /*!< Corresponding to +3dbm */
ESP_PWR_LVL_P6 = 10, /*!< Corresponding to +6dbm */
ESP_PWR_LVL_P9 = 11, /*!< Corresponding to +9dbm */
ESP_PWR_LVL_P12 = 12, /*!< Corresponding to +12dbm */
ESP_PWR_LVL_P15 = 13, /*!< Corresponding to +15dbm */
ESP_PWR_LVL_P18 = 14, /*!< Corresponding to +18dbm */
ESP_PWR_LVL_P20 = 15, /*!< Corresponding to +20dbm */
ESP_PWR_LVL_P21 = 15, /*!< Corresponding to +20dbm, this enum variable has been deprecated */
ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */
} esp_power_level_t;
/**
* @brief The enhanced type of which tx power, could set Advertising/Connection/Default and etc.
*/
typedef enum {
ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT = 0,
ESP_BLE_ENHANCED_PWR_TYPE_ADV,
ESP_BLE_ENHANCED_PWR_TYPE_SCAN,
ESP_BLE_ENHANCED_PWR_TYPE_INIT,
ESP_BLE_ENHANCED_PWR_TYPE_CONN,
ESP_BLE_ENHANCED_PWR_TYPE_MAX,
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 */
} esp_ble_enhanced_power_type_t;
/**
* @brief Set BLE TX power
* Connection Tx power should only be set after connection created.
* @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
* @param power_level: Power level(index) corresponding to absolute value(dbm)
* @return ESP_OK - success, other - failed
* @brief Bluetooth TX power level (index). Each index corresponds to a specific power value in dBm.
*/
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level);
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;
/**
* @brief Get BLE TX power
* Connection Tx power should only be get after connection created.
* @param power_type : The type of which tx power, could set Advertising/Connection/Default and etc
* @return >= 0 - Power level, < 0 - Invalid
*/
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
/**
* @brief ENHANCED API for Setting BLE TX power
* Connection Tx power should only be set after connection created.
* @param power_type : The enhanced type of which tx power, could set Advertising/Connection/Default and etc.
* @param handle : The handle of Advertising or Connection and the value 0 for other enhanced power types.
* @param power_level: Power level(index) corresponding to absolute value(dbm)
* @return ESP_OK - success, other - failed
*/
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);
/**
* @brief ENHANCED API of Getting BLE TX power
* Connection Tx power should only be get after connection created.
* @param power_type : The enhanced type of which tx power, could set Advertising/Connection/Default and etc
* @param handle : The handle of Advertising or Connection and the value 0 for other enhanced power types.
* @return >= 0 - Power level, < 0 - Invalid
*/
esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle);
/**
* @brief Initialize BT controller to allocate task and other resource.
* This function should be called only once, before any other BT functions are called.
* @param cfg: Initial configuration of BT controller. Different from previous version, there's a mode and some
* connection configuration in "cfg" to configure controller work mode and allocate the resource which is needed.
* @return ESP_OK - success, other - failed
* @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
*
*/
esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg);
/**
* @brief De-initialize BT controller to free resource and delete task.
* You should stop advertising and scanning, as well as
* disconnect all existing connections before de-initializing BT controller.
* @brief De-initialize Bluetooth Controller to free resources and delete tasks
*
* This function should be called only once, after any other BT functions are called.
* This function is not whole completed, esp_bt_controller_init cannot called after this function.
* @return ESP_OK - success, other - failed
* @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
*/
esp_err_t esp_bt_controller_deinit(void);
/**
* @brief Enable BT controller.
* Due to a known issue, you cannot call esp_bt_controller_enable() a second time
* to change the controller mode dynamically. To change controller mode, call
* esp_bt_controller_disable() and then call esp_bt_controller_enable() with the new mode.
* @param mode : the mode(BLE/BT/BTDM) to enable. For compatible of API, retain this argument. This mode must be
* equal as the mode in "cfg" of esp_bt_controller_init().
* @return ESP_OK - success, other - failed
* @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
*/
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode);
/**
* @brief Disable BT controller
* @return ESP_OK - success, other - failed
* @brief Disable Bluetooth Controller
*
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
*/
esp_err_t esp_bt_controller_disable(void);
/**
* @brief Get BT controller is initialised/de-initialised/enabled/disabled
* @return status value
* @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.
*/
esp_bt_controller_status_t esp_bt_controller_get_status(void);
/** @brief esp_vhci_host_callback
* used for vhci call host function to notify what host need to do
*/
typedef struct esp_vhci_host_callback {
void (*notify_host_send_available)(void); /*!< callback used to notify that the host can send packet to controller */
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*/
} esp_vhci_host_callback_t;
/** @brief esp_vhci_host_check_send_available
* used for check actively if the host can send packet to controller or not.
* @return true for ready to send, false means cannot send packet
*/
bool esp_vhci_host_check_send_available(void);
/** @brief esp_vhci_host_send_packet
* host send packet to controller
/**
* @brief Release the Controller memory as per the mode
*
* Should not call this function from within a critical section
* or when the scheduler is suspended.
* This function releases the BSS, data and other sections of the Controller to heap. The total size is about 70 KB.
*
* @param data the packet point
* @param len the packet length
*/
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
/** @brief esp_vhci_host_register_callback
* register the vhci reference callback
* struct defined by vhci_host_callback structure.
* @param callback esp_vhci_host_callback type variable
* @return ESP_OK - success, ESP_FAIL - failed
*/
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
/** @brief esp_bt_controller_mem_release
* release the controller memory 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 releases the BSS, data and other sections of the controller to heap. The total size is about 70k bytes.
* 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.
*
* esp_bt_controller_mem_release(mode) should be called only before esp_bt_controller_init()
* or after esp_bt_controller_deinit().
*
* Note that once BT controller memory is released, the process cannot be reversed. It means you cannot use the bluetooth
* mode which you have released by this function.
* @param[in] mode The Bluetooth Controller mode
*
* If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
* then do not call this function.
*
* If the app calls esp_bt_controller_enable(ESP_BT_MODE_BLE) to use BLE only then it is safe to call
* esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT) at initialization time to free unused BT Classic memory.
*
* 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,
* which internally calls esp_bt_controller_mem_release(ESP_BT_MODE_BTDM) and additionally releases the BSS and data
* consumed by the BT/BLE host stack to heap. For more details about usage please refer to the documentation of
* esp_bt_mem_release() function
*
* @param mode : the mode want to release memory
* @return ESP_OK - success, other - failed
* @return
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_NOT_FOUND: Requested resource not found
*/
esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode);
/** @brief esp_bt_mem_release
* release controller memory and BSS and data section of the BT/BLE host stack as per the mode
/** @brief Release the Controller memory, BSS and data section of the BLE Host stack as per the mode
*
* This function first releases controller memory by internally calling esp_bt_controller_mem_release().
* 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
* @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.
*
* Note that once BT memory is released, the process cannot be reversed. It means you cannot use the bluetooth
* mode which you have released by this function.
* This function first releases Controller memory by internally calling `esp_bt_controller_mem_release()`, then releases Host memory.
*
* If your firmware will later upgrade the Bluetooth controller mode (BLE -> BT Classic or disabled -> enabled)
* then do not call this function.
* 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.
*
* If you never intend to use bluetooth in a current boot-up cycle, you can call esp_bt_mem_release(ESP_BT_MODE_BTDM)
* before esp_bt_controller_init or after esp_bt_controller_deinit.
*
* 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".
* In such cases, after receiving the WiFi configuration, you can disable/deinit bluetooth and release its memory.
* 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_BTDM);
* esp_bluedroid_disable();
* esp_bluedroid_deinit();
* esp_bt_controller_disable();
* esp_bt_controller_deinit();
* esp_bt_mem_release(ESP_BT_MODE_BLE);
*
* @param mode : the mode whose memory is to be released
* @return ESP_OK - success, other - failed
* @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
*/
esp_err_t esp_bt_mem_release(esp_bt_mode_t mode);
/**
* @brief enable bluetooth to enter modem sleep
* @brief Enable Bluetooth modem sleep
*
* Note that this function shall not be invoked before esp_bt_controller_enable()
* 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.
*
* 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.
* 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()`.
*
* For ORIG mode:
* 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".
* @note This function shall not be invoked before `esp_bt_controller_enable()`.
*
* @return
* - ESP_OK : success
* - other : failed
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED: Operation or feature not supported
*/
esp_err_t esp_bt_sleep_enable(void);
/**
* @brief disable bluetooth modem sleep
* @brief Disable Bluetooth modem sleep
*
* Note that this function shall not be invoked before esp_bt_controller_enable()
*
* If esp_bt_sleep_disable() is called, bluetooth controller will not be allowed to enter modem sleep;
*
* 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.
* In this case, esp_bt_controller_wakeup_request() can be used to shorten the time for wakeup.
* @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
* - other : failed
* - ESP_OK: Success
* - ESP_ERR_INVALID_STATE: Invalid Bluetooth Controller state
* - ESP_ERR_NOT_SUPPORTED: Operation or feature not supported
*/
esp_err_t esp_bt_sleep_disable(void);
/**
* @brief to check whether bluetooth controller is sleeping at the instant, if modem sleep is enabled
* @brief Get the Bluetooth sleep clock source.
*
* Note that this function shall not be invoked before esp_bt_controller_enable()
* This function is supposed to be used ORIG mode of modem sleep
*
* @return true if in modem sleep state, false otherwise
*/
bool esp_bt_controller_is_sleeping(void);
/**
* @brief request controller to wakeup from sleeping state during sleep mode
*
* Note that this function shall not be invoked before esp_bt_controller_enable()
* Note that this function is supposed to be used ORIG mode of modem sleep
* Note that after this request, bluetooth controller may again enter sleep as long as the modem sleep is enabled
*
* Profiling shows that it takes several milliseconds to wakeup from modem sleep after this request.
* 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.
*/
void esp_bt_controller_wakeup_request(void);
/**
* @brief notify bluetooth controller task to process the event upon Tx or Rx done
*
* Note that this function shall not be invoked before esp_bt_controller_enable()
* This function can be called in both ISR and non-ISR context
*
*/
int esp_bt_h4tl_eif_io_event_notify(int event);
/**
* @brief bt Wi-Fi power domain power on
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief bt Wi-Fi power domain power off
*/
void esp_wifi_bt_power_domain_off(void);
/**
* @brief Get the Bluetooth module sleep clock source.
*
* Note that this function shall not be invoked before esp_bt_controller_init()
* @note This function shall not be invoked before `esp_bt_controller_init()`.
*
* @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.
*
* @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.
*
* @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
*
* Profiling shows that it takes several milliseconds to wakeup from modem sleep after this request.
*
* 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.
*
* @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.
*/
void esp_bt_controller_wakeup_request(void);
/**
* @brief Set BLE TX power for the specified power type
*
* It is recommended to use `esp_ble_tx_power_set_enhanced` to set TX power for individual advertising and connection handle.
*
* @note Connection TX power should only be set after the connection is established.
*
* @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)
*
* @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
*
* 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`.
*
* @param[in] power_type The type of TX power. It could be Advertising/Connection/Default and etc.
*
* @return
* - Power level
*
*/
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
/**
* @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.
*
* 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.
*
* @note
* 1. Connection TX power should only be set after connection created.
*
* @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)
*
* @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_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle, esp_power_level_t power_level);
/**
* @brief Get BLE TX power of 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.
*
* 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.
*
* @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`.
*
* @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
*/
esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type, uint16_t handle);
/**
* @brief Notify Bluetooth Controller task to process the event upon TX or RX done
*
* @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
*/
int esp_bt_h4tl_eif_io_event_notify(int event);
/**
* @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
*
* If the return value is True, the Host can send the HCI data to the Controller.
*
* @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.
*/
bool esp_vhci_host_check_send_available(void);
/**
* @brief Send the HCI data to the Controller
*
* @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.
*
* @param[in] data Pointer to the HCI data
* @param[in] len The HCI data length
*/
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len);
/**
* @brief Register the VHCI callback functions defined in `esp_vhci_host_callback` structure.
*
* @param[in] callback `esp_vhci_host_callback` type variable
*
* @return
* - ESP_OK: Success
* - ESP_FAIL: Failure
*/
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback);
/**
* @brief Power on Bluetooth Wi-Fi power domain
*
* @note This function is not recommended to use due to potential risk.
*/
void esp_wifi_bt_power_domain_on(void);
/**
* @brief Power off Bluetooth Wi-Fi power domain
*
* @note This function is not recommended to use due to potential risk.
*/
void esp_wifi_bt_power_domain_off(void);
#ifdef __cplusplus
}
#endif