8000 ESP.deepSleep[Instant] refactoring to match the setting of RF mode in… · dok-net/arduino-esp8266@93c524c · GitHub
[go: up one dir, main page]

Skip to content

Commit 93c524c

Browse files
committed
ESP.deepSleep[Instant] refactoring to match the setting of RF mode in user_rf_pre_init
Since WiFi is disabled at boot by default, and the above change to ESP.deepSleep..., (sample) sketches for special RF modes on resume from deep sleep may need fixing or documentation update. That's not done by this commit alone.
1 parent 469c523 commit 93c524c

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

cores/esp8266/Esp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ void EspClass::wdtFeed(void)
117117

118118
extern "C" void esp_yield();
119119

120-
void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
120+
void EspClass::deepSleep(uint64_t time_us)
121121
{
122-
system_deep_sleep_set_option(static_cast<int>(mode));
122+
system_deep_sleep_set_option(__get_rf_mode());
123123
system_deep_sleep(time_us);
124124
esp_yield();
125125
}
126126

127-
void EspClass::deepSleepInstant(uint64_t time_us, WakeMode mode)
127+
void EspClass::deepSleepInstant(uint64_t time_us)
128128
{
129-
system_deep_sleep_set_option(static_cast<int>(mode));
129+
system_deep_sleep_set_option(__get_rf_mode());
130130
system_deep_sleep_instant(time_us);
131131
esp_yield();
132132
}

cores/esp8266/Esp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class EspClass {
9191
void wdtDisable();
9292
void wdtFeed();
9393

94-
void deepSleep(uint64_t time_us, RFMode mode = RF_DEFAULT);
95-
void deepSleepInstant(uint64_t time_us, RFMode mode = RF_DEFAULT);
94+
void deepSleep(uint64_t time_us);
95+
void deepSleepInstant(uint64_t time_us);
9696
uint64_t deepSleepMax();
9797

9898
bool forcedModemSleep(uint32_t duration_us = 0 10000 , void (*wakeupCb)() = nullptr);

libraries/ESP8266WiFi/examples/WiFiShutdown/WiFiShutdown.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void setup() {
5050
WiFi.mode(WIFI_OFF);
5151
Serial.println("Cannot connect!");
5252
Serial.flush();
53-
ESP.deepSleep(10e6, RF_DISABLED);
53+
ESP.deepSleep(10e6);
5454
return;
5555
}
5656
}
@@ -72,9 +72,9 @@ void setup() {
7272

7373
Serial.println("Done.");
7474
Serial.flush();
75-
ESP.deepSleep(10e6, RF_DISABLED);
75+
ESP.deepSleep(10e6);
7676
}
7777

7878
void loop() {
7979
// Nothing to do here.
80-
}
80+
}

