summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-07-11 15:58:15 +0700
committerGitHub <[email protected]>2025-07-11 15:58:15 +0700
commit5ce3e3bc0121441004227d4be3c1064231be1cbe (patch)
tree28d4cb8e892d622b802013f4f2f2a08a09edc431
parent40dc1dd436ce96d9d3257d6de60f3c28fd38e294 (diff)
parentf14fcaa84d44855ac3718eb2a786114385b53657 (diff)
Merge pull request #3168 from hathach/feature/add_tusb_teardown
Feature/add tusb teardown
-rw-r--r--src/tusb.c23
-rw-r--r--src/tusb.h7
2 files changed, 27 insertions, 3 deletions
diff --git a/src/tusb.c b/src/tusb.c
index 13b89997c..5a3ea356b 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -136,6 +136,29 @@ void tusb_int_handler(uint8_t rhport, bool in_isr) {
#endif
}
+bool tusb_deinit(uint8_t rhport) {
+ TU_VERIFY(rhport < TUP_USBIP_CONTROLLER_NUM);
+ bool ret = false;
+
+ #if CFG_TUD_ENABLED
+ if (_tusb_rhport_role[rhport] == TUSB_ROLE_DEVICE) {
+ TU_ASSERT(tud_deinit(rhport));
+ _tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
+ ret = true;
+ }
+ #endif
+
+ #if CFG_TUH_ENABLED
+ if (_tusb_rhport_role[rhport] == TUSB_ROLE_HOST) {
+ TU_ASSERT(tuh_deinit(rhport));
+ _tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
+ ret = true;
+ }
+ #endif
+
+ return ret;
+}
+
//--------------------------------------------------------------------+
// Descriptor helper
//--------------------------------------------------------------------+
diff --git a/src/tusb.h b/src/tusb.h
index dfba21ddf..e794a8b0b 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -140,7 +140,7 @@ bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init);
// Initialize roothub port with device/host role
// Note: when using with RTOS, this should be called after scheduler/kernel is started.
-// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
+// Since USB IRQ handler does use RTOS queue API.
// Note2: defined as macro for backward compatible with tusb_init(void), can be changed to function in the future.
#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
#define _tusb_init_arg0() tusb_rhport_init(0, NULL)
@@ -158,14 +158,15 @@ bool tusb_inited(void);
// Called to handle usb interrupt/event. tusb_init(rhport, role) must be called before
void tusb_int_handler(uint8_t rhport, bool in_isr);
-// TODO
-// bool tusb_teardown(void);
+// Deinit usb stack on roothub port
+bool tusb_deinit(uint8_t rhport);
#else
#define tusb_init(...) (false)
#define tusb_int_handler(...) do {}while(0)
#define tusb_inited() (false)
+#define tusb_deinit(...) (false)
#endif