change(esp_hw_support): deprecate esp_sleep_get_wakeup_cause with esp_sleep_get_wakeup_causes

This commit is contained in:
wuzhenghui
2025-06-25 17:29:45 +08:00
parent 5ba8b5e3dc
commit 879713d589
38 changed files with 234 additions and 306 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -1935,8 +1935,15 @@ static void test_deep_sleep_init(void)
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG)); printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG));
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_EXT1: { uint32_t wakeup_causes = esp_sleep_get_wakeup_causes();
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************");
/* Sleep pad should be init once. */
test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]);
} else {
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) { if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1; int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -1944,22 +1951,12 @@ static void test_deep_sleep_init(void)
} else { } else {
printf("Wake up from GPIO\n"); printf("Wake up from GPIO\n");
} }
break;
} }
case ESP_SLEEP_WAKEUP_TIMER: { if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms); printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
break;
} }
case ESP_SLEEP_WAKEUP_TOUCHPAD: { if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status()); printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default: {
printf("Not a deep sleep reset\n");
ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************");
/* Sleep pad should be init once. */
test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]);
} }
} }

View File

@@ -880,7 +880,7 @@ TEST_CASE("GPIO_light_sleep_wake_up_test", "[gpio][ignore]")
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_light_sleep_start(); esp_light_sleep_start();
printf("Waked up from light sleep\n"); printf("Waked up from light sleep\n");
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO); TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO));
} }
#endif #endif

View File

@@ -199,16 +199,13 @@ static void enter_sleep_and_send_respond(void)
printf("sleep duration: %lld\n", t_after_us - t_before_us); printf("sleep duration: %lld\n", t_after_us - t_before_us);
/* Determine the reason for uart wakeup */ /* Determine the reason for uart wakeup */
switch (esp_sleep_get_wakeup_cause()) { if (esp_sleep_get_wakeup_causes() & (BIT(ESP_SLEEP_WAKEUP_UART + SLAVE_UART_NUM))) {
case ESP_SLEEP_WAKEUP_UART:
/* Hang-up for a while to switch and execute the uart task /* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */ * Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1); vTaskDelay(1);
uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11); uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11);
break; } else {
default:
uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15); uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15);
break;
} }
/* Wait for uart write finish */ /* Wait for uart write finish */

View File

@@ -1855,7 +1855,7 @@ esp_err_t esp_sleep_enable_touchpad_wakeup(void)
int esp_sleep_get_touchpad_wakeup_status(void) int esp_sleep_get_touchpad_wakeup_status(void)
{ {
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) { if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD))) {
return -1; return -1;
} }
uint32_t chan_num; uint32_t chan_num;
@@ -2080,7 +2080,7 @@ static void ext1_wakeup_prepare(void)
uint64_t esp_sleep_get_ext1_wakeup_status(void) uint64_t esp_sleep_get_ext1_wakeup_status(void)
{ {
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) { if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_EXT1))) {
return 0; return 0;
} }
uint32_t status = rtc_hal_ext1_get_wakeup_status(); uint32_t status = rtc_hal_ext1_get_wakeup_status();
@@ -2104,7 +2104,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status(void)
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED
uint64_t esp_sleep_get_gpio_wakeup_status(void) uint64_t esp_sleep_get_gpio_wakeup_status(void)
{ {
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_GPIO) { if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO))) {
return 0; return 0;
} }
return rtc_hal_gpio_get_wakeup_status(); return rtc_hal_gpio_get_wakeup_status();

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -59,17 +59,7 @@ static void test_lightsleep(bool force_rtc_periph)
/* Enter sleep mode */ /* Enter sleep mode */
esp_light_sleep_start(); esp_light_sleep_start();
/* Determine wake up reason */ printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
default:
wakeup_reason = "other";
break;
}
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
vTaskDelay(1000/portTICK_PERIOD_MS); vTaskDelay(1000/portTICK_PERIOD_MS);
} }
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -91,18 +91,7 @@ static void test_lightsleep(void)
/* Enter sleep mode */ /* Enter sleep mode */
esp_light_sleep_start(); esp_light_sleep_start();
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
default:
wakeup_reason = "other";
break;
}
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
vTaskDelay(1000/portTICK_PERIOD_MS); vTaskDelay(1000/portTICK_PERIOD_MS);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -142,19 +142,7 @@ static void s_lp_vad_config(void)
/* Enter sleep mode */ /* Enter sleep mode */
esp_light_sleep_start(); esp_light_sleep_start();
/* Determine wake up reason */ ESP_LOGI(TAG, "wakeup, reason: %s", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_VAD)) ? "vad" : "other");
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_VAD:
wakeup_reason = "vad";
break;
default:
wakeup_reason = "other";
TEST_ASSERT(false);
break;
}
ESP_LOGI(TAG, "wakeup, reason: %s", wakeup_reason);
} }
TEST_CASE_MULTIPLE_DEVICES("test LP VAD wakeup", "[vad][ignore][manual]", s_hp_i2s_config, s_lp_vad_config); TEST_CASE_MULTIPLE_DEVICES("test LP VAD wakeup", "[vad][ignore][manual]", s_hp_i2s_config, s_lp_vad_config);

