1717#define THRESHOLD 0 /* Lower the value, more the sensitivity */
1818#endif
1919
20- // External wakeup
21- #define BUTTON_PIN_BITMASK (GPIO ) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex
22-
23- #if CONFIG_IDF_TARGET_ESP32H2
24- #define WAKEUP_GPIO GPIO_NUM_7 // Only RTC IO are allowed
25- #define TARGET_FREQ 32
26- #else
27- #define WAKEUP_GPIO GPIO_NUM_4 // Only RTC IO are allowed
28- #define TARGET_FREQ 40
29- #endif
20+ #define TARGET_FREQ CONFIG_XTAL_FREQ
3021
3122RTC_DATA_ATTR int boot_count = 0 ;
3223uint32_t orig_freq = 0 ;
@@ -60,30 +51,6 @@ void setup_touchpad() {
6051#endif
6152}
6253
63- void setup_rtc_io () {
64- #if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT0_WAKEUP
65- esp_sleep_enable_ext0_wakeup (WAKEUP_GPIO, 1 );
66- rtc_gpio_pullup_en (WAKEUP_GPIO);
67- rtc_gpio_pulldown_dis (WAKEUP_GPIO);
68- #endif
69- }
70-
71- void setup_rtc_cntl () {
72- #if SOC_RTCIO_WAKE_SUPPORTED && SOC_PM_SUPPORT_EXT1_WAKEUP
73- esp_sleep_enable_ext1_wakeup_io (BUTTON_PIN_BITMASK (WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
74- rtc_gpio_pulldown_dis (WAKEUP_GPIO);
75- rtc_gpio_pullup_en (WAKEUP_GPIO);
76- #endif
77- }
78-
79- void setup_gpio () {
80- esp_sleep_pd_config (ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON);
81- gpio_pullup_dis (WAKEUP_GPIO);
82- gpio_pulldown_en (WAKEUP_GPIO);
83- gpio_wakeup_enable (WAKEUP_GPIO, GPIO_INTR_LOW_LEVEL);
84- esp_sleep_enable_gpio_wakeup ();
85- }
86-
8754void setup_uart () {
8855 uart_set_wakeup_threshold (UART_NUM_0, 9 ); // wake up with "aaa" string (9 positive edges)
8956 esp_sleep_enable_uart_wakeup (UART_NUM_0);
@@ -126,18 +93,6 @@ void loop() {
12693 esp_deep_sleep_start ();
12794 Serial.println (" FAIL" );
12895 while (1 );
129- } else if (command == " rtc_io_deep" ) {
130- // Test external wakeup from deep sleep using RTC IO
131- setup_rtc_io ();
132- esp_deep_sleep_start ();
133- Serial.println (" FAIL" );
134- while (1 );
135- } else if (command == " rtc_cntl_deep" ) {
136- // Test external wakeup from deep sleep using RTC controller
137- setup_rtc_cntl ();
138- esp_deep_sleep_start ();
139- Serial.println (" FAIL" );
140- while (1 );
14196 } else if (command == " timer_light" ) {
14297 // Test timer wakeup from light sleep
14398 setup_timer ();
@@ -148,15 +103,6 @@ void loop() {
148103 } else if (command == " touchpad_light" ) {
149104 // Test touchpad wakeup from light sleep
150105 setup_touchpad ();
151- } else if (command == " rtc_io_light" ) {
152- // Test external wakeup from light sleep using RTC IO
153- setup_rtc_io ();
154- } else if (command == " rtc_cntl_light" ) {
155- // Test external wakeup from light sleep using RTC controller
156- setup_rtc_cntl ();
157- } else if (command == " gpio_light" ) {
158- // Test external wakeup from light sleep using GPIO
159- setup_gpio ();
160106 } else if (command == " uart_light" ) {
161107 // Test external wakeup from light sleep using UART
162108 setup_uart ();
@@ -169,7 +115,6 @@ void loop() {
169115 Serial.println (" Woke up from light sleep" );
170116 print_wakeup_reason ();
171117 Serial.flush ();
172- gpio_hold_dis (WAKEUP_GPIO);
173118 setCpuFrequencyMhz (orig_freq);
174119 }
175120}
0 commit comments