From 8ab21b52d66c49ccc7fed230335959cdfbfce505 Mon Sep 17 00:00:00 2001 From: "peter.marcisovsky" Date: Tue, 7 Oct 2025 11:33:16 +0200 Subject: [PATCH] feat(esp_hal_usb): Add remote wakeup support --- components/esp_hal_usb/include/hal/usb_dwc_hal.h | 5 +++-- components/esp_hal_usb/usb_dwc_hal.c | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/esp_hal_usb/include/hal/usb_dwc_hal.h b/components/esp_hal_usb/include/hal/usb_dwc_hal.h index 879ba44d89..3b567a5718 100644 --- a/components/esp_hal_usb/include/hal/usb_dwc_hal.h +++ b/components/esp_hal_usb/include/hal/usb_dwc_hal.h @@ -67,6 +67,7 @@ typedef enum { USB_DWC_HAL_PORT_EVENT_DISABLED, /**< The host port has been disabled (no more SOFs). Could be due to disable/reset request, or a port error (e.g. port babble condition. See 11.8.1 of USB2.0 spec) */ USB_DWC_HAL_PORT_EVENT_OVRCUR, /**< The host port has encountered an overcurrent condition */ USB_DWC_HAL_PORT_EVENT_OVRCUR_CLR, /**< The host port has been cleared of the overcurrent condition */ + USB_DWC_HAL_PORT_EVENT_REMOTE_WAKEUP, /**< The host port has detected remote wakeup sequence from a device */ } usb_dwc_hal_port_event_t; /** @@ -304,7 +305,7 @@ static inline void usb_dwc_hal_port_init(usb_dwc_hal_context_t *hal) { //Configure Host related interrupts usb_dwc_ll_haintmsk_dis_chan_intr(hal->dev, 0xFFFFFFFF); //Disable interrupts for all channels - usb_dwc_ll_gintmsk_en_intrs(hal->dev, USB_DWC_LL_INTR_CORE_PRTINT | USB_DWC_LL_INTR_CORE_HCHINT); + usb_dwc_ll_gintmsk_en_intrs(hal->dev, USB_DWC_LL_INTR_CORE_PRTINT | USB_DWC_LL_INTR_CORE_HCHINT | USB_DWC_LL_INTR_CORE_WKUPINT); } /** @@ -317,7 +318,7 @@ static inline void usb_dwc_hal_port_init(usb_dwc_hal_context_t *hal) static inline void usb_dwc_hal_port_deinit(usb_dwc_hal_context_t *hal) { //Disable Host port and channel interrupts - usb_dwc_ll_gintmsk_dis_intrs(hal->dev, USB_DWC_LL_INTR_CORE_PRTINT | USB_DWC_LL_INTR_CORE_HCHINT); + usb_dwc_ll_gintmsk_dis_intrs(hal->dev, USB_DWC_LL_INTR_CORE_PRTINT | USB_DWC_LL_INTR_CORE_HCHINT | USB_DWC_LL_INTR_CORE_WKUPINT); } /** diff --git a/components/esp_hal_usb/usb_dwc_hal.c b/components/esp_hal_usb/usb_dwc_hal.c index db889e6121..2fbf7b5324 100644 --- a/components/esp_hal_usb/usb_dwc_hal.c +++ b/components/esp_hal_usb/usb_dwc_hal.c @@ -44,7 +44,8 @@ //Interrupts that pertain to core events #define CORE_EVENTS_INTRS_MSK (USB_DWC_LL_INTR_CORE_DISCONNINT | \ - USB_DWC_LL_INTR_CORE_HCHINT) + USB_DWC_LL_INTR_CORE_HCHINT | \ + USB_DWC_LL_INTR_CORE_WKUPINT) //Interrupt that pertain to host port events #define PORT_EVENTS_INTRS_MSK (USB_DWC_LL_INTR_HPRT_PRTCONNDET | \ @@ -462,6 +463,8 @@ usb_dwc_hal_port_event_t usb_dwc_hal_decode_intr(usb_dwc_hal_context_t *hal) } else if (intrs_port & USB_DWC_LL_INTR_HPRT_PRTCONNDET && !hal->flags.dbnc_lock_enabled) { event = USB_DWC_HAL_PORT_EVENT_CONN; debounce_lock_enable(hal); + } else if (intrs_core & USB_DWC_LL_INTR_CORE_WKUPINT) { + event = USB_DWC_HAL_PORT_EVENT_REMOTE_WAKEUP; // Remote wakeup was generated from device } } //Port events always take precedence over channel events