Skip to content

Commit 4697a06

Browse files
meirarmondpgeorge
authored andcommitted
esp32/modesp32: Make wake_on_ext0 available only on SoCs supporting it.
The `esp32.wake_on_ext0()` method should only be available on boards that have SOC_PM_SUPPORT_EXT0_WAKEUP=y. And update docs to reflect this. Signed-off-by: Meir Armon <[email protected]>
1 parent cb315bb commit 4697a06

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

docs/library/esp32.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Functions
3333
or a valid Pin object. *level* should be ``esp32.WAKEUP_ALL_LOW`` or
3434
``esp32.WAKEUP_ANY_HIGH``.
3535

36+
.. note:: This is only available for boards that have ext0 support.
37+
3638
.. function:: wake_on_ext1(pins, level)
3739

3840
Configure how EXT1 wakes the device from sleep. *pins* can be ``None``

ports/esp32/machine_pin.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
335335
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin for wake"));
336336
}
337337

338+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
338339
if (machine_rtc_config.ext0_pin == -1) {
339340
machine_rtc_config.ext0_pin = index;
340341
} else if (machine_rtc_config.ext0_pin != index) {
@@ -343,10 +344,13 @@ static mp_obj_t machine_pin_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_
343344

344345
machine_rtc_config.ext0_level = trigger == GPIO_INTR_LOW_LEVEL ? 0 : 1;
345346
machine_rtc_config.ext0_wake_types = wake;
347+
#endif
346348
} else {
349+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
347350
if (machine_rtc_config.ext0_pin == index) {
348351
machine_rtc_config.ext0_pin = -1;
349352
}
353+
#endif
350354

351355
if (handler == mp_const_none) {
352356
handler = MP_OBJ_NULL;

ports/esp32/machine_rtc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ static const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
8383

8484
machine_rtc_config_t machine_rtc_config = {
8585
.ext1_pins = 0,
86+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
8687
.ext0_pin = -1
88+
#endif
8789
};
8890

8991
static mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {

ports/esp32/machine_rtc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@
3232

3333
typedef struct {
3434
uint64_t ext1_pins; // set bit == pin#
35+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
3536
int8_t ext0_pin; // just the pin#, -1 == None
37+
#endif
3638
#if SOC_TOUCH_SENSOR_SUPPORTED
3739
bool wake_on_touch : 1;
3840
#endif
3941
#if SOC_ULP_SUPPORTED
4042
bool wake_on_ulp : 1;
4143
#endif
44+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
4245
bool ext0_level : 1;
4346
wake_type_t ext0_wake_types;
47+
#endif
4448
bool ext1_level : 1;
4549
} machine_rtc_config_t;
4650

ports/esp32/modesp32.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static mp_obj_t esp32_wake_on_touch(const mp_obj_t wake) {
6060
static MP_DEFINE_CONST_FUN_OBJ_1(esp32_wake_on_touch_obj, esp32_wake_on_touch);
6161
#endif
6262

63+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
6364
static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
6465

6566
#if SOC_TOUCH_SENSOR_SUPPORTED
@@ -94,6 +95,7 @@ static mp_obj_t esp32_wake_on_ext0(size_t n_args, const mp_obj_t *pos_args, mp_m
9495
return mp_const_none;
9596
}
9697
static MP_DEFINE_CONST_FUN_OBJ_KW(esp32_wake_on_ext0_obj, 0, esp32_wake_on_ext0);
98+
#endif
9799

98100
static mp_obj_t esp32_wake_on_ext1(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
99101
enum {ARG_pins, ARG_level};
@@ -267,7 +269,9 @@ static const mp_rom_map_elem_t esp32_module_globals_table[] = {
267269
#if SOC_TOUCH_SENSOR_SUPPORTED
268270
{ MP_ROM_QSTR(MP_QSTR_wake_on_touch), MP_ROM_PTR(&esp32_wake_on_touch_obj) },
269271
#endif
272+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
270273
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext0), MP_ROM_PTR(&esp32_wake_on_ext0_obj) },
274+
#endif
271275
{ MP_ROM_QSTR(MP_QSTR_wake_on_ext1), MP_ROM_PTR(&esp32_wake_on_ext1_obj) },
272276
#if SOC_ULP_SUPPORTED
273277
{ MP_ROM_QSTR(MP_QSTR_wake_on_ulp), MP_ROM_PTR(&esp32_wake_on_ulp_obj) },

0 commit comments

Comments
 (0)