From d7bfbef8623213ba18facd953e261d182e4bf820 Mon Sep 17 00:00:00 2001 From: zhaoweiliang Date: Tue, 31 Mar 2026 20:19:20 +0800 Subject: [PATCH] feat(ble): add adv tx options on ESP32-C5 --- components/bt/controller/esp32c5/Kconfig.in | 96 +++++++++++++++++++ components/bt/controller/esp32c5/esp_bt_cfg.h | 36 +++++++ .../bt/include/esp32c5/include/esp_bt.h | 4 +- 3 files changed, 134 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32c5/Kconfig.in b/components/bt/controller/esp32c5/Kconfig.in index 8f9caa610a..64748184b5 100644 --- a/components/bt/controller/esp32c5/Kconfig.in +++ b/components/bt/controller/esp32c5/Kconfig.in @@ -852,3 +852,99 @@ config BT_LE_CTRL_ADV_FAST_TX_EN and the actual on-air transmission by executing the advertising TX path from IRAM. Note: Enabling this option increases IRAM usage. + +menu "Adv Tx Options" + config BT_LE_CTRL_ADV_EVENT_INC_ON_FULL_TX_EN + bool "Increment advertising event count only on full PDU TX success" + default n + help + When enabled, the advertising event count is incremented only + if all PDUs in an advertising event are transmitted successfully. + If disabled, the event count is incremented regardless of transmission success. + + config BT_LE_CTRL_ADV_CH38_39_TX_AVOID_CONFLICT_EN + bool "Delay advertising TX on channels 38/39 to avoid scheduling conflicts" + default n + help + When enabled, advertising transmissions on channels 38 and 39 + are delayed if a scheduling conflict occurs. + + config BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN + bool "Enable separate TX power for advertising on channel 39" + default n + help + When enabled, the TX power for advertising transmissions + on channel 39 can be configured independently of other channels. + + config BT_LE_CTRL_ADV_TX_CONTINUE_WHEN_EXCEED_ITVL_EN + bool "Allow advertising TX to continue if data TX exceeds interval" + default n + help + When enabled, advertising transmission continues even if the + TX duration for advertising data exceeds the configured advertising interval. + + config BT_LE_CTRL_ADV_RAND_CH_IDX_EN + bool "Enable Randomized Advertising Channel Indexing" + default n + help + When enabled, the advertising channel sequence is randomized + according to the Randomized Advertising Channel Indexing feature. + If disabled, the standard channel sequence is used. + + choice BT_LE_DFT_CH39_TX_POWER_LEVEL_DBM + prompt "BLE default Tx power level(dBm)" + depends on BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN + default BT_LE_DFT_CH39_TX_POWER_LEVEL_P9 + help + Specify default Tx power level(dBm). + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N24 + bool "-24dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N21 + bool "-21dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N18 + bool "-18dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N15 + bool "-15dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N12 + bool "-12dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N9 + bool "-9dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N6 + bool "-6dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N3 + bool "-3dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_N0 + bool "0dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P3 + bool "+3dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P6 + bool "+6dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P9 + bool "+9dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P12 + bool "+12dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P15 + bool "+15dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P18 + bool "+18dBm" + config BT_LE_DFT_CH39_TX_POWER_LEVEL_P20 + bool "+20dBm" + endchoice + + config BT_LE_DFT_CH39_TX_POWER_LEVEL_DBM_EFF + int + default -15 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N15 + default -12 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N12 + default -9 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N9 + default -6 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N6 + default -3 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N3 + default 0 if BT_LE_DFT_CH39_TX_POWER_LEVEL_N0 + default 3 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P3 + default 6 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P6 + default 9 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P9 + default 12 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P12 + default 15 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P15 + default 18 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P18 + default 20 if BT_LE_DFT_CH39_TX_POWER_LEVEL_P20 + default 0 +endmenu diff --git a/components/bt/controller/esp32c5/esp_bt_cfg.h b/components/bt/controller/esp32c5/esp_bt_cfg.h index 5d547e6ac4..034db10c38 100644 --- a/components/bt/controller/esp32c5/esp_bt_cfg.h +++ b/components/bt/controller/esp32c5/esp_bt_cfg.h @@ -314,6 +314,42 @@ extern "C" { #define DEFAULT_BT_LE_CTRL_RXBUF_MEM_RESV (0) #endif +#ifdef CONFIG_BT_LE_CTRL_ADV_EVENT_INC_ON_FULL_TX_EN +#define DEFAULT_BT_LE_CTRL_ADV_EVENT_INC_ON_FULL_TX_EN (1<<0) +#else +#define DEFAULT_BT_LE_CTRL_ADV_EVENT_INC_ON_FULL_TX_EN (0) +#endif + +#ifdef CONFIG_BT_LE_CTRL_ADV_CH38_39_TX_AVOID_CONFLICT_EN +#define DEFAULT_BT_LE_CTRL_ADV_CH38_39_TX_AVOID_CONFLICT_EN (1<<1) +#else +#define DEFAULT_BT_LE_CTRL_ADV_CH38_39_TX_AVOID_CONFLICT_EN (0) +#endif + +#ifdef CONFIG_BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN +#define DEFAULT_BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN (1<<2) +#define BLE_CH39_TX_PWR_DBM_N (CONFIG_BT_LE_DFT_CH39_TX_POWER_LEVEL_DBM_EFF) +#else +#define DEFAULT_BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN (0) +#define BLE_CH39_TX_PWR_DBM_N (CONFIG_BT_LE_DFT_TX_POWER_LEVEL_DBM_EFF) +#endif + +#ifdef CONFIG_BT_LE_CTRL_ADV_TX_CONTINUE_WHEN_EXCEED_ITVL_EN +#define DEFAULT_BT_LE_CTRL_ADV_TX_CONTINUE_WHEN_EXCEED_ITVL_EN (1<<3) +#else +#define DEFAULT_BT_LE_CTRL_ADV_TX_CONTINUE_WHEN_EXCEED_ITVL_EN (0) +#endif + +#ifdef CONFIG_BT_LE_CTRL_ADV_RAND_CH_IDX_EN +#define DEFAULT_BT_LE_CTRL_ADV_RAND_CH_IDX_EN (1<<4) +#else +#define DEFAULT_BT_LE_CTRL_ADV_RAND_CH_IDX_EN (0) +#endif + +#define DEFAULT_BT_LE_ADV_TX_OPTIONS (DEFAULT_BT_LE_CTRL_ADV_EVENT_INC_ON_FULL_TX_EN | \ + DEFAULT_BT_LE_CTRL_ADV_CH38_39_TX_AVOID_CONFLICT_EN | DEFAULT_BT_LE_ADV_CH39_TXPWR_CONFIG_SEPARATELY_EN | \ + DEFAULT_BT_LE_CTRL_ADV_TX_CONTINUE_WHEN_EXCEED_ITVL_EN | DEFAULT_BT_LE_CTRL_ADV_RAND_CH_IDX_EN ) + /* Unchanged configuration */ #define BLE_LL_CTRL_PROC_TIMEOUT_MS_N (40000) /* ms */ diff --git a/components/bt/include/esp32c5/include/esp_bt.h b/components/bt/include/esp32c5/include/esp_bt.h index 2f55323117..4576f1638c 100644 --- a/components/bt/include/esp32c5/include/esp_bt.h +++ b/components/bt/include/esp32c5/include/esp_bt.h @@ -295,10 +295,10 @@ typedef struct { .ble_data_lenth_zero_aux = DEFAULT_BT_LE_CTRL_ADV_DATA_LENGTH_ZERO_AUX, \ .vhci_enabled = DEFAULT_BT_LE_VHCI_ENABLED, \ .ptr_check_enabled = DEFAULT_BT_LE_PTR_CHECK_ENABLED, \ - .ble_adv_tx_options = 0, \ + .ble_adv_tx_options = DEFAULT_BT_LE_ADV_TX_OPTIONS, \ .skip_unnecessary_checks_en = 0, \ .fast_conn_data_tx_en = DEFAULT_BT_LE_CTRL_FAST_CONN_DATA_TX_EN, \ - .ch39_txpwr = BLE_LL_TX_PWR_DBM_N, \ + .ch39_txpwr = BLE_CH39_TX_PWR_DBM_N, \ .adv_rsv_cnt = BLE_LL_ADV_SM_RESERVE_CNT_N, \ .conn_rsv_cnt = BLE_LL_CONN_SM_RESERVE_CNT_N, \ .priority_level_cfg = BT_LL_CTRL_PRIO_LVL_CFG, \