Skip to content

Commit 879713d

Browse files
committed
change(esp_hw_support): deprecate esp_sleep_get_wakeup_cause with esp_sleep_get_wakeup_causes
1 parent 5ba8b5e commit 879713d

File tree

38 files changed

+233
-305
lines changed

38 files changed

+233
-305
lines changed

components/driver/test_apps/touch_sensor_v2/main/test_touch_v2.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -1935,32 +1935,29 @@ static void test_deep_sleep_init(void)
19351935
gettimeofday(&now, NULL);
19361936
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
19371937
printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG));
1938-
switch (esp_sleep_get_wakeup_cause()) {
1939-
case ESP_SLEEP_WAKEUP_EXT1: {
1940-
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
1941-
if (wakeup_pin_mask != 0) {
1942-
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
1943-
printf("Wake up from GPIO %"PRIu32"\n", pin);
1944-
} else {
1945-
printf("Wake up from GPIO\n");
1946-
}
1947-
break;
1948-
}
1949-
case ESP_SLEEP_WAKEUP_TIMER: {
1950-
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
1951-
break;
1952-
}
1953-
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
1954-
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
1955-
break;
1956-
}
1957-
case ESP_SLEEP_WAKEUP_UNDEFINED:
1958-
default: {
1938+
1939+
uint32_t wakeup_causes = esp_sleep_get_wakeup_causes();
1940+
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
19591941
printf("Not a deep sleep reset\n");
19601942
ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************");
19611943
/* Sleep pad should be init once. */
19621944
test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]);
1963-
}
1945+
} else {
1946+
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
1947+
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
1948+
if (wakeup_pin_mask != 0) {
1949+
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
1950+
printf("Wake up from GPIO %"PRIu32"\n", pin);
1951+
} else {
1952+
printf("Wake up from GPIO\n");
1953+
}
1954+
}
1955+
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
1956+
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
1957+
}
1958+
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
1959+
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
1960+
}
19641961
}
19651962

19661963
vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS);

components/esp_driver_gpio/test_apps/gpio/main/test_gpio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ TEST_CASE("GPIO_light_sleep_wake_up_test", "[gpio][ignore]")
880880
vTaskDelay(1000 / portTICK_PERIOD_MS);
881881
esp_light_sleep_start();
882882
printf("Waked up from light sleep\n");
883-
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO);
883+
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO));
884884
}
885885
#endif
886886

components/esp_driver_uart/test_apps/uart/main/test_hp_uart_wakeup.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,13 @@ static void enter_sleep_and_send_respond(void)
199199
printf("sleep duration: %lld\n", t_after_us - t_before_us);
200200

201201
/* Determine the reason for uart wakeup */
202-
switch (esp_sleep_get_wakeup_cause()) {
203-
case ESP_SLEEP_WAKEUP_UART:
202+
if (esp_sleep_get_wakeup_causes() & (BIT(ESP_SLEEP_WAKEUP_UART + SLAVE_UART_NUM))) {
204203
/* Hang-up for a while to switch and execute the uart task
205-
* Otherwise the chip may fall sleep again before running uart task */
204+
* Otherwise the chip may fall sleep again before running uart task */
206205
vTaskDelay(1);
207206
uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11);
208-
break;
209-
default:
207+
} else {
210208
uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15);
211-
break;
212209
}
213210

214211
/* Wait for uart write finish */

components/esp_hw_support/sleep_modes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ esp_err_t esp_sleep_enable_touchpad_wakeup(void)
18551855

18561856
int esp_sleep_get_touchpad_wakeup_status(void)
18571857
{
1858-
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) {
1858+
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD))) {
18591859
return -1;
18601860
}
18611861
uint32_t chan_num;
@@ -2080,7 +2080,7 @@ static void ext1_wakeup_prepare(void)
20802080

20812081
uint64_t esp_sleep_get_ext1_wakeup_status(void)
20822082
{
2083-
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) {
2083+
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_EXT1))) {
20842084
return 0;
20852085
}
20862086
uint32_t status = rtc_hal_ext1_get_wakeup_status();
@@ -2104,7 +2104,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status(void)
21042104
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED
21052105
uint64_t esp_sleep_get_gpio_wakeup_status(void)
21062106
{
2107-
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_GPIO) {
2107+
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO))) {
21082108
return 0;
21092109
}
21102110
return rtc_hal_gpio_get_wakeup_status();

components/esp_hw_support/test_apps/rtc_8md256/main/test_rtc_8md256.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -59,17 +59,7 @@ static void test_lightsleep(bool force_rtc_periph)
5959
/* Enter sleep mode */
6060
esp_light_sleep_start();
6161

