34
34
#include "freertos/task.h"
35
35
#include "rom/ets_sys.h"
36
36
#include "esp_system.h"
37
+ #include "driver/touch_pad.h"
37
38
38
39
#include "py/obj.h"
39
40
#include "py/runtime.h"
43
44
#include "extmod/machine_i2c.h"
44
45
#include "extmod/machine_spi.h"
45
46
#include "modmachine.h"
47
+ #include "machine_rtc.h"
46
48
47
49
#if MICROPY_PY_MACHINE
48
50
49
51
// amount of time to sleep
50
- extern uint64_t machine_rtc_expiry ;
52
+ extern machine_rtc_config_t machine_rtc_config ;
51
53
#define MACHINE_WAKE_DEEPSLEEP (0x04)
52
54
53
55
STATIC mp_obj_t machine_freq (size_t n_args , const mp_obj_t * args ) {
@@ -69,9 +71,26 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
69
71
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (machine_freq_obj , 0 , 1 , machine_freq );
70
72
71
73
STATIC mp_obj_t machine_deepsleep (void ) {
72
- if (machine_rtc_expiry != 0 ) {
73
- esp_deep_sleep_enable_timer_wakeup (machine_rtc_expiry );
74
+
75
+ if (machine_rtc_config .expiry != 0 ) {
76
+ esp_deep_sleep_enable_timer_wakeup (machine_rtc_config .expiry );
77
+ }
78
+
79
+ if (machine_rtc_config .ext0_pin != -1 ) {
80
+ esp_deep_sleep_enable_ext0_wakeup (machine_rtc_config .ext0_pin , machine_rtc_config .ext0_level ? 1 : 0 );
81
+ }
82
+
83
+ if (machine_rtc_config .ext1_pins != 0 ) {
84
+ esp_deep_sleep_enable_ext1_wakeup (
85
+ machine_rtc_config .ext1_pins ,
86
+ machine_rtc_config .ext1_level ? ESP_EXT1_WAKEUP_ANY_HIGH : ESP_EXT1_WAKEUP_ALL_LOW );
87
+ }
88
+
89
+ if (machine_rtc_config .wake_on_touch ) {
90
+ // esp_deep_sleep_enable_touchpad_wakeup();
91
+ nlr_raise (mp_obj_new_exception_msg (& mp_type_RuntimeError , "touchpad wakeup not available for this version of ESP-IDF" ));
74
92
}
93
+
75
94
esp_deep_sleep_start ();
76
95
return mp_const_none ;
77
96
}
0 commit comments