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
*/
@@ -1935,32 +1935,29 @@ static void test_deep_sleep_init(void)
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;
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: {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
printf("Wake up from GPIO %"PRIu32"\n", pin);
} else {
printf("Wake up from GPIO\n");
}
break;
}
case ESP_SLEEP_WAKEUP_TIMER: {
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default: {
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();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
printf("Wake up from GPIO %"PRIu32"\n", pin);
} else {
printf("Wake up from GPIO\n");
}
}
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
}
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
}
}
vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS);

View File

@@ -880,7 +880,7 @@ TEST_CASE("GPIO_light_sleep_wake_up_test", "[gpio][ignore]")
vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_light_sleep_start();
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

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);
/* Determine the reason for uart wakeup */
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_UART:
if (esp_sleep_get_wakeup_causes() & (BIT(ESP_SLEEP_WAKEUP_UART + SLAVE_UART_NUM))) {
/* 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);
uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11);
break;
default:
} else {
uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15);
break;
}
/* 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)
{
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) {
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD))) {
return -1;
}
uint32_t chan_num;
@@ -2080,7 +2080,7 @@ static void ext1_wakeup_prepare(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;
}
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
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 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
*/
@@ -59,17 +59,7 @@ static void test_lightsleep(bool force_rtc_periph)
/* Enter sleep mode */
esp_light_sleep_start();
/* 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);
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
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
*/
@@ -91,18 +91,7 @@ static void test_lightsleep(void)
/* Enter sleep mode */
esp_light_sleep_start();
/* 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);
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
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
*/
@@ -142,19 +142,7 @@ static void s_lp_vad_config(void)
/* Enter sleep mode */
esp_light_sleep_start();
/* Determine wake up reason */
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);
ESP_LOGI(TAG, "wakeup, reason: %s", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_VAD)) ? "vad" : "other");
}
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;
}
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_EXT1: {
uint32_t causes = esp_sleep_get_wakeup_causes();
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
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
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");
}
break;
}
case ESP_SLEEP_WAKEUP_GPIO: {
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
if (esp_reset_reason() == ESP_RST_DEEPSLEEP) {
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
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_high(&GPIO, 0xFFFFFFFF);
}
break;
}
default: {
printf("Wakeup cause err\n");
}
}
return 0;
}

View File

@@ -338,8 +338,7 @@ bool te_is_touch_dsleep_wakeup(void)
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
return false;
}
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
return !!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD));
}
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)
{
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)
@@ -213,7 +213,7 @@ static void check_reset_reason_and_sleep_duration(void)
struct timeval tv_stop = {};
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 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
*/
@@ -193,8 +193,8 @@ TEST_CASE("ULP FSM light-sleep wakeup test", "[ulp]")
TEST_ASSERT(esp_light_sleep_start() == ESP_OK);
/* Wait for wakeup from ULP FSM Coprocessor */
printf("cause %d\r\n", esp_sleep_get_wakeup_cause());
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_ULP);
printf("causes %lx\r\n", esp_sleep_get_wakeup_causes());
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
}
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)
{
TEST_ASSERT_EQUAL(ESP_RST_DEEPSLEEP, esp_reset_reason());
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
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]",

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
*/
@@ -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_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_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();
/* 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(cause == ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG);
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG));
printf("Resetting the ULP\n");
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)
{
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)

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
*/
@@ -313,23 +313,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout);
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;
switch (cause) {
case ESP_SLEEP_WAKEUP_GPIO:
cause_str = "GPIO";
break;
case ESP_SLEEP_WAKEUP_UART:
cause_str = "UART";
break;
case ESP_SLEEP_WAKEUP_TIMER:
cause_str = "timer";
break;
default:
cause_str = "unknown";
printf("%d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Woke up from: unknown");
printf("%lx\n", causes);
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
ESP_LOGI(TAG, "Woke up from: GPIO");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
ESP_LOGI(TAG, "Woke up from: UART");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Woke up from: timer");
}
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0;
}

View File

