HAL_RTC.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. ******************************************************************************
  3. * @file HAL_RTC.h
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief Header file of RTC HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_RTC_H__
  10. #define __HAL_RTC_H__
  11. #include "ACM32Fxx_HAL.h"
  12. /************************************************************************************/
  13. /* Registers Bits Definition */
  14. /************************************************************************************/
  15. /**************** Bit definition for RTC IE Register ***********************/
  16. #define RTC_IE_STP2RIE (BIT16)
  17. #define RTC_IE_STP2FIE (BIT15)
  18. #define RTC_IE_STP1RIE (BIT14)
  19. #define RTC_IE_STP1FIE (BIT13)
  20. #define RTC_IE_ADJ32 (BIT12)
  21. #define RTC_IE_ALM (BIT11)
  22. #define RTC_IE_1KHZ (BIT10)
  23. #define RTC_IE_256HZ (BIT9)
  24. #define RTC_IE_64HZ (BIT8)
  25. #define RTC_IE_16HZ (BIT7)
  26. #define RTC_IE_8HZ (BIT6)
  27. #define RTC_IE_4HZ (BIT5)
  28. #define RTC_IE_2HZ (BIT4)
  29. #define RTC_IE_SEC (BIT3)
  30. #define RTC_IE_MIN (BIT2)
  31. #define RTC_IE_HOUR (BIT1)
  32. #define RTC_IE_DATE (BIT0)
  33. /**************** Bit definition for RTC SR Register ***********************/
  34. #define RTC_SR_STP2RIE (BIT16)
  35. #define RTC_SR_STP2FIE (BIT15)
  36. #define RTC_SR_STP1RIE (BIT14)
  37. #define RTC_SR_STP1FIE (BIT13)
  38. #define RTC_SR_ADJ32 (BIT12)
  39. #define RTC_SR_ALM (BIT11)
  40. #define RTC_SR_1KHZ (BIT10)
  41. #define RTC_SR_256HZ (BIT9)
  42. #define RTC_SR_64HZ (BIT8)
  43. #define RTC_SR_16HZ (BIT7)
  44. #define RTC_SR_8HZ (BIT6)
  45. #define RTC_SR_4HZ (BIT5)
  46. #define RTC_SR_2HZ (BIT4)
  47. #define RTC_SR_SEC (BIT3)
  48. #define RTC_SR_MIN (BIT2)
  49. #define RTC_SR_HOUR (BIT1)
  50. #define RTC_SR_DATE (BIT0)
  51. /**************** Bit definition for RTC CR Register ***********************/
  52. #define RTC_CR_TAMPFLTCLK (BIT22)
  53. #define RTC_CR_TS2EDGE (BIT21)
  54. #define RTC_CR_TAMP2FLT (BIT19|BIT20)
  55. #define RTC_CR_TAMP2FLTEN (BIT18)
  56. #define RTC_CR_TAMP2FCLR (BIT17)
  57. #define RTC_CR_TAMP2RCLR (BIT16)
  58. #define RTC_CR_TS1EDGE (BIT15)
  59. #define RTC_CR_TAMP1FLT (BIT13|BIT14)
  60. #define RTC_CR_TAMP1FLTEN (BIT12)
  61. #define RTC_CR_ALM_MKSD (BIT11)
  62. #define RTC_CR_ALM_MSKH (BIT10)
  63. #define RTC_CR_ALM_MSKM (BIT9)
  64. #define RTC_CR_TAMP1FCLR (BIT8)
  65. #define RTC_CR_TAMP1RCLR (BIT7)
  66. #define RTC_CR_TAMP2EN (BIT6)
  67. #define RTC_CR_TAMP1EN (BIT5)
  68. #define RTC_CR_ALM_EN (BIT4)
  69. #define RTC_CR_FSEL (BIT0|BIT1|BIT2|BIT3)
  70. /**************** Bit definition for RTC_PMU CR Register ***********************/
  71. #define RPMU_CR_WU6FILEN BIT29
  72. #define RPMU_CR_WU5FILEN BIT28
  73. #define RPMU_CR_WU4FILEN BIT27
  74. #define RPMU_CR_WU3FILEN BIT26
  75. #define RPMU_CR_WU2FILEN BIT25
  76. #define RPMU_CR_WU1FILEN BIT24
  77. #define RPMU_CR_EWUP6 BIT21
  78. #define RPMU_CR_EWUP5 BIT20
  79. #define RPMU_CR_EWUP4 BIT19
  80. #define RPMU_CR_EWUP3 BIT18
  81. #define RPMU_CR_EWUP2 BIT17
  82. #define RPMU_CR_EWUP1 BIT16
  83. #define RPMU_CR_BORRST_EN BIT12
  84. #define RPMU_CR_WK_TIME (BIT9|BIT10|BIT11)
  85. #define RPMU_CR_STB_EN BIT8
  86. #define RPMU_CR_BDRST BIT6
  87. #define RPMU_CR_RTCEN BIT5
  88. #define RPMU_CR_RTCSEL (BIT2|BIT3)
  89. #define RPMU_CR_CWUF BIT1
  90. #define RPMU_CR_CSBF BIT0
  91. /**************** Bit definition for RTC_PMU ANACR Register ***********************/
  92. #define RPMU_SR_BORWUF BIT13
  93. #define RPMU_SR_IWDTWUF BIT12
  94. #define RPMU_SR_RSTWUF BIT11
  95. #define RPMU_SR_RTCWUF BIT10
  96. #define RPMU_SR_WUP6F BIT6
  97. #define RPMU_SR_WUP5F BIT5
  98. #define RPMU_SR_WUP4F BIT4
  99. #define RPMU_SR_WUP3F BIT3
  100. #define RPMU_SR_WUP2F BIT2
  101. #define RPMU_SR_WUP1F BIT1
  102. #define RPMU_SR_SBF BIT0
  103. /**************** Bit definition for RTC_PMU ANACR Register ***********************/
  104. #define RPMU_ANACR_BOR_CFG (BIT24|BIT25)
  105. #define RPMU_ANACR_BOR_EN BIT23
  106. #define RPMU_ANACR_LPBGR_TRIM (BIT20|BIT21|BIT22)
  107. #define RPMU_ANACR_RC32K_TRIM (BIT10|BIT11|BIT12|BIT13|BIT14|BIT15)
  108. #define RPMU_ANACR_RC32K_RDY BIT9
  109. #define RPMU_ANACR_RC32K_EN BIT8
  110. #define RPMU_ANACR_XTLDRV_2 BIT5
  111. #define RPMU_ANACR_XTLDRV_1 BIT4
  112. #define RPMU_ANACR_XTLDRV_0 BIT3
  113. #define RPMU_ANACR_XTLDRV (BIT3|BIT4|BIT5)
  114. #define RPMU_ANACR_XTLBYO BIT2
  115. #define RPMU_ANACR_XTLRDY BIT1
  116. #define RPMU_ANACR_XTLEN BIT0
  117. /** @defgroup ClockSource
  118. * @{
  119. */
  120. #define RTC_CLOCK_RC32K (0x00000000)
  121. #define RTC_CLOCK_XTL (0x00000004)
  122. /**
  123. * @}
  124. */
  125. /** @defgroup Clock_Compensation
  126. * @{
  127. */
  128. #define COMPENSATION_INCREASE (0x00000000)
  129. #define COMPENSATION_DECREASE (0x00000400)
  130. /**
  131. * @}
  132. */
  133. /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
  134. * @{
  135. */
  136. /* Coded in BCD format */
  137. #define RTC_MONTH_JANUARY (0x01)
  138. #define RTC_MONTH_FEBRUARY (0x02)
  139. #define RTC_MONTH_MARCH (0x03)
  140. #define RTC_MONTH_APRIL (0x04)
  141. #define RTC_MONTH_MAY (0x05)
  142. #define RTC_MONTH_JUNE (0x06)
  143. #define RTC_MONTH_JULY (0x07)
  144. #define RTC_MONTH_AUGUST (0x08)
  145. #define RTC_MONTH_SEPTEMBER (0x09)
  146. #define RTC_MONTH_OCTOBER (0x10)
  147. #define RTC_MONTH_NOVEMBER (0x11)
  148. #define RTC_MONTH_DECEMBER (0x12)
  149. /**
  150. * @}
  151. */
  152. /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
  153. * @{
  154. */
  155. #define RTC_WEEKDAY_MONDAY (0x01)
  156. #define RTC_WEEKDAY_TUESDAY (0x02)
  157. #define RTC_WEEKDAY_WEDNESDAY (0x03)
  158. #define RTC_WEEKDAY_THURSDAY (0x04)
  159. #define RTC_WEEKDAY_FRIDAY (0x05)
  160. #define RTC_WEEKDAY_SATURDAY (0x06)
  161. #define RTC_WEEKDAY_SUNDAY (0x07)
  162. /**
  163. * @}
  164. */
  165. /** @defgroup RTC_Alarm_Mode Definitions
  166. * @{
  167. */
  168. #define RTC_ALARM_WEEK_MODE (0x00000000)
  169. #define RTC_ALARM_DAY_MODE (0x80000000)
  170. /**
  171. * @}
  172. */
  173. /** @defgroup RTC_AlarmInterrupt Definitions
  174. * @{
  175. */
  176. #define RTC_ALARM_INT_ENABLE (0x00000000)
  177. #define RTC_ALARM_INT_DISABLE (0x00000001)
  178. /**
  179. * @}
  180. */
  181. /** @defgroup RTC_DayMask Definitions
  182. * @{
  183. */
  184. #define RTC_ALARM_DAY_MASK_ENABLE RTC_CR_ALM_MKSD
  185. #define RTC_ALARM_DAY_MASK_DISABLE (0x00000000)
  186. /**
  187. * @}
  188. */
  189. /** @defgroup RTC_HourMask Definitions
  190. * @{
  191. */
  192. #define RTC_ALARM_HOUR_MASK_ENABLE RTC_CR_ALM_MSKH
  193. #define RTC_ALARM_HOUR_MASK_DISABLE (0x00000000)
  194. /**
  195. * @}
  196. */
  197. /** @defgroup RTC_MinMask Definitions
  198. * @{
  199. */
  200. #define RTC_ALARM_MIN_MASK_ENABLE RTC_CR_ALM_MSKM
  201. #define RTC_ALARM_MIN_MASK_DISABLE (0x00000000)
  202. /**
  203. * @}
  204. */
  205. /** @defgroup RTC_Alarm_WeekSelect Definitions
  206. * @{
  207. */
  208. #define RTC_ALARM_WEEK_SUNDAY (0x01000000)
  209. #define RTC_ALARM_WEEK_MONDAY (0x02000000)
  210. #define RTC_ALARM_WEEK_TUESDAY (0x04000000)
  211. #define RTC_ALARM_WEEK_WEDNESDAY (0x08000000)
  212. #define RTC_ALARM_WEEK_THURSDAY (0x10000000)
  213. #define RTC_ALARM_WEEK_FRIDAY (0x20000000)
  214. #define RTC_ALARM_WEEK_SATURDAY (0x40000000)
  215. /**
  216. * @}
  217. */
  218. /** @defgroup RTC_Temper_edge Definitions
  219. * @{
  220. */
  221. #define RTC_TEMP_EDGE_RISING (0x00000000)
  222. #define RTC_TEMP_EDGE_FALLING (0x00000001)
  223. /**
  224. * @}
  225. */
  226. /** @defgroup RTC_TemperInterrupt Definitions
  227. * @{
  228. */
  229. #define RTC_TEMP_INT_DISABLE (0x00000000)
  230. #define RTC_TEMP_INT_ENABLE (0x00000001)
  231. /**
  232. * @}
  233. */
  234. /** @defgroup RTC_ClearBackup Definitions
  235. * @{
  236. */
  237. #define RTC_TEMP_CLEAR_DISABLE (0x00000000)
  238. #define RTC_TEMP_CLEAR_ENABLE (0x00000001)
  239. /**
  240. * @}
  241. */
  242. /** @defgroup RTC_TemperFilter Definitions
  243. * @{
  244. */
  245. #define RTC_TEMP_FILTER_DISABLE (0x00000000)
  246. #define RTC_TEMP_FILTER_512_RTCCLK (0x00000001)
  247. #define RTC_TEMP_FILTER_1_RTCCLK (0x00000002)
  248. #define RTC_TEMP_FILTER_2_RTCCLK (0x00000003)
  249. #define RTC_TEMP_FILTER_4_RTCCLK (0x00000004)
  250. #define RTC_TEMP_FILTER_8_RTCCLK (0x00000005)
  251. /**
  252. * @}
  253. */
  254. /**
  255. * @brief RTC Temper index definition
  256. */
  257. typedef enum
  258. {
  259. RTC_TEMPER_1,
  260. RTC_TEMPER_2,
  261. }enum_Temper_t;
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @brief RTC wakeup source form standby
  267. */
  268. typedef enum
  269. {
  270. RTC_WAKEUP_RTC_INT = 0,
  271. RTC_WAKEUP_WKUP1 = 0x00010000, // PA0
  272. RTC_WAKEUP_WKUP2 = 0x00020000, // PC13
  273. RTC_WAKEUP_WKUP3 = 0x00040000, // PA2
  274. RTC_WAKEUP_WKUP4 = 0x00080000, // PC5
  275. RTC_WAKEUP_WKUP5 = 0x00100000, // PB5
  276. RTC_WAKEUP_WKUP6 = 0x00200000, // PB15
  277. RTC_WAKEUP_STAMP2 = (RTC_IE_STP2RIE | RTC_IE_STP2FIE),
  278. RTC_WAKEUP_STAMP1 = (RTC_IE_STP1RIE | RTC_IE_STP1FIE),
  279. RTC_WAKEUP_32S = RTC_IE_ADJ32,
  280. RTC_WAKEUP_ALARM = RTC_IE_ALM,
  281. RTC_WAKEUP_SEC = RTC_IE_SEC,
  282. RTC_WAKEUP_MIN = RTC_IE_MIN,
  283. RTC_WAKEUP_HOUR = RTC_IE_HOUR,
  284. RTC_WAKEUP_DATE = RTC_IE_DATE,
  285. }enum_WKUP_t;
  286. #define STANDBY_WAKEUP_RISING 0
  287. #define STANDBY_WAKEUP_FALLING 1
  288. /**
  289. * @}
  290. */
  291. /**
  292. * @brief Check RTC wakeup source form standby
  293. */
  294. #define RTC_WAKEUP_SOURCE_BORWUF (0x00002000)
  295. #define RTC_WAKEUP_SOURCE_IWDTWUF (0x00001000)
  296. #define RTC_WAKEUP_SOURCE_RSTWUF (0x00000800)
  297. #define RTC_WAKEUP_SOURCE_RTCWUF (0x00000400)
  298. #define RTC_WAKEUP_SOURCE_WKUP6 (0x00000040)
  299. #define RTC_WAKEUP_SOURCE_WKUP5 (0x00000020)
  300. #define RTC_WAKEUP_SOURCE_WKUP4 (0x00000010)
  301. #define RTC_WAKEUP_SOURCE_WKUP3 (0x00000008)
  302. #define RTC_WAKEUP_SOURCE_WKUP2 (0x00000004)
  303. #define RTC_WAKEUP_SOURCE_WKUP1 (0x00000002)
  304. /**
  305. * @}
  306. */
  307. /**
  308. * @brief RTC Configuration Structure definition
  309. */
  310. typedef struct
  311. {
  312. uint32_t u32_ClockSource; /*!< The RTC Clock Source to be configured.
  313. This parameter can be a value of @ref ClockSource */
  314. uint32_t u32_Compensation; /*!< The RTC Clock Compensation to be configured.
  315. This parameter can be a value of @ref Clock_Compensation */
  316. uint32_t u32_CompensationValue; /*!< The RTC Clock Compensation Value to be configured.
  317. This parameter must be a number between Min_Data = 0x000 and Max_Data = 0x1FF */
  318. }RTC_ConfigTypeDef;
  319. /**
  320. * @brief RTC Date structure definition
  321. */
  322. typedef struct
  323. {
  324. uint8_t u8_Year; /*!< Specifies the RTC Date Year.
  325. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x99 */
  326. uint8_t u8_Month; /*!< Specifies the RTC Date Month (in BCD format).
  327. This parameter can be a value of @ref RTC_Month_Date_Definitions */
  328. uint8_t u8_Date; /*!< Specifies the RTC Date.
  329. This parameter must be a number between Min_Data = 0x01 and Max_Data = 0x31 */
  330. uint8_t u8_WeekDay; /*!< Specifies the RTC Date WeekDay.
  331. This parameter can be a value of @ref RTC_WeekDay_Definitions */
  332. }RTC_DateTypeDef;
  333. /* Attention: Year、Month、Date、Week use BCD code */
  334. /**
  335. * @brief RTC Time structure definition
  336. */
  337. typedef struct
  338. {
  339. uint8_t u8_Hours; /*!< Specifies the RTC Time Hour.
  340. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x23 */
  341. uint8_t u8_Minutes; /*!< Specifies the RTC Time Minutes.
  342. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x59 */
  343. uint8_t u8_Seconds; /*!< Specifies the RTC Time Seconds.
  344. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x59 */
  345. }RTC_TimeTypeDef;
  346. /* Attention: Hour、Minute、Second use BCD code */
  347. /**
  348. * @brief RTC Time structure definition
  349. */
  350. typedef struct
  351. {
  352. uint32_t u32_AlarmMode; /*!< Specifies the RTC alarm Mode.
  353. This parameter can be a value of @ref RTC_Alarm_Mode */
  354. uint32_t u32_AlarmInterrupt; /*!< Specifies the RTC alarm interrupt Enable or Disable.
  355. This parameter can be a value of @ref RTC_AlarmInterrupt */
  356. uint32_t u32_DayMask; /*!< Specifies the RTC alarm Day/Week Mask.
  357. This parameter can be a value of @ref RTC_DayMask */
  358. uint32_t u32_HourMask; /*!< Specifies the RTC alarm Hour Mask.
  359. This parameter can be a value of @ref RTC_HourMask */
  360. uint32_t u32_MinMask; /*!< Specifies the RTC alarm Min Mask.
  361. This parameter can be a value of @ref RTC_MinMask */
  362. uint32_t u32_AlarmWeek; /*!< Specifies the RTC alarm week select(Select WeekMode this parameter is valid).
  363. This parameter can be a value of @ref RTC_Alarm_WeekSelect */
  364. uint32_t u32_AlarmDay; /*!< Specifies the RTC alarm day select(Select DayMode this parameter is valid).
  365. This parameter must be a number between Min_Data = 0x01 and Max_Data = 0x31 */
  366. uint32_t u32_Hours; /*!< Specifies the RTC alarm Hour.
  367. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x23 */
  368. uint32_t u32_Minutes; /*!< Specifies the RTC alarm Minutes.
  369. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x59 */
  370. uint32_t u32_Seconds; /*!< Specifies the RTC alarm Seconds.
  371. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x59 */
  372. }RTC_AlarmTypeDef;
  373. /**
  374. * @brief RTC Temper structure definition
  375. */
  376. typedef struct
  377. {
  378. uint32_t u32_TemperEdge; /*!< Specifies the RTC Temper edge select.
  379. This parameter can be a value of @ref RTC_Temper_edge */
  380. uint32_t u32_InterruptEN; /*!< Specifies the RTC Temper interrupt enable.
  381. This parameter can be a value of @ref RTC_TemperInterrupt */
  382. uint32_t u32_ClearBackup; /*!< Specifies the RTC Temper clear backup register.
  383. This parameter can be a value of @ref RTC_ClearBackup */
  384. uint32_t u32_Filter; /*!< Specifies the RTC Temper Filter select.
  385. This parameter can be a value of @ref RTC_TemperFilter */
  386. }RTC_TemperTypeDef;
  387. /** @brief PC13 function select
  388. * @param __FUNC__: PC13 function select.
  389. * This parameter can be 0: GPIO,1:RTC Fout,2:RTC tamper 3:PC13 Value
  390. */
  391. #define __HAL_RTC_PC13_SEL(__FUNC__) (PMU->IOSEL |= (PMU->IOSEL & ~(0x3)) | (__FUNC__))
  392. /** @brief PC14 function select
  393. * @param __FUNC__: PC14 function select.
  394. * This parameter can be 0: GPIO,1:PC14 Value
  395. */
  396. #define __HAL_RTC_PC14_SEL(__FUNC__) (PMU->IOSEL |= (PMU->IOSEL & ~(0x3 << 3)) | (__FUNC__ << 3))
  397. /** @brief PC15 function select
  398. * @param __FUNC__: PC15 function select.
  399. * This parameter can be 0: GPIO,1:PC15 Value
  400. */
  401. #define __HAL_RTC_PC15_SEL(__FUNC__) (PMU->IOSEL |= (PMU->IOSEL & ~(0x3 << 5)) | (__FUNC__ << 5))
  402. /** @brief PC13 Value set
  403. * @param __FUNC__: PC13 Value set.
  404. * This parameter can be 0: set,1:claer
  405. */
  406. #define __HAL_RTC_PC13_VALUE(__VALUE__) (PMU->IOSEL |= (PMU->IOSEL & ~(1 << 8)) | (__VALUE__ << 8))
  407. /** @brief PC14 Value set
  408. * @param __FUNC__: PC14 Value set.
  409. * This parameter can be 0: set,1:claer
  410. */
  411. #define __HAL_RTC_PC14_VALUE(__VALUE__) (PMU->IOSEL |= (PMU->IOSEL & ~(1 << 9)) | (__VALUE__ << 9))
  412. /** @brief PC15 Value set
  413. * @param __FUNC__: PC15 Value set.
  414. * This parameter can be 0: set,1:claer
  415. */
  416. #define __HAL_RTC_PC15_VALUE(__VALUE__) (PMU->IOSEL |= (PMU->IOSEL & ~(1 << 10)) | (__VALUE__ << 10))
  417. /* @brief PC13、PC14、PC15 pull up or pull down */
  418. #define __HAL_RTC_PC13_PULL_UP_ENABLE() (PMU->IOCR |= BIT0)
  419. #define __HAL_RTC_PC13_PULL_UP_DISABLE() (PMU->IOCR &= ~BIT0)
  420. #define __HAL_RTC_PC13_PULL_DOWN_ENABLE() (PMU->IOCR |= BIT1)
  421. #define __HAL_RTC_PC13_PULL_DOWN_DISABLE() (PMU->IOCR &= ~BIT1)
  422. #define __HAL_RTC_PC14_PULL_UP_ENABLE() (PMU->IOCR |= BIT8)
  423. #define __HAL_RTC_PC14_PULL_UP_DISABLE() (PMU->IOCR &= ~BIT8)
  424. #define __HAL_RTC_PC14_PULL_DOWN_ENABLE() (PMU->IOCR |= BIT9)
  425. #define __HAL_RTC_PC14_PULL_DOWN_DISABLE() (PMU->IOCR &= ~BIT9)
  426. #define __HAL_RTC_PC15_PULL_UP_ENABLE() (PMU->IOCR |= BIT16)
  427. #define __HAL_RTC_PC15_PULL_UP_DISABLE() (PMU->IOCR &= ~BIT16)
  428. #define __HAL_RTC_PC15_PULL_DOWN_ENABLE() (PMU->IOCR |= BIT17)
  429. #define __HAL_RTC_PC15_PULL_DOWN_DISABLE() (PMU->IOCR &= ~BIT17)
  430. /* @brief PC13、PC14、PC15 digit or analog */
  431. #define __HAL_RTC_PC13_ANALOG() (PMU->IOCR |= BIT6)
  432. #define __HAL_RTC_PC13_DIGIT() (PMU->IOCR &= ~BIT6)
  433. #define __HAL_RTC_PC14_ANALOG() (PMU->IOCR |= BIT14)
  434. #define __HAL_RTC_PC14_DIGIT() (PMU->IOCR &= ~BIT14)
  435. #define __HAL_RTC_PC15_ANALOG() (PMU->IOCR |= BIT22)
  436. #define __HAL_RTC_PC15_DIGIT() (PMU->IOCR &= ~BIT22)
  437. /** @defgroup RTC Private Macros
  438. * @{
  439. */
  440. #define IS_RTC_CLOCKSRC(__CLOCKSRC__) (((__CLOCKSRC__) == RTC_CLOCK_RC32K) || \
  441. ((__CLOCKSRC__) == RTC_CLOCK_XTL))
  442. #define IS_RTC_COMPENSATION(__COMPENSATION__) (((__COMPENSATION__) == COMPENSATION_INCREASE) || \
  443. ((__COMPENSATION__) == COMPENSATION_DECREASE))
  444. #define IS_RTC_YEAR(__YEAR__) ((__YEAR__) <= 0x99)
  445. #define IS_RTC_MONTH(__MONTH__) (((__MONTH__) == RTC_MONTH_JANUARY) || \
  446. ((__MONTH__) == RTC_MONTH_FEBRUARY) || \
  447. ((__MONTH__) == RTC_MONTH_MARCH) || \
  448. ((__MONTH__) == RTC_MONTH_APRIL) || \
  449. ((__MONTH__) == RTC_MONTH_MAY) || \
  450. ((__MONTH__) == RTC_MONTH_JUNE) || \
  451. ((__MONTH__) == RTC_MONTH_JULY) || \
  452. ((__MONTH__) == RTC_MONTH_AUGUST) || \
  453. ((__MONTH__) == RTC_MONTH_SEPTEMBER) || \
  454. ((__MONTH__) == RTC_MONTH_OCTOBER) || \
  455. ((__MONTH__) == RTC_MONTH_NOVEMBER) || \
  456. ((__MONTH__) == RTC_MONTH_DECEMBER))
  457. #define IS_RTC_DAY(__DAY__) ((__DAY__) >= 0x01 && (__DAY__) <= 0x31)
  458. #define IS_RTC_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_WEEKDAY_MONDAY) || \
  459. ((__WEEKDAY__) == RTC_WEEKDAY_TUESDAY) || \
  460. ((__WEEKDAY__) == RTC_WEEKDAY_WEDNESDAY) || \
  461. ((__WEEKDAY__) == RTC_WEEKDAY_THURSDAY) || \
  462. ((__WEEKDAY__) == RTC_WEEKDAY_FRIDAY) || \
  463. ((__WEEKDAY__) == RTC_WEEKDAY_SATURDAY) || \
  464. ((__WEEKDAY__) == RTC_WEEKDAY_SUNDAY))
  465. #define IS_RTC_HOUR(__HOUR__) ((__HOUR__) <= 0x23)
  466. #define IS_RTC_MIN(__MIN__) ((__MIN__) <= 0x59)
  467. #define IS_RTC_SEC(__SEC__) ((__SEC__) <= 0x60)
  468. #define IS_RTC_ALARM_MODE(__MODE__) (((__MODE__) == RTC_ALARM_WEEK_MODE) || \
  469. ((__MODE__) == RTC_ALARM_DAY_MODE))
  470. #define IS_RTC_ALARM_INT(__INT__) (((__INT__) == RTC_ALARM_INT_ENABLE) || \
  471. ((__INT__) == RTC_ALARM_INT_DISABLE))
  472. #define IS_RTC_ALARM_DAY_MASK(__MASKD__) (((__MASKD__) == RTC_ALARM_DAY_MASK_ENABLE) || \
  473. ((__MASKD__) == RTC_ALARM_DAY_MASK_DISABLE))
  474. #define IS_RTC_ALARM_HOUR_MASK(__MASKH__) (((__MASKH__) == RTC_ALARM_HOUR_MASK_ENABLE) || \
  475. ((__MASKH__) == RTC_ALARM_HOUR_MASK_DISABLE))
  476. #define IS_RTC_ALARM_MIN_MASK(__MASKM__) (((__MASKM__) == RTC_ALARM_MIN_MASK_ENABLE) || \
  477. ((__MASKM__) == RTC_ALARM_MIN_MASK_DISABLE))
  478. #define IS_RTC_ALARM_WEEKDAY(__WEEKDAY__) (((__WEEKDAY__) == RTC_ALARM_WEEK_SUNDAY) || \
  479. ((__WEEKDAY__) == RTC_ALARM_WEEK_MONDAY) || \
  480. ((__WEEKDAY__) == RTC_ALARM_WEEK_TUESDAY) || \
  481. ((__WEEKDAY__) == RTC_ALARM_WEEK_WEDNESDAY) || \
  482. ((__WEEKDAY__) == RTC_ALARM_WEEK_THURSDAY) || \
  483. ((__WEEKDAY__) == RTC_ALARM_WEEK_FRIDAY) || \
  484. ((__WEEKDAY__) == RTC_ALARM_WEEK_SATURDAY) || \
  485. ((__WEEKDAY__) >= 0x01000000 && (__WEEKDAY__) <= 0x7F000000))
  486. #define IS_RTC_TEMP_EDGE(__EDGE__) (((__EDGE__) == RTC_TEMP_EDGE_RISING) || \
  487. ((__EDGE__) == RTC_TEMP_EDGE_FALLING))
  488. #define IS_RTC_TEMP_INT(__INT__) (((__INT__) == RTC_TEMP_INT_ENABLE) || \
  489. ((__INT__) == RTC_TEMP_INT_DISABLE))
  490. #define IS_RTC_TEMP_CLEAR_BACKUP(__CLEAR__) (((__CLEAR__) == RTC_TEMP_CLEAR_DISABLE) || \
  491. ((__CLEAR__) == RTC_TEMP_CLEAR_ENABLE))
  492. #define IS_RTC_TEMP_FILTER(__FILTER__) (((__FILTER__) == RTC_TEMP_FILTER_DISABLE) || \
  493. ((__FILTER__) == RTC_TEMP_FILTER_512_RTCCLK) || \
  494. ((__FILTER__) == RTC_TEMP_FILTER_1_RTCCLK) || \
  495. ((__FILTER__) == RTC_TEMP_FILTER_2_RTCCLK) || \
  496. ((__FILTER__) == RTC_TEMP_FILTER_4_RTCCLK) || \
  497. ((__FILTER__) == RTC_TEMP_FILTER_8_RTCCLK))
  498. /**
  499. * @}
  500. */
  501. /* RTC stamp1 interrupt enable、disable */
  502. #define __HAL_RTC_ENABLE_STAMP1_IT (RTC->IE |= (RTC_IE_STP1RIE | RTC_IE_STP1FIE))
  503. #define __HAL_RTC_DISABLE_STAMP1_IT (RTC->IE &= ~(RTC_IE_STP1RIE | RTC_IE_STP1FIE))
  504. /* RTC stamp2 interrupt enable、disable */
  505. #define __HAL_RTC_ENABLE_STAMP2_IT (RTC->IE |= (RTC_IE_STP2RIE | RTC_IE_STP2FIE))
  506. #define __HAL_RTC_DISABLE_STAMP2_IT (RTC->IE &= ~(RTC_IE_STP2RIE | RTC_IE_STP2FIE))
  507. /* RTC 32S interrupt enable、disable */
  508. #define __HAL_RTC_ENABLE_32S_IT (RTC->IE |= RTC_IE_ADJ32)
  509. #define __HAL_RTC_DISABLE_32S_IT (RTC->IE &= ~RTC_IE_ADJ32)
  510. /* RTC alarm interrupt enable、disable */
  511. #define __HAL_RTC_ENABLE_ALM_IT (RTC->IE |= RTC_IE_ALM)
  512. #define __HAL_RTC_DISABLE_ALM_IT (RTC->IE &= RTC_IE_ALM)
  513. /* RTC sec interrupt enable、disable */
  514. #define __HAL_RTC_ENABLE_SEC_IT (RTC->IE |= RTC_IE_SEC)
  515. #define __HAL_RTC_DISABLE_SEC_IT (RTC->IE &= ~RTC_IE_SEC)
  516. /* RTC Minutes interrupt enable、disable */
  517. #define __HAL_RTC_ENABLE_MIN_IT (RTC->IE |= RTC_IE_MIN)
  518. #define __HAL_RTC_DISABLE_MIN_IT (RTC->IE &= ~RTC_IE_MIN)
  519. /* RTC Hour interrupt enable、disable */
  520. #define __HAL_RTC_ENABLE_HOUR_IT (RTC->IE |= RTC_IE_HOUR)
  521. #define __HAL_RTC_DISABLE_HOUR_IT (RTC->IE &= ~RTC_IE_HOUR)
  522. /* RTC Date interrupt enable、disable */
  523. #define __HAL_RTC_ENABLE_DATE_IT (RTC->IE |= RTC_IE_DATE)
  524. #define __HAL_RTC_DISABLE_DATE_IT (RTC->IE &= ~RTC_IE_DATE)
  525. /* HAL_RTC_Config */
  526. HAL_StatusTypeDef HAL_RTC_Config(RTC_ConfigTypeDef *hrtc);
  527. /* HAL_RTC_SetTime */
  528. void HAL_RTC_SetTime(RTC_TimeTypeDef *fp_Time);
  529. /* HAL_RTC_GetTime */
  530. void HAL_RTC_GetTime(RTC_TimeTypeDef *fp_Time);
  531. /* HAL_RTC_SetDate */
  532. void HAL_RTC_SetDate(RTC_DateTypeDef *fp_Date);
  533. /* HAL_RTC_GetDate */
  534. void HAL_RTC_GetDate(RTC_DateTypeDef *fp_Date);
  535. /* HAL_RTC_AlarmConfig */
  536. void HAL_RTC_AlarmConfig(RTC_AlarmTypeDef *fp_Alarm);
  537. /* HAL_RTC_AlarmEnable */
  538. void HAL_RTC_AlarmEnable(void);
  539. /* HAL_RTC_AlarmDisable */
  540. void HAL_RTC_AlarmDisable(void);
  541. /* HAL_RTC_Tamper */
  542. void HAL_RTC_Tamper(enum_Temper_t fe_Temper, RTC_TemperTypeDef *fp_Temper);
  543. /* HAL_RTC_TamperEnable */
  544. void HAL_RTC_TamperEnable(enum_Temper_t fe_Temper);
  545. /* HAL_RTC_TamperDisable */
  546. void HAL_RTC_TamperDisable(enum_Temper_t fe_Temper);
  547. /* HAL_RTC_Standby_Wakeup */
  548. void HAL_RTC_Standby_Wakeup(enum_WKUP_t fe_Wakeup, uint32_t fu32_Edge);
  549. /* HAL_RTC_Get_StandbyStatus */
  550. bool HAL_RTC_Get_StandbyStatus(void);
  551. /* HAL_RTC_Get_StandbyWakeupSource */
  552. uint32_t HAL_RTC_Get_StandbyWakeupSource(void);
  553. #endif