28#ifndef TUSB_DWC2_ESP32_H_
29#define TUSB_DWC2_ESP32_H_
35#include "freertos/FreeRTOS.h"
36#include "freertos/task.h"
38#include "esp_intr_alloc.h"
39#include "soc/periph_defs.h"
40#include "soc/usb_wrap_struct.h"
42#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
43#define DWC2_FS_REG_BASE 0x60080000UL
47 { .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
50#elif TU_CHECK_MCU(OPT_MCU_ESP32P4)
51#define DWC2_FS_REG_BASE 0x50040000UL
52#define DWC2_HS_REG_BASE 0x50000000UL
58{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 },
59{ .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .ep_fifo_size = 4096 }
69 const uint8_t rhport =
tu_u16_low((uint16_t)(uintptr_t)arg);
70 const tusb_role_t role = (tusb_role_t)
tu_u16_high((uint16_t)(uintptr_t)arg);
72 if (role == TUSB_ROLE_DEVICE) {
77 if (role == TUSB_ROLE_HOST) {
83TU_ATTR_ALWAYS_INLINE
static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role,
bool enabled) {
88 esp_intr_free(
usb_ih[rhport]);
92#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true)
93#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false)
96 vTaskDelay(pdMS_TO_TICKS(1));
void dcd_int_handler(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled)
static const dwc2_controller_t _dwc2_controller[]
static TU_ATTR_ALWAYS_INLINE void dwc2_remote_wakeup_delay(void)
static TU_ATTR_ALWAYS_INLINE void dwc2_phy_init(dwc2_regs_t *dwc2, uint8_t hs_phy_type)
static intr_handle_t usb_ih[TU_ARRAY_SIZE(_dwc2_controller)]
static void dwc2_int_handler_wrap(void *arg)
static TU_ATTR_ALWAYS_INLINE void dwc2_phy_update(dwc2_regs_t *dwc2, uint8_t hs_phy_type)
void hcd_int_handler(uint8_t rhport, bool in_isr)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_u16_low(uint16_t ui16)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_u16_high(uint16_t ui16)
static TU_ATTR_ALWAYS_INLINE uint16_t tu_u16(uint8_t high, uint8_t low)