From ff3768244b7a355b4f04188c4cd5e60059fd48f4 Mon Sep 17 00:00:00 2001 From: whowechina Date: Sun, 22 Oct 2023 10:48:24 +0800 Subject: [PATCH] SN display in CLI --- firmware/src/cli.c | 2 ++ firmware/src/save.c | 22 ++++++++++++++++++++++ firmware/src/save.h | 3 +++ 3 files changed, 27 insertions(+) diff --git a/firmware/src/cli.c b/firmware/src/cli.c index e1c5ef2..3ba1ffc 100644 --- a/firmware/src/cli.c +++ b/firmware/src/cli.c @@ -7,6 +7,7 @@ #include "pico/stdio.h" #include "pico/stdlib.h" #include "cli.h" +#include "save.h" #define MAX_COMMANDS 32 #define MAX_PARAMETERS 6 @@ -57,6 +58,7 @@ int cli_match_prefix(const char *str[], int num, const char *prefix) static void handle_help(int argc, char *argv[]) { printf("%s", cli_logo); + printf("\tSN: %016llx\n\n", board_id_64()); printf("Available commands:\n"); for (int i = 0; i < num_commands; i++) { printf("%*s: %s\n", max_cmd_len + 2, commands[i], helps[i]); diff --git a/firmware/src/save.c b/firmware/src/save.c index d3b227e..3afec3c 100644 --- a/firmware/src/save.c +++ b/firmware/src/save.c @@ -19,6 +19,7 @@ #include "hardware/flash.h" #include "pico/multicore.h" +#include "pico/unique_id.h" static struct { size_t size; @@ -109,6 +110,27 @@ static void save_loaded() } } +static union __attribute__((packed)) { + pico_unique_board_id_t id; + struct { + uint32_t id32h; + uint32_t id32l; + }; + uint64_t id64; +} board_id; + +uint32_t board_id_32() +{ + pico_get_unique_board_id(&board_id.id); + return board_id.id32h ^ board_id.id32l; +} + +uint64_t board_id_64() +{ + pico_get_unique_board_id(&board_id.id); + return board_id.id64; +} + void save_init(uint32_t magic, mutex_t *locker) { my_magic = magic; diff --git a/firmware/src/save.h b/firmware/src/save.h index 2cf5f1b..cde4229 100644 --- a/firmware/src/save.h +++ b/firmware/src/save.h @@ -12,6 +12,9 @@ #include "pico/multicore.h" +uint32_t board_id_32(); +uint64_t board_id_64(); + /* It's safer to lock other I/O ops during saving, so we need a locker */ typedef void (*io_locker_func)(bool pause); void save_init(uint32_t magic, mutex_t *lock);