Skip to content

Commit b6ae084

Browse files
feat: Implement PMU management functions to keep power management unit awake
1 parent ad62981 commit b6ae084

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tx_websocket_gateway/LoRaBoards.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ static void setPmuFlag()
4444
{
4545
pmuInterrupt = true;
4646
}
47+
48+
static void keepPmuAwake()
49+
{
50+
if (!PMU) {
51+
return;
52+
}
53+
54+
const auto chip = PMU->getChipModel();
55+
if (chip == XPOWERS_AXP2101) {
56+
auto *axp2101 = static_cast<XPowersAXP2101 *>(PMU);
57+
axp2101->disableSleep();
58+
axp2101->disableLongPressShutdown();
59+
axp2101->setLongPressRestart();
60+
axp2101->disableWatchdog();
61+
axp2101->setLowBatShutdownThreshold(0);
62+
} else if (chip == XPOWERS_AXP192) {
63+
auto *axp192 = static_cast<XPowersAXP192 *>(PMU);
64+
axp192->disablePowerKeyLongPressPowerOff();
65+
}
66+
}
4767
#endif
4868

4969
bool beginPower()
@@ -76,6 +96,7 @@ bool beginPower()
7696
}
7797

7898
PMU->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
99+
keepPmuAwake();
79100

80101
pinMode(PMU_IRQ, INPUT_PULLUP);
81102
attachInterrupt(PMU_IRQ, setPmuFlag, FALLING);
@@ -847,4 +868,4 @@ bool beginGPS()
847868
SerialGPS.write("$PCAS11,3*1E\r\n");
848869
return result;
849870
}
850-
#endif
871+
#endif

tx_websocket_gateway/tx_websocket_gateway.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <Arduino.h>
22
#include <WiFi.h>
3+
#if defined(ESP32)
4+
#include <esp_wifi.h>
5+
#endif
36
#include <ArduinoWebsockets.h>
47
#include <ArduinoJson.h>
58
#include <SPI.h>
@@ -82,13 +85,20 @@ void loop() {
8285

8386
wsClient.poll();
8487
publishStatus();
88+
#ifdef HAS_PMU
89+
loopPMU();
90+
#endif
8591
delay(5);
8692
}
8793

8894
// ----- Wi-Fi & WebSocket ---------------------------------------------
8995
void connectWiFi() {
9096
Serial.printf("[WiFi] Connecting to %s\n", WIFI_SSID);
9197
WiFi.mode(WIFI_STA);
98+
#if defined(ESP32)
99+
WiFi.setSleep(false);
100+
esp_wifi_set_ps(WIFI_PS_NONE);
101+
#endif
92102
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
93103

94104
const uint32_t start = millis();

0 commit comments

Comments
 (0)