add tuh_edpt_close() API, it will abort any pending transfer

implement hcd_edpt_close() for pio-usb and max3421e, also move max3421e api into its own header.
This commit is contained in:
hathach
2025-03-25 16:15:58 +07:00
parent b99b811308
commit 65e01fff2e
8 changed files with 213 additions and 159 deletions

View File

@@ -165,6 +165,9 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
// Open an endpoint
bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const * ep_desc);
// Close an endpoint
bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr);
// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);

View File

@@ -994,6 +994,12 @@ bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const* desc_ep) {
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, desc_ep);
}
bool tuh_edpt_close(uint8_t daddr, uint8_t ep_addr) {
TU_VERIFY(0 != tu_edpt_number(ep_addr)); // cannot close EP0
tuh_edpt_abort_xfer(daddr, ep_addr); // abort any pending transfer
return hcd_edpt_close(usbh_get_rhport(daddr), daddr, ep_addr);
}
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) {
usbh_device_t* dev = get_device(dev_addr);
TU_VERIFY(dev);

View File

@@ -33,6 +33,10 @@
#include "common/tusb_common.h"
#if CFG_TUH_MAX3421
#include "portable/analog/max3421/hcd_max3421.h"
#endif
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -227,6 +231,9 @@ bool tuh_edpt_xfer(tuh_xfer_t* xfer);
// Open a non-control endpoint
bool tuh_edpt_open(uint8_t daddr, tusb_desc_endpoint_t const * desc_ep);
// Close a non-control endpoint, it will abort any pending transfer
bool tuh_edpt_close(uint8_t daddr, uint8_t ep_addr);
// Abort a queued transfer. Note: it can only abort transfer that has not been started
// Return true if a queued transfer is aborted, false if there is no transfer to abort
bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr);