forked from Jason2866/esp32-arduino-lib-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinyusb_dcd_dwc2.diff
85 lines (78 loc) · 2.63 KB
/
tinyusb_dcd_dwc2.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--- a/components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c 2024-06-10 22:10:55.000000000 +0300
+++ b/components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c 2024-06-10 22:20:01.000000000 +0300
@@ -186,6 +186,18 @@
return true;
}
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+// Keep count of how many FIFOs are in use
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
+
+// Will either return an unused FIFO number, or 0 if all are used.
+static uint8_t get_free_fifo(void)
+{
+ if (_allocated_fifos < 5) return _allocated_fifos++;
+ return 0;
+}
+#endif
+
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
@@ -205,7 +217,18 @@
dwc2->epout[epnum].doepctl = dxepctl;
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
} else {
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
+ uint8_t fifo_num = epnum;
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
+ // we can give it a fake FIFO
+ if (epnum == 5) {
+ fifo_num = epnum;
+ } else {
+ fifo_num = get_free_fifo();
+ }
+ TU_ASSERT(fifo_num != 0);
+#endif
+ dwc2->epin[epnum].diepctl = dxepctl | (fifo_num << DIEPCTL_TXFNUM_Pos);
dwc2->daintmsk |= (1 << (DAINTMSK_IEPM_Pos + epnum));
}
}
@@ -728,6 +751,10 @@
// reset allocated fifo IN
_allocated_fifo_words_tx = 16;
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+#endif
+
fifo_flush_tx(dwc2, 0x10); // all tx fifo
fifo_flush_rx(dwc2);
}
@@ -1096,6 +1123,9 @@
if (int_status & GINTSTS_USBRST) {
// USBRST is start of reset.
dwc2->gintsts = GINTSTS_USBRST;
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+#endif
bus_reset(rhport);
}
@@ -1127,7 +1157,11 @@
if (int_status & GINTSTS_USBSUSP) {
dwc2->gintsts = GINTSTS_USBSUSP;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+#endif
}
if (int_status & GINTSTS_WKUINT) {
@@ -1144,6 +1178,9 @@
if (otg_int & GOTGINT_SEDET) {
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+#endif
}
dwc2->gotgint = otg_int;