View File

@@ -362,8 +362,13 @@ static int process_get_wakeup_cause(int argc, char **argv)
return 1; return 1;
} }
switch (esp_sleep_get_wakeup_cause()) { uint32_t causes = esp_sleep_get_wakeup_causes();
case ESP_SLEEP_WAKEUP_EXT1: { if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Wakeup cause err\n");
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
#if SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0 #if SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) { if (wakeup_pin_mask != 0) {
@@ -374,9 +379,9 @@ static int process_get_wakeup_cause(int argc, char **argv)
{ {
printf("Wake up from EXT1 triggered, but unknown wake-up IO\n"); printf("Wake up from EXT1 triggered, but unknown wake-up IO\n");
} }
break;
} }
case ESP_SLEEP_WAKEUP_GPIO: {
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
if (esp_reset_reason() == ESP_RST_DEEPSLEEP) { if (esp_reset_reason() == ESP_RST_DEEPSLEEP) {
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status(); 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)
gpio_ll_clear_intr_status(&GPIO, 0xFFFFFFFF); gpio_ll_clear_intr_status(&GPIO, 0xFFFFFFFF);
gpio_ll_clear_intr_status_high(&GPIO, 0xFFFFFFFF); gpio_ll_clear_intr_status_high(&GPIO, 0xFFFFFFFF);
} }
break;
}
default: {
printf("Wakeup cause err\n");
}
} }
return 0; return 0;
} }

View File

@@ -338,8 +338,7 @@ bool te_is_touch_dsleep_wakeup(void)
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) { if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
return false; return false;
} }
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause(); return !!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD));
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
} }
touch_pad_t te_get_sleep_channel(void) touch_pad_t te_get_sleep_channel(void)

View File

