chanage(example/power_save): add wifi band (2.4 GHz and 5 GHz) menuconfig option for esp32c5

This commit is contained in:
Lou Tianhao 2024-04-17 20:09:55 +08:00 committed by Li Shuai
parent d63beec095
commit 1604cef916
2 changed files with 27 additions and 0 deletions

View File

@ -37,6 +37,21 @@ menu "Example Configuration"
For Station, If the station does not receive a beacon frame from the connected SoftAP during the For Station, If the station does not receive a beacon frame from the connected SoftAP during the
inactive time, disconnect from SoftAP. Default 6s. inactive time, disconnect from SoftAP. Default 6s.
choice EXAMPLE_WIFI_BAND_MODE
prompt "wifi band"
default EXAMPLE_WIFI_BAND_MODE_2G
depends on SOC_WIFI_HE_SUPPORT_5G
help
WiFi band for the example to use.
config EXAMPLE_WIFI_BAND_MODE_2G
bool "2G"
config EXAMPLE_WIFI_BAND_MODE_5G
bool "5G"
config EXAMPLE_WIFI_BAND_MODE_AUTO
bool "Auto"
endchoice
choice EXAMPLE_POWER_SAVE_MODE choice EXAMPLE_POWER_SAVE_MODE
prompt "power save mode" prompt "power save mode"
default EXAMPLE_POWER_SAVE_MIN_MODEM default EXAMPLE_POWER_SAVE_MIN_MODEM

View File

@ -36,6 +36,15 @@
#define DEFAULT_PS_MODE WIFI_PS_NONE #define DEFAULT_PS_MODE WIFI_PS_NONE
#endif /*CONFIG_POWER_SAVE_MODEM*/ #endif /*CONFIG_POWER_SAVE_MODEM*/
#if SOC_WIFI_HE_SUPPORT_5G
#if CONFIG_EXAMPLE_WIFI_BAND_MODE_2G
#define DEFAULT_WIFI_BAND_MODE WIFI_BAND_MODE_2G_ONLY
#elif CONFIG_EXAMPLE_WIFI_BAND_MODE_5G
#define DEFAULT_WIFI_BAND_MODE WIFI_BAND_MODE_5G_ONLY
#else
#define DEFAULT_WIFI_BAND_MODE WIFI_BAND_MODE_AUTO
#endif
#endif
static const char *TAG = "power_save"; static const char *TAG = "power_save";
@ -80,6 +89,9 @@ static void wifi_power_save(void)
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); 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_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start()); ESP_ERROR_CHECK(esp_wifi_start());
#if SOC_WIFI_HE_SUPPORT_5G
ESP_ERROR_CHECK(esp_wifi_set_band_mode(DEFAULT_WIFI_BAND_MODE));
#endif
ESP_ERROR_CHECK(esp_wifi_set_inactive_time(WIFI_IF_STA, DEFAULT_BEACON_TIMEOUT)); ESP_ERROR_CHECK(esp_wifi_set_inactive_time(WIFI_IF_STA, DEFAULT_BEACON_TIMEOUT));
ESP_LOGI(TAG, "esp_wifi_set_ps()."); ESP_LOGI(TAG, "esp_wifi_set_ps().");