summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Hogg <me@jonathanhogg.com>2022-03-07 09:22:00 +0000
committerDamien George <damien@micropython.org>2022-03-21 23:59:07 +1100
commit21d0599bd10aa567e3fdee5e39da1fe9a9f816e6 (patch)
tree8077890e02e6ec38fcefbb26b2970c809f46f2aa
parent7684c996bc2b2521fa4bd023e4fa24622092cd5f (diff)
esp32/modesp32: Add new gpio_deep_sleep_hold function.
Add a new function to control whether held pins will retain their function through deep-sleep. Also document this function and explain how to use this in quickref to retain pin configuration during deep-sleep.
-rw-r--r--docs/esp32/quickref.rst17
-rw-r--r--docs/library/esp32.rst5
-rw-r--r--ports/esp32/modesp32.c11
3 files changed, 33 insertions, 0 deletions
diff --git a/docs/esp32/quickref.rst b/docs/esp32/quickref.rst
index dd7e515f1..894508f4c 100644
--- a/docs/esp32/quickref.rst
+++ b/docs/esp32/quickref.rst
@@ -562,6 +562,23 @@ deep-sleep if pad hold is enabled with the ``hold=True`` argument to
``Pin.init()``.
Non-RTC GPIO pins will be disconnected by default on entering deep-sleep.
+Configuration of non-RTC pins - including output level - can be retained by
+enabling pad hold on the pin and enabling GPIO pad hold during deep-sleep::
+
+ from machine import Pin, deepsleep
+ import esp32
+
+ opin = Pin(19, Pin.OUT, value=1, hold=True) # hold output level
+ ipin = Pin(21, Pin.IN, Pin.PULL_UP, hold=True) # hold pull-up
+
+ # enable pad hold in deep-sleep for non-RTC GPIO
+ esp32.gpio_deep_sleep_hold(True)
+
+ # put the device to sleep for 10 seconds
+ deepsleep(10000)
+
+The pin configuration - including the pad hold - will be retained on wake from
+sleep. See :ref:`Pins_and_GPIO` above for a further discussion of pad holding.
SD card
-------
diff --git a/docs/library/esp32.rst b/docs/library/esp32.rst
index da5fa8c3c..334800349 100644
--- a/docs/library/esp32.rst
+++ b/docs/library/esp32.rst
@@ -30,6 +30,11 @@ Functions
or a tuple/list of valid Pin objects. *level* should be ``esp32.WAKEUP_ALL_LOW``
or ``esp32.WAKEUP_ANY_HIGH``.
+.. function:: gpio_deep_sleep_hold(enable)
+
+ Configure whether non-RTC GPIO pin configuration is retained during
+ deep-sleep mode for held pads. *enable* should be a boolean value.
+
.. function:: raw_temperature()
Read the raw value of the internal temperature sensor, returning an integer.
diff --git a/ports/esp32/modesp32.c b/ports/esp32/modesp32.c
index 75e5b3ed8..4579c5de1 100644
--- a/ports/esp32/modesp32.c
+++ b/ports/esp32/modesp32.c
@@ -131,6 +131,16 @@ STATIC mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_m
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext1_obj, 0, esp32_wake_on_ext1);
+STATIC mp_obj_t esp32_gpio_deep_sleep_hold(const mp_obj_t enable) {
+ if (mp_obj_is_true(enable)) {
+ gpio_deep_sleep_hold_en();
+ } else {
+ gpio_deep_sleep_hold_dis();
+ }
+ return mp_const_none;
+}
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(esp32_gpio_deep_sleep_hold_obj, esp32_gpio_deep_sleep_hold);
+
#if CONFIG_IDF_TARGET_ESP32
#include "soc/sens_reg.h"
@@ -187,6 +197,7 @@ STATIC const mp_rom_map_elem_t esp32_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_wake_on_touch), MP_ROM_PTR(&esp32_wake_on_touch_obj) },
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext0), MP_ROM_PTR(&esp32_wake_on_ext0_obj) },
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext1), MP_ROM_PTR(&esp32_wake_on_ext1_obj) },
+ { MP_ROM_QSTR(MP_QSTR_gpio_deep_sleep_hold), MP_ROM_PTR(&esp32_gpio_deep_sleep_hold_obj) },
#if CONFIG_IDF_TARGET_ESP32
{ MP_ROM_QSTR(MP_QSTR_raw_temperature), MP_ROM_PTR(&esp32_raw_temperature_obj) },
{ MP_ROM_QSTR(MP_QSTR_hall_sensor), MP_ROM_PTR(&esp32_hall_sensor_obj) },