Skip to content

Commit f14fcaa

Browse files
committed
rename to tusb_deinit() to match other namingg
1 parent 77be5f9 commit f14fcaa

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed

src/tusb.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,38 +136,27 @@ 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);
139+
bool tusb_deinit(uint8_t rhport) {
140+
TU_VERIFY(rhport < TUP_USBIP_CONTROLLER_NUM);
141+
bool ret = false;
159142

160143
#if CFG_TUD_ENABLED
161-
TU_ASSERT( tud_deinit(rhport) );
162-
_tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
144+
if (_tusb_rhport_role[rhport] == TUSB_ROLE_DEVICE) {
145+
TU_ASSERT(tud_deinit(rhport));
146+
_tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
147+
ret = true;
148+
}
163149
#endif
164150

165151
#if CFG_TUH_ENABLED
166-
TU_ASSERT( tuh_deinit(rhport) );
167-
_tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
152+
if (_tusb_rhport_role[rhport] == TUSB_ROLE_HOST) {
153+
TU_ASSERT(tuh_deinit(rhport));
154+
_tusb_rhport_role[rhport] = TUSB_ROLE_INVALID;
155+
ret = true;
156+
}
168157
#endif
169158

170-
return true;
159+
return ret;
171160
}
172161

173162
//--------------------------------------------------------------------+

src/tusb.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool tusb_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init);
140140

141141
// Initialize roothub port with device/host role
142142
// Note: when using with RTOS, this should be called after scheduler/kernel is started.
143-
// Otherwise, it could cause kernel issue since USB IRQ handler does use RTOS queue API.
143+
// Since USB IRQ handler does use RTOS queue API.
144144
// Note2: defined as macro for backward compatible with tusb_init(void), can be changed to function in the future.
145145
#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
146146
#define _tusb_init_arg0() tusb_rhport_init(0, NULL)
@@ -158,24 +158,15 @@ bool tusb_inited(void);
158158
// Called to handle usb interrupt/event. tusb_init(rhport, role) must be called before
159159
void tusb_int_handler(uint8_t rhport, bool in_isr);
160160

161-
// Internal helper for backward compatibility with tusb_init(void)
162-
bool tusb_rhport_teardown(uint8_t rhport);
163-
164-
#if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
165-
#define _tusb_teardown_arg0() tusb_rhport_teardown(0)
166-
#else
167-
#define _tusb_teardown_arg0() TU_VERIFY_STATIC(false, "CFG_TUSB_RHPORT0_MODE/CFG_TUSB_RHPORT1_MODE must be defined")
168-
#endif
169-
170-
#define _tusb_teardown_arg1(_rhport) tusb_rhport_teardown(_rhport)
171-
#define tusb_teardown(...) TU_FUNC_OPTIONAL_ARG(_tusb_teardown, __VA_ARGS__)
161+
// Deinit usb stack on roothub port
162+
bool tusb_deinit(uint8_t rhport);
172163

173164
#else
174165

175166
#define tusb_init(...) (false)
176167
#define tusb_int_handler(...) do {}while(0)
177168
#define tusb_inited() (false)
178-
#define tusb_teardown(...) (false)
169+
#define tusb_deinit(...) (false)
179170

180171
#endif
181172

0 commit comments

Comments
 (0)