Skip to content

Commit

Permalink
fix/enhancement: TFT device powersave (part 3) (#3600)
Browse files Browse the repository at this point in the history
* fix: device TFT powersave (part 3)

* trunk fmt

* trunk fmt

* undo bluetooth deinit from #3596

* revert code for heltec tracker

---------

Co-authored-by: Ben Meadors <[email protected]>
  • Loading branch information
mverch67 and thebentern authored Apr 14, 2024
1 parent ec3971b commit 5047468
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/PowerFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "sleep.h"
#include "target_specific.h"

#ifndef SLEEP_TIME
#define SLEEP_TIME 30
#endif

/// Should we behave as if we have AC power now?
static bool isPowered()
{
Expand Down Expand Up @@ -81,7 +85,7 @@ static void lsIdle()
// If some other service would stall sleep, don't let sleep happen yet
if (doPreflightSleep()) {
// Briefly come out of sleep long enough to blink the led once every few seconds
uint32_t sleepTime = 30;
uint32_t sleepTime = SLEEP_TIME;

setLed(false); // Never leave led on while in light sleep
esp_sleep_source_t wakeCause2 = doLightSleep(sleepTime * 1000LL);
Expand Down
13 changes: 9 additions & 4 deletions src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ void TFTDisplay::sendCommand(uint8_t com)
#elif defined(ST7735_BL_V05)
pinMode(ST7735_BL_V05, OUTPUT);
digitalWrite(ST7735_BL_V05, TFT_BACKLIGHT_ON);
#endif
#if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
tft->wakeup();
tft->powerSaveOff();
#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
digitalWrite(TFT_BL, TFT_BACKLIGHT_ON);
#endif

Expand Down Expand Up @@ -596,10 +598,13 @@ void TFTDisplay::sendCommand(uint8_t com)
#elif defined(ST7735_BL_V05)
pinMode(ST7735_BL_V05, OUTPUT);
digitalWrite(ST7735_BL_V05, !TFT_BACKLIGHT_ON);
#endif
#if defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
tft->sleep();
tft->powerSaveOn();
#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON)
digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON);
#endif

#ifdef VTFT_CTRL_V03
digitalWrite(VTFT_CTRL_V03, HIGH);
#endif
Expand Down
6 changes: 6 additions & 0 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ void NodeDB::initConfigIntervals()
config.power.wait_bluetooth_secs = default_wait_bluetooth_secs;

config.display.screen_on_secs = default_screen_on_secs;

#if defined(T_WATCH_S3) || defined(T_DECK)
config.power.is_power_saving = true;
config.display.screen_on_secs = 30;
config.power.wait_bluetooth_secs = 30;
#endif
}

void NodeDB::installDefaultModuleConfig()
Expand Down
4 changes: 2 additions & 2 deletions src/nimble/NimbleBluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void NimbleBluetooth::shutdown()
pAdvertising->reset();
pAdvertising->stop();

#if defined(ARCH_ESP32)
// Saving of ~1mA for esp32-s3 and 0.1mA for esp32
#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0)
// Saving of ~1mA
// Probably applicable to other ESP32 boards - unverified
NimBLEDevice::deinit();
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r

gpio_wakeup_enable(pin, GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup();
#endif
#ifdef T_WATCH_S3
gpio_wakeup_enable((gpio_num_t)SCREEN_TOUCH_INT, GPIO_INTR_LOW_LEVEL);
#endif
enableLoraInterrupt();
#ifdef PMU_IRQ
Expand Down Expand Up @@ -385,6 +388,10 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
buttonThread->attachButtonInterrupts();
#endif

#ifdef T_WATCH_S3
gpio_wakeup_disable((gpio_num_t)SCREEN_TOUCH_INT);
#endif

#if !defined(SOC_PM_SUPPORT_EXT_WAKEUP) && defined(LORA_DIO1) && (LORA_DIO1 != RADIOLIB_NC)
if (radioType != RF95_RADIO) {
gpio_wakeup_disable((gpio_num_t)LORA_DIO1);
Expand Down
2 changes: 2 additions & 0 deletions variants/t-deck/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#define TOUCH_I2C_PORT 0
#define TOUCH_SLAVE_ADDRESS 0x5D // GT911

#define SLEEP_TIME 120

#define BUTTON_PIN 0
// #define BUTTON_NEED_PULLUP

Expand Down
2 changes: 0 additions & 2 deletions variants/t-watch-s3/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
extends = esp32s3_base
board = t-watch-s3
upload_protocol = esptool
upload_speed = 115200
upload_port = /dev/tty.usbmodem3485188D636C1

build_flags = ${esp32_base.build_flags}
-DT_WATCH_S3
Expand Down
2 changes: 2 additions & 0 deletions variants/t-watch-s3/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define TOUCH_I2C_PORT 1
#define TOUCH_SLAVE_ADDRESS 0x38

#define SLEEP_TIME 180

#define I2C_SDA1 39 // Used for capacitive touch
#define I2C_SCL1 40 // Used for capacitive touch

Expand Down

0 comments on commit 5047468

Please sign in to comment.