keep CPU at full speed when not power saving and WiFi is enabled

This commit is contained in:
m1nl 2025-08-22 13:59:51 +02:00
parent 32cd4c0868
commit 050b967d5f
3 changed files with 28 additions and 20 deletions

View File

@ -1503,8 +1503,15 @@ void setup()
PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS
powerFSMthread = new PowerFSMThread();
#if !HAS_TFT
setCPUFast(false); // 80MHz is fine for our slow peripherals
#ifndef ARCH_PORTDUINO
auto cpuFast = false;
#if HAS_TFT
cpuFast |= true;
#endif
#if HAS_WIFI
cpuFast |= !config.power.is_power_saving && isWifiAvailable();
#endif
setCPUFast(cpuFast);
#endif
#ifdef ARDUINO_ARCH_ESP32

View File

@ -303,8 +303,20 @@ bool initWifi()
WiFi.setAutoReconnect(true);
WiFi.setSleep(false);
// This is needed to improve performance.
esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving
bool wifi_high_performance = false;
#if HAS_UDP_MULTICAST
// need to increase WiFi performance (decrease DTIM interval) to avoid missing UDP packet broadcasts
wifi_high_performance |=
udpHandler && (config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST);
#endif
if (wifi_high_performance) {
esp_wifi_set_ps(config.power.is_power_saving ? WIFI_PS_MIN_MODEM : WIFI_PS_NONE);
} else {
esp_wifi_set_ps(config.power.is_power_saving ? WIFI_PS_MAX_MODEM : WIFI_PS_MIN_MODEM);
}
WiFi.onEvent(
[](WiFiEvent_t event, WiFiEventInfo_t info) {
@ -512,4 +524,4 @@ uint8_t getWifiDisconnectReason()
{
return wifiDisconnectReason;
}
#endif // HAS_WIFI
#endif // HAS_WIFI

View File

@ -83,21 +83,10 @@ RTC_DATA_ATTR int bootCount = 0;
*/
void setCPUFast(bool on)
{
#if defined(ARCH_ESP32) && !HAS_TFT
#ifdef HAS_WIFI
if (isWifiAvailable()) {
#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(WIFI_MAX_PERFORMANCE)
LOG_DEBUG("Set CPU to 240MHz because WiFi is in use");
setCpuFrequencyMhz(240);
return;
#endif
}
#endif
// The Heltec LORA32 V1 runs at 26 MHz base frequency and doesn't react well to switching to 80 MHz...
#if !defined(ARDUINO_HELTEC_WIFI_LORA_32) && !defined(CONFIG_IDF_TARGET_ESP32C3)
setCpuFrequencyMhz(on ? 240 : 80);
#endif
#ifdef ARCH_ESP32
uint8_t targetFrequency = on ? 240 : 80;
setCpuFrequencyMhz(targetFrequency);
LOG_INFO("CPU frequency set to %u MHz", targetFrequency);
#endif
}