@@ -24,16 +24,20 @@ void app_main(void)
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
#endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT) {
#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY
printf("Wake up from VBAT low power\n");
#else
printf("Wake up from VBAT brownout\n");
#endif
} else if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) {
printf("Wake up from Timer\n");
} else {
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
printf("Wake up from VBAT low power\n");
#else
printf("Wake up from VBAT brownout\n");
#endif
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from Timer\n");
}
}
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
*
@@ -115,20 +115,17 @@ static void ot_deep_sleep_init(void)
struct timeval now;
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;
esp_sleep_wakeup_cause_t wake_up_cause = esp_sleep_get_wakeup_cause();
switch (wake_up_cause) {
case ESP_SLEEP_WAKEUP_TIMER: {
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:
uint32_t wake_up_causes = esp_sleep_get_wakeup_causes();
if (wake_up_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
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:

View File

@@ -156,7 +156,7 @@ void example_prepare_sleep(void)
/* Enter the light sleep */
esp_light_sleep_start();
/* 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");
} else {
ESP_LOGE(TAG, "Wake up by other source\n");
@@ -180,7 +180,7 @@ void app_main(void)
{
#if CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP
/* 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");
}
#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
*/
@@ -167,24 +167,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout);
fsync(fileno(stdout));
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;
switch (cause) {
case ESP_SLEEP_WAKEUP_GPIO:
cause_str = "GPIO";
break;
case ESP_SLEEP_WAKEUP_UART:
cause_str = "UART";
break;
case ESP_SLEEP_WAKEUP_TIMER:
cause_str = "timer";
break;
default:
cause_str = "unknown";
printf("%d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Woke up from: unknown");
printf("%lx\n", causes);
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
ESP_LOGI(TAG, "Woke up from: GPIO");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
ESP_LOGI(TAG, "Woke up from: UART");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Woke up from: timer");
}
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0;
}

View File

@@ -59,14 +59,15 @@ static void deep_sleep_task(void *args)
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;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER: {
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_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
break;
}
#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();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -74,19 +75,15 @@ static void deep_sleep_task(void *args)
} else {
printf("Wake up from GPIO\n");
}
break;
}
#endif //CONFIG_EXAMPLE_GPIO_WAKEUP
#if CONFIG_EXAMPLE_EXT0_WAKEUP
case ESP_SLEEP_WAKEUP_EXT0: {
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT0)) {
printf("Wake up from ext0\n");
break;
}
#endif // CONFIG_EXAMPLE_EXT0_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();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -94,13 +91,8 @@ static void deep_sleep_task(void *args)
} else {
printf("Wake up from GPIO\n");
}
break;
}
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
printf("Not a deep sleep reset\n");
}
vTaskDelay(1000 / portTICK_PERIOD_MS);

View File

@@ -26,7 +26,7 @@ void app_main(void)
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;
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);
}

View File