@@ -156,7 +156,7 @@ static void do_ulp_wakeup_deepsleep(lp_core_test_commands_t ulp_cmd)
static void check_reset_reason_ulp_wakeup(void) static void check_reset_reason_ulp_wakeup(void)
{ {
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
} }
static void do_ulp_wakeup_after_short_delay_deepsleep(void) static void do_ulp_wakeup_after_short_delay_deepsleep(void)
@@ -213,7 +213,7 @@ static void check_reset_reason_and_sleep_duration(void)
struct timeval tv_stop = {}; struct timeval tv_stop = {};
gettimeofday(&tv_stop, NULL); gettimeofday(&tv_stop, NULL);
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
int64_t sleep_duration = (tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000; int64_t sleep_duration = (tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000;
int64_t expected_sleep_duration_ms = ulp_counter_wakeup_limit * LP_TIMER_TEST_SLEEP_DURATION_US / 1000; int64_t expected_sleep_duration_ms = ulp_counter_wakeup_limit * LP_TIMER_TEST_SLEEP_DURATION_US / 1000;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -193,8 +193,8 @@ TEST_CASE("ULP FSM light-sleep wakeup test", "[ulp]")
TEST_ASSERT(esp_light_sleep_start() == ESP_OK); TEST_ASSERT(esp_light_sleep_start() == ESP_OK);
/* Wait for wakeup from ULP FSM Coprocessor */ /* Wait for wakeup from ULP FSM Coprocessor */
printf("cause %d\r\n", esp_sleep_get_wakeup_cause()); printf("causes %lx\r\n", esp_sleep_get_wakeup_causes());
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_ULP); TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
} }
static void ulp_fsm_deepsleep_wakeup_test(void) static void ulp_fsm_deepsleep_wakeup_test(void)
@@ -239,8 +239,8 @@ static void ulp_fsm_deepsleep_wakeup_test(void)
static void check_sleep_reset(void) static void check_sleep_reset(void)
{ {
TEST_ASSERT_EQUAL(ESP_RST_DEEPSLEEP, esp_reset_reason()); TEST_ASSERT_EQUAL(ESP_RST_DEEPSLEEP, esp_reset_reason());
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, cause); TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), causes & BIT(ESP_SLEEP_WAKEUP_ULP));
} }
TEST_CASE_MULTIPLE_STAGES("ULP FSM deep-sleep wakeup test", "[deepsleep][reset=DEEPSLEEP_RESET]", TEST_CASE_MULTIPLE_STAGES("ULP FSM deep-sleep wakeup test", "[deepsleep][reset=DEEPSLEEP_RESET]",

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -196,7 +196,7 @@ TEST_CASE("ULP-RISC-V can be loaded with and run multiple firmwares", "[ulp]")
TEST_ASSERT(ulp_riscv_is_running(&ulp_riscv_counter)); TEST_ASSERT(ulp_riscv_is_running(&ulp_riscv_counter));
} }
TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp]") TEST_CASE("ULP-RISC-V can be reloaded with a good firmware after a crash", "[ulp]")
{ {
/* Load ULP RISC-V firmware and start the ULP RISC-V Coprocessor */ /* Load ULP RISC-V firmware and start the ULP RISC-V Coprocessor */
load_and_start_ulp_firmware(ulp_main_bin_start, ulp_main_bin_length); load_and_start_ulp_firmware(ulp_main_bin_start, ulp_main_bin_length);
@@ -218,8 +218,7 @@ TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp]
esp_light_sleep_start(); esp_light_sleep_start();
/* Verify that main CPU wakes up by a COCPU trap signal trigger */ /* Verify that main CPU wakes up by a COCPU trap signal trigger */
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG));
TEST_ASSERT(cause == ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG);
printf("Resetting the ULP\n"); printf("Resetting the ULP\n");
ulp_riscv_reset(); ulp_riscv_reset();
@@ -312,7 +311,7 @@ static void do_ulp_wakeup_deepsleep(riscv_test_commands_t ulp_cmd, bool rtc_peri
static void check_reset_reason_ulp_wakeup(void) static void check_reset_reason_ulp_wakeup(void)
{ {
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause()); TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
} }
static void do_ulp_wakeup_after_long_delay_deepsleep(void) static void do_ulp_wakeup_after_long_delay_deepsleep(void)

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -313,23 +313,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout); fflush(stdout);
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM); uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
esp_light_sleep_start(); esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str; uint32_t causes = esp_sleep_get_wakeup_causes();
switch (cause) { if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
case ESP_SLEEP_WAKEUP_GPIO: ESP_LOGI(TAG, "Woke up from: unknown");
cause_str = "GPIO"; printf("%lx\n", causes);
break; return 0;
case ESP_SLEEP_WAKEUP_UART: }
cause_str = "UART"; if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
break; ESP_LOGI(TAG, "Woke up from: GPIO");
case ESP_SLEEP_WAKEUP_TIMER: }
cause_str = "timer"; if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
break; ESP_LOGI(TAG, "Woke up from: UART");
default: }
cause_str = "unknown"; if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("%d\n", cause); ESP_LOGI(TAG, "Woke up from: timer");
} }
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0; return 0;
} }

View File

