diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 0805bedc41..1df82ad95e 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -237,6 +237,13 @@ config BT_LE_CTE_FEATURE_ENABLED This feature allows devices to determine the direction of a Bluetooth CTE signal, enabling Angle of Arrival (AoA) and Angle of Departure (AoD) functionality. +config BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED + bool "Enable BLE periodic advertising with response" + depends on BT_LE_50_FEATURE_SUPPORT + default n + help + This enables BLE periodic advertising with response feature + menu "Memory Settings" depends on !BT_NIMBLE_ENABLED diff --git a/components/bt/controller/esp32c6/ble.c b/components/bt/controller/esp32c6/ble.c index 60dfaa2a01..792211e83f 100644 --- a/components/bt/controller/esp32c6/ble.c +++ b/components/bt/controller/esp32c6/ble.c @@ -17,11 +17,6 @@ void base_stack_deinitEnv(void); int base_stack_enable(void); void base_stack_disable(void); -int conn_stack_initEnv(void); -void conn_stack_deinitEnv(void); -int conn_stack_enable(void); -void conn_stack_disable(void); - int adv_stack_initEnv(void); void adv_stack_deinitEnv(void); int adv_stack_enable(void); @@ -44,6 +39,11 @@ int dtm_stack_enable(void); void dtm_stack_disable(void); #endif // CONFIG_BT_LE_DTM_ENABLED +int conn_stack_initEnv(void); +void conn_stack_deinitEnv(void); +int conn_stack_enable(void); +void conn_stack_disable(void); + #if CONFIG_BT_LE_ERROR_SIM_ENABLED int conn_errorSim_initEnv(void); void conn_errorSim_deinitEnv(void); @@ -51,6 +51,25 @@ int conn_errorSim_enable(void); void conn_errorSim_disable(void); #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED +int ble_single_env_init(void); +void ble_single_env_deinit(void); +int ble_single_init(void); +void ble_single_deinit(void); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + +#if DEFAULT_BT_LE_PAWR_SUPPORTED +int pawrBcast_stack_initEnv(void); +void pawrBcast_stack_deinitEnv(void); +int pawrBcast_stack_enable(void); +void pawrBcast_stack_disable(void); + +int pawrSync_stack_initEnv(void); +void pawrSync_stack_deinitEnv(void); +int pawrSync_stack_enable(void); +void pawrSync_stack_disable(void); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED + #if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) void adv_stack_enableClearLegacyAdvVsCmd(bool en); void scan_stack_enableAdvFlowCtrlVsCmd(bool en); @@ -61,9 +80,6 @@ void chanSel_stack_enableSetCsaVsCmd(bool en); void log_stack_enableLogsRelatedVsCmd(bool en); void hci_stack_enableSetVsEvtMaskVsCmd(bool en); void winWiden_stack_enableSetConstPeerScaVsCmd(bool en); -#if CONFIG_IDF_TARGET_ESP32C61_ECO3 -void conn_stack_enableSetPrefTxRxCntVsCmd(bool en); -#endif // CONFIG_IDF_TARGET_ESP32C61_ECO3 void adv_stack_enableScanReqRxdVsEvent(bool en); void conn_stack_enableChanMapUpdCompVsEvent(bool en); @@ -88,9 +104,6 @@ void ble_stack_enableVsCmds(bool en) log_stack_enableLogsRelatedVsCmd(en); hci_stack_enableSetVsEvtMaskVsCmd(en); winWiden_stack_enableSetConstPeerScaVsCmd(en); -#if CONFIG_IDF_TARGET_ESP32C61_ECO3 - conn_stack_enableSetPrefTxRxCntVsCmd(en); -#endif // CONFIG_IDF_TARGET_ESP32C61_ECO3 } void ble_stack_enableVsEvents(bool en) @@ -113,19 +126,6 @@ int ble_stack_initEnv(void) return rc; } -#if DEFAULT_BT_LE_MAX_CONNECTIONS - rc = conn_stack_initEnv(); - if (rc) { - return rc; - } -#if CONFIG_BT_LE_ERROR_SIM_ENABLED - rc = conn_errorSim_initEnv(); - if (rc) { - return rc; - } -#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED -#endif // DEFAULT_BT_LE_MAX_CONNECTIONS - rc = adv_stack_initEnv(); if (rc) { return rc; @@ -147,11 +147,58 @@ int ble_stack_initEnv(void) return rc; } #endif // CONFIG_BT_LE_DTM_ENABLED + +#if DEFAULT_BT_LE_MAX_CONNECTIONS + rc = conn_stack_initEnv(); + if (rc) { + return rc; + } +#if CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = conn_errorSim_initEnv(); + if (rc) { + return rc; + } +#endif // CONFIG_BT_LE_ERROR_SIM_ENABLED +#endif // DEFAULT_BT_LE_MAX_CONNECTIONS + +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = ble_single_env_init(); + if (rc) { + return rc; + } + + rc = ble_single_init(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + +#if DEFAULT_BT_LE_PAWR_SUPPORTED + rc = pawrBcast_stack_initEnv(); + if (rc) { + return rc; + } + + rc = pawrSync_stack_initEnv(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED + return 0; } void ble_stack_deinitEnv(void) { +#if DEFAULT_BT_LE_PAWR_SUPPORTED + pawrSync_stack_deinitEnv(); + pawrBcast_stack_deinitEnv(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + ble_single_deinit(); + ble_single_env_deinit(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + #if DEFAULT_BT_LE_MAX_CONNECTIONS #if CONFIG_BT_LE_ERROR_SIM_ENABLED conn_errorSim_deinitEnv(); @@ -161,6 +208,7 @@ void ble_stack_deinitEnv(void) #if CONFIG_BT_LE_DTM_ENABLED dtm_stack_deinitEnv(); #endif // CONFIG_BT_LE_DTM_ENABLED + sync_stack_deinitEnv(); extAdv_stack_deinitEnv(); adv_stack_deinitEnv(); @@ -210,6 +258,17 @@ int ble_stack_enable(void) } #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED #endif // DEFAULT_BT_LE_MAX_CONNECTIONS +#if DEFAULT_BT_LE_PAWR_SUPPORTED + rc = pawrBcast_stack_enable(); + if (rc) { + return rc; + } + + rc = pawrSync_stack_enable(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED #if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) ble_stack_enableVsCmds(true); @@ -229,7 +288,10 @@ void ble_stack_disable(void) ble_stack_enableVsEvents(false); ble_stack_enableVsCmds(false); #endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) - +#if DEFAULT_BT_LE_PAWR_SUPPORTED + pawrSync_stack_disable(); + pawrBcast_stack_disable(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED #if DEFAULT_BT_LE_MAX_CONNECTIONS #if CONFIG_BT_LE_ERROR_SIM_ENABLED conn_errorSim_disable(); diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 70cd94f8bd..8b6fe442fa 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -919,8 +919,20 @@ static void ble_rtc_clk_init(esp_bt_controller_config_t *cfg) #if CONFIG_RTC_CLK_SRC_INT_RC s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_RC_SLOW; #elif CONFIG_RTC_CLK_SRC_EXT_CRYS + uint32_t clk_freq = 0; + if (rtc_clk_slow_src_get() == SOC_RTC_SLOW_CLK_SRC_XTAL32K) { - s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_XTAL32K; + if (!esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_XTAL32K, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &clk_freq)) { + if (clk_freq > 32700 && clk_freq < 33800) { + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_XTAL32K; + } else { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL detection error, switch to main XTAL as Bluetooth sleep clock"); + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; + } + } else { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL detection error, switch to main XTAL as Bluetooth sleep clock"); + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; + } } else { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock"); s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; diff --git a/components/bt/controller/esp32c6/esp_bt_cfg.h b/components/bt/controller/esp32c6/esp_bt_cfg.h index 6def839e56..07a3acdb5e 100644 --- a/components/bt/controller/esp32c6/esp_bt_cfg.h +++ b/components/bt/controller/esp32c6/esp_bt_cfg.h @@ -46,6 +46,11 @@ extern "C" { #else #define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0) #endif + #if CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES + #define DEFAULT_BT_LE_PAWR_SUPPORTED (1) + #else + #define DEFAULT_BT_LE_PAWR_SUPPORTED (0) + #endif // CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES #else #if CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY @@ -72,6 +77,12 @@ extern "C" { #define DEFAULT_BT_LE_MAX_CONNECTIONS (2) #endif + #if defined(CONFIG_BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED) + #define DEFAULT_BT_LE_PAWR_SUPPORTED (CONFIG_BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED) + #else + #define DEFAULT_BT_LE_PAWR_SUPPORTED (0) + #endif + #if defined(CONFIG_BT_LE_ACL_BUF_SIZE) #define DEFAULT_BT_LE_ACL_BUF_SIZE (CONFIG_BT_LE_ACL_BUF_SIZE) #else diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index fd0dff5b73..6f6290765e 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -240,6 +240,13 @@ config BT_LE_CTE_FEATURE_ENABLED communication scenarios. If you are using chip esp32h2, ensure that encryption is disabled when using this feature. +config BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED + bool "Enable BLE periodic advertising with response" + depends on BT_LE_50_FEATURE_SUPPORT + default n + help + This enables BLE periodic advertising with response feature + menu "Memory Settings" depends on !BT_NIMBLE_ENABLED diff --git a/components/bt/controller/esp32h2/ble.c b/components/bt/controller/esp32h2/ble.c index 70fb867eec..0b6fc1e7d0 100644 --- a/components/bt/controller/esp32h2/ble.c +++ b/components/bt/controller/esp32h2/ble.c @@ -17,11 +17,6 @@ void base_stack_deinitEnv(void); int base_stack_enable(void); void base_stack_disable(void); -int conn_stack_initEnv(void); -void conn_stack_deinitEnv(void); -int conn_stack_enable(void); -void conn_stack_disable(void); - int adv_stack_initEnv(void); void adv_stack_deinitEnv(void); int adv_stack_enable(void); @@ -44,6 +39,30 @@ int dtm_stack_enable(void); void dtm_stack_disable(void); #endif // CONFIG_BT_LE_DTM_ENABLED +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED +int ble_single_env_init(void); +void ble_single_env_deinit(void); +int ble_single_init(void); +void ble_single_deinit(void); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + +#if DEFAULT_BT_LE_PAWR_SUPPORTED +int pawrBcast_stack_initEnv(void); +void pawrBcast_stack_deinitEnv(void); +int pawrBcast_stack_enable(void); +void pawrBcast_stack_disable(void); + +int pawrSync_stack_initEnv(void); +void pawrSync_stack_deinitEnv(void); +int pawrSync_stack_enable(void); +void pawrSync_stack_disable(void); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED + +int conn_stack_initEnv(void); +void conn_stack_deinitEnv(void); +int conn_stack_enable(void); +void conn_stack_disable(void); + #if CONFIG_BT_LE_ERROR_SIM_ENABLED int conn_errorSim_initEnv(void); void conn_errorSim_deinitEnv(void); @@ -142,11 +161,44 @@ int ble_stack_initEnv(void) #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED #endif // DEFAULT_BT_LE_MAX_CONNECTIONS +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + rc = ble_single_env_init(); + if (rc) { + return rc; + } + + rc = ble_single_init(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + +#if DEFAULT_BT_LE_PAWR_SUPPORTED + rc = pawrBcast_stack_initEnv(); + if (rc) { + return rc; + } + + rc = pawrSync_stack_initEnv(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED + return 0; } void ble_stack_deinitEnv(void) { +#if DEFAULT_BT_LE_PAWR_SUPPORTED + pawrSync_stack_deinitEnv(); + pawrBcast_stack_deinitEnv(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED +#if DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + ble_single_deinit(); + ble_single_env_deinit(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED || CONFIG_BT_LE_ERROR_SIM_ENABLED + #if DEFAULT_BT_LE_MAX_CONNECTIONS #if CONFIG_BT_LE_ERROR_SIM_ENABLED conn_errorSim_deinitEnv(); @@ -156,6 +208,7 @@ void ble_stack_deinitEnv(void) #if CONFIG_BT_LE_DTM_ENABLED dtm_stack_deinitEnv(); #endif // CONFIG_BT_LE_DTM_ENABLED + sync_stack_deinitEnv(); extAdv_stack_deinitEnv(); adv_stack_deinitEnv(); @@ -205,6 +258,17 @@ int ble_stack_enable(void) } #endif // CONFIG_BT_LE_ERROR_SIM_ENABLED #endif // DEFAULT_BT_LE_MAX_CONNECTIONS +#if DEFAULT_BT_LE_PAWR_SUPPORTED + rc = pawrBcast_stack_enable(); + if (rc) { + return rc; + } + + rc = pawrSync_stack_enable(); + if (rc) { + return rc; + } +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED #if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) ble_stack_enableVsCmds(true); @@ -224,7 +288,10 @@ void ble_stack_disable(void) ble_stack_enableVsEvents(false); ble_stack_enableVsCmds(false); #endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) - +#if DEFAULT_BT_LE_PAWR_SUPPORTED + pawrSync_stack_disable(); + pawrBcast_stack_disable(); +#endif // DEFAULT_BT_LE_PAWR_SUPPORTED #if DEFAULT_BT_LE_MAX_CONNECTIONS #if CONFIG_BT_LE_ERROR_SIM_ENABLED conn_errorSim_disable(); diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index bdd0dffed1..0a1cf93ae1 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -846,8 +846,20 @@ static void ble_rtc_clk_init(esp_bt_controller_config_t *cfg) #if CONFIG_RTC_CLK_SRC_INT_RC s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_RC_SLOW; #elif CONFIG_RTC_CLK_SRC_EXT_CRYS + uint32_t clk_freq = 0; + if (rtc_clk_slow_src_get() == SOC_RTC_SLOW_CLK_SRC_XTAL32K) { - s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_XTAL32K; + if (!esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_XTAL32K, ESP_CLK_TREE_SRC_FREQ_PRECISION_EXACT, &clk_freq)) { + if (clk_freq > 32700 && clk_freq < 33800) { + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_XTAL32K; + } else { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL detection error, switch to main XTAL as Bluetooth sleep clock"); + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; + } + } else { + ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL detection error, switch to main XTAL as Bluetooth sleep clock"); + s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; + } } else { ESP_LOGW(NIMBLE_PORT_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock"); s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL; diff --git a/components/bt/controller/esp32h2/esp_bt_cfg.h b/components/bt/controller/esp32h2/esp_bt_cfg.h index 01f9dc6182..4734737c5a 100644 --- a/components/bt/controller/esp32h2/esp_bt_cfg.h +++ b/components/bt/controller/esp32h2/esp_bt_cfg.h @@ -45,6 +45,11 @@ extern "C" { #else #define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0) #endif + #if CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES + #define DEFAULT_BT_LE_PAWR_SUPPORTED (1) + #else + #define DEFAULT_BT_LE_PAWR_SUPPORTED (0) + #endif // CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES #else #if CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY @@ -71,6 +76,12 @@ extern "C" { #define DEFAULT_BT_LE_MAX_CONNECTIONS (2) #endif + #if defined(CONFIG_BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED) + #define DEFAULT_BT_LE_PAWR_SUPPORTED (CONFIG_BT_LE_PERIODIC_ADV_WITH_RESPONSE_ENABLED) + #else + #define DEFAULT_BT_LE_PAWR_SUPPORTED (0) + #endif + #if defined(CONFIG_BT_LE_ACL_BUF_SIZE) #define DEFAULT_BT_LE_ACL_BUF_SIZE (CONFIG_BT_LE_ACL_BUF_SIZE) #else diff --git a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib index 3655fcdaad..3c4701301c 160000 --- a/components/bt/controller/lib_esp32c6/esp32c6-bt-lib +++ b/components/bt/controller/lib_esp32c6/esp32c6-bt-lib @@ -1 +1 @@ -Subproject commit 3655fcdaadb66bb4cd4d497c2dbd4e6e2a4cc696 +Subproject commit 3c4701301cd4253b99e9b0e39f603852ded06b7b diff --git a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib index a2ba40fae2..0a35e009b9 160000 --- a/components/bt/controller/lib_esp32h2/esp32h2-bt-lib +++ b/components/bt/controller/lib_esp32h2/esp32h2-bt-lib @@ -1 +1 @@ -Subproject commit a2ba40fae2462488f65efca042e5cecd9e018c7e +Subproject commit 0a35e009b9a31993d998492a0c0d3a34a881514f