From ffb1647a93ace2b765a47798eee8500daf577c3d Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 3 Nov 2023 22:24:47 +0700 Subject: [PATCH] retired all transferring endpoint if device is disconnected --- src/pio_usb_host.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pio_usb_host.c b/src/pio_usb_host.c index ae65a4a..864d048 100644 --- a/src/pio_usb_host.c +++ b/src/pio_usb_host.c @@ -195,6 +195,16 @@ static bool __no_inline_not_in_flash_func(connection_check)(root_port_t *port) { port->connected = false; port->suspended = true; port->ints |= PIO_USB_INTS_DISCONNECT_BITS; + + // failed/retired all queuing transfer in this root + uint8_t root_idx = port - PIO_USB_ROOT_PORT(0); + for (int ep_idx = 0; ep_idx < PIO_USB_EP_POOL_CNT; ep_idx++) { + endpoint_t *ep = PIO_USB_ENDPOINT(ep_idx); + if ((ep->root_idx == root_idx) && ep->size && ep->has_transfer) { + pio_usb_ll_transfer_complete(ep, PIO_USB_INTS_ENDPOINT_ERROR_BITS); + } + } + return false; } }