mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
feat(bt): Update bt lib for ESP32-C3 and ESP32-S3(4e58df9)
- Support enhanced BLE TX power setting and getting
This commit is contained in:
committed by
zhanghaipeng
parent
6568f8c553
commit
cfebc2052a
@ -118,6 +118,8 @@ do{\
|
|||||||
#define OSI_VERSION 0x00010009
|
#define OSI_VERSION 0x00010009
|
||||||
#define OSI_MAGIC_VALUE 0xFADEBEAD
|
#define OSI_MAGIC_VALUE 0xFADEBEAD
|
||||||
|
|
||||||
|
#define BLE_PWR_HDL_INVL 0xFFFF
|
||||||
|
|
||||||
/* Types definition
|
/* Types definition
|
||||||
************************************************************************
|
************************************************************************
|
||||||
*/
|
*/
|
||||||
@ -254,8 +256,8 @@ extern bool API_vhci_host_check_send_available(void);
|
|||||||
extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len);
|
extern void API_vhci_host_send_packet(uint8_t *data, uint16_t len);
|
||||||
extern int API_vhci_host_register_callback(const vhci_host_callback_t *callback);
|
extern int API_vhci_host_register_callback(const vhci_host_callback_t *callback);
|
||||||
/* TX power */
|
/* TX power */
|
||||||
extern int ble_txpwr_set(int power_type, int power_level);
|
extern int ble_txpwr_set(int power_type, uint16_t handle, int power_level);
|
||||||
extern int ble_txpwr_get(int power_type);
|
extern int ble_txpwr_get(int power_type, uint16_t handle);
|
||||||
|
|
||||||
extern uint16_t l2c_ble_link_get_tx_buf_num(void);
|
extern uint16_t l2c_ble_link_get_tx_buf_num(void);
|
||||||
extern void coex_pti_v2(void);
|
extern void coex_pti_v2(void);
|
||||||
@ -1674,16 +1676,89 @@ esp_bt_controller_status_t esp_bt_controller_get_status(void)
|
|||||||
return btdm_controller_status;
|
return btdm_controller_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int enh_power_type_get(esp_ble_power_type_t power_type)
|
||||||
|
{
|
||||||
|
switch (power_type) {
|
||||||
|
case ESP_BLE_PWR_TYPE_ADV:
|
||||||
|
return ESP_BLE_ENHANCED_PWR_TYPE_ADV;
|
||||||
|
case ESP_BLE_PWR_TYPE_SCAN:
|
||||||
|
return ESP_BLE_ENHANCED_PWR_TYPE_SCAN;
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL0:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL1:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL2:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL3:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL4:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL5:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL6:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL7:
|
||||||
|
case ESP_BLE_PWR_TYPE_CONN_HDL8:
|
||||||
|
return ESP_BLE_ENHANCED_PWR_TYPE_CONN;
|
||||||
|
case ESP_BLE_PWR_TYPE_DEFAULT:
|
||||||
|
return ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return power_type;
|
||||||
|
}
|
||||||
|
|
||||||
/* extra functions */
|
/* extra functions */
|
||||||
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level)
|
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level)
|
||||||
|
{
|
||||||
|
esp_err_t stat = ESP_FAIL;
|
||||||
|
uint16_t handle = BLE_PWR_HDL_INVL;
|
||||||
|
int enh_pwr_type = enh_power_type_get(power_type);
|
||||||
|
|
||||||
|
if (power_type > ESP_BLE_PWR_TYPE_DEFAULT) {
|
||||||
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enh_pwr_type == ESP_BLE_ENHANCED_PWR_TYPE_CONN) {
|
||||||
|
handle = power_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ble_txpwr_set(enh_pwr_type, handle, power_level) == 0) {
|
||||||
|
stat = ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stat;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type)
|
||||||
|
{
|
||||||
|
esp_power_level_t lvl;
|
||||||
|
uint16_t handle = BLE_PWR_HDL_INVL;
|
||||||
|
int enh_pwr_type = enh_power_type_get(power_type);
|
||||||
|
|
||||||
|
if (power_type > ESP_BLE_PWR_TYPE_DEFAULT) {
|
||||||
|
return ESP_PWR_LVL_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enh_pwr_type == ESP_BLE_ENHANCED_PWR_TYPE_CONN) {
|
||||||
|
handle = power_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
lvl = (esp_power_level_t)ble_txpwr_get(power_type, handle);
|
||||||
|
|
||||||
|
return lvl;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
esp_err_t stat = ESP_FAIL;
|
esp_err_t stat = ESP_FAIL;
|
||||||
|
|
||||||
switch (power_type) {
|
switch (power_type) {
|
||||||
case ESP_BLE_PWR_TYPE_ADV:
|
case ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT:
|
||||||
case ESP_BLE_PWR_TYPE_SCAN:
|
case ESP_BLE_ENHANCED_PWR_TYPE_SCAN:
|
||||||
case ESP_BLE_PWR_TYPE_DEFAULT:
|
case ESP_BLE_ENHANCED_PWR_TYPE_INIT:
|
||||||
if (ble_txpwr_set(power_type, power_level) == 0) {
|
if (ble_txpwr_set(power_type, BLE_PWR_HDL_INVL, power_level) == 0) {
|
||||||
|
stat = ESP_OK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ESP_BLE_ENHANCED_PWR_TYPE_ADV:
|
||||||
|
case ESP_BLE_ENHANCED_PWR_TYPE_CONN:
|
||||||
|
if (ble_txpwr_set(power_type, handle, power_level) == 0) {
|
||||||
stat = ESP_OK;
|
stat = ESP_OK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1695,33 +1770,26 @@ esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_
|
|||||||
return stat;
|
return stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type)
|
esp_power_level_t esp_ble_tx_power_get_enhanced(esp_ble_enhanced_power_type_t power_type,
|
||||||
|
uint16_t handle)
|
||||||
{
|
{
|
||||||
esp_power_level_t lvl;
|
int tx_level = 0;
|
||||||
|
|
||||||
switch (power_type) {
|
switch (power_type) {
|
||||||
case ESP_BLE_PWR_TYPE_ADV:
|
case ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT:
|
||||||
case ESP_BLE_PWR_TYPE_SCAN:
|
case ESP_BLE_ENHANCED_PWR_TYPE_SCAN:
|
||||||
lvl = (esp_power_level_t)ble_txpwr_get(power_type);
|
case ESP_BLE_ENHANCED_PWR_TYPE_INIT:
|
||||||
|
tx_level = ble_txpwr_get(power_type, BLE_PWR_HDL_INVL);
|
||||||
break;
|
break;
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL0:
|
case ESP_BLE_ENHANCED_PWR_TYPE_ADV:
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL1:
|
case ESP_BLE_ENHANCED_PWR_TYPE_CONN:
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL2:
|
tx_level = ble_txpwr_get(power_type, handle);
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL3:
|
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL4:
|
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL5:
|
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL6:
|
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL7:
|
|
||||||
case ESP_BLE_PWR_TYPE_CONN_HDL8:
|
|
||||||
case ESP_BLE_PWR_TYPE_DEFAULT:
|
|
||||||
lvl = (esp_power_level_t)ble_txpwr_get(ESP_BLE_PWR_TYPE_DEFAULT);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
lvl = ESP_PWR_LVL_INVALID;
|
return ESP_PWR_LVL_INVALID;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lvl;
|
return (esp_power_level_t)tx_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_bt_sleep_enable (void)
|
esp_err_t esp_bt_sleep_enable (void)
|
||||||
|
Submodule components/bt/controller/lib_esp32c3_family updated: bfdfe8f851...d4922c5890
@ -390,6 +390,18 @@ typedef enum {
|
|||||||
ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */
|
ESP_PWR_LVL_INVALID = 0xFF, /*!< Indicates an invalid value */
|
||||||
} esp_power_level_t;
|
} 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_power_type_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set BLE TX power
|
* @brief Set BLE TX power
|
||||||
* Connection Tx power should only be set after connection created.
|
* Connection Tx power should only be set after connection created.
|
||||||
@ -407,6 +419,25 @@ esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_
|
|||||||
*/
|
*/
|
||||||
esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type);
|
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.
|
* @brief Initialize BT controller to allocate task and other resource.
|
||||||
* This function should be called only once, before any other BT functions are called.
|
* This function should be called only once, before any other BT functions are called.
|
||||||
|
Reference in New Issue
Block a user