@@ -24,16 +24,20 @@ void app_main(void)
ESP_ERROR_CHECK(esp_pm_configure(&pm_config)); ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
#endif #endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT) { uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
} else {
if (causes & BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT)) {
#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY #if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY
printf("Wake up from VBAT low power\n"); printf("Wake up from VBAT low power\n");
#else #else
printf("Wake up from VBAT brownout\n"); printf("Wake up from VBAT brownout\n");
#endif #endif
} else if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) { }
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from Timer\n"); printf("Wake up from Timer\n");
} else { }
printf("Not a deep sleep reset\n");
} }
esp_err_t sleep_result; esp_err_t sleep_result;

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: CC0-1.0 * SPDX-License-Identifier: CC0-1.0
* *
@@ -115,20 +115,17 @@ static void ot_deep_sleep_init(void)
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - s_sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - s_sleep_enter_time.tv_usec) / 1000; int sleep_time_ms = (now.tv_sec - s_sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - s_sleep_enter_time.tv_usec) / 1000;
esp_sleep_wakeup_cause_t wake_up_cause = esp_sleep_get_wakeup_cause();
switch (wake_up_cause) { uint32_t wake_up_causes = esp_sleep_get_wakeup_causes();
case ESP_SLEEP_WAKEUP_TIMER: { if (wake_up_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_EXT1: {
ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
ESP_LOGI(TAG, "Not a deep sleep reset"); ESP_LOGI(TAG, "Not a deep sleep reset");
break; } else {
if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms);
}
if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms);
}
} }
// Set the methods of how to wake up: // Set the methods of how to wake up:

View File

@@ -156,7 +156,7 @@ void example_prepare_sleep(void)
/* Enter the light sleep */ /* Enter the light sleep */
esp_light_sleep_start(); esp_light_sleep_start();
/* Keep executing the code after waking up from the light sleep */ /* Keep executing the code after waking up from the light sleep */
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) { if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
ESP_LOGI(TAG, "Wake up by touch\n"); ESP_LOGI(TAG, "Wake up by touch\n");
} else { } else {
ESP_LOGE(TAG, "Wake up by other source\n"); ESP_LOGE(TAG, "Wake up by other source\n");
@@ -180,7 +180,7 @@ void app_main(void)
{ {
#if CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP #if CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP
/* Printing the log if the chip is waken up from deepsleep by the touchpad */ /* Printing the log if the chip is waken up from deepsleep by the touchpad */
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) { if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
ESP_LOGI(TAG, "Wake up by touch\n"); ESP_LOGI(TAG, "Wake up by touch\n");
} }
#endif // CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP #endif // CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -167,24 +167,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout); fflush(stdout);
fsync(fileno(stdout)); fsync(fileno(stdout));
esp_light_sleep_start(); esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str; uint32_t causes = esp_sleep_get_wakeup_causes();
switch (cause) { if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
case ESP_SLEEP_WAKEUP_GPIO: ESP_LOGI(TAG, "Woke up from: unknown");
cause_str = "GPIO"; printf("%lx\n", causes);
break; return 0;
case ESP_SLEEP_WAKEUP_UART: }
cause_str = "UART"; if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
break; ESP_LOGI(TAG, "Woke up from: GPIO");
case ESP_SLEEP_WAKEUP_TIMER: }
cause_str = "timer"; if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
break; ESP_LOGI(TAG, "Woke up from: UART");
default: }
cause_str = "unknown"; if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("%d\n", cause); ESP_LOGI(TAG, "Woke up from: timer");
} }
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0; return 0;
} }

View File

@@ -59,14 +59,15 @@ static void deep_sleep_task(void *args)
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
switch (esp_sleep_get_wakeup_cause()) { uint32_t causes = esp_sleep_get_wakeup_causes();
case ESP_SLEEP_WAKEUP_TIMER: { if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
} else {
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
break;
} }
#if CONFIG_EXAMPLE_GPIO_WAKEUP #if CONFIG_EXAMPLE_GPIO_WAKEUP
case ESP_SLEEP_WAKEUP_GPIO: { if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status(); uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status();
if (wakeup_pin_mask != 0) { if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1; int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -74,19 +75,15 @@ static void deep_sleep_task(void *args)
} else { } else {
printf("Wake up from GPIO\n"); printf("Wake up from GPIO\n");
} }
break;
} }
#endif //CONFIG_EXAMPLE_GPIO_WAKEUP #endif //CONFIG_EXAMPLE_GPIO_WAKEUP
#if CONFIG_EXAMPLE_EXT0_WAKEUP #if CONFIG_EXAMPLE_EXT0_WAKEUP
case ESP_SLEEP_WAKEUP_EXT0: { if (causes & BIT(ESP_SLEEP_WAKEUP_EXT0)) {
printf("Wake up from ext0\n"); printf("Wake up from ext0\n");
break;
} }
#endif // CONFIG_EXAMPLE_EXT0_WAKEUP #endif // CONFIG_EXAMPLE_EXT0_WAKEUP
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP #ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_EXT1: { if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status(); uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) { if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1; int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -94,13 +91,8 @@ static void deep_sleep_task(void *args)
} else { } else {
printf("Wake up from GPIO\n"); printf("Wake up from GPIO\n");
} }
break;
} }
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP #endif // CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
printf("Not a deep sleep reset\n");
} }
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);

