add tuh_inited() and tud_inited()

This commit is contained in:
hathach
2021-05-02 01:46:22 +07:00
parent 68fa17e17c
commit 2666e1efec
4 changed files with 36 additions and 3 deletions

View File

@@ -121,6 +121,8 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
static bool _initialized = false;
// including zero-address
CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
@@ -170,8 +172,19 @@ void osal_task_delay(uint32_t msec)
//--------------------------------------------------------------------+
// CLASS-USBD API (don't require to verify parameters)
//--------------------------------------------------------------------+
bool tuh_inited(void)
{
return _initialized;
}
bool tuh_init(void)
{
// skip if already initialized
if (_initialized) return _initialized;
TU_LOG2("USBH init\r\n");
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
//------------- Enumeration & Reporter Task init -------------//
@@ -202,6 +215,7 @@ bool tuh_init(void)
TU_ASSERT(hcd_init(TUH_OPT_RHPORT));
hcd_int_enable(TUH_OPT_RHPORT);
_initialized = true;
return true;
}

View File

@@ -78,6 +78,9 @@ typedef bool (*tuh_control_complete_cb_t)(uint8_t dev_addr, tusb_control_request
// Init host stack
bool tuh_init(void);
// Check if host stack is already initialized
bool tuh_inited(void);
// Task function should be called in main/rtos loop
void tuh_task(void);