From 85bf5f8aba18dc38cef433f0a8d1e11adc9bbe1e Mon Sep 17 00:00:00 2001 From: alanmaxwell Date: Fri, 22 Mar 2024 11:18:35 +0800 Subject: [PATCH] change(phy): change wifi multi ant api to phy multi ant --- .../antenna_soft_switch/antenna_switch.c | 43 ++++++++++--------- examples/phy/antenna/main/CMakeLists.txt | 2 +- .../main/antenna_switch_example_main.c | 16 ++++--- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/examples/phy/antenna/components/antenna_soft_switch/antenna_switch.c b/examples/phy/antenna/components/antenna_soft_switch/antenna_switch.c index 4574c3cd1b..97cdd43933 100644 --- a/examples/phy/antenna/components/antenna_soft_switch/antenna_switch.c +++ b/examples/phy/antenna/components/antenna_soft_switch/antenna_switch.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -16,6 +16,7 @@ #include "freertos/event_groups.h" #include "freertos/queue.h" #include "esp_wifi.h" +#include "esp_phy.h" #include "esp_log.h" #include "esp_check.h" @@ -46,17 +47,17 @@ static TaskHandle_t antenna_task_handle; /**< Select the optimal antenna*/ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *config) { - wifi_ant_config_t wifi_ant_config; + esp_phy_ant_config_t wifi_ant_config; wifi_ap_record_t wifi_ap_record; int16_t rssi_ant0 = INT16_MIN, rssi_ant1 = INT16_MIN, rssi_ant2 = INT16_MIN, rssi_max, rssi_min; /**< Monitor antenna zero signal strength*/ - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0; - wifi_ant_config.rx_ant_default = WIFI_ANT_MODE_ANT0; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT0; + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT0; + wifi_ant_config.rx_ant_default = ESP_PHY_ANT_MODE_ANT0; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT0; wifi_ant_config.enabled_ant0 = config->ant_zero; wifi_ant_config.enabled_ant1 = config->ant_one; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); /**< Wait for parameters to take effect*/ vTaskDelay(100/portTICK_PERIOD_MS); while(ESP_OK != esp_wifi_sta_get_ap_info(&wifi_ap_record)) { @@ -80,9 +81,9 @@ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *con ESP_LOGD(TAG, "The signal strength of the antenna zero :%d", rssi_ant0); /**< Monitor antenna one signal strength*/ - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT1; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT1; + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); /**< Wait for parameters to take effect*/ vTaskDelay(100/portTICK_PERIOD_MS); while(ESP_OK != esp_wifi_sta_get_ap_info(&wifi_ap_record)) { @@ -107,10 +108,10 @@ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *con if(config->ant_num == ANT_TOTAL_THREE) { /**< Monitor antenna two signal strength*/ - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT1; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT1; wifi_ant_config.enabled_ant1 = config->ant_two; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); /**< Wait for parameters to take effect*/ vTaskDelay(100/portTICK_PERIOD_MS); while(ESP_OK != esp_wifi_sta_get_ap_info(&wifi_ap_record)) { @@ -137,31 +138,31 @@ static void antenna_switch_function(const wifi_antenna_auto_switch_config_t *con if(rssi_ant0 >= rssi_ant1 && rssi_ant0 >= rssi_ant2) { /**< antenna zero signal strength best*/ ESP_LOGD(TAG, "Antenna soft switching selection ant0"); - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT0; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT0; + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT0; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT0; wifi_ant_config.enabled_ant0 = config->ant_zero; wifi_ant_config.enabled_ant1 = config->ant_one; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); } if(rssi_ant1 > rssi_ant0 && rssi_ant1 > rssi_ant2) { /**< antenna one signal strength best*/ ESP_LOGD(TAG, "Antenna soft switching selection ant1"); - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT1; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT1; wifi_ant_config.enabled_ant0 = config->ant_zero; wifi_ant_config.enabled_ant1 = config->ant_one; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); } if(rssi_ant2 > rssi_ant0 && rssi_ant2 > rssi_ant1) { /**< antenna two signal strength best*/ ESP_LOGD(TAG, "Antenna soft switching selection ant2"); - wifi_ant_config.rx_ant_mode = WIFI_ANT_MODE_ANT1; - wifi_ant_config.tx_ant_mode = WIFI_ANT_MODE_ANT1; + wifi_ant_config.rx_ant_mode = ESP_PHY_ANT_MODE_ANT1; + wifi_ant_config.tx_ant_mode = ESP_PHY_ANT_MODE_ANT1; wifi_ant_config.enabled_ant0 = config->ant_zero; wifi_ant_config.enabled_ant1 = config->ant_two; - ESP_ERROR_CHECK(esp_wifi_set_ant(&wifi_ant_config)); + ESP_ERROR_CHECK(esp_phy_set_ant(&wifi_ant_config)); } } diff --git a/examples/phy/antenna/main/CMakeLists.txt b/examples/phy/antenna/main/CMakeLists.txt index 6ba481b183..f8f2232d61 100644 --- a/examples/phy/antenna/main/CMakeLists.txt +++ b/examples/phy/antenna/main/CMakeLists.txt @@ -1,2 +1,2 @@ idf_component_register(SRCS "antenna_switch_example_main.c" - REQUIRES nvs_flash esp_wifi antenna_soft_switch) + REQUIRES nvs_flash esp_wifi esp_phy antenna_soft_switch) diff --git a/examples/phy/antenna/main/antenna_switch_example_main.c b/examples/phy/antenna/main/antenna_switch_example_main.c index af9e1ccd4f..c40a23c320 100644 --- a/examples/phy/antenna/main/antenna_switch_example_main.c +++ b/examples/phy/antenna/main/antenna_switch_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -21,6 +21,7 @@ #include "esp_log.h" #include "nvs_flash.h" #include "esp_wifi.h" +#include "esp_phy.h" #include "lwip/err.h" #include "lwip/sys.h" @@ -128,7 +129,8 @@ void wifi_init_sta(void) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) ); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); ESP_ERROR_CHECK(esp_wifi_start() ); - + /* PHY multiple antenna api should be called when PHY is enabled, disable WI-FI Modem sleep can keep PHY always enabled */ + ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE) ); ESP_LOGI(TAG, "wifi_init_sta finished."); /* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum @@ -165,13 +167,13 @@ void app_main(void) ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); wifi_init_sta(); - wifi_ant_gpio_config_t ant_gpio_config = { + esp_phy_ant_gpio_config_t ant_gpio_config = { // ESP32-WROOM-DA boards default antenna pins .gpio_cfg[0] = {.gpio_select = 1, .gpio_num = 21}, .gpio_cfg[1] = {.gpio_select = 1, .gpio_num = 22}, }; - ESP_ERROR_CHECK(esp_wifi_set_ant_gpio(&ant_gpio_config)); - ESP_ERROR_CHECK(esp_wifi_get_ant_gpio(&ant_gpio_config)); + ESP_ERROR_CHECK(esp_phy_set_ant_gpio(&ant_gpio_config)); + ESP_ERROR_CHECK(esp_phy_get_ant_gpio(&ant_gpio_config)); ESP_LOGI(TAG, "GPIO: [0].pin = %d, [1].pin = %d",ant_gpio_config.gpio_cfg[0].gpio_num, ant_gpio_config.gpio_cfg[1].gpio_num); wifi_antenna_auto_switch_config_t wifi_antenna_auto_switch_config; @@ -183,8 +185,8 @@ void app_main(void) ESP_ERROR_CHECK(esp_wifi_set_ant_soft_switch(&wifi_antenna_auto_switch_config)); while(true) { - wifi_ant_config_t ant_config; - esp_wifi_get_ant(&ant_config); + esp_phy_ant_config_t ant_config; + esp_phy_get_ant(&ant_config); ESP_LOGI(TAG, "rx mode = %d, tx mode = %d, ant0_en = %d, ant1_en = %d",ant_config.rx_ant_mode, ant_config.tx_ant_mode, ant_config.enabled_ant0, ant_config.enabled_ant1); vTaskDelay(500 / portTICK_PERIOD_MS); }