38
38
// Serial is 64-bit DeviceID -> 16 chars len
39
39
uint16_t usb_desc_str_serial[1 +16 ] = { TUD_DESC_STR_HEADER (16 ) };
40
40
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.
43
43
extern " C" void tusb_hal_nrf_power_event (uint32_t event);
44
44
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
-
57
45
// USB Device Driver task
58
46
// This top level thread process all usb events and invoke callbacks
59
47
static void usb_device_task (void * param)
@@ -68,8 +56,8 @@ static void usb_device_task(void* param)
68
56
}
69
57
}
70
58
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 )
73
61
{
74
62
// Power module init
75
63
const nrfx_power_config_t pwr_cfg = { 0 };
@@ -91,7 +79,10 @@ void usb_init(void)
91
79
92
80
if ( usb_reg & POWER_USBREGSTATUS_VBUSDETECT_Msk ) tusb_hal_nrf_power_event (NRFX_POWER_USB_EVT_DETECTED);
93
81
if ( usb_reg & POWER_USBREGSTATUS_OUTPUTRDY_Msk ) tusb_hal_nrf_power_event (NRFX_POWER_USB_EVT_READY);
82
+ }
94
83
84
+ void Adafruit_TinyUSB_Core_init (void )
85
+ {
95
86
// Create Serial string descriptor
96
87
char tmp_serial[17 ];
97
88
sprintf (tmp_serial, " %08lX%08lX" , NRF_FICR->DEVICEID [1 ], NRF_FICR->DEVICEID [0 ]);
@@ -101,6 +92,13 @@ void usb_init(void)
101
92
usb_desc_str_serial[1 +i] = tmp_serial[i];
102
93
}
103
94
95
+
96
+ USBDevice.addInterface ( (Adafruit_USBD_Interface&) Serial);
97
+ USBDevice.setID (USB_VID, USB_PID);
98
+ USBDevice.begin ();
99
+
100
+ usb_hardware_init ();
101
+
104
102
// Init tinyusb stack
105
103
tusb_init ();
106
104
0 commit comments