File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -136,6 +136,40 @@ void tusb_int_handler(uint8_t rhport, bool in_isr) {
136136 #endif
137137}
138138
139+ bool tusb_rhport_teardown (uint8_t rhport ) {
140+ // backward compatible call with tusb_init(void)
141+ #if defined(TUD_OPT_RHPORT ) || defined(TUH_OPT_RHPORT )
142+ #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT )
143+ // deinit device stack, CFG_TUSB_RHPORTx_MODE must be defined
144+ TU_ASSERT ( tud_deinit (TUD_OPT_RHPORT ) );
145+ _tusb_rhport_role [TUD_OPT_RHPORT ] = TUSB_ROLE_INVALID ;
146+ #endif
147+
148+ #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT )
149+ // deinit host stack CFG_TUSB_RHPORTx_MODE must be defined
150+ TU_ASSERT ( tuh_deinit (TUH_OPT_RHPORT ) );
151+ _tusb_rhport_role [TUH_OPT_RHPORT ] = TUSB_ROLE_INVALID ;
152+ #endif
153+
154+ return true;
155+ #endif
156+
157+ // new API with explicit rhport and role
158+ TU_ASSERT (rhport < TUP_USBIP_CONTROLLER_NUM );
159+
160+ #if CFG_TUD_ENABLED
161+ TU_ASSERT ( tud_deinit (rhport ) );
162+ _tusb_rhport_role [rhport ] = TUSB_ROLE_INVALID ;
163+ #endif
164+
165+ #if CFG_TUH_ENABLED
166+ TU_ASSERT ( tuh_deinit (rhport ) );
167+ _tusb_rhport_role [rhport ] = TUSB_ROLE_INVALID ;
168+ #endif
169+
170+ return true;
171+ }
172+
139173//--------------------------------------------------------------------+
140174// Descriptor helper
141175//--------------------------------------------------------------------+
Original file line number Diff line number Diff line change @@ -154,14 +154,24 @@ bool tusb_inited(void);
154154// Called to handle usb interrupt/event. tusb_init(rhport, role) must be called before
155155void tusb_int_handler (uint8_t rhport , bool in_isr );
156156
157- // TODO
158- // bool tusb_teardown(void);
157+ // Internal helper for backward compatibility with tusb_init(void)
158+ bool tusb_rhport_teardown (uint8_t rhport );
159+
160+ #if defined(TUD_OPT_RHPORT ) || defined(TUH_OPT_RHPORT )
161+ #define _tusb_teardown_arg0 () tusb_rhport_teardown(0)
162+ #else
163+ #define _tusb_teardown_arg0 () TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined")
164+ #endif
165+
166+ #define _tusb_teardown_arg1 (_rhport ) tusb_rhport_teardown(_rhport)
167+ #define tusb_teardown (...) TU_FUNC_OPTIONAL_ARG(_tusb_teardown, __VA_ARGS__)
159168
160169#else
161170
162171#define tusb_init (...) (false)
163172#define tusb_int_handler (...) do {}while(0)
164173#define tusb_inited () (false)
174+ #define tusb_teardown (...) (false)
165175
166176#endif
167177
You can’t perform that action at this time.
0 commit comments