feat(sleep/usb): support usb as wakeup source from light sleep

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
JiangGuangMing
2026-06-11 09:05:40 +08:00
co-authored by Cursor
parent 0b816722db
commit 3b32b1fc96
4 changed files with 56 additions and 5 deletions
+21 -5
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -119,9 +119,10 @@ typedef enum {
ESP_SLEEP_WAKEUP_WIFI, //!< Wakeup caused by WIFI (light sleep only) ESP_SLEEP_WAKEUP_WIFI, //!< Wakeup caused by WIFI (light sleep only)
ESP_SLEEP_WAKEUP_COCPU, //!< Wakeup caused by COCPU int ESP_SLEEP_WAKEUP_COCPU, //!< Wakeup caused by COCPU int
ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG, //!< Wakeup caused by COCPU crash ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG, //!< Wakeup caused by COCPU crash
ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only) ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only)
ESP_SLEEP_WAKEUP_VAD, //!< Wakeup caused by VAD ESP_SLEEP_WAKEUP_VAD, //!< Wakeup caused by VAD
ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, //!< Wakeup caused by VDD_BAT under voltage. ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, //!< Wakeup caused by VDD_BAT under voltage.
ESP_SLEEP_WAKEUP_USB, //!< Wakeup caused by USB HS (light sleep only)
} esp_sleep_source_t; } esp_sleep_source_t;
/** /**
@@ -134,7 +135,6 @@ typedef enum {
/* Leave this type define for compatibility */ /* Leave this type define for compatibility */
typedef esp_sleep_source_t esp_sleep_wakeup_cause_t; typedef esp_sleep_source_t esp_sleep_wakeup_cause_t;
enum { enum {
ESP_ERR_SLEEP_REJECT = ESP_ERR_INVALID_STATE, ESP_ERR_SLEEP_REJECT = ESP_ERR_INVALID_STATE,
ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG, ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG,
@@ -536,6 +536,22 @@ esp_err_t esp_sleep_enable_bt_wakeup(void);
*/ */
esp_err_t esp_sleep_disable_bt_wakeup(void); esp_err_t esp_sleep_disable_bt_wakeup(void);
/**
* @brief Enable wakeup by High-Speed USB-OTG
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if wakeup from USB is not supported
*/
esp_err_t esp_sleep_enable_usb_wakeup(void);
/**
* @brief Disable wakeup by High-Speed USB-OTG
* @return
* - ESP_OK on success
* - ESP_ERR_NOT_SUPPORTED if wakeup from USB is not supported
*/
esp_err_t esp_sleep_disable_usb_wakeup(void);
/** /**
* @brief Enable wakeup by WiFi MAC * @brief Enable wakeup by WiFi MAC
* @return * @return
+30
View File
@@ -1730,6 +1730,11 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source)
else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, RTC_VBAT_UNDER_VOLT_TRIG_EN)) { else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, RTC_VBAT_UNDER_VOLT_TRIG_EN)) {
s_config.wakeup_triggers &= ~RTC_VBAT_UNDER_VOLT_TRIG_EN; s_config.wakeup_triggers &= ~RTC_VBAT_UNDER_VOLT_TRIG_EN;
} }
#endif
#if SOC_PM_SUPPORT_USB_WAKEUP
else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_USB, RTC_USB_TRIG_EN)) {
s_config.wakeup_triggers &= ~RTC_USB_TRIG_EN;
}
#endif #endif
else { else {
ESP_LOGE(TAG, "Incorrect wakeup source (%d) to disable.", (int) source); ESP_LOGE(TAG, "Incorrect wakeup source (%d) to disable.", (int) source);
@@ -2299,6 +2304,26 @@ esp_err_t esp_sleep_disable_bt_wakeup(void)
#endif #endif
} }
esp_err_t esp_sleep_enable_usb_wakeup(void)
{
#if SOC_PM_SUPPORT_USB_WAKEUP
s_config.wakeup_triggers |= RTC_USB_TRIG_EN;
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif
}
esp_err_t esp_sleep_disable_usb_wakeup(void)
{
#if SOC_PM_SUPPORT_USB_WAKEUP
s_config.wakeup_triggers &= (~RTC_USB_TRIG_EN);
return ESP_OK;
#else
return ESP_ERR_NOT_SUPPORTED;
#endif
}
esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void) esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
{ {
if (esp_rom_get_reset_reason(0) != RESET_REASON_CORE_DEEP_SLEEP && !s_light_sleep_wakeup) { if (esp_rom_get_reset_reason(0) != RESET_REASON_CORE_DEEP_SLEEP && !s_light_sleep_wakeup) {
@@ -2461,6 +2486,11 @@ uint32_t esp_sleep_get_wakeup_causes(void)
if (wakeup_cause_raw & RTC_VBAT_UNDER_VOLT_TRIG_EN) { if (wakeup_cause_raw & RTC_VBAT_UNDER_VOLT_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT); wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT);
} }
#endif
#if SOC_PM_SUPPORT_USB_WAKEUP
if (wakeup_cause_raw & RTC_USB_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_USB);
}
#endif #endif
if (wakeup_cause == 0) { if (wakeup_cause == 0) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED); wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
@@ -1395,6 +1395,10 @@ config SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO
bool bool
default y default y
config SOC_PM_SUPPORT_USB_WAKEUP
int
default 1
config SOC_PARLIO_GROUPS config SOC_PARLIO_GROUPS
int int
default 1 default 1
@@ -494,6 +494,7 @@
// USB PHY Caps // USB PHY Caps
#define SOC_USB_UTMI_PHY_NUM (1U) #define SOC_USB_UTMI_PHY_NUM (1U)
#define SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO 1 #define SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO 1
#define SOC_PM_SUPPORT_USB_WAKEUP (1U)
/*-------------------------- PARLIO CAPS --------------------------------------*/ /*-------------------------- PARLIO CAPS --------------------------------------*/
#define SOC_PARLIO_GROUPS 1U /*!< Number of parallel IO peripherals */ #define SOC_PARLIO_GROUPS 1U /*!< Number of parallel IO peripherals */