From 5c6f6257ceccf1245b35f2dc00163b12fbfe2894 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Thu, 9 Jan 2025 16:16:35 +0100 Subject: [PATCH] Add tuh_enumeration_cb to intercept enumeration xfers --- src/host/usbh.c | 10 ++++++++++ src/host/usbh.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/host/usbh.c b/src/host/usbh.c index a2994cde7a..226250daea 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -65,6 +65,11 @@ TU_ATTR_WEAK void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_is (void) in_isr; } +TU_ATTR_WEAK bool tuh_enumeration_cb(tuh_xfer_t* xfer) { + (void) xfer; + return false; +} + TU_ATTR_WEAK bool hcd_dcache_clean(const void* addr, uint32_t data_size) { (void) addr; (void) data_size; return false; @@ -1331,6 +1336,11 @@ static void enum_full_complete(void); // process device enumeration static void process_enumeration(tuh_xfer_t* xfer) { + // Call callback and skip if returns true + if (tuh_enumeration_cb(xfer)) { + return; + } + // Retry a few times with transfers in enumeration since device can be unstable when starting up enum { ATTEMPT_COUNT_MAX = 3, diff --git a/src/host/usbh.h b/src/host/usbh.h index 72c2375739..1e72787ed8 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -108,6 +108,9 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr); // Invoked when there is a new usb event, which need to be processed by tuh_task()/tuh_task_ext() void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr); +// Invoked when an usb enumeration transfer is completed +bool tuh_enumeration_cb(tuh_xfer_t* xfer); + //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+