Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: device PMU shutdown (part 2) #3596

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,7 @@ void Power::shutdown()
{
LOG_INFO("Shutting down\n");

#ifdef HAS_PMU
if (pmu_found == true) {
PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF);
PMU->shutdown();
}
#elif defined(ARCH_NRF52) || defined(ARCH_ESP32)
#if defined(ARCH_NRF52) || defined(ARCH_ESP32)
#ifdef PIN_LED1
ledOff(PIN_LED1);
#endif
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(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0)
// Saving of ~1mA
#if defined(ARCH_ESP32)
// Saving of ~1mA for esp32-s3 and 0.1mA for esp32
// Probably applicable to other ESP32 boards - unverified
NimBLEDevice::deinit();
#endif
Expand Down
39 changes: 23 additions & 16 deletions src/sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
digitalWrite(VEXT_ENABLE, 1); // turn off the display power
#endif

#ifdef ARCH_ESP32
if (shouldLoraWake(msecToWake)) {
enableLoraInterrupt();
}
#ifdef BUTTON_PIN
// Avoid leakage through button pin
pinMode(BUTTON_PIN, INPUT);
gpio_hold_en((gpio_num_t)BUTTON_PIN);
#endif

// LoRa CS (RADIO_NSS) needs to stay HIGH, even during deep sleep
pinMode(LORA_CS, OUTPUT);
digitalWrite(LORA_CS, HIGH);
gpio_hold_en((gpio_num_t)LORA_CS);
#endif

#ifdef HAS_PMU
if (pmu_found && PMU) {
// Obsolete comment: from back when we we used to receive lora packets while CPU was in deep sleep.
Expand All @@ -257,6 +273,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
// If we want to leave the radio receiving in would be 11.5mA current draw, but most of the time it is just waiting
// in its sequencer (true?) so the average power draw should be much lower even if we were listinging for packets
// all the time.
PMU->setChargingLedMode(XPOWERS_CHG_LED_OFF);

uint8_t model = PMU->getChipModel();
if (model == XPOWERS_AXP2101) {
Expand All @@ -271,25 +288,15 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
// t-beam v1.1 radio power channel
PMU->disablePowerOutput(XPOWERS_LDO2); // lora radio power channel
}
if (msecToWake == portMAX_DELAY) {
LOG_INFO("PMU shutdown.\n");
console->flush();
PMU->shutdown();
}
}
#endif

#ifdef ARCH_ESP32
if (shouldLoraWake(msecToWake)) {
enableLoraInterrupt();
}

#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) // Applicable to most ESP32 boards?
// Avoid leakage through button pin
pinMode(BUTTON_PIN, INPUT);
rtc_gpio_hold_en((gpio_num_t)BUTTON_PIN);

// LoRa CS (RADIO_NSS) needs to stay HIGH, even during deep sleep
pinMode(LORA_CS, OUTPUT);
digitalWrite(LORA_CS, HIGH);
rtc_gpio_hold_en((gpio_num_t)LORA_CS);
#endif
#endif
console->flush();
cpuDeepSleep(msecToWake);
}

Expand Down
Loading