Skip to content

Commit cdeedc5

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'feat/new_api_to_get_all_wakeup_causes_v5.5' into 'release/v5.5'
feat(esp_hw_support): add new API to get all wakeup sources (v5.5) See merge request espressif/esp-idf!41497
2 parents c5a8693 + be1687d commit cdeedc5

File tree

2 files changed

+103
-1
lines changed

2 files changed

+103
-1
lines changed

components/esp_hw_support/include/esp_sleep.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ typedef enum {
113113
ESP_SLEEP_WAKEUP_TOUCHPAD, //!< Wakeup caused by touchpad
114114
ESP_SLEEP_WAKEUP_ULP, //!< Wakeup caused by ULP program
115115
ESP_SLEEP_WAKEUP_GPIO, //!< Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
116-
ESP_SLEEP_WAKEUP_UART, //!< Wakeup caused by UART (light sleep only)
116+
ESP_SLEEP_WAKEUP_UART, //!< Wakeup caused by UART0 (light sleep only)
117+
ESP_SLEEP_WAKEUP_UART1, //!< Wakeup caused by UART1 (light sleep only)
118+
ESP_SLEEP_WAKEUP_UART2, //!< Wakeup caused by UART2 (light sleep only)
117119
ESP_SLEEP_WAKEUP_WIFI, //!< Wakeup caused by WIFI (light sleep only)
118120
ESP_SLEEP_WAKEUP_COCPU, //!< Wakeup caused by COCPU int
119121
ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG, //!< Wakeup caused by COCPU crash
@@ -691,10 +693,19 @@ void esp_deep_sleep_deregister_hook(esp_deep_sleep_cb_t old_dslp_cb);
691693
/**
692694
* @brief Get the wakeup source which caused wakeup from sleep
693695
*
696+
* @note !!! This API will only return one wakeup source. If multiple wakeup sources
697+
* wake up at the same time, the wakeup source information may be lost.
698+
*
694699
* @return cause of wake up from last sleep (deep sleep or light sleep)
695700
*/
696701
esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void);
697702

703+
/**
704+
* @brief Get all wakeup sources bitmap which caused wakeup from sleep.
705+
*
706+
* @return The bitmap of the wakeup sources of the last wakeup from sleep. (deep sleep or light sleep)
707+
*/
708+
uint32_t esp_sleep_get_wakeup_causes(void);
698709

699710
/**
700711
* @brief Default stub to run on wake from deep sleep.

components/esp_hw_support/sleep_modes.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,97 @@ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
23422342
}
23432343
}
23442344

2345+
uint32_t esp_sleep_get_wakeup_causes(void)
2346+
{
2347+
uint32_t wakeup_cause = 0;
2348+
2349+
if (esp_rom_get_reset_reason(0) != RESET_REASON_CORE_DEEP_SLEEP && !s_light_sleep_wakeup) {
2350+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
2351+
return wakeup_cause;
2352+
}
2353+
2354+
#if SOC_PMU_SUPPORTED
2355+
uint32_t wakeup_cause_raw = pmu_ll_hp_get_wakeup_cause(&PMU);
2356+
#else
2357+
uint32_t wakeup_cause_raw = rtc_cntl_ll_get_wakeup_cause();
2358+
#endif
2359+
2360+
if (wakeup_cause_raw & RTC_TIMER_TRIG_EN) {
2361+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_TIMER);
2362+
}
2363+
if (wakeup_cause_raw & RTC_GPIO_TRIG_EN) {
2364+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_GPIO);
2365+
}
2366+
if (wakeup_cause_raw & RTC_UART0_TRIG_EN) {
2367+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART);
2368+
}
2369+
if (wakeup_cause_raw & RTC_UART1_TRIG_EN) {
2370+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART1);
2371+
}
2372+
#if SOC_PMU_SUPPORTED && (SOC_UART_HP_NUM > 2)
2373+
if (wakeup_cause_raw & RTC_UART2_TRIG_EN) {
2374+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART2);
2375+
}
2376+
#endif
2377+
#if SOC_PM_SUPPORT_EXT0_WAKEUP
2378+
if (wakeup_cause_raw & RTC_EXT0_TRIG_EN) {
2379+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_EXT0);
2380+
}
2381+
#endif
2382+
#if SOC_PM_SUPPORT_EXT1_WAKEUP
2383+
if (wakeup_cause_raw & RTC_EXT1_TRIG_EN) {
2384+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_EXT1);
2385+
}
2386+
#endif
2387+
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
2388+
if (wakeup_cause_raw & RTC_TOUCH_TRIG_EN) {
2389+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_TOUCHPAD);
2390+
}
2391+
#endif
2392+
#if SOC_ULP_FSM_SUPPORTED
2393+
if (wakeup_cause_raw & RTC_ULP_TRIG_EN) {
2394+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
2395+
}
2396+
#endif
2397+
#if SOC_PM_SUPPORT_WIFI_WAKEUP
2398+
if (wakeup_cause_raw & RTC_WIFI_TRIG_EN) {
2399+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_WIFI);
2400+
}
2401+
#endif
2402+
#if SOC_PM_SUPPORT_BT_WAKEUP
2403+
if (wakeup_cause_raw & RTC_BT_TRIG_EN) {
2404+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_BT);
2405+
}
2406+
#endif
2407+
#if SOC_RISCV_COPROC_SUPPORTED
2408+
if (wakeup_cause_raw & RTC_COCPU_TRIG_EN) {
2409+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
2410+
}
2411+
if (wakeup_cause_raw & RTC_COCPU_TRAP_TRIG_EN) {
2412+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG);
2413+
}
2414+
#endif
2415+
#if SOC_LP_CORE_SUPPORTED
2416+
if (wakeup_cause_raw & RTC_LP_CORE_TRIG_EN) {
2417+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
2418+
}
2419+
#endif
2420+
#if SOC_LP_VAD_SUPPORTED
2421+
if (wakeup_cause_raw & RTC_LP_VAD_TRIG_EN) {
2422+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VAD);
2423+
}
2424+
#endif
2425+
#if SOC_VBAT_SUPPORTED
2426+
if (wakeup_cause_raw & RTC_VBAT_UNDER_VOLT_TRIG_EN) {
2427+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT);
2428+
}
2429+
#endif
2430+
if (wakeup_cause == 0) {
2431+
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
2432+
}
2433+
return wakeup_cause;
2434+
}
2435+
23452436
esp_err_t esp_sleep_pd_config(esp_sleep_pd_domain_t domain, esp_sleep_pd_option_t option)
23462437
{
23472438
if (domain >= ESP_PD_DOMAIN_MAX || option > ESP_PD_OPTION_AUTO) {

0 commit comments

Comments
 (0)