summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2024-03-17 22:48:35 +0800
committersakumisu <[email protected]>2024-03-17 22:48:35 +0800
commitb628c737ecd7dd20594def945c0ef1a6f04e4800 (patch)
tree5321d44272a8819a7ea1d8bea78fd4a18a7d5e9f
parente40c72f3a81d8357a0a082de081d2908c0339fba (diff)
add esp dwc2 glue
-rw-r--r--port/dwc2/usb_glue_esp.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/port/dwc2/usb_glue_esp.c b/port/dwc2/usb_glue_esp.c
new file mode 100644
index 00000000..f7e642e2
--- /dev/null
+++ b/port/dwc2/usb_glue_esp.c
@@ -0,0 +1,77 @@
+/*
+ * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+#include "sdkconfig.h"
+#include "esp_idf_version.h"
+#include "esp_intr_alloc.h"
+#include "esp_private/usb_phy.h"
+#include "soc/periph_defs.h"
+#include "usb_config.h"
+#include "usb_log.h"
+
+#ifdef CONFIG_IDF_TARGET_ESP32S2
+#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S2_DEFAULT_CPU_FREQ_MHZ
+#elif CONFIG_IDF_TARGET_ESP32S3
+#define DEFAULT_CPU_FREQ_MHZ CONFIG_ESP32S3_DEFAULT_CPU_FREQ_MHZ
+#else
+#define DEFAULT_CPU_FREQ_MHZ 160
+#endif
+
+uint32_t SystemCoreClock = (DEFAULT_CPU_FREQ_MHZ*1000*1000);
+static usb_phy_handle_t s_phy_handle = NULL;
+static intr_handle_t s_interrupt_handle = NULL;
+
+static void usb_dc_interrupt_cb(void *arg_pv)
+{
+ extern void USBD_IRQHandler(0);
+ USBD_IRQHandler(0);
+}
+
+void usb_dc_low_level_init(void)
+{
+ usb_phy_config_t phy_config = {
+ .controller = USB_PHY_CTRL_OTG,
+ .otg_mode = USB_OTG_MODE_DEVICE,
+ .target = USB_PHY_TARGET_INT,
+ };
+
+ esp_err_t ret = usb_new_phy(&phy_config, &s_phy_handle);
+ if (ret != ESP_OK) {
+ USB_LOG_ERR("USB Phy Init Failed!\r\n");
+ return;
+ }
+
+ // TODO: Check when to enable interrupt
+ ret = esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LEVEL2, usb_dc_interrupt_cb, 0, &s_interrupt_handle);
+ if (ret != ESP_OK) {
+ USB_LOG_ERR("USB Interrupt Init Failed!\r\n");
+ return;
+ }
+ USB_LOG_INFO("cherryusb, version: 0x%06x\r\n", CHERRYUSB_VERSION);
+ USB_LOG_INFO("esp_cherryusb, version: %d.%d.%d\r\n", ESP_CHERRYUSB_VER_MAJOR, ESP_CHERRYUSB_VER_MINOR, ESP_CHERRYUSB_VER_PATCH);
+}
+
+void usb_dc_low_level_deinit(void)
+{
+ if (s_interrupt_handle) {
+ esp_intr_free(s_interrupt_handle);
+ s_interrupt_handle = NULL;
+ }
+ if (s_phy_handle) {
+ usb_del_phy(s_phy_handle);
+ s_phy_handle = NULL;
+ }
+}
+
+uint32_t usbd_get_dwc2_gccfg_conf(void)
+{
+ return 0;
+}
+
+// USB Host only support HS mode?
+// void usb_hc_low_level_init(void)
+
+// There is no usb_hc_deinit, deinit USB Host is not supported
+// void usb_hc_low_level_deinit(void) \ No newline at end of file