From 48153fadd912073385bdcccdfa836cd0cdae5ca3 Mon Sep 17 00:00:00 2001 From: Pavel Moravec Date: Wed, 15 Feb 2023 15:51:04 +0100 Subject: [PATCH] Improve power usage by reducing CPU clock --- src/LoRa_APRS_Tracker.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 3db62ed..a22ba17 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -4,9 +4,13 @@ #include #include #include -#include +#ifdef ESP32 +# include +#endif #include - +#ifdef ESP32 +# include +#endif #include "BeaconManager.h" #include "configuration.h" #include "display.h" @@ -93,10 +97,26 @@ void setup() { digitalWrite(Config.ptt.io_pin, Config.ptt.reverse ? HIGH : LOW); } +#ifdef ESP32 // make sure wifi and bt is off as we don't need it: WiFi.mode(WIFI_OFF); btStop(); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "WiFi and BT controller stopped"); + esp_bt_controller_disable(); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "BT controller disabled"); +# if defined(TTGO_T_Beam_V1_0) // || defined(TTGO_T_Beam_V0_7) + // TTGO_T_Beam_V0_7 should probably work as well but could not be confirmed so it is disabled now + //Going to 20MHz breaks the display in 3.0.x SDK + //40 MHz reduces power consumption by ~15-20mA but is broken in present SDK + //Using 80 MHz as a safe value works + if (setCpuFrequencyMhz(80)) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CPU frequency set to 80MHz"); + } else { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "CPU frequency unchanged"); + } +# endif +#endif if (Config.button.tx) { // attach TX action to user button (defined by BUTTON_PIN) userButton.attachClick(handle_tx_click);