usbh: add roothub debounncing flag to ignore attach/remove event on the roothub that is currently doing debouncing delay

This commit is contained in:
hathach
2025-04-28 12:59:59 +07:00
parent b5d4d0f623
commit 2c1414b4c1
2 changed files with 21 additions and 20 deletions

View File

@@ -107,7 +107,6 @@ 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;
@@ -423,11 +422,6 @@ 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;
}
@@ -1328,10 +1322,7 @@ static void handle_hprt_irq(uint8_t rhport, bool in_isr) {
hprt |= HPRT_CONN_DETECT;
if (hprt_bm.conn_status) {
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);
}
hcd_event_device_attach(rhport, in_isr);
}
}
@@ -1398,12 +1389,8 @@ void hcd_int_handler(uint8_t rhport, bool in_isr) {
// Device disconnected
dwc2->gintsts = GINTSTS_DISCINT;
// 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);
}
if (!(dwc2->hprt & HPRT_CONN_STATUS)) {
hcd_event_device_remove(rhport, in_isr);
}
}