0
mirror of https://gitlab.com/hyperglitch/jellyfish.git synced 2025-12-26 23:16:46 +00:00
2025-06-12 10:31:43 +02:00

47 lines
1.1 KiB
C

/*
* SPDX-FileCopyrightText: 2025 Igor Brkic <igor@hyperglitch.com>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "jf_common.h"
#include <string.h>
#include "main.h"
static uint32_t uid[3] = {0};
// keep this in sync with enum in header file
const char jf_dev_revision_names[2][5] = {
"v0.1",
"v2.0"
};
jf_dev_revision_t jf_get_dev_revision(){
if (uid[0]==0) {
uid[0] = HAL_GetUIDw0();
uid[1] = HAL_GetUIDw1();
uid[2] = HAL_GetUIDw2();
}
// since there are no hardware features to detect the revision (and since
// there's only one device in the v0.1 revision) rev0.1 is detected by MCU UID
if (uid[0]==0x240034 && uid[1]==0x59315016 && uid[2]==0x20333046) {
return JF_HWREV_v01;
}
return JF_HWREV_v20;
}
void jf_dev_get_uid(uint32_t *uid_out) {
if (uid[0]==0) {
jf_get_dev_revision();
}
for(int i=0; i<3; i++) {
uid_out[i] = uid[i];
}
}
void jf_get_dev_revision_name(char *name_out) {
strncpy(name_out, jf_dev_revision_names[jf_get_dev_revision()], sizeof(jf_dev_revision_names[0]));
}