serial descriptor clean up

This commit is contained in:
hathach 2019-11-11 15:35:43 +07:00
parent 126115a2cb
commit c6d02901b3
3 changed files with 12 additions and 13 deletions

View File

@ -40,9 +40,6 @@
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // 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) /* 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. */ * 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); 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); 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 // Init TinyUSB stack
sprintf(usb_desc_str_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
// Init tusb stack
tusb_init(); tusb_init();
} }

View File

@ -33,8 +33,12 @@ enum {
ITF_STR_MSC ITF_STR_MSC
}; };
// CDC + MSC or CDC only mode
static bool _cdc_only = false; static bool _cdc_only = false;
// Serial is 64-bit DeviceID -> 16 chars len
static char desc_str_serial[1+16];
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Device Descriptor // Device Descriptor
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -112,7 +116,7 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
} }
// Enumerate as CDC + MSC or CDC only // 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; _cdc_only = cdc_only;
@ -121,6 +125,9 @@ void usb_desc_set_mode(bool cdc_only)
// Change PID to CDC only // Change PID to CDC only
desc_device.idProduct = USB_DESC_CDC_ONLY_PID; 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 #endif
// Serial is 64-bit DeviceID -> 16 chars len
char usb_desc_str_serial[1+16];
// array of pointer to string descriptors // array of pointer to string descriptors
char const* string_desc_arr [] = 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) (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"Adafruit Industries", // 1: Manufacturer "Adafruit Industries", // 1: Manufacturer
"Bluefruit DFU", // 2: Product "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 Serial", // 4: CDC Interface
"Bluefruit UF2", // 5: MSC Interface "Bluefruit UF2", // 5: MSC Interface
}; };

View File

@ -28,7 +28,7 @@
#include "tusb.h" #include "tusb.h"
#include "boards.h" #include "boards.h"
void usb_desc_set_mode(bool cdc_only); void usb_desc_init(bool cdc_only);
#ifndef USB_DESC_VID #ifndef USB_DESC_VID
#define USB_DESC_VID 0x239A #define USB_DESC_VID 0x239A