From de53280ffc1963609379379be4c4682e9c4f2546 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 8 Jul 2023 21:01:00 -0500 Subject: [PATCH] PIN_GPS_EN power toggling (#2592) * PIN_GPS_EN * Remove extra digitalWrite * GPS_POWER_TOGGLE macro enabled. Added WSLv3 too * Update variant.h * Update variant.h * Fixed macro guard --- src/gps/GPS.cpp | 9 ++++----- src/sleep.cpp | 6 +++++- variants/heltec_v3/platformio.ini | 1 + variants/heltec_v3/variant.h | 4 +++- variants/heltec_wsl_v3/platformio.ini | 1 + variants/heltec_wsl_v3/variant.h | 4 +++- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 566d90a5c..65fb9595c 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -419,13 +419,12 @@ bool GPS::setupGPS() bool GPS::setup() { // Master power for the GPS -#ifdef PIN_GPS_EN - digitalWrite(PIN_GPS_EN, 1); - pinMode(PIN_GPS_EN, OUTPUT); -#endif -#ifdef HAS_PMU +#if defined(HAS_PMU) || defined(PIN_GPS_EN) if (config.position.gps_enabled) { +#ifdef PIN_GPS_EN + pinMode(PIN_GPS_EN, OUTPUT); +#endif setGPSPower(true); } #endif diff --git a/src/sleep.cpp b/src/sleep.cpp index 5331eaf75..483c491b4 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -99,6 +99,10 @@ void setGPSPower(bool on) { LOG_INFO("Setting GPS power=%d\n", on); +#ifdef PIN_GPS_EN + digitalWrite(PIN_GPS_EN, on ? 1 : 0); +#endif + #ifdef HAS_PMU if (pmu_found && PMU) { uint8_t model = PMU->getChipModel(); @@ -185,7 +189,7 @@ static void waitEnterSleep() void doGPSpowersave(bool on) { -#ifdef HAS_PMU +#if defined(HAS_PMU) || defined(PIN_GPS_EN) if (on) { LOG_INFO("Turning GPS back on\n"); gps->forceWake(1); diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index 3e0ace39c..58ee0b5ba 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -4,3 +4,4 @@ board = heltec_wifi_lora_32_V3 # Temporary until espressif creates a release with this new target build_flags = ${esp32s3_base.build_flags} -D HELTEC_V3 -I variants/heltec_v3 + -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. \ No newline at end of file diff --git a/variants/heltec_v3/variant.h b/variants/heltec_v3/variant.h index d9fc0b4c2..aedfbe677 100644 --- a/variants/heltec_v3/variant.h +++ b/variants/heltec_v3/variant.h @@ -7,6 +7,8 @@ #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 +#define PIN_GPS_EN 46 // GPS power enable pin + #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider @@ -29,4 +31,4 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_E22 \ No newline at end of file +#define SX126X_E22 diff --git a/variants/heltec_wsl_v3/platformio.ini b/variants/heltec_wsl_v3/platformio.ini index 5f89a7466..c95659156 100644 --- a/variants/heltec_wsl_v3/platformio.ini +++ b/variants/heltec_wsl_v3/platformio.ini @@ -4,3 +4,4 @@ board = heltec_wifi_lora_32_V3 # Temporary until espressif creates a release with this new target build_flags = ${esp32s3_base.build_flags} -D HELTEC_WSL_V3 -I variants/heltec_wsl_v3 + -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. \ No newline at end of file diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 0ecc5bea7..ec5796313 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -8,6 +8,8 @@ #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost #define BUTTON_PIN 0 +#define PIN_GPS_EN 46 // GPS power enable pin + #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider @@ -30,4 +32,4 @@ #define SX126X_DIO1 LORA_DIO1 #define SX126X_BUSY LORA_DIO2 #define SX126X_RESET LORA_RESET -#define SX126X_E22 \ No newline at end of file +#define SX126X_E22