2525#include "usb_desc.h"
2626
2727enum {
28- ITF_STR_LANGUAGE = 0 ,
29- ITF_STR_MANUFACTURER ,
30- ITF_STR_PRODUCT ,
31- ITF_STR_SERIAL ,
32- ITF_STR_CDC ,
33- ITF_STR_MSC
28+ STRID_LANGUAGE = 0 ,
29+ STRID_MANUFACTURER ,
30+ STRID_PRODUCT ,
31+ STRID_SERIAL ,
32+ STRID_CDC ,
33+ STRID_MSC
3434};
3535
3636// CDC + MSC or CDC only mode
@@ -84,25 +84,25 @@ enum {
8484 ITF_NUM_TOTAL
8585};
8686
87- uint8_t const desc_configuration_cdc_msc [] =
87+ uint8_t desc_configuration_cdc_msc [] =
8888{
8989 // Interface count, string index, total length, attribute, power in mA
90- TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN , TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP , 100 ),
90+ TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL , 0 , TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN , 0 , 100 ),
9191
9292 // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
93- TUD_CDC_DESCRIPTOR (ITF_NUM_CDC , ITF_STR_CDC , 0x81 , 8 , 0x02 , 0x82 , 64 ),
93+ TUD_CDC_DESCRIPTOR (ITF_NUM_CDC , STRID_CDC , 0x81 , 8 , 0x02 , 0x82 , 64 ),
9494
9595 // Interface number, string index, EP Out & EP In address, EP size
96- TUD_MSC_DESCRIPTOR (ITF_NUM_MSC , ITF_STR_MSC , 0x03 , 0x83 , 64 ),
96+ TUD_MSC_DESCRIPTOR (ITF_NUM_MSC , STRID_MSC , 0x03 , 0x83 , 64 ),
9797};
9898
99- uint8_t const desc_configuration_cdc_only [] =
99+ uint8_t desc_configuration_cdc_only [] =
100100{
101101 // Interface count, string index, total length, attribute, power in mA
102- TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL - 1 , 0 , TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN , TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP , 100 ),
102+ TUD_CONFIG_DESCRIPTOR (1 , ITF_NUM_TOTAL - 1 , 0 , TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN , 0 , 100 ),
103103
104104 // Interface number, string index, EP notification address and size, EP data address (out, in) and size.
105- TUD_CDC_DESCRIPTOR (ITF_NUM_CDC , ITF_STR_CDC , 0x81 , 8 , 0x02 , 0x82 , 64 ),
105+ TUD_CDC_DESCRIPTOR (ITF_NUM_CDC , STRID_CDC , 0x81 , 8 , 0x02 , 0x82 , 64 ),
106106};
107107
108108
@@ -127,7 +127,19 @@ void usb_desc_init(bool cdc_only)
127127 }
128128
129129 // Create Serial string descriptor
130- sprintf (desc_str_serial , "%08lX%08lX" , NRF_FICR -> DEVICEID [1 ], NRF_FICR -> DEVICEID [0 ]);
130+ uint8_t const * device_id = (uint8_t const * ) & NRF_FICR -> DEVICEID ;
131+
132+ for ( uint8_t i = 0 ; i < 8 ; i ++ )
133+ {
134+ for ( uint8_t j = 0 ; j < 2 ; j ++ )
135+ {
136+ const char nibble_to_hex [16 ] = {'0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' };
137+
138+ uint8_t nibble = (device_id [i ] >> (j * 4 )) & 0xf ;
139+ desc_str_serial [15 - (i * 2 + j )] = nibble_to_hex [nibble ]; // memory is little endian
140+ }
141+ }
142+ desc_str_serial [16 ] = 0 ;
131143}
132144
133145//--------------------------------------------------------------------+
@@ -156,7 +168,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
156168
157169 uint8_t chr_count ;
158170
159- if ( index == 0 )
171+ if ( index == STRID_LANGUAGE )
160172 {
161173 memcpy (& _desc_str [1 ], string_desc_arr [0 ], 2 );
162174 chr_count = 1 ;
0 commit comments