From 3a7f8b3ac3988eeb653ada6e3efdd7acb68fbe0f Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 May 2021 17:32:52 +0700 Subject: separte tusb_init/inited() to tud/tuh init/inited add rhport to tud_init() --- src/tusb.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/tusb.c') diff --git a/src/tusb.c b/src/tusb.c index 31452e897..0350fa1de 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -30,8 +30,6 @@ #include "tusb.h" -static bool _initialized = false; - // TODO clean up #if TUSB_OPT_DEVICE_ENABLED #include "device/usbd_pvt.h" @@ -39,25 +37,30 @@ static bool _initialized = false; bool tusb_init(void) { - // skip if already initialized - if (_initialized) return true; - -#if TUSB_OPT_HOST_ENABLED - TU_ASSERT( tuh_init() ); // init host stack -#endif - #if TUSB_OPT_DEVICE_ENABLED - TU_ASSERT ( tud_init() ); // init device stack + TU_ASSERT ( tud_init(TUD_OPT_RHPORT) ); // init device stack #endif - _initialized = true; +#if TUSB_OPT_HOST_ENABLED + TU_ASSERT( tuh_init(TUH_OPT_RHPORT) ); // init host stack +#endif return true; } bool tusb_inited(void) { - return _initialized; + bool ret = false; + +#if TUSB_OPT_DEVICE_ENABLED + ret = ret || tud_inited(); +#endif + +#if TUSB_OPT_HOST_ENABLED + ret = ret || tuh_inited(); +#endif + + return ret; } /*------------------------------------------------------------------*/ -- cgit v1.3.1