Skip to content

Commit c6d0290

Browse files
committed
serial descriptor clean up
1 parent 126115a commit c6d0290

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/usb/usb.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
4141
//--------------------------------------------------------------------+
4242

43-
// Serial string using unique Device ID
44-
extern char usb_desc_str_serial[1+16];
45-
4643
/* tinyusb function that handles power event (detected, ready, removed)
4744
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
4845
extern void tusb_hal_nrf_power_event(uint32_t event);
@@ -90,12 +87,9 @@ void usb_init(bool cdc_only)
9087
tusb_hal_nrf_power_event(NRFX_POWER_USB_EVT_READY);
9188
}
9289

93-
usb_desc_set_mode(cdc_only);
94-
95-
// Create Serial string descriptor
96-
sprintf(usb_desc_str_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
90+
usb_desc_init(cdc_only);
9791

98-
// Init tusb stack
92+
// Init TinyUSB stack
9993
tusb_init();
10094
}
10195

src/usb/usb_desc.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ enum {
3333
ITF_STR_MSC
3434
};
3535

36+
// CDC + MSC or CDC only mode
3637
static bool _cdc_only = false;
3738

39+
// Serial is 64-bit DeviceID -> 16 chars len
40+
static char desc_str_serial[1+16];
41+
3842
//--------------------------------------------------------------------+
3943
// Device Descriptor
4044
//--------------------------------------------------------------------+
@@ -112,7 +116,7 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
112116
}
113117

114118
// Enumerate as CDC + MSC or CDC only
115-
void usb_desc_set_mode(bool cdc_only)
119+
void usb_desc_init(bool cdc_only)
116120
{
117121
_cdc_only = cdc_only;
118122

@@ -121,6 +125,9 @@ void usb_desc_set_mode(bool cdc_only)
121125
// Change PID to CDC only
122126
desc_device.idProduct = USB_DESC_CDC_ONLY_PID;
123127
}
128+
129+
// Create Serial string descriptor
130+
sprintf(desc_str_serial, "%08lX%08lX", NRF_FICR->DEVICEID[1], NRF_FICR->DEVICEID[0]);
124131
}
125132

126133
//--------------------------------------------------------------------+
@@ -149,16 +156,14 @@ void usb_desc_set_mode(bool cdc_only)
149156
}
150157
#endif
151158

152-
// Serial is 64-bit DeviceID -> 16 chars len
153-
char usb_desc_str_serial[1+16];
154159

155160
// array of pointer to string descriptors
156161
char const* string_desc_arr [] =
157162
{
158163
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
159164
"Adafruit Industries", // 1: Manufacturer
160165
"Bluefruit DFU", // 2: Product
161-
usb_desc_str_serial, // 3: Serials, should use chip ID
166+
desc_str_serial, // 3: Serials, should use chip ID
162167
"Bluefruit Serial", // 4: CDC Interface
163168
"Bluefruit UF2", // 5: MSC Interface
164169
};

src/usb/usb_desc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "tusb.h"
2929
#include "boards.h"
3030

31-
void usb_desc_set_mode(bool cdc_only);
31+
void usb_desc_init(bool cdc_only);
3232

3333
#ifndef USB_DESC_VID
3434
#define USB_DESC_VID 0x239A

0 commit comments

Comments
 (0)