@@ -37,22 +37,18 @@ static void light_sleep_task(void *args)
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
case ESP_SLEEP_WAKEUP_GPIO:
wakeup_reason = "pin";
break;
case ESP_SLEEP_WAKEUP_UART:
wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
break;
default:
wakeup_reason = "other";
break;
uint32_t wakup_causes = esp_sleep_get_wakeup_causes();
if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
wakeup_reason = "timer";
} else if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
wakeup_reason = "pin";
} else if (wakup_causes & (BIT(ESP_SLEEP_WAKEUP_UART) | BIT(ESP_SLEEP_WAKEUP_UART1) | BIT(ESP_SLEEP_WAKEUP_UART2))) {
wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
} else {
wakeup_reason = "other";
}
#if CONFIG_NEWLIB_NANO_FORMAT
/* 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",
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
#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*/
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
*/
@@ -43,18 +43,15 @@ void app_main(void)
rtc_gpio_pulldown_dis(WAKEUP_PIN);
rtc_gpio_pullup_dis(WAKEUP_PIN);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP read and detected a change in GPIO_0, prints */
printf("ULP woke up the main CPU! \n");
printf("ULP read changes in GPIO_0 current is: %s \n",
(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 */

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
*/
@@ -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);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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();
} else {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP woke up the main CPU!\n");
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 */

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
*/
@@ -48,18 +48,15 @@ void app_main(void)
wakeup_gpio_init();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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)) {
/* 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 */
printf("Not a ULP wakeup, initializing it! \n");
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 */
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
*/
@@ -62,9 +62,12 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
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");
/* Initialize LP_I2C from the main processor */
@@ -72,9 +75,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */
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 */

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
*/
@@ -78,9 +78,12 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (esp_sleep_get_wakeup_causes() & BIT(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);
} else {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_SPI from the main processor */
@@ -88,9 +91,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */
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 */

View File

@@ -154,9 +154,9 @@ void app_main(void)
*/
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 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("LP core woke up the main CPU\n");
// We can access the LP core global variable by adding `ulp_` prefix
uint32_t touch_data = ulp_touch_data;
@@ -169,7 +169,7 @@ void app_main(void)
}
/* Woke up by other source, like power_on */
else {
printf("Not an LP core wakeup. Cause = %d\n", cause);
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* 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
*/
@@ -50,9 +50,9 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* 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
*/
@@ -51,9 +51,9 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_UART */

View File

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

View File

@@ -51,8 +51,8 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not ULP wakeup\n");
init_ulp_program();
} 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
*/
@@ -37,16 +37,16 @@ void app_main(void)
*/
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 */
if ((cause != ESP_SLEEP_WAKEUP_ULP) && (cause != ESP_SLEEP_WAKEUP_TIMER)) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause);
if (!(causes & (BIT(ESP_SLEEP_WAKEUP_ULP) | BIT(ESP_SLEEP_WAKEUP_TIMER)))) {
printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program();
}
/* 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("Threshold: high = %"PRIu32"\n", ulp_adc_threshold);
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
*/
@@ -44,15 +44,15 @@ void app_main(void)
*/
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 */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause);
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program();
}
/* 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 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
*/
@@ -45,15 +45,15 @@ void app_main(void)
rtc_gpio_pullup_dis(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 */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* 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 read changes in GPIO_0 current is: %s \n",
(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
*/
@@ -49,15 +49,15 @@ void app_main(void)
*/
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 */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
wakeup_gpio_init();
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");
}

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
*/
@@ -52,7 +52,7 @@ void app_main(void)
int32_t pressure = 0;
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
* Initialize RTC I2C
@@ -61,8 +61,8 @@ void app_main(void)
* Load the ULP firmware
* Go to deep sleep
*/
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC V wakeup (cause = %d)\n", cause);
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC V wakeup (causes = %lx)\n", causes);
/* Initialize RTC I2C */
init_i2c();
@@ -76,7 +76,7 @@ void app_main(void)
ulp_riscv_i2c_master_write_to_device(&data_wr, 1);
/* 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_read_from_device(&data_rd, 1);
@@ -103,7 +103,7 @@ void app_main(void)
/* Calculate real temperature value */
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 */
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 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP RISC-V woke up the main CPU\n");
/* 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 */
temperature = 0;
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 */
pressure = 0;
@@ -283,19 +283,19 @@ static void bmp180_read_up_data(int32_t *up_data, oss_mode_t oss_mode)
{
case 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;
case 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;
case 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;
case 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;
}

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
*/
@@ -26,15 +26,8 @@ static void init_ulp_program(void);
void app_main(void)
{
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP RISC-V handled an interrupt on GPIO#0 */
printf("ULP RISC-V woke up the main CPU! \n");
if (ulp_wake_by_sw) {
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");
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 */

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
*/
@@ -83,19 +83,8 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP RISC-V detected a touch input */
printf("ULP-RISC-V woke up the main CPU! \n");
uint32_t touch_data = ulp_touch_data;
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
@@ -104,6 +93,14 @@ void app_main(void)
}
}
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 */

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
*/
@@ -33,19 +33,15 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* 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)) {
/* 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 */
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
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 */
printf("Entering in deep sleep\n\n");