2021-05-18 09:23:14 +00:00
|
|
|
#include <api-hal-version.h>
|
|
|
|
#include <stm32wbxx.h>
|
|
|
|
#include <stm32wbxx_ll_rtc.h>
|
2021-06-07 16:05:47 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "ble.h"
|
|
|
|
|
|
|
|
#define FLIPPER_NAME_LENGTH 8
|
2021-05-18 09:23:14 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t version;
|
|
|
|
uint8_t target;
|
|
|
|
uint8_t body;
|
|
|
|
uint8_t connect;
|
|
|
|
uint32_t timestamp;
|
2021-06-07 16:05:47 +00:00
|
|
|
char name[FLIPPER_NAME_LENGTH];
|
2021-05-18 09:23:14 +00:00
|
|
|
} ApiHalVersionOTP;
|
|
|
|
|
2021-06-07 16:05:47 +00:00
|
|
|
#define FLIPPER_ARRAY_NAME_LENGTH (FLIPPER_NAME_LENGTH + 1)
|
|
|
|
// BLE symbol + "Flipper " + name
|
|
|
|
#define FLIPPER_DEVICE_NAME_LENGTH (1 + 8 + FLIPPER_ARRAY_NAME_LENGTH)
|
|
|
|
|
2021-05-24 18:06:53 +00:00
|
|
|
// Initialiazed from OTP, used to guarantee zero terminated C string
|
2021-06-07 16:05:47 +00:00
|
|
|
static char flipper_name[FLIPPER_ARRAY_NAME_LENGTH];
|
|
|
|
static char flipper_device_name[FLIPPER_DEVICE_NAME_LENGTH];
|
2021-05-24 18:06:53 +00:00
|
|
|
|
|
|
|
void api_hal_version_init() {
|
|
|
|
char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
|
2021-06-07 16:05:47 +00:00
|
|
|
strlcpy(flipper_name, name, FLIPPER_ARRAY_NAME_LENGTH);
|
|
|
|
|
|
|
|
if(api_hal_version_get_name_ptr() != NULL) {
|
|
|
|
snprintf(
|
|
|
|
flipper_device_name,
|
|
|
|
FLIPPER_DEVICE_NAME_LENGTH,
|
|
|
|
"xFlipper %s",
|
|
|
|
flipper_name);
|
|
|
|
} else {
|
|
|
|
snprintf(
|
|
|
|
flipper_device_name,
|
|
|
|
FLIPPER_DEVICE_NAME_LENGTH,
|
|
|
|
"xFlipper");
|
|
|
|
}
|
|
|
|
|
|
|
|
flipper_device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
2021-05-24 18:06:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 09:23:14 +00:00
|
|
|
bool api_hal_version_do_i_belong_here() {
|
2021-05-25 18:26:42 +00:00
|
|
|
return api_hal_version_get_hw_target() == 6;
|
2021-05-18 09:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t api_hal_version_get_hw_version() {
|
|
|
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t api_hal_version_get_hw_target() {
|
|
|
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t api_hal_version_get_hw_body() {
|
|
|
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t api_hal_version_get_hw_connect() {
|
|
|
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t api_hal_version_get_hw_timestamp() {
|
|
|
|
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
|
|
|
|
}
|
|
|
|
|
2021-06-07 16:05:47 +00:00
|
|
|
const char* api_hal_version_get_name_ptr() {
|
2021-05-24 18:06:53 +00:00
|
|
|
return *flipper_name == 0xFFU ? NULL : flipper_name;
|
2021-05-18 09:23:14 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 16:05:47 +00:00
|
|
|
const char* api_hal_version_get_device_name_ptr() {
|
|
|
|
return flipper_device_name + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* api_hal_version_get_ble_local_device_name_ptr() {
|
|
|
|
return flipper_device_name;
|
|
|
|
}
|
|
|
|
|
2021-05-18 09:23:14 +00:00
|
|
|
const struct Version* api_hal_version_get_fw_version(void) {
|
|
|
|
return version_get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct Version* api_hal_version_get_boot_version(void) {
|
|
|
|
#ifdef NO_BOOTLOADER
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
/* Backup register which points to structure in flash memory */
|
2021-06-07 16:05:47 +00:00
|
|
|
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
2021-05-18 09:23:14 +00:00
|
|
|
#endif
|
|
|
|
}
|