Skip to content

Add instantly option to deepSleep #5052

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

Merged
merged 3 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ void EspClass::wdtFeed(void)

extern "C" void esp_yield();

void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
void EspClass::deepSleep(uint64_t time_us, WakeMode mode, bool instantly)
{
system_deep_sleep_set_option(static_cast<int>(mode));
system_deep_sleep(time_us);
if (instantly) {
system_deep_sleep_instant(time_us);
} else {
system_deep_sleep(time_us);
}
esp_yield();
}

Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class EspClass {
void wdtDisable();
void wdtFeed();

void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT, bool instantly = false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding new function, deepSleepInstant. This way, only one of system_deep_sleep_instant/system_deep_sleep will be linked into the final application, depending on what the user needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.

uint64_t deepSleepMax();

bool rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion doc/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ESP-specific APIs

Some ESP-specific APIs related to deep sleep, RTC and flash memories are available in the ``ESP`` object.

``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.
``ESP.deepSleep(microseconds, mode, instantly)`` will put the chip into deep sleep. ``mode`` is one of ``WAKE_RF_DEFAULT``, ``WAKE_RFCAL``, ``WAKE_NO_RFCAL``, ``WAKE_RF_DISABLED``. ``instantly`` defaults to false, setting to true means sleep instantly without waiting for WiFi to shutdown. (GPIO16 needs to be tied to RST to wake from deepSleep.) The chip can sleep for at most ``ESP.deepSleepMax()`` microseconds.

``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.

Expand Down