Skip to content

Commit 7b8e161

Browse files
committed
usb_microphone: Add serial ID
Add serial ID number to the USB microphone example using function pico_get_unique_board_id_string from library pico_unique_id. Signed-off-by: Leon Anavi <[email protected]>
1 parent a837f63 commit 7b8e161

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ target_include_directories(pico_pdm_microphone INTERFACE
2626

2727
pico_generate_pio_header(pico_pdm_microphone ${CMAKE_CURRENT_LIST_DIR}/src/pdm_microphone.pio)
2828

29-
target_link_libraries(pico_pdm_microphone INTERFACE pico_stdlib hardware_dma hardware_pio)
29+
target_link_libraries(pico_pdm_microphone INTERFACE pico_stdlib hardware_dma hardware_pio pico_unique_id)
3030

3131

3232
add_library(pico_analog_microphone INTERFACE)

examples/usb_microphone/usb_descriptors.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*
2424
*/
2525

26+
#include "pico/unique_id.h"
2627
#include "tusb.h"
2728

2829
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -111,13 +112,16 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
111112
// String Descriptors
112113
//--------------------------------------------------------------------+
113114

115+
// buffer to hold flash ID
116+
char serial[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1];
117+
114118
// array of pointer to string descriptors
115119
char const* string_desc_arr [] =
116120
{
117121
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
118122
"PaniRCorp", // 1: Manufacturer
119123
"MicNode", // 2: Product
120-
"123456", // 3: Serials, should use chip ID
124+
serial, // 3: Serials, should use chip ID
121125
"UAC2", // 4: Audio Interface
122126
};
123127

@@ -137,6 +141,9 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
137141
chr_count = 1;
138142
}else
139143
{
144+
// Get unique ID in string format
145+
if (index == 3) pico_get_unique_board_id_string(serial, sizeof(serial));
146+
140147
// Convert ASCII string into UTF-16
141148

142149
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;

0 commit comments

Comments
 (0)