implement #19 serial descriptor based on deviceid

This commit is contained in:
hathach 2018-08-21 14:53:06 +07:00
parent 6feea4e069
commit daa1b83144
3 changed files with 25 additions and 2 deletions

@ -1 +1 @@
Subproject commit e07b1acbed02fff395c91b421b7fdf6c7cda61a4
Subproject commit 7b35cd0203bc409d7c1aefc075672103cb4a913e

View File

@ -54,6 +54,13 @@
extern tusb_desc_device_t usb_desc_dev;
extern usb_desc_cfg_t usb_desc_cfg;
/* Serial should be different for Application mode, DFU with UF2, and DFU with CDC only therefore
* - DeviceID : (Arduino + CircuitPython)
* - DeviceID + 1 : DFU with UF2
* - DeviceID + 2 : DFU with CDC only
*/
extern uint16_t 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);
@ -100,6 +107,8 @@ void usb_init(bool cdc_only)
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
}
uint32_t devid_low = NRF_FICR->DEVICEID[0] + 1; // default uf2
if ( cdc_only )
{
// Change PID to CDC only
@ -108,6 +117,17 @@ void usb_init(bool cdc_only)
// Remove MSC interface = reduce total interface + adjust config desc length
usb_desc_cfg.config.bNumInterfaces--;
usb_desc_cfg.config.wTotalLength -= sizeof(usb_desc_cfg.msc);
devid_low++;
}
// Create Serial string descriptor
char tmp_serial[17];
sprintf(tmp_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], devid_low);
for(uint8_t i=0; i<16; i++)
{
usb_desc_str_serial[1+i] = tmp_serial[i];
}
// Init tusb stack

View File

@ -77,6 +77,9 @@ enum {
// STRING DESCRIPTORS
//--------------------------------------------------------------------+
// Serial is 64-bit DeviceID -> 16 chars len
uint16_t usb_desc_str_serial[1+16] = { TUD_DESC_STR_HEADER(16) };
// array of pointer to string descriptors
uint16_t const * const string_desc_arr [] =
{
@ -90,7 +93,7 @@ uint16_t const * const string_desc_arr [] =
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','n','R','F','5','2','8','4','0', ' ', 'D','F','U'),
// 3: Serials TODO use chip ID
TUD_DESC_STRCONV('1', '2', '3', '4'),
usb_desc_str_serial,
// 4: CDC Interface
TUD_DESC_STRCONV('B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l'),