2021-06-28 23:03:02 +00:00
|
|
|
// vim: set et:
|
|
|
|
|
2021-02-16 02:19:13 +00:00
|
|
|
#include <stdint.h>
|
2021-06-28 23:03:02 +00:00
|
|
|
|
2021-06-13 23:32:21 +00:00
|
|
|
#include <pico/stdlib.h>
|
|
|
|
#include <pico/unique_id.h>
|
2021-02-16 02:19:13 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
#include "tusb.h"
|
2021-06-14 00:01:35 +00:00
|
|
|
#include "util.h"
|
2021-06-13 23:32:21 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
uint8_t get_unique_id_u8(uint8_t* desc_str) {
|
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
|
|
|
uint8_t chr_count = 0;
|
2021-06-13 23:32:21 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
pico_get_unique_board_id(&uid);
|
2021-06-13 23:32:21 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
for (size_t byte = 0; byte < TU_ARRAY_SIZE(uid.id); byte++) {
|
|
|
|
uint8_t tmp = uid.id[byte];
|
|
|
|
for (int digit = 0; digit < 2; digit++) {
|
|
|
|
desc_str[chr_count++] = nyb2hex(tmp & 0xf);
|
|
|
|
tmp >>= 4;
|
|
|
|
}
|
|
|
|
}
|
2021-06-13 23:32:21 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
return chr_count;
|
2021-06-13 23:32:21 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
uint8_t get_unique_id_u16(uint16_t* desc_str) {
|
|
|
|
pico_unique_board_id_t uid;
|
|
|
|
|
|
|
|
uint8_t chr_count = 0;
|
2021-02-16 02:19:13 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
pico_get_unique_board_id(&uid);
|
2021-02-16 02:19:13 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
for (size_t byte = 0; byte < TU_ARRAY_SIZE(uid.id); byte++) {
|
|
|
|
uint8_t tmp = uid.id[byte];
|
|
|
|
for (int digit = 0; digit < 2; digit++) {
|
|
|
|
desc_str[chr_count++] = nyb2hex(tmp & 0xf);
|
|
|
|
tmp >>= 4;
|
|
|
|
}
|
|
|
|
}
|
2021-02-16 02:19:13 +00:00
|
|
|
|
2021-06-28 23:03:02 +00:00
|
|
|
return chr_count;
|
2021-02-16 02:19:13 +00:00
|
|
|
}
|
|
|
|
|