-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathdcd_dwc2.patch
84 lines (76 loc) · 2.54 KB
/
dcd_dwc2.patch
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
--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300
+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300
@@ -243,6 +243,17 @@
//--------------------------------------------------------------------
// Endpoint
//--------------------------------------------------------------------
+#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, const tusb_desc_endpoint_t* p_endpoint_desc) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
@@ -266,7 +277,18 @@
depctl.set_data0_iso_even = 1;
}
if (dir == TUSB_DIR_IN) {
- depctl.tx_fifo_num = epnum;
+ //depctl.tx_fifo_num = epnum;
+ 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();
+ }
+#endif
+ depctl.tx_fifo_num = fifo_num;
}
dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum];
@@ -557,6 +579,10 @@
}
}
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+#endif
+
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
dfifo_flush_rx(dwc2);
@@ -997,6 +1023,9 @@
if (gintsts & 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
handle_bus_reset(rhport);
}
@@ -1008,7 +1037,11 @@
if (gintsts & 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 (gintsts & GINTSTS_WKUINT) {
@@ -1025,6 +1058,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;