libraries/esp8266/examples/LowPowerDemo/LowPowerDemo.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ void runTest7() {
295295
Serial.println(F("going into Deep Sleep now..."));
296296
printMillis(); // show time difference across sleep
297297
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
298-
ESP.deepSleep(10E6, WAKE_RF_DEFAULT); // good night! D0 fires a reset in 10 seconds...
299-
// if you do ESP.deepSleep(0, mode); it needs a RESET to come out of sleep (RTC is disconnected)
298+
ESP.deepSleep(10E6); // good night! D0 fires a reset in 10 seconds...
299+
// if you do ESP.deepSleep(0); it needs a RESET to come out of sleep (RTC is disconnected)
300300
// maximum timed Deep Sleep interval ~ 3 to 4 hours depending on the RTC timer, see the README
301301
// the 2 uA GPIO amperage during Deep Sleep can't drive the LED so it's not lit now, although
302302
// depending on the LED used, you might see it very dimly lit in a dark room during this test
@@ -313,7 +313,7 @@ void runTest8() {
313313
Serial.println(F("going into Deep Sleep now..."));
314314
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
315315
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
316-
ESP.deepSleep(10E6, WAKE_RFCAL); // good night! D0 fires a reset in 10 seconds...
316+
ESP.deepSleep(10E6); // good night! D0 fires a reset in 10 seconds...
317317
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
318318
}
319319

@@ -326,7 +326,7 @@ void runTest9() {
326326
Serial.println(F("going into Deep Sleep now..."));
327327
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
328328
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
329-
ESP.deepSleepInstant(10E6, WAKE_NO_RFCAL); // good night! D0 fires a reset in 10 seconds...
329+
ESP.deepSleepInstant(10E6); // good night! D0 fires a reset in 10 seconds...
330330
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
331331
}
332332

@@ -339,7 +339,7 @@ void runTest10() {
339339
Serial.println(F("going into Deep Sleep now..."));
340340
Serial.flush(); // needs a delay(10) or Serial.flush() else it doesn't print the whole message
341341
testPoint_HIGH; // testPoint set HIGH to track Deep Sleep period, cleared at startup()
342-
ESP.deepSleepInstant(10E6, WAKE_RF_DISABLED); // good night! D0 fires a reset in 10 seconds...
342+
ESP.deepSleepInstant(10E6); // good night! D0 fires a reset in 10 seconds...
343343
Serial.println(F("What... I'm not asleep?!?")); // it will never get here
344344
}
345345

libraries/esp8266/examples/LowPowerDemo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ Similar to timed Deep Sleep, but it wakes with an interrupt at the next line in
7171

7272
Similar to ESP.deepSleep(0). The chip sleeps at 0.4 mA amperage until it is woken by an external interrupt. The only allowed interrupts are high level and low level; edge interrupts won't work. If you have a design that needs to be woken more often than every 2 seconds then you should consider using Forced Light Sleep. For sleep periods longer than 2 seconds, Deep Sleep will be more energy efficient. The chip wakes after an interrupt in about 3 to 5.5 mS (regardless of CPU speed), but WiFi was turned off to enter Forced Light Sleep so you will need to re-initialize it if you are using WiFi. Any user timers (including PWM) will keep the chip from going fully into Forced Light Sleep, and amperage will be ~ 2 mA with timers enabled.
7373

74-
### Test 7 - Deep Sleep, wake with RF_DEFAULT
74+
### Test 7 - Deep Sleep
7575

76-
In Deep Sleep almost everything is turned off, and the chip draws ~ 20 uA. If you have D0/GPIO16 connected to RST, you can use the RTC timer to wake the chip up at a timed interval. You can also wake it solely with an external RESET with ESP.deepSleep(0, wake option), which disconnects the timer. Waking with RF_DEFAULT means it will do an RFCAL if it needs to. Doing **ESP.deepSleep(time)** without the mode variable uses this wake mode. These first two Deep Sleep tests use the standard Deep Sleep function, so the WiFi connection is closed and the modem turned off, which takes up to 270 mS before Deep Sleep begins. Deep Sleep ends with a RESET, and the boot time after that is ~ 130 mS. Any Deep Sleep less than 2 seconds is wasting energy due to the modem shut-off and boot times, and Forced Light Sleep will be a better choice as it recovers in < 5.5 mS from the previous program state. The Deep Sleep tests will not go into Automatic Modem Sleep because delay() is not used.
76+
In Deep Sleep almost everything is turned off, and the chip draws ~ 20 uA. If you have D0/GPIO16 connected to RST, you can use the RTC timer to wake the chip up at a timed interval. You can also wake it solely with an external RESET with ESP.deepSleep(0), which disconnects the timer. Doing **ESP.deepSleep(time)** without the mode variable uses this wake mode. These first two Deep Sleep tests use the standard Deep Sleep function, so the WiFi connection is closed and the modem turned off, which takes up to 270 mS before Deep Sleep begins. Deep Sleep ends with a RESET, and the boot time after that is ~ 130 mS. Any Deep Sleep less than 2 seconds is wasting energy due to the modem shut-off and boot times, and Forced Light Sleep will be a better choice as it recovers in < 5.5 mS from the previous program state. The Deep Sleep tests will not go into Automatic Modem Sleep because delay() is not used.
7777

7878
Note that a RESET during Deep Sleep (either external or from D0/GPIO16) does not clear the GPIO pins; some of them hold their previous state. It's unknown how much else survives a reset, as it's not well documented.
7979

80-
### Test 8 - Deep Sleep, wake with RFCAL
80+
### Test 8 - Deep Sleep, wake with RFCAL - BREAKING CHANGE: MUST use __get_rf_mode overrides to alter WAKE modes
8181

8282
Identical to the test above, but the modem always does an RF power calibration when booting. In normal use, most people would do WAKE_RF_DEFAULT instead to avoid the extra RFCAL power burst coming out of Deep Sleep if it's not needed. Note that most of the time both of these modes (WAKE_RF_DEFAULT and WAKE_RFCAL) do a 100 mS long RFCAL *before* going into Deep Sleep (the RFCAL after Deep Sleep is much shorter). If the modem is shut down, this long RFCAL doesn't happen.
8383

0 commit comments

Comments
 (0)
0