File tree 2 files changed +46
-2
lines changed
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) {
136
136
#endif
137
137
}
138
138
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
+
139
173
//--------------------------------------------------------------------+
140
174
// Descriptor helper
141
175
//--------------------------------------------------------------------+
Original file line number Diff line number Diff line change @@ -154,14 +154,24 @@ bool tusb_inited(void);
154
154
// Called to handle usb interrupt/event. tusb_init(rhport, role) must be called before
155
155
void tusb_int_handler (uint8_t rhport , bool in_isr );
156
156
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__)
159
168
160
169
#else
161
170
162
171
#define tusb_init (...) (false)
163
172
#define tusb_int_handler (...) do {}while(0)
164
173
#define tusb_inited () (false)
174
+ #define tusb_teardown (...) (false)
165
175
166
176
#endif
167
177
You can’t perform that action at this time.
0 commit comments