Skip to content

Commit 8da1d78

Browse files
devyteigrr
authored andcommitted
Change argument to Esp.deepSleep from uint32 to uint64 to match SDK, add deepSleepMax based on the cali_proc function per SDK
1 parent 8b87491 commit 8da1d78

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: cores/esp8266/Esp.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,22 @@ void EspClass::wdtFeed(void)
107107

108108
extern "C" void esp_yield();
109109

110-
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
110+
void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
111111
{
112112
system_deep_sleep_set_option(static_cast<int>(mode));
113113
system_deep_sleep(time_us);
114114
esp_yield();
115115
}
116116

117+
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0.
118+
//Note: system_rtc_clock_cali_proc() returns a uint32_t, even though system_deep_sleep() takes a uint64_t.
119+
uint64_t EspClass::deepSleepMax()
120+
{
121+
//cali*(2^31-1)/(2^12)
122+
return (uint64_t)system_rtc_clock_cali_proc()*(0x80000000-1)/(0x1000);
123+
124+
}
125+
117126
bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
118127
{
119128
if (size + offset > 512) {

Diff for: cores/esp8266/Esp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class EspClass {
9292
void wdtDisable();
9393
void wdtFeed();
9494

95-
void deepSleep(uint32_t time_us, RFMode mode = RF_DEFAULT);
95+
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
96+
uint64_t deepSleepMax();
9697

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

0 commit comments

Comments
 (0)