separte tusb_init/inited() to tud/tuh init/inited

add rhport to tud_init()
This commit is contained in:
hathach 2021-05-11 17:32:52 +07:00
parent 2666e1efec
commit 3a7f8b3ac3
5 changed files with 31 additions and 28 deletions

View File

@ -242,7 +242,7 @@ static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
// DCD Event // DCD Event
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool _initialized = false; static bool _usbd_initialized = false;
// Event queue // Event queue
// OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr) // OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr)
@ -373,13 +373,13 @@ bool tud_connect(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
bool tud_inited(void) bool tud_inited(void)
{ {
return _initialized; return _usbd_initialized;
} }
bool tud_init (void) bool tud_init (uint8_t rhport)
{ {
// skip if already initialized // skip if already initialized
if (_initialized) return _initialized; if (_usbd_initialized) return _usbd_initialized;
TU_LOG2("USBD init\r\n"); TU_LOG2("USBD init\r\n");
@ -410,10 +410,10 @@ bool tud_init (void)
} }
// Init device controller driver // Init device controller driver
dcd_init(TUD_OPT_RHPORT); dcd_init(rhport);
dcd_int_enable(TUD_OPT_RHPORT); dcd_int_enable(rhport);
_initialized = true; _usbd_initialized = true;
return true; return true;
} }

View File

@ -41,7 +41,7 @@ extern "C" {
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Init device stack // Init device stack
bool tud_init (void); bool tud_init (uint8_t rhport);
// Check if device stack is already initialized // Check if device stack is already initialized
bool tud_inited(void); bool tud_inited(void);

View File

@ -121,7 +121,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
static bool _initialized = false; static bool _usbh_initialized = false;
// including zero-address // including zero-address
CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
@ -175,13 +175,13 @@ void osal_task_delay(uint32_t msec)
bool tuh_inited(void) bool tuh_inited(void)
{ {
return _initialized; return _usbh_initialized;
} }
bool tuh_init(void) bool tuh_init(uint8_t rhport)
{ {
// skip if already initialized // skip if already initialized
if (_initialized) return _initialized; if (_usbh_initialized) return _usbh_initialized;
TU_LOG2("USBH init\r\n"); TU_LOG2("USBH init\r\n");
@ -212,10 +212,10 @@ bool tuh_init(void)
usbh_class_drivers[drv_id].init(); usbh_class_drivers[drv_id].init();
} }
TU_ASSERT(hcd_init(TUH_OPT_RHPORT)); TU_ASSERT(hcd_init(rhport));
hcd_int_enable(TUH_OPT_RHPORT); hcd_int_enable(rhport);
_initialized = true; _usbh_initialized = true;
return true; return true;
} }

View File

@ -76,7 +76,7 @@ typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Init host stack // Init host stack
bool tuh_init(void); bool tuh_init(uint8_t rhport);
// Check if host stack is already initialized // Check if host stack is already initialized
bool tuh_inited(void); bool tuh_inited(void);

View File

@ -30,8 +30,6 @@
#include "tusb.h" #include "tusb.h"
static bool _initialized = false;
// TODO clean up // TODO clean up
#if TUSB_OPT_DEVICE_ENABLED #if TUSB_OPT_DEVICE_ENABLED
#include "device/usbd_pvt.h" #include "device/usbd_pvt.h"
@ -39,25 +37,30 @@ static bool _initialized = false;
bool tusb_init(void) bool tusb_init(void)
{ {
// skip if already initialized #if TUSB_OPT_DEVICE_ENABLED
if (_initialized) return true; TU_ASSERT ( tud_init(TUD_OPT_RHPORT) ); // init device stack
#endif
#if TUSB_OPT_HOST_ENABLED #if TUSB_OPT_HOST_ENABLED
TU_ASSERT( tuh_init() ); // init host stack TU_ASSERT( tuh_init(TUH_OPT_RHPORT) ); // init host stack
#endif #endif
#if TUSB_OPT_DEVICE_ENABLED
TU_ASSERT ( tud_init() ); // init device stack
#endif
_initialized = true;
return true; return true;
} }
bool tusb_inited(void) 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;
} }
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/