Skip to content

Commit 4991c68

Browse files
authored
Update and rename dcd_esp32sx.c to dcd_dwc2.patch
1 parent 7d67041 commit 4991c68

File tree

2 files changed

+83
-965
lines changed

2 files changed

+83
-965
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300
2+
+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300
3+
@@ -316,6 +316,16 @@
4+
//--------------------------------------------------------------------
5+
// Endpoint
6+
//--------------------------------------------------------------------
7+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
8+
+// Keep count of how many FIFOs are in use
9+
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
10+
+
11+
+// Will either return an unused FIFO number, or 0 if all are used.
12+
+static uint8_t get_free_fifo(void) {
13+
+ if (_allocated_fifos < 5) return _allocated_fifos++;
14+
+ return 0;
15+
+}
16+
+#endif
17+
18+
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
19+
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
20+
@@ -336,7 +346,18 @@
21+
dwc2->epout[epnum].doepctl = dxepctl;
22+
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
23+
} else {
24+
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
25+
+ uint8_t fifo_num = epnum;
26+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
27+
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
28+
+ // we can give it a fake FIFO
29+
+ if (epnum == 5) {
30+
+ fifo_num = epnum;
31+
+ } else {
32+
+ fifo_num = get_free_fifo();
33+
+ }
34+
+ //TU_ASSERT(fifo_num != 0);
35+
+#endif
36+
+ dwc2->epin[epnum].diepctl = dxepctl | (fifo_num << DIEPCTL_TXFNUM_Pos);
37+
dwc2->daintmsk |= TU_BIT(DAINTMSK_IEPM_Pos + epnum);
38+
}
39+
}
40+
@@ -850,6 +871,10 @@
41+
xfer_status[n][TUSB_DIR_IN].max_size = 0;
42+
}
43+
44+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
45+
+ _allocated_fifos = 1;
46+
+#endif
47+
+
48+
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
49+
dfifo_flush_rx(dwc2);
50+
51+
@@ -1204,6 +1229,9 @@
52+
if (int_status & GINTSTS_USBRST) {
53+
// USBRST is start of reset.
54+
dwc2->gintsts = GINTSTS_USBRST;
55+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
56+
+ _allocated_fifos = 1;
57+
+#endif
58+
bus_reset(rhport);
59+
}
60+
61+
@@ -1235,7 +1263,11 @@
62+
63+
if (int_status & GINTSTS_USBSUSP) {
64+
dwc2->gintsts = GINTSTS_USBSUSP;
65+
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
66+
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
67+
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
68+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
69+
+ _allocated_fifos = 1;
70+
+#endif
71+
}
72+
73+
if (int_status & GINTSTS_WKUINT) {
74+
@@ -1252,6 +1284,9 @@
75+
76+
if (otg_int & GOTGINT_SEDET) {
77+
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
78+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
79+
+ _allocated_fifos = 1;
80+
+#endif
81+
}
82+
83+
dwc2->gotgint = otg_int;

0 commit comments

Comments
 (0)