Skip to content

Commit d5bb5fa

Browse files
committed
more clean up
1 parent 290b3b7 commit d5bb5fa

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

cores/nRF5/Adafruit_TinyUSB_core/Adafruit_TinyUSB_Core.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,10 @@
3838
// Serial is 64-bit DeviceID -> 16 chars len
3939
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
4040

41-
/* tinyusb function that handles power event (detected, ready, removed)
42-
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
41+
// tinyusb function that handles power event (detected, ready, removed)
42+
// We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled.
4343
extern "C" void tusb_hal_nrf_power_event(uint32_t event);
4444

45-
void usb_init(void);
46-
47-
void Adafruit_TinyUSB_Core_init(void)
48-
{
49-
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
50-
USBDevice.setID(USB_VID, USB_PID);
51-
USBDevice.begin();
52-
53-
usb_init();
54-
}
55-
56-
5745
// USB Device Driver task
5846
// This top level thread process all usb events and invoke callbacks
5947
static void usb_device_task(void* param)
@@ -68,8 +56,8 @@ static void usb_device_task(void* param)
6856
}
6957
}
7058

71-
// Init usb when starting up. Softdevice is not enabled yet
72-
void usb_init(void)
59+
// Init usb hardware when starting up. Softdevice is not enabled yet
60+
static void usb_hardware_init(void)
7361
{
7462
// Power module init
7563
const nrfx_power_config_t pwr_cfg = { 0 };
@@ -91,7 +79,10 @@ void usb_init(void)
9179

9280
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_DETECTED);
9381
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
82+
}
9483

84+
void Adafruit_TinyUSB_Core_init(void)
85+
{
9586
// Create Serial string descriptor
9687
char tmp_serial[17];
9788
sprintf(tmp_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
@@ -101,6 +92,13 @@ void usb_init(void)
10192
usb_desc_str_serial[1+i] = tmp_serial[i];
10293
}
10394

95+
96+
USBDevice.addInterface( (Adafruit_USBD_Interface&) Serial);
97+
USBDevice.setID(USB_VID, USB_PID);
98+
USBDevice.begin();
99+
100+
usb_hardware_init();
101+
104102
// Init tinyusb stack
105103
tusb_init();
106104

cores/nRF5/Adafruit_TinyUSB_core/Adafruit_TinyUSB_Core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "Adafruit_USBD_CDC.h"
3333
#endif
3434

35+
// Called by main.cpp to initialize usb device typically with CDC device for Serial
3536
void Adafruit_TinyUSB_Core_init(void);
3637

3738
#endif /* ADAFRUIT_TINYUSB_CORE_H_ */

0 commit comments

Comments
 (0)