furi_hal_rtc.h 6.5 KB

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