furi_hal_rtc.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /**
  2. * @file furi_hal_rtc.h
  3. * Furi Hal RTC API
  4. */
  5. #pragma once
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct {
  12. // Time
  13. uint8_t hour; /**< Hour in 24H format: 0-23 */
  14. uint8_t minute; /**< Minute: 0-59 */
  15. uint8_t second; /**< Second: 0-59 */
  16. // Date
  17. uint8_t day; /**< Current day: 1-31 */
  18. uint8_t month; /**< Current month: 1-12 */
  19. uint16_t year; /**< Current year: 2000-2099 */
  20. uint8_t weekday; /**< Current weekday: 1-7 */
  21. } FuriHalRtcDateTime;
  22. typedef enum {
  23. FuriHalRtcFlagDebug = (1 << 0),
  24. FuriHalRtcFlagFactoryReset = (1 << 1),
  25. FuriHalRtcFlagLock = (1 << 2),
  26. FuriHalRtcFlagC2Update = (1 << 3),
  27. FuriHalRtcFlagHandOrient = (1 << 4),
  28. FuriHalRtcFlagLegacySleep = (1 << 5),
  29. } FuriHalRtcFlag;
  30. typedef enum {
  31. FuriHalRtcBootModeNormal = 0, /**< Normal boot mode, default value */
  32. FuriHalRtcBootModeDfu, /**< Boot to DFU (MCU bootloader by ST) */
  33. FuriHalRtcBootModePreUpdate, /**< Boot to Update, pre update */
  34. FuriHalRtcBootModeUpdate, /**< Boot to Update, main */
  35. FuriHalRtcBootModePostUpdate, /**< Boot to Update, post update */
  36. } FuriHalRtcBootMode;
  37. typedef enum {
  38. FuriHalRtcHeapTrackModeNone = 0, /**< Disable allocation tracking */
  39. FuriHalRtcHeapTrackModeMain, /**< Enable allocation tracking for main application thread */
  40. FuriHalRtcHeapTrackModeTree, /**< Enable allocation tracking for main and children application threads */
  41. FuriHalRtcHeapTrackModeAll, /**< Enable allocation tracking for all threads */
  42. } FuriHalRtcHeapTrackMode;
  43. typedef enum {
  44. FuriHalRtcRegisterHeader, /**< RTC structure header */
  45. FuriHalRtcRegisterSystem, /**< Various system bits */
  46. FuriHalRtcRegisterVersion, /**< Pointer to Version */
  47. FuriHalRtcRegisterLfsFingerprint, /**< LFS geometry fingerprint */
  48. FuriHalRtcRegisterFaultData, /**< Pointer to last fault message */
  49. FuriHalRtcRegisterPinFails, /**< Failed pins count */
  50. /* Index of FS directory entry corresponding to FW update to be applied */
  51. FuriHalRtcRegisterUpdateFolderFSIndex,
  52. FuriHalRtcRegisterMAX, /**< Service value, do not use */
  53. } FuriHalRtcRegister;
  54. typedef enum {
  55. FuriHalRtcLocaleUnitsMetric = 0, /**< Metric measurement units */
  56. FuriHalRtcLocaleUnitsImperial = 1, /**< Imperial measurement units */
  57. } FuriHalRtcLocaleUnits;
  58. typedef enum {
  59. FuriHalRtcLocaleTimeFormat24h = 0, /**< 24-hour format */
  60. FuriHalRtcLocaleTimeFormat12h = 1, /**< 12-hour format */
  61. } FuriHalRtcLocaleTimeFormat;
  62. typedef enum {
  63. FuriHalRtcLocaleDateFormatDMY = 0, /**< Day/Month/Year */
  64. FuriHalRtcLocaleDateFormatMDY = 1, /**< Month/Day/Year */
  65. FuriHalRtcLocaleDateFormatYMD = 2, /**< Year/Month/Day */
  66. } FuriHalRtcLocaleDateFormat;
  67. /** Early initialization */
  68. void furi_hal_rtc_init_early();
  69. /** Early de-initialization */
  70. void furi_hal_rtc_deinit_early();
  71. /** Initialize RTC subsystem */
  72. void furi_hal_rtc_init();
  73. /** Force sync shadow registers */
  74. void furi_hal_rtc_sync_shadow();
  75. /** Get RTC register content
  76. *
  77. * @param[in] reg The register identifier
  78. *
  79. * @return content of the register
  80. */
  81. uint32_t furi_hal_rtc_get_register(FuriHalRtcRegister reg);
  82. /** Set register content
  83. *
  84. * @param[in] reg The register identifier
  85. * @param[in] value The value to store into register
  86. */
  87. void furi_hal_rtc_set_register(FuriHalRtcRegister reg, uint32_t value);
  88. /** Set Log Level value
  89. *
  90. * @param[in] level The level to store
  91. */
  92. void furi_hal_rtc_set_log_level(uint8_t level);
  93. /** Get Log Level value
  94. *
  95. * @return The Log Level value
  96. */
  97. uint8_t furi_hal_rtc_get_log_level();
  98. /** Set RTC Flag
  99. *
  100. * @param[in] flag The flag to set
  101. */
  102. void furi_hal_rtc_set_flag(FuriHalRtcFlag flag);
  103. /** Reset RTC Flag
  104. *
  105. * @param[in] flag The flag to reset
  106. */
  107. void furi_hal_rtc_reset_flag(FuriHalRtcFlag flag);
  108. /** Check if RTC Flag is set
  109. *
  110. * @param[in] flag The flag to check
  111. *
  112. * @return true if set
  113. */
  114. bool furi_hal_rtc_is_flag_set(FuriHalRtcFlag flag);
  115. /** Set RTC boot mode
  116. *
  117. * @param[in] mode The mode to set
  118. */
  119. void furi_hal_rtc_set_boot_mode(FuriHalRtcBootMode mode);
  120. /** Get RTC boot mode
  121. *
  122. * @return The RTC boot mode.
  123. */
  124. FuriHalRtcBootMode furi_hal_rtc_get_boot_mode();
  125. /** Set Heap Track mode
  126. *
  127. * @param[in] mode The mode to set
  128. */
  129. void furi_hal_rtc_set_heap_track_mode(FuriHalRtcHeapTrackMode mode);
  130. /** Get RTC Heap Track mode
  131. *
  132. * @return The RTC heap track mode.
  133. */
  134. FuriHalRtcHeapTrackMode furi_hal_rtc_get_heap_track_mode();
  135. /** Set locale units
  136. *
  137. * @param[in] mode The RTC Locale Units
  138. */
  139. void furi_hal_rtc_set_locale_units(FuriHalRtcLocaleUnits value);
  140. /** Get RTC Locale Units
  141. *
  142. * @return The RTC Locale Units.
  143. */
  144. FuriHalRtcLocaleUnits furi_hal_rtc_get_locale_units();
  145. /** Set RTC Locale Time Format
  146. *
  147. * @param[in] value The RTC Locale Time Format
  148. */
  149. void furi_hal_rtc_set_locale_timeformat(FuriHalRtcLocaleTimeFormat value);
  150. /** Get RTC Locale Time Format
  151. *
  152. * @return The RTC Locale Time Format.
  153. */
  154. FuriHalRtcLocaleTimeFormat furi_hal_rtc_get_locale_timeformat();
  155. /** Set RTC Locale Date Format
  156. *
  157. * @param[in] value The RTC Locale Date Format
  158. */
  159. void furi_hal_rtc_set_locale_dateformat(FuriHalRtcLocaleDateFormat value);
  160. /** Get RTC Locale Date Format
  161. *
  162. * @return The RTC Locale Date Format
  163. */
  164. FuriHalRtcLocaleDateFormat furi_hal_rtc_get_locale_dateformat();
  165. /** Set RTC Date Time
  166. *
  167. * @param datetime The date time to set
  168. */
  169. void furi_hal_rtc_set_datetime(FuriHalRtcDateTime* datetime);
  170. /** Get RTC Date Time
  171. *
  172. * @param datetime The datetime
  173. */
  174. void furi_hal_rtc_get_datetime(FuriHalRtcDateTime* datetime);
  175. /** Validate Date Time
  176. *
  177. * @param datetime The datetime to validate
  178. *
  179. * @return { description_of_the_return_value }
  180. */
  181. bool furi_hal_rtc_validate_datetime(FuriHalRtcDateTime* datetime);
  182. /** Set RTC Fault Data
  183. *
  184. * @param[in] value The value
  185. */
  186. void furi_hal_rtc_set_fault_data(uint32_t value);
  187. /** Get RTC Fault Data
  188. *
  189. * @return RTC Fault Data value
  190. */
  191. uint32_t furi_hal_rtc_get_fault_data();
  192. /** Set Pin Fails count
  193. *
  194. * @param[in] value The Pin Fails count
  195. */
  196. void furi_hal_rtc_set_pin_fails(uint32_t value);
  197. /** Get Pin Fails count
  198. *
  199. * @return Pin Fails Count
  200. */
  201. uint32_t furi_hal_rtc_get_pin_fails();
  202. /** Get UNIX Timestamp
  203. *
  204. * @return Unix Timestamp in seconds from UNIX epoch start
  205. */
  206. uint32_t furi_hal_rtc_get_timestamp();
  207. /** Convert DateTime to UNIX timestamp
  208. *
  209. * @param datetime The datetime
  210. *
  211. * @return UNIX Timestamp in seconds from UNIX epoch start
  212. */
  213. uint32_t furi_hal_rtc_datetime_to_timestamp(FuriHalRtcDateTime* datetime);
  214. #ifdef __cplusplus
  215. }
  216. #endif