From 45ae795739a78c5dbffc3b5cfc59b2bd21aeba20 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Tue, 14 Mar 2017 20:49:41 +1100 Subject: [PATCH] Extend node.dsleep() to support instant sleep. (#1859) --- app/modules/node.c | 10 +++++++++- docs/en/modules/node.md | 6 +++++- sdk-overrides/include/user_interface.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/modules/node.c b/app/modules/node.c index 57d03208..2a34111f 100644 --- a/app/modules/node.c +++ b/app/modules/node.c @@ -53,6 +53,9 @@ static int node_deepsleep( lua_State* L ) else system_deep_sleep_set_option( option ); } + bool instant = false; + if (lua_isnumber(L, 3)) + instant = lua_tointeger(L, 3); // Set deleep time, skip if nil if ( lua_isnumber(L, 1) ) { @@ -61,7 +64,12 @@ static int node_deepsleep( lua_State* L ) if ( us < 0 ) return luaL_error( L, "wrong arg range" ); else - system_deep_sleep( us ); + { + if (instant) + system_deep_sleep_instant(us); + else + system_deep_sleep( us ); + } } return 0; } diff --git a/docs/en/modules/node.md b/docs/en/modules/node.md index 4892e913..a957936a 100644 --- a/docs/en/modules/node.md +++ b/docs/en/modules/node.md @@ -95,7 +95,7 @@ Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes. This function can only be used in the condition that esp8266 PIN32(RST) and PIN8(XPD_DCDC aka GPIO16) are connected together. Using sleep(0) will set no wake up timer, connect a GPIO to pin RST, the chip will wake up by a falling-edge on pin RST. #### Syntax -`node.dsleep(us, option)` +`node.dsleep(us, option, instant)` #### Parameters - `us` number (integer) or `nil`, sleep time in micro second. If `us == 0`, it will sleep forever. If `us == nil`, will not set sleep time. @@ -107,6 +107,10 @@ Firmware from before 05 Jan 2016 have a maximum sleeptime of ~35 minutes. - 1, RF_CAL after deep-sleep wake up, there will be large current - 2, no RF_CAL after deep-sleep wake up, there will only be small current - 4, disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current + - `instant` number (integer) or `nil`. If present and non-zero, do not use + the normal grace time before entering deep sleep. This is a largely + undocumented feature, and is only briefly mentioned in Espressif's + [low power solutions](https://espressif.com/sites/default/files/documentation/9b-esp8266_low_power_solutions_en.pdf#page=10) document (chapter 4.5). #### Returns `nil` diff --git a/sdk-overrides/include/user_interface.h b/sdk-overrides/include/user_interface.h index 61ce8356..246b02b9 100644 --- a/sdk-overrides/include/user_interface.h +++ b/sdk-overrides/include/user_interface.h @@ -12,5 +12,7 @@ enum ext_flash_size_map { FLASH_SIZE_128M_MAP = 9 }; +// Documented in section 4.5 of 9b-esp8266_low_power_solutions_en.pdf +void system_deep_sleep_instant(uint32 time_in_us); #endif /* SDK_OVERRIDES_INCLUDE_USER_INTERFACE_H_ */