Skip to content

Commit 5c7dbf4

Browse files
torntrousersdevyte
authored andcommitted
Add instantly option to deepSleep (#5052)
* Add instantly option to deepSleep * Move system_deep_sleep_instant to a new deepSleepInstant function
1 parent 61cc11d commit 5c7dbf4

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Diff for: cores/esp8266/Esp.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
114114
esp_yield();
115115
}
116116

117+
void EspClass::deepSleepInstant(uint64_t time_us, WakeMode mode)
118+
{
119+
system_deep_sleep_set_option(static_cast<int>(mode));
120+
system_deep_sleep_instant(time_us);
121+
esp_yield();
122+
}
123+
117124
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0.
118125
//Note: system_rtc_clock_cali_proc() returns a uint32_t, even though system_deep_sleep() takes a uint64_t.
119126
uint64_t EspClass::deepSleepMax()

Diff for: cores/esp8266/Esp.h

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class EspClass {
9393
void wdtFeed();
9494

9595
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
96+
void deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT);
9697
uint64_t deepSleepMax();
9798

9899
bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);

Diff for: doc/libraries.rst

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Some ESP-specific APIs related to deep sleep, RTC and flash memories are availab
7373

7474
``ESP.deepSleep(microseconds, mode)`` will put the chip into deep sleep. ``mode`` is one of ``WAKE_RF_DEFAULT``, ``WAKE_RFCAL``, ``WAKE_NO_RFCAL``, ``WAKE_RF_DISABLED``. (GPIO16 needs to be tied to RST to wake from deepSleep.) The chip can sleep for at most ``ESP.deepSleepMax()`` microseconds.
7575

76+
``ESP.deepSleepInstant(microseconds, mode)`` works similarly to ``ESP.deepSleep`` but sleeps instantly without waiting for WiFi to shutdown.
77+
7678
``ESP.rtcUserMemoryWrite(offset, &data, sizeof(data))`` and ``ESP.rtcUserMemoryRead(offset, &data, sizeof(data))`` allow data to be stored in and retrieved from the RTC user memory of the chip respectively. Total size of RTC user memory is 512 bytes, so ``offset + sizeof(data)`` shouldn't exceed 512. Data should be 4-byte aligned. The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the chip.
7779

7880
``ESP.restart()`` restarts the CPU.

0 commit comments

Comments
 (0)