62-
/* Determine wake up reason */
63-
const char* wakeup_reason;
64-
switch (esp_sleep_get_wakeup_cause()) {
65-
case ESP_SLEEP_WAKEUP_TIMER:
66-
wakeup_reason = "timer";
67-
break;
68-
default:
69-
wakeup_reason = "other";
70-
break;
71-
}
72-
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
62+
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
7363
vTaskDelay(1000/portTICK_PERIOD_MS);
7464
}
7565
}

components/esp_hw_support/test_apps/rtc_power_modes/main/test_rtc_power.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -91,18 +91,7 @@ static void test_lightsleep(void)
9191

9292
/* Enter sleep mode */
9393
esp_light_sleep_start();
94-
95-
/* Determine wake up reason */
96-
const char* wakeup_reason;
97-
switch (esp_sleep_get_wakeup_cause()) {
98-
case ESP_SLEEP_WAKEUP_TIMER:
99-
wakeup_reason = "timer";
100-
break;
101-
default:
102-
wakeup_reason = "other";
103-
break;
104-
}
105-
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
94+
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
10695

10796
vTaskDelay(1000/portTICK_PERIOD_MS);
10897
}

components/esp_hw_support/test_apps/vad_wakeup/main/test_vad_wakeup.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Unlicense OR CC0-1.0
55
*/
@@ -142,19 +142,7 @@ static void s_lp_vad_config(void)
142142
/* Enter sleep mode */
143143
esp_light_sleep_start();
144144

145-
/* Determine wake up reason */
146-
const char* wakeup_reason;
147-
switch (esp_sleep_get_wakeup_cause()) {
148-
case ESP_SLEEP_WAKEUP_VAD:
149-
wakeup_reason = "vad";
150-
break;
151-
default:
152-
wakeup_reason = "other";
153-
TEST_ASSERT(false);
154-
break;
155-
}
156-
157-
ESP_LOGI(TAG, "wakeup, reason: %s", wakeup_reason);
145+
ESP_LOGI(TAG, "wakeup, reason: %s", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_VAD)) ? "vad" : "other");
158146
}
159147

160148
TEST_CASE_MULTIPLE_DEVICES("test LP VAD wakeup", "[vad][ignore][manual]", s_hp_i2s_config, s_lp_vad_config);

components/esp_hw_support/test_apps/wakeup_tests/main/src/io_wakeup_cmd.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,13 @@ static int process_get_wakeup_cause(int argc, char **argv)
362362
return 1;
363363
}
364364

365-
switch (esp_sleep_get_wakeup_cause()) {
366-
case ESP_SLEEP_WAKEUP_EXT1: {
365+
uint32_t causes = esp_sleep_get_wakeup_causes();
366+
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
367+
printf("Wakeup cause err\n");
368+
return 0;
369+
}
370+
371+
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
367372
#if SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0
368373
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
369374
if (wakeup_pin_mask != 0) {
@@ -374,9 +379,9 @@ static int process_get_wakeup_cause(int argc, char **argv)
374379
{
375380
printf("Wake up from EXT1 triggered, but unknown wake-up IO\n");
376381
}
377-
break;
378382
}
379-
case ESP_SLEEP_WAKEUP_GPIO: {
383+
384+
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
380385
if (esp_reset_reason() == ESP_RST_DEEPSLEEP) {
381386
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
382387
uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status();
@@ -409,11 +414,6 @@ static int process_get_wakeup_cause(int argc, char **argv)
409414
gpio_ll_clear_intr_status(&GPIO, 0xFFFFFFFF);
410415
gpio_ll_clear_intr_status_high(&GPIO, 0xFFFFFFFF);
411416
}
412-
break;
413-
}
414-
default: {
415-
printf("Wakeup cause err\n");
416-
}
417417
}
418418
return 0;
419419
}

components/touch_element/touch_element.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ bool te_is_touch_dsleep_wakeup(void)
338338
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
339339
return false;
340340
}
341-
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
342-
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
341+
return !!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD));
343342
}
344343

345344
touch_pad_t te_get_sleep_channel(void)

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static void do_ulp_wakeup_deepsleep(lp_core_test_commands_t ulp_cmd)
156156

157157
static void check_reset_reason_ulp_wakeup(void)
158158
{
159-
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause());
159+
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
160160
}
161161

162162
static void do_ulp_wakeup_after_short_delay_deepsleep(void)
@@ -213,7 +213,7 @@ static void check_reset_reason_and_sleep_duration(void)
213213
struct timeval tv_stop = {};
214214
gettimeofday(&tv_stop, NULL);
215215

216-
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause());
216+
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
217217

218218
int64_t sleep_duration = (tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000;
219219
int64_t expected_sleep_duration_ms = ulp_counter_wakeup_limit * LP_TIMER_TEST_SLEEP_DURATION_US / 1000;

0 commit comments

Comments
 (0)