1
0
mirror of https://github.com/whowechina/chu_pico.git synced 2024-11-24 11:00:10 +01:00

SN display in CLI

This commit is contained in:
whowechina 2023-10-22 10:48:24 +08:00
parent de27dbbd09
commit ff3768244b
3 changed files with 27 additions and 0 deletions

View File

@ -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]);

View File

@ -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;

View File

@ -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);