Skip to content

Commit

Permalink
Address review comments, fix api typing
Browse files Browse the repository at this point in the history
Use cleaner binary-to-hex conversion.  Update the length parameter to
use uint per the SDK standard .
  • Loading branch information
earlephilhower committed Mar 27, 2021
1 parent c40000b commit e18a4f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/rp2_common/pico_stdio_usb/stdio_usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
static uint16_t desc_str[DESC_STR_MAX];

// Assign the SN using the unique flash id
if (!usbd_serial_str[0])
if (!usbd_serial_str[0]) {
pico_get_unique_board_id_string(usbd_serial_str, sizeof(usbd_serial_str));
}

uint8_t len;
if (index == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/rp2_common/pico_unique_id/include/pico/unique_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void pico_get_unique_board_id(pico_unique_board_id_t *id_out);
* \param id_out a pointer to a char buffer of size len, to which the identifier will be written
* \param len the size of id_out. For full serial, len >= 2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1
*/
void pico_get_unique_board_id_string(char *id_out, size_t len);
void pico_get_unique_board_id_string(char *id_out, uint len);


#ifdef __cplusplus
Expand Down
8 changes: 3 additions & 5 deletions src/rp2_common/pico_unique_id/unique_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ void pico_get_unique_board_id(pico_unique_board_id_t *id_out) {
*id_out = retrieved_id;
}

void pico_get_unique_board_id_string(char *id_out, size_t len) {
pico_unique_board_id_t temp = retrieved_id;
void pico_get_unique_board_id_string(char *id_out, uint len) {
assert(len > 0);
size_t i;
// Generate hex one nibble at a time
for (i = 0; (i < len - 1) && (i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2); i++) {
size_t bi = i / 2;
int nibble = (temp.id[bi] >> 4) & 0x0F;
temp.id[bi] = (uint8_t)(temp.id[bi] << 4);
int nibble = (retrieved_id.id[i/2] >> (4 - 4 * (i&1))) & 0xf;
id_out[i] = (char)(nibble < 10 ? nibble + '0' : nibble + 'A' - 10);
}
id_out[i] = 0;
Expand Down

0 comments on commit e18a4f1

Please sign in to comment.