api-hal-version.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <api-hal-version.h>
  2. #include <stm32wbxx.h>
  3. #include <stm32wbxx_ll_rtc.h>
  4. typedef struct {
  5. uint8_t version;
  6. uint8_t target;
  7. uint8_t body;
  8. uint8_t connect;
  9. uint32_t timestamp;
  10. char name[8];
  11. } ApiHalVersionOTP;
  12. // Initialiazed from OTP, used to guarantee zero terminated C string
  13. static char flipper_name[9];
  14. void api_hal_version_init() {
  15. char* name = ((ApiHalVersionOTP*)OTP_AREA_BASE)->name;
  16. strlcpy(flipper_name, name, 9);
  17. }
  18. bool api_hal_version_do_i_belong_here() {
  19. return api_hal_version_get_hw_target() == 5;
  20. }
  21. const uint8_t api_hal_version_get_hw_version() {
  22. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
  23. }
  24. const uint8_t api_hal_version_get_hw_target() {
  25. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->target;
  26. }
  27. const uint8_t api_hal_version_get_hw_body() {
  28. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
  29. }
  30. const uint8_t api_hal_version_get_hw_connect() {
  31. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
  32. }
  33. const uint32_t api_hal_version_get_hw_timestamp() {
  34. return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
  35. }
  36. const char * api_hal_version_get_name_ptr() {
  37. return *flipper_name == 0xFFU ? NULL : flipper_name;
  38. }
  39. const struct Version* api_hal_version_get_fw_version(void) {
  40. return version_get();
  41. }
  42. const struct Version* api_hal_version_get_boot_version(void) {
  43. #ifdef NO_BOOTLOADER
  44. return 0;
  45. #else
  46. /* Backup register which points to structure in flash memory */
  47. return (const struct Version*) LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
  48. #endif
  49. }