summaryrefslogtreecommitdiff
path: root/src/portable/synopsys
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-04-21 22:46:15 +0700
committerGitHub <[email protected]>2025-04-21 22:46:15 +0700
commit18d7a993bec0dfd4e08871516e32731f1a252bb6 (patch)
tree1d42210bb8363ae0eb0ac303100bb91a12ab3232 /src/portable/synopsys
parent56ed51c8fb99d571ad3a203ef1e5160a4881e88c (diff)
parent5725d33121d483162730c7bb06cada3faf0da9af (diff)
Merge pull request #3075 from maximevince/dwc2-proper-attach-debouncing
dwc2/host: attach debouncing fixes
Diffstat (limited to 'src/portable/synopsys')
-rw-r--r--src/portable/synopsys/dwc2/hcd_dwc2.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c
index 53349f7f9..53bc0b059 100644
--- a/src/portable/synopsys/dwc2/hcd_dwc2.c
+++ b/src/portable/synopsys/dwc2/hcd_dwc2.c
@@ -106,6 +106,7 @@ typedef struct {
typedef struct {
hcd_xfer_t xfer[DWC2_CHANNEL_COUNT_MAX];
hcd_endpoint_t edpt[CFG_TUH_DWC2_ENDPOINT_MAX];
+ bool attach_debounce; // if true: wait for the debounce delay before issuing new attach events
} hcd_data_t;
hcd_data_t _hcd_data;
@@ -421,6 +422,11 @@ uint32_t hcd_frame_number(uint8_t rhport) {
// Get the current connect status of roothub port
bool hcd_port_connect_status(uint8_t rhport) {
+ // this is called from enum_new_device() - after the debouncing delays
+ if (_hcd_data.attach_debounce) {
+ _hcd_data.attach_debounce = false; // allow new attach events again
+ }
+
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
return dwc2->hprt & HPRT_CONN_STATUS;
}
@@ -1321,7 +1327,10 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) {
hprt |= HPRT_CONN_DETECT;
if (hprt_bm.conn_status) {
- hcd_event_device_attach(rhport, in_isr);
+ if (!_hcd_data.attach_debounce) {
+ _hcd_data.attach_debounce = true; // block new attach events until the debounce delay is over
+ hcd_event_device_attach(rhport, in_isr);
+ }
}
}
@@ -1387,8 +1396,13 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
if (gintsts & GINTSTS_DISCINT) {
// Device disconnected
dwc2->gintsts = GINTSTS_DISCINT;
- if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
- hcd_event_device_remove(rhport, in_isr);
+
+ // ignore device removal if attach debounce is active
+ // it will evaluate the port status after the debounce delay
+ if (!_hcd_data.attach_debounce) {
+ if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
+ hcd_event_device_remove(rhport, in_isr);
+ }
}
}