Skip to content

Commit da95468

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 da95468

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
111111
// String Descriptors
112112
//--------------------------------------------------------------------+
113113

114+
// buffer to hold flash ID
115+
char serial[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1];
116+
114117
// array of pointer to string descriptors
115118
char const* string_desc_arr [] =
116119
{
117120
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
118121
"PaniRCorp", // 1: Manufacturer
119122
"MicNode", // 2: Product
120-
"123456", // 3: Serials, should use chip ID
123+
serial, // 3: Serials, should use chip ID
121124
"UAC2", // 4: Audio Interface
122125
};
123126

@@ -137,6 +140,9 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
137140
chr_count = 1;
138141
}else
139142
{
143+
// Get unique ID in string format
144+
if (index == 3) pico_get_unique_board_id_string(serial, sizeof(serial));
145+
140146
// Convert ASCII string into UTF-16
141147

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

0 commit comments

Comments
 (0)