mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
allow tusb_init() to call multiple times
enhance nrf5x
This commit is contained in:
parent
fc139b009f
commit
40de723d41
@ -134,6 +134,12 @@ static void hfclk_disable(void)
|
|||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
bool tusb_hal_init(void)
|
bool tusb_hal_init(void)
|
||||||
{
|
{
|
||||||
|
// TODO may move to application
|
||||||
|
|
||||||
|
// USB power may already be ready at this time -> no event generated
|
||||||
|
// We need to execute the handler based on the status
|
||||||
|
uint32_t usb_reg;
|
||||||
|
|
||||||
#ifdef SOFTDEVICE_PRESENT
|
#ifdef SOFTDEVICE_PRESENT
|
||||||
if ( is_sd_enabled() )
|
if ( is_sd_enabled() )
|
||||||
{
|
{
|
||||||
@ -141,22 +147,22 @@ bool tusb_hal_init(void)
|
|||||||
sd_power_usbpwrrdy_enable(true);
|
sd_power_usbpwrrdy_enable(true);
|
||||||
sd_power_usbremoved_enable(true);
|
sd_power_usbremoved_enable(true);
|
||||||
|
|
||||||
// USB power may already be ready at this time -> no event generated
|
|
||||||
// We need to execute the handler based on the status
|
|
||||||
uint32_t usb_reg;
|
|
||||||
sd_power_usbregstatus_get(&usb_reg);
|
sd_power_usbregstatus_get(&usb_reg);
|
||||||
|
}else
|
||||||
if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk )
|
|
||||||
{
|
|
||||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk )
|
|
||||||
{
|
|
||||||
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
usb_reg = NRF_POWER->USBREGSTATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk )
|
||||||
|
{
|
||||||
|
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk )
|
||||||
|
{
|
||||||
|
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,14 @@
|
|||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "device/usbd_pvt.h"
|
#include "device/usbd_pvt.h"
|
||||||
|
|
||||||
|
static bool _initialized = false;
|
||||||
|
|
||||||
|
|
||||||
tusb_error_t tusb_init(void)
|
tusb_error_t tusb_init(void)
|
||||||
{
|
{
|
||||||
|
// skip if already initialized
|
||||||
|
if (_initialized) return TUSB_ERROR_NONE;
|
||||||
|
|
||||||
VERIFY( tusb_hal_init(), TUSB_ERROR_FAILED ) ; // hardware init
|
VERIFY( tusb_hal_init(), TUSB_ERROR_FAILED ) ; // hardware init
|
||||||
|
|
||||||
#if MODE_HOST_SUPPORTED
|
#if MODE_HOST_SUPPORTED
|
||||||
@ -53,6 +59,8 @@ tusb_error_t tusb_init(void)
|
|||||||
TU_ASSERT_ERR ( usbd_init() ); // device stack init
|
TU_ASSERT_ERR ( usbd_init() ); // device stack init
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
_initialized = true;
|
||||||
|
|
||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user