summaryrefslogtreecommitdiff
path: root/src/portable
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-07-05 00:23:47 +0700
committerhathach <[email protected]>2018-07-05 00:23:47 +0700
commit40de723d417e253e3346b58cd2ce8b5dbf60d0ac (patch)
treeec70e81df9043057f9bf581e17b230c13fb37d1f /src/portable
parentfc139b009f4c49d4fdbf1b80097c94c8dabb1ee1 (diff)
allow tusb_init() to call multiple times
enhance nrf5x
Diffstat (limited to 'src/portable')
-rw-r--r--src/portable/nordic/nrf5x/hal_nrf5x.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c
index f616264f0..68e19a42c 100644
--- a/src/portable/nordic/nrf5x/hal_nrf5x.c
+++ b/src/portable/nordic/nrf5x/hal_nrf5x.c
@@ -134,6 +134,12 @@ static void hfclk_disable(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
if ( is_sd_enabled() )
{
@@ -141,22 +147,22 @@ bool tusb_hal_init(void)
sd_power_usbpwrrdy_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);
+ }else
+#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_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);
- }
+ if (usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk )
+ {
+ tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
}
-#endif
return true;
}