View File

@@ -26,7 +26,7 @@ void app_main(void)
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000; int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) { if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms); printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
} }

View File

@@ -37,22 +37,18 @@ static void light_sleep_task(void *args)
/* Determine wake up reason */ /* Determine wake up reason */
const char* wakeup_reason; const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) { uint32_t wakup_causes = esp_sleep_get_wakeup_causes();
case ESP_SLEEP_WAKEUP_TIMER: if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
wakeup_reason = "timer"; wakeup_reason = "timer";
break; } else if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
case ESP_SLEEP_WAKEUP_GPIO:
wakeup_reason = "pin"; wakeup_reason = "pin";
break; } else if (wakup_causes & (BIT(ESP_SLEEP_WAKEUP_UART) | BIT(ESP_SLEEP_WAKEUP_UART1) | BIT(ESP_SLEEP_WAKEUP_UART2))) {
case ESP_SLEEP_WAKEUP_UART:
wakeup_reason = "uart"; wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task /* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */ * Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1); vTaskDelay(1);
break; } else {
default:
wakeup_reason = "other"; wakeup_reason = "other";
break;
} }
#if CONFIG_NEWLIB_NANO_FORMAT #if CONFIG_NEWLIB_NANO_FORMAT
/* printf in newlib-nano does not support %ll format, causing example test fail */ /* printf in newlib-nano does not support %ll format, causing example test fail */
@@ -62,7 +58,7 @@ static void light_sleep_task(void *args)
printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n", printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000); wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
#endif #endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) { if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/ /* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
example_wait_gpio_inactive(); example_wait_gpio_inactive();
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -43,18 +43,15 @@ void app_main(void)
rtc_gpio_pulldown_dis(WAKEUP_PIN); rtc_gpio_pulldown_dis(WAKEUP_PIN);
rtc_gpio_pullup_dis(WAKEUP_PIN); rtc_gpio_pullup_dis(WAKEUP_PIN);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP read and detected a change in GPIO_0, prints */ /* ULP read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP woke up the main CPU! \n"); printf("ULP woke up the main CPU! \n");
printf("ULP read changes in GPIO_0 current is: %s \n", printf("ULP read changes in GPIO_0 current is: %s \n",
(bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" ); (bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" );
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
} }
/* Go back to sleep, only the ULP will run */ /* Go back to sleep, only the ULP will run */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -47,14 +47,13 @@ void app_main(void)
printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT); printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
} else {
printf("ULP woke up the main CPU!\n"); printf("ULP woke up the main CPU!\n");
printf("Pulse count: %"PRIu32"\n", ulp_pulse_count); printf("Pulse count: %"PRIu32"\n", ulp_pulse_count);
} else {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
} }
/* Go back to sleep, only the ULP will run */ /* Go back to sleep, only the ULP will run */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -48,18 +48,15 @@ void app_main(void)
wakeup_gpio_init(); wakeup_gpio_init();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP read and detected a change in WAKEUP_PIN, prints */
printf("ULP woke up the main CPU! \n");
} else {
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP wakeup, initializing it! \n"); printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program(); init_ulp_program();
} }
/* ULP read and detected a change in WAKEUP_PIN, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP woke up the main CPU! \n");
}
/* Go back to sleep, only the ULP will run */ /* Go back to sleep, only the ULP will run */
printf("Entering deep sleep\n\n"); printf("Entering deep sleep\n\n");

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -62,9 +62,12 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("Not an LP core wakeup. Cause = %d\n", cause); printf("LP core woke up the main CPU\n");
printf("Lux = %ld\n", ulp_lux);
} else {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n"); printf("Initializing...\n");
/* Initialize LP_I2C from the main processor */ /* Initialize LP_I2C from the main processor */
@@ -72,9 +75,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */ /* Load LP Core binary and start the coprocessor */
lp_core_init(); lp_core_init();
} else if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("LP core woke up the main CPU\n");
printf("Lux = %ld\n", ulp_lux);
} }
/* Setup wakeup triggers */ /* Setup wakeup triggers */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -78,9 +78,12 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("Not an LP core wakeup. Cause = %d\n", cause); printf("LP core woke up the main CPU\n");
printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0);
} else {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n"); printf("Initializing...\n");
/* Initialize LP_SPI from the main processor */ /* Initialize LP_SPI from the main processor */
@@ -88,9 +91,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */ /* Load LP Core binary and start the coprocessor */
lp_core_init(); lp_core_init();
} else if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("LP core woke up the main CPU\n");
printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0);
} }
/* Setup wakeup triggers */ /* Setup wakeup triggers */

