diff --git a/src/usb/usb.c b/src/usb/usb.c index 1137fbf..0115072 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -40,9 +40,6 @@ // MACRO TYPEDEF CONSTANT ENUM DECLARATION //--------------------------------------------------------------------+ -// Serial string using unique Device ID -extern char usb_desc_str_serial[1+16]; - /* tinyusb function that handles power event (detected, ready, removed) * We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */ extern void tusb_hal_nrf_power_event(uint32_t event); @@ -90,12 +87,9 @@ void usb_init(bool cdc_only) tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY); } - usb_desc_set_mode(cdc_only); + usb_desc_init(cdc_only); - // Create Serial string descriptor - sprintf(usb_desc_str_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); - - // Init tusb stack + // Init TinyUSB stack tusb_init(); } diff --git a/src/usb/usb_desc.c b/src/usb/usb_desc.c index 5ca1856..69bc652 100644 --- a/src/usb/usb_desc.c +++ b/src/usb/usb_desc.c @@ -33,8 +33,12 @@ enum { ITF_STR_MSC }; +// CDC + MSC or CDC only mode static bool _cdc_only = false; +// Serial is 64-bit DeviceID -> 16 chars len +static char desc_str_serial[1+16]; + //--------------------------------------------------------------------+ // Device Descriptor //--------------------------------------------------------------------+ @@ -112,7 +116,7 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index) } // Enumerate as CDC + MSC or CDC only -void usb_desc_set_mode(bool cdc_only) +void usb_desc_init(bool cdc_only) { _cdc_only = cdc_only; @@ -121,6 +125,9 @@ void usb_desc_set_mode(bool cdc_only) // Change PID to CDC only desc_device.idProduct = USB_DESC_CDC_ONLY_PID; } + + // Create Serial string descriptor + sprintf(desc_str_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]); } //--------------------------------------------------------------------+ @@ -149,8 +156,6 @@ void usb_desc_set_mode(bool cdc_only) } #endif -// Serial is 64-bit DeviceID -> 16 chars len -char usb_desc_str_serial[1+16]; // array of pointer to string descriptors char const* string_desc_arr [] = @@ -158,7 +163,7 @@ char const* string_desc_arr [] = (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409) "Adafruit Industries", // 1: Manufacturer "Bluefruit DFU", // 2: Product - usb_desc_str_serial, // 3: Serials, should use chip ID + desc_str_serial, // 3: Serials, should use chip ID "Bluefruit Serial", // 4: CDC Interface "Bluefruit UF2", // 5: MSC Interface }; diff --git a/src/usb/usb_desc.h b/src/usb/usb_desc.h index da292ff..8f83d0e 100644 --- a/src/usb/usb_desc.h +++ b/src/usb/usb_desc.h @@ -28,7 +28,7 @@ #include "tusb.h" #include "boards.h" -void usb_desc_set_mode(bool cdc_only); +void usb_desc_init(bool cdc_only); #ifndef USB_DESC_VID #define USB_DESC_VID 0x239A