View File

@@ -154,9 +154,9 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* Woke up by LP core, i.e., wake up the main CPU in the LP program */ /* Woke up by LP core, i.e., wake up the main CPU in the LP program */
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("LP core woke up the main CPU\n"); printf("LP core woke up the main CPU\n");
// We can access the LP core global variable by adding `ulp_` prefix // We can access the LP core global variable by adding `ulp_` prefix
uint32_t touch_data = ulp_touch_data; uint32_t touch_data = ulp_touch_data;
@@ -169,7 +169,7 @@ void app_main(void)
} }
/* Woke up by other source, like power_on */ /* Woke up by other source, like power_on */
else { else {
printf("Not an LP core wakeup. Cause = %d\n", cause); printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n"); printf("Initializing...\n");
/* Initialize Touch sensor from the main processor */ /* Initialize Touch sensor from the main processor */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -50,9 +50,9 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Cause = %d\n", cause); printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n"); printf("Initializing...\n");
/* Initialize LP_UART */ /* Initialize LP_UART */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -51,9 +51,9 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Cause = %d\n", cause); printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n"); printf("Initializing...\n");
/* Initialize LP_UART */ /* Initialize LP_UART */

View File

@@ -42,8 +42,8 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not ULP wakeup, initializing ULP\n"); printf("Not ULP wakeup, initializing ULP\n");
init_ulp_program(); init_ulp_program();
} else { } else {

View File

@@ -51,8 +51,8 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not ULP wakeup\n"); printf("Not ULP wakeup\n");
init_ulp_program(); init_ulp_program();
} else { } else {

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -37,16 +37,16 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if ((cause != ESP_SLEEP_WAKEUP_ULP) && (cause != ESP_SLEEP_WAKEUP_TIMER)) { if (!(causes & (BIT(ESP_SLEEP_WAKEUP_ULP) | BIT(ESP_SLEEP_WAKEUP_TIMER)))) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause); printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program(); init_ulp_program();
} }
/* ULP Risc-V read and detected a temperature above the limit */ /* ULP Risc-V read and detected a temperature above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU\n"); printf("ULP-RISC-V woke up the main CPU\n");
printf("Threshold: high = %"PRIu32"\n", ulp_adc_threshold); printf("Threshold: high = %"PRIu32"\n", ulp_adc_threshold);
printf("Value = %"PRIu32" was above threshold\n", ulp_wakeup_result); printf("Value = %"PRIu32" was above threshold\n", ulp_wakeup_result);

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -44,15 +44,15 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause); printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program(); init_ulp_program();
} }
/* ULP Risc-V read and detected a temperature above the limit */ /* ULP Risc-V read and detected a temperature above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU, temperature is above set limit! \n"); printf("ULP-RISC-V woke up the main CPU, temperature is above set limit! \n");
printf("ULP-RISC-V read temperature is %f\n", ulp_temp_reg_val / 16.0); printf("ULP-RISC-V read temperature is %f\n", ulp_temp_reg_val / 16.0);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -45,15 +45,15 @@ void app_main(void)
rtc_gpio_pullup_dis(GPIO_NUM_0); rtc_gpio_pullup_dis(GPIO_NUM_0);
rtc_gpio_hold_en(GPIO_NUM_0); rtc_gpio_hold_en(GPIO_NUM_0);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n"); printf("Not a ULP-RISC-V wakeup, initializing it! \n");
init_ulp_program(); init_ulp_program();
} }
/* ULP Risc-V read and detected a change in GPIO_0, prints */ /* ULP Risc-V read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU! \n"); printf("ULP-RISC-V woke up the main CPU! \n");
printf("ULP-RISC-V read changes in GPIO_0 current is: %s \n", printf("ULP-RISC-V read changes in GPIO_0 current is: %s \n",
(bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" ); (bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" );

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -49,15 +49,15 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n"); printf("Not a ULP-RISC-V wakeup, initializing it! \n");
wakeup_gpio_init(); wakeup_gpio_init();
init_ulp_program(); init_ulp_program();
} }
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU! \n"); printf("ULP-RISC-V woke up the main CPU! \n");
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -52,7 +52,7 @@ void app_main(void)
int32_t pressure = 0; int32_t pressure = 0;
oss_mode_t oss_mode; oss_mode_t oss_mode;
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); uint32_t causes = esp_sleep_get_wakeup_causes();
/* Not a wakeup from ULP /* Not a wakeup from ULP
* Initialize RTC I2C * Initialize RTC I2C
@@ -61,8 +61,8 @@ void app_main(void)
* Load the ULP firmware * Load the ULP firmware
* Go to deep sleep * Go to deep sleep
*/ */
if (cause != ESP_SLEEP_WAKEUP_ULP) { if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC V wakeup (cause = %d)\n", cause); printf("Not a ULP-RISC V wakeup (causes = %lx)\n", causes);
/* Initialize RTC I2C */ /* Initialize RTC I2C */
init_i2c(); init_i2c();
@@ -76,7 +76,7 @@ void app_main(void)
ulp_riscv_i2c_master_write_to_device(&data_wr, 1); ulp_riscv_i2c_master_write_to_device(&data_wr, 1);
/* Confirm that the sensor is alive /* Confirm that the sensor is alive
* The BMP180 returns the chip id 0x55 on quering reg addr 0xD0 * The BMP180 returns the chip id 0x55 on querying reg addr 0xD0
*/ */
ulp_riscv_i2c_master_set_slave_reg_addr(BMP180_SENSOR_REG_ADDR_WHO_AM_I); ulp_riscv_i2c_master_set_slave_reg_addr(BMP180_SENSOR_REG_ADDR_WHO_AM_I);
ulp_riscv_i2c_master_read_from_device(&data_rd, 1); ulp_riscv_i2c_master_read_from_device(&data_rd, 1);
@@ -103,7 +103,7 @@ void app_main(void)
/* Calculate real temperature value */ /* Calculate real temperature value */
temperature = bmp180_calculate_real_temp((int32_t)ut_data); temperature = bmp180_calculate_real_temp((int32_t)ut_data);
printf("Real Temperature = %f deg celcius\n", (float)(temperature/10.0)); printf("Real Temperature = %f deg celsius\n", (float)(temperature/10.0));
/* Calculate real pressure value */ /* Calculate real pressure value */
pressure = bmp180_calculate_real_pressure(up_data, (int32_t)ut_data, oss_mode); pressure = bmp180_calculate_real_pressure(up_data, (int32_t)ut_data, oss_mode);
@@ -120,7 +120,7 @@ void app_main(void)
} }
/* ULP RISC-V read and detected a temperature or pressure above the limit */ /* ULP RISC-V read and detected a temperature or pressure above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) { if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP RISC-V woke up the main CPU\n"); printf("ULP RISC-V woke up the main CPU\n");
/* Pause ULP while we are using the RTC I2C from the main CPU */ /* Pause ULP while we are using the RTC I2C from the main CPU */
@@ -138,7 +138,7 @@ void app_main(void)
/* Calculate real temperature and pressure again */ /* Calculate real temperature and pressure again */
temperature = 0; temperature = 0;
temperature = bmp180_calculate_real_temp((int32_t)ulp_ut_data); temperature = bmp180_calculate_real_temp((int32_t)ulp_ut_data);
printf("New Real Temperature = %f deg celcius\n", (float)(temperature/10.0)); printf("New Real Temperature = %f deg celsius\n", (float)(temperature/10.0));
/* Calculate real pressure value */ /* Calculate real pressure value */
pressure = 0; pressure = 0;
@@ -283,19 +283,19 @@ static void bmp180_read_up_data(int32_t *up_data, oss_mode_t oss_mode)
{ {
case OSS_0: case OSS_0:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_0; cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_0;
wait = 5; // Wait atleast 4.5 msec wait = 5; // Wait at least 4.5 msec
break; break;
case OSS_1: case OSS_1:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_1; cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_1;
wait = 8; // Wait atleast 7.5 msec wait = 8; // Wait at least 7.5 msec
break; break;
case OSS_2: case OSS_2:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_2; cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_2;
wait = 14; // Wait atleast 13.5 msec wait = 14; // Wait at least 13.5 msec
break; break;
case OSS_3: case OSS_3:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_3; cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_3;
wait = 26; // Wait atleast 25.5 msec wait = 26; // Wait at least 25.5 msec
break; break;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -26,15 +26,8 @@ static void init_ulp_program(void);
void app_main(void) void app_main(void)
{ {
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP RISC-V handled an interrupt on GPIO#0 */ /* ULP RISC-V handled an interrupt on GPIO#0 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP RISC-V woke up the main CPU! \n"); printf("ULP RISC-V woke up the main CPU! \n");
if (ulp_wake_by_sw) { if (ulp_wake_by_sw) {
printf("ULP RISC-V SW Interrupt triggered %lu times.\r\n", ulp_sw_int_cnt); printf("ULP RISC-V SW Interrupt triggered %lu times.\r\n", ulp_sw_int_cnt);
@@ -43,6 +36,10 @@ void app_main(void)
printf("ULP RISC-V GPIO Interrupt triggered.\r\n"); printf("ULP RISC-V GPIO Interrupt triggered.\r\n");
ulp_wake_by_gpio = 0; ulp_wake_by_gpio = 0;
} }
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP RISC-V wakeup, initializing it! \n");
init_ulp_program();
} }
/* Go back to sleep, only the ULP RISC-V will run */ /* Go back to sleep, only the ULP RISC-V will run */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -83,19 +83,8 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup, initializing ...\n");
/* Initialize Touch peripheral */
init_touch_pad();
/* Initialize ULP core */
init_ulp_program();
}
/* ULP RISC-V detected a touch input */ /* ULP RISC-V detected a touch input */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP-RISC-V woke up the main CPU! \n"); printf("ULP-RISC-V woke up the main CPU! \n");
uint32_t touch_data = ulp_touch_data; uint32_t touch_data = ulp_touch_data;
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) { for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
@@ -104,6 +93,14 @@ void app_main(void)
} }
} }
printf("\n"); printf("\n");
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP-RISC-V wakeup, initializing ...\n");
/* Initialize Touch peripheral */
init_touch_pad();
/* Initialize ULP core */
init_ulp_program();
} }
/* Go to sleep, only the ULP RISC-V will run */ /* Go to sleep, only the ULP RISC-V will run */

View File

@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Unlicense OR CC0-1.0 * SPDX-License-Identifier: Unlicense OR CC0-1.0
*/ */
@@ -33,19 +33,15 @@ void app_main(void)
*/ */
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP Risc-V read and detected a change in GPIO_0, prints */
printf("ULP-RISC-V woke up the main CPU! \n");
} else {
/* not a wakeup from ULP, load the firmware */ /* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n"); printf("Not a ULP-RISC-V wakeup, initializing it! \n");
init_ulp_program(); init_ulp_program();
} }
/* ULP Risc-V read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP-RISC-V woke up the main CPU! \n");
}
/* Go back to sleep, only the ULP Risc-V will run */ /* Go back to sleep, only the ULP Risc-V will run */
printf("Entering in deep sleep\n\n"); printf("Entering in deep sleep\n\n");