1 /**
2   ******************************************************************************
3   * @file    stm32g4xx_hal_rtc.h
4   * @author  MCD Application Team
5   * @brief   Header file of RTC HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32G4xx_HAL_RTC_H
21 #define STM32G4xx_HAL_RTC_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx_hal_def.h"
29 
30 /** @addtogroup STM32G4xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup RTC RTC
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup RTC_Exported_Types RTC Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  HAL State structures definition
45   */
46 typedef enum
47 {
48   HAL_RTC_STATE_RESET             = 0x00U,  /*!< RTC not yet initialized or disabled */
49   HAL_RTC_STATE_READY             = 0x01U,  /*!< RTC initialized and ready for use   */
50   HAL_RTC_STATE_BUSY              = 0x02U,  /*!< RTC process is ongoing              */
51   HAL_RTC_STATE_TIMEOUT           = 0x03U,  /*!< RTC timeout state                   */
52   HAL_RTC_STATE_ERROR             = 0x04U   /*!< RTC error state                     */
53 
54 } HAL_RTCStateTypeDef;
55 
56 /**
57   * @brief  RTC Configuration Structure definition
58   */
59 typedef struct
60 {
61   uint32_t HourFormat;        /*!< Specifies the RTC Hour Format.
62                                  This parameter can be a value of @ref RTC_Hour_Formats */
63 
64   uint32_t AsynchPrediv;      /*!< Specifies the RTC Asynchronous Predivider value.
65                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7F */
66 
67   uint32_t SynchPrediv;       /*!< Specifies the RTC Synchronous Predivider value.
68                                  This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x7FFF */
69 
70   uint32_t OutPut;            /*!< Specifies which signal will be routed to the RTC output.
71                                  This parameter can be a value of @ref RTCEx_Output_selection_Definitions */
72 
73   uint32_t OutPutRemap;       /*!< Specifies the remap for RTC output.
74                                  This parameter can be a value of @ref  RTC_Output_ALARM_OUT_Remap */
75 
76   uint32_t OutPutPolarity;    /*!< Specifies the polarity of the output signal.
77                                  This parameter can be a value of @ref RTC_Output_Polarity_Definitions */
78 
79   uint32_t OutPutType;        /*!< Specifies the RTC Output Pin mode.
80                                  This parameter can be a value of @ref RTC_Output_Type_ALARM_OUT */
81 
82   uint32_t OutPutPullUp;      /*!< Specifies the RTC Output Pull-Up mode.
83                                  This parameter can be a value of @ref RTC_Output_PullUp_ALARM_OUT */
84 } RTC_InitTypeDef;
85 
86 /**
87   * @brief  RTC Time structure definition
88   */
89 typedef struct
90 {
91   uint8_t Hours;            /*!< Specifies the RTC Time Hour.
92                                  This parameter must be a number between Min_Data = 0 and Max_Data = 12 if the RTC_HourFormat_12 is selected.
93                                  This parameter must be a number between Min_Data = 0 and Max_Data = 23 if the RTC_HourFormat_24 is selected */
94 
95   uint8_t Minutes;          /*!< Specifies the RTC Time Minutes.
96                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
97 
98   uint8_t Seconds;          /*!< Specifies the RTC Time Seconds.
99                                  This parameter must be a number between Min_Data = 0 and Max_Data = 59 */
100 
101   uint8_t TimeFormat;       /*!< Specifies the RTC AM/PM Time.
102                                  This parameter can be a value of @ref RTC_AM_PM_Definitions */
103 
104   uint32_t SubSeconds;     /*!< Specifies the RTC_SSR RTC Sub Second register content.
105                                  This parameter corresponds to a time unit range between [0-1] Second
106                                  with [1 Sec / SecondFraction +1] granularity */
107 
108   uint32_t SecondFraction;  /*!< Specifies the range or granularity of Sub Second register content
109                                  corresponding to Synchronous pre-scaler factor value (PREDIV_S)
110                                  This parameter corresponds to a time unit range between [0-1] Second
111                                  with [1 Sec / SecondFraction +1] granularity.
112                                  This field will be used only by HAL_RTC_GetTime function */
113 
114   uint32_t DayLightSaving;  /*!< This interface is deprecated. To manage Daylight Saving Time,
115                                  please use HAL_RTC_DST_xxx functions */
116 
117   uint32_t StoreOperation;  /*!< This interface is deprecated. To manage Daylight Saving Time,
118                                  please use HAL_RTC_DST_xxx functions */
119 } RTC_TimeTypeDef;
120 
121 /**
122   * @brief  RTC Date structure definition
123   */
124 typedef struct
125 {
126   uint8_t WeekDay;  /*!< Specifies the RTC Date WeekDay.
127                          This parameter can be a value of @ref RTC_WeekDay_Definitions */
128 
129   uint8_t Month;    /*!< Specifies the RTC Date Month (in BCD format).
130                          This parameter can be a value of @ref RTC_Month_Date_Definitions */
131 
132   uint8_t Date;     /*!< Specifies the RTC Date.
133                          This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
134 
135   uint8_t Year;     /*!< Specifies the RTC Date Year.
136                          This parameter must be a number between Min_Data = 0 and Max_Data = 99 */
137 } RTC_DateTypeDef;
138 
139 /**
140   * @brief  RTC Alarm structure definition
141   */
142 typedef struct
143 {
144   RTC_TimeTypeDef AlarmTime;     /*!< Specifies the RTC Alarm Time members */
145 
146   uint32_t AlarmMask;            /*!< Specifies the RTC Alarm Masks.
147                                       This parameter can be a value of @ref RTC_AlarmMask_Definitions */
148 
149   uint32_t AlarmSubSecondMask;   /*!< Specifies the RTC Alarm SubSeconds Masks.
150                                       This parameter can be a value of @ref RTC_Alarm_Sub_Seconds_Masks_Definitions */
151 
152   uint32_t AlarmDateWeekDaySel;  /*!< Specifies the RTC Alarm is on Date or WeekDay.
153                                      This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
154 
155   uint8_t AlarmDateWeekDay;      /*!< Specifies the RTC Alarm Date/WeekDay.
156                                       If the Alarm Date is selected, this parameter must be set to a value in the 1-31 range.
157                                       If the Alarm WeekDay is selected, this parameter can be a value of @ref RTC_WeekDay_Definitions */
158 
159   uint32_t Alarm;                /*!< Specifies the alarm .
160                                       This parameter can be a value of @ref RTC_Alarms_Definitions */
161 } RTC_AlarmTypeDef;
162 
163 /**
164   * @brief  RTC Handle Structure definition
165   */
166 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
167 typedef struct __RTC_HandleTypeDef
168 #else
169 typedef struct
170 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
171 {
172   RTC_TypeDef               *Instance;  /*!< Legacy register base address. Not used anymore,
173                                              the driver directly uses cmsis base address */
174 
175   RTC_InitTypeDef           Init;       /*!< RTC required parameters  */
176 
177   HAL_LockTypeDef           Lock;       /*!< RTC locking object       */
178 
179   __IO HAL_RTCStateTypeDef  State;      /*!< Time communication state */
180 
181 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
182   void (* AlarmAEventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Alarm A Event callback           */
183   void (* AlarmBEventCallback)(struct __RTC_HandleTypeDef *hrtc);                   /*!< RTC Alarm B Event callback           */
184   void (* TimeStampEventCallback)(struct __RTC_HandleTypeDef *hrtc);                /*!< RTC TimeStamp Event callback         */
185   void (* WakeUpTimerEventCallback)(struct __RTC_HandleTypeDef *hrtc);              /*!< RTC WakeUpTimer Event callback       */
186 
187   void (* Tamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc);                  /*!< RTC Tamper 1 Event callback          */
188   void (* Tamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc);                  /*!< RTC Tamper 2 Event callback          */
189 #if (RTC_TAMP_NB == 3)
190   void (* Tamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc);                  /*!< RTC Tamper 3 Event callback          */
191 #endif /* RTC_TAMP_NB */
192   void (* InternalTamper1EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 1 Event callback */
193 #ifdef RTC_TAMP_INT_2_SUPPORT
194   void (* InternalTamper2EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 2 Event callback */
195 #endif /* RTC_TAMP_INT_2_SUPPORT */
196   void (* InternalTamper3EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 3 Event callback */
197   void (* InternalTamper4EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 4 Event callback */
198   void (* InternalTamper5EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 5 Event callback */
199 #ifdef RTC_TAMP_INT_6_SUPPORT
200   void (* InternalTamper6EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 6 Event callback */
201 #endif /* RTC_TAMP_INT_6_SUPPORT */
202 #ifdef RTC_TAMP_INT_7_SUPPORT
203   void (* InternalTamper7EventCallback)(struct __RTC_HandleTypeDef *hrtc);          /*!< RTC Internal Tamper 7 Event callback */
204 #endif /* RTC_TAMP_INT_7_SUPPORT */
205 
206   void (* MspInitCallback)(struct __RTC_HandleTypeDef *hrtc);                       /*!< RTC Msp Init callback                */
207   void (* MspDeInitCallback)(struct __RTC_HandleTypeDef *hrtc);                     /*!< RTC Msp DeInit callback              */
208 
209 #endif /* (USE_HAL_RTC_REGISTER_CALLBACKS) */
210 
211 } RTC_HandleTypeDef;
212 
213 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
214 /**
215   * @brief  HAL LPTIM Callback ID enumeration definition
216   */
217 typedef enum
218 {
219   HAL_RTC_ALARM_A_EVENT_CB_ID           = 0x00U,    /*!< RTC Alarm A Event Callback ID      */
220   HAL_RTC_ALARM_B_EVENT_CB_ID           = 0x01U,    /*!< RTC Alarm B Event Callback ID      */
221   HAL_RTC_TIMESTAMP_EVENT_CB_ID         = 0x02U,    /*!< RTC TimeStamp Event Callback ID    */
222   HAL_RTC_WAKEUPTIMER_EVENT_CB_ID       = 0x03U,    /*!< RTC WakeUp Timer Event Callback ID */
223   HAL_RTC_TAMPER1_EVENT_CB_ID           = 0x04U,    /*!< RTC Tamper 1 Callback ID           */
224   HAL_RTC_TAMPER2_EVENT_CB_ID           = 0x05U,    /*!< RTC Tamper 2 Callback ID           */
225   HAL_RTC_TAMPER3_EVENT_CB_ID           = 0x06U,    /*!< RTC Tamper 3 Callback ID           */
226   HAL_RTC_INTERNAL_TAMPER1_EVENT_CB_ID  = 0x07U,    /*!< RTC Internal Tamper 1 Callback ID  */
227   HAL_RTC_INTERNAL_TAMPER2_EVENT_CB_ID  = 0x08U,    /*!< RTC Internal Tamper 2 Callback ID  */
228   HAL_RTC_INTERNAL_TAMPER3_EVENT_CB_ID  = 0x09U,    /*!< RTC Internal Tamper 3 Callback ID  */
229   HAL_RTC_INTERNAL_TAMPER4_EVENT_CB_ID  = 0x0AU,    /*!< RTC Internal Tamper 4 Callback ID  */
230   HAL_RTC_INTERNAL_TAMPER5_EVENT_CB_ID  = 0x0BU,    /*!< RTC Internal Tamper 5 Callback ID  */
231   HAL_RTC_INTERNAL_TAMPER6_EVENT_CB_ID  = 0x0CU,    /*!< RTC Internal Tamper 6 Callback ID  */
232   HAL_RTC_INTERNAL_TAMPER7_EVENT_CB_ID  = 0x0DU,    /*!< RTC Internal Tamper 7 Callback ID  */
233   HAL_RTC_MSPINIT_CB_ID                 = 0x0EU,    /*!< RTC Msp Init callback ID           */
234   HAL_RTC_MSPDEINIT_CB_ID               = 0x0FU     /*!< RTC Msp DeInit callback ID         */
235 } HAL_RTC_CallbackIDTypeDef;
236 
237 /**
238   * @brief  HAL RTC Callback pointer definition
239   */
240 typedef  void (*pRTC_CallbackTypeDef)(RTC_HandleTypeDef *hrtc); /*!< pointer to an RTC callback function */
241 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
242 
243 /**
244   * @}
245   */
246 
247 /* Exported constants --------------------------------------------------------*/
248 /** @defgroup RTC_Exported_Constants RTC Exported Constants
249   * @{
250   */
251 
252 /** @defgroup RTC_Hour_Formats RTC Hour Formats
253   * @{
254   */
255 #define RTC_HOURFORMAT_24                   0x00000000U
256 #define RTC_HOURFORMAT_12                   RTC_CR_FMT
257 /**
258   * @}
259   */
260 
261 /** @defgroup RTCEx_Output_selection_Definitions RTCEx Output Selection Definition
262   * @{
263   */
264 #define RTC_OUTPUT_DISABLE                  0x00000000U
265 #define RTC_OUTPUT_ALARMA                   RTC_CR_OSEL_0
266 #define RTC_OUTPUT_ALARMB                   RTC_CR_OSEL_1
267 #define RTC_OUTPUT_WAKEUP                   RTC_CR_OSEL
268 #define RTC_OUTPUT_TAMPER                   RTC_CR_TAMPOE
269 /**
270   * @}
271   */
272 
273 
274 /** @defgroup RTC_Output_Polarity_Definitions RTC Output Polarity Definitions
275   * @{
276   */
277 #define RTC_OUTPUT_POLARITY_HIGH            0x00000000U
278 #define RTC_OUTPUT_POLARITY_LOW             RTC_CR_POL
279 /**
280   * @}
281   */
282 
283 /** @defgroup RTC_Output_Type_ALARM_OUT RTC Output Type ALARM OUT
284   * @{
285   */
286 #define RTC_OUTPUT_TYPE_PUSHPULL            0x00000000U
287 #define RTC_OUTPUT_TYPE_OPENDRAIN           RTC_CR_TAMPALRM_TYPE
288 /**
289   * @}
290   */
291 
292 /** @defgroup RTC_Output_PullUp_ALARM_OUT RTC Output Pull-Up ALARM OUT
293   * @{
294   */
295 #define RTC_OUTPUT_PULLUP_NONE              0x00000000U
296 #define RTC_OUTPUT_PULLUP_ON                RTC_CR_TAMPALRM_PU
297 /**
298   * @}
299   */
300 
301 /** @defgroup RTC_Output_ALARM_OUT_Remap RTC Output ALARM OUT Remap
302   * @{
303   */
304 #define RTC_OUTPUT_REMAP_NONE               0x00000000U
305 #define RTC_OUTPUT_REMAP_POS1               RTC_CR_OUT2EN
306 /**
307   * @}
308   */
309 
310 /** @defgroup RTC_AM_PM_Definitions RTC AM PM Definitions
311   * @{
312   */
313 #define RTC_HOURFORMAT12_AM                 0x0U
314 #define RTC_HOURFORMAT12_PM                 0x1U
315 /**
316   * @}
317   */
318 
319 /** @defgroup RTC_DayLightSaving_Definitions RTC DayLightSaving Definitions
320   * @{
321   */
322 #define RTC_DAYLIGHTSAVING_SUB1H            RTC_CR_SUB1H
323 #define RTC_DAYLIGHTSAVING_ADD1H            RTC_CR_ADD1H
324 #define RTC_DAYLIGHTSAVING_NONE             0x00000000U
325 /**
326   * @}
327   */
328 
329 /** @defgroup RTC_StoreOperation_Definitions RTC StoreOperation Definitions
330   * @{
331   */
332 #define RTC_STOREOPERATION_RESET            0x00000000U
333 #define RTC_STOREOPERATION_SET              RTC_CR_BKP
334 /**
335   * @}
336   */
337 
338 /** @defgroup RTC_Input_parameter_format_definitions RTC Input Parameter Format Definitions
339   * @{
340   */
341 #define RTC_FORMAT_BIN                      0x00000000U
342 #define RTC_FORMAT_BCD                      0x00000001U
343 /**
344   * @}
345   */
346 
347 /** @defgroup RTC_Month_Date_Definitions RTC Month Date Definitions
348   * @{
349   */
350 
351 /* Coded in BCD format */
352 #define RTC_MONTH_JANUARY                   ((uint8_t)0x01U)
353 #define RTC_MONTH_FEBRUARY                  ((uint8_t)0x02U)
354 #define RTC_MONTH_MARCH                     ((uint8_t)0x03U)
355 #define RTC_MONTH_APRIL                     ((uint8_t)0x04U)
356 #define RTC_MONTH_MAY                       ((uint8_t)0x05U)
357 #define RTC_MONTH_JUNE                      ((uint8_t)0x06U)
358 #define RTC_MONTH_JULY                      ((uint8_t)0x07U)
359 #define RTC_MONTH_AUGUST                    ((uint8_t)0x08U)
360 #define RTC_MONTH_SEPTEMBER                 ((uint8_t)0x09U)
361 #define RTC_MONTH_OCTOBER                   ((uint8_t)0x10U)
362 #define RTC_MONTH_NOVEMBER                  ((uint8_t)0x11U)
363 #define RTC_MONTH_DECEMBER                  ((uint8_t)0x12U)
364 
365 /**
366   * @}
367   */
368 
369 /** @defgroup RTC_WeekDay_Definitions RTC WeekDay Definitions
370   * @{
371   */
372 #define RTC_WEEKDAY_MONDAY                  ((uint8_t)0x01U)
373 #define RTC_WEEKDAY_TUESDAY                 ((uint8_t)0x02U)
374 #define RTC_WEEKDAY_WEDNESDAY               ((uint8_t)0x03U)
375 #define RTC_WEEKDAY_THURSDAY                ((uint8_t)0x04U)
376 #define RTC_WEEKDAY_FRIDAY                  ((uint8_t)0x05U)
377 #define RTC_WEEKDAY_SATURDAY                ((uint8_t)0x06U)
378 #define RTC_WEEKDAY_SUNDAY                  ((uint8_t)0x07U)
379 
380 /**
381   * @}
382   */
383 
384 /** @defgroup RTC_AlarmDateWeekDay_Definitions RTC AlarmDateWeekDay Definitions
385   * @{
386   */
387 #define RTC_ALARMDATEWEEKDAYSEL_DATE        0x00000000U
388 #define RTC_ALARMDATEWEEKDAYSEL_WEEKDAY     RTC_ALRMAR_WDSEL
389 
390 /**
391   * @}
392   */
393 
394 /** @defgroup RTC_AlarmMask_Definitions RTC AlarmMask Definitions
395   * @{
396   */
397 #define RTC_ALARMMASK_NONE                  0x00000000U
398 #define RTC_ALARMMASK_DATEWEEKDAY           RTC_ALRMAR_MSK4
399 #define RTC_ALARMMASK_HOURS                 RTC_ALRMAR_MSK3
400 #define RTC_ALARMMASK_MINUTES               RTC_ALRMAR_MSK2
401 #define RTC_ALARMMASK_SECONDS               RTC_ALRMAR_MSK1
402 #define RTC_ALARMMASK_ALL                   (RTC_ALARMMASK_DATEWEEKDAY | RTC_ALARMMASK_HOURS  | \
403                                              RTC_ALARMMASK_MINUTES | RTC_ALARMMASK_SECONDS)
404 
405 /**
406   * @}
407   */
408 
409 /** @defgroup RTC_Alarms_Definitions RTC Alarms Definitions
410   * @{
411   */
412 #define RTC_ALARM_A                         RTC_CR_ALRAE
413 #define RTC_ALARM_B                         RTC_CR_ALRBE
414 
415 /**
416   * @}
417   */
418 
419 
420 /** @defgroup RTC_Alarm_Sub_Seconds_Masks_Definitions RTC Alarm Sub Seconds Masks Definitions
421   * @{
422   */
423 #define RTC_ALARMSUBSECONDMASK_ALL          0x00000000U                                                              /*!< All Alarm SS fields are masked.
424                                                                                                                           There is no comparison on sub seconds
425                                                                                                                           for Alarm */
426 #define RTC_ALARMSUBSECONDMASK_SS14_1       RTC_ALRMASSR_MASKSS_0                                                    /*!< SS[14:1] not used in Alarm
427                                                                                                                           comparison. Only SS[0] is compared.    */
428 #define RTC_ALARMSUBSECONDMASK_SS14_2       RTC_ALRMASSR_MASKSS_1                                                    /*!< SS[14:2] not used in Alarm
429                                                                                                                           comparison. Only SS[1:0] are compared  */
430 #define RTC_ALARMSUBSECONDMASK_SS14_3       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1)                          /*!< SS[14:3] not used in Alarm
431                                                                                                                           comparison. Only SS[2:0] are compared  */
432 #define RTC_ALARMSUBSECONDMASK_SS14_4       RTC_ALRMASSR_MASKSS_2                                                    /*!< SS[14:4] not used in Alarm
433                                                                                                                           comparison. Only SS[3:0] are compared  */
434 #define RTC_ALARMSUBSECONDMASK_SS14_5       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:5] not used in Alarm
435                                                                                                                           comparison. Only SS[4:0] are compared  */
436 #define RTC_ALARMSUBSECONDMASK_SS14_6       (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)                          /*!< SS[14:6] not used in Alarm
437                                                                                                                           comparison. Only SS[5:0] are compared  */
438 #define RTC_ALARMSUBSECONDMASK_SS14_7       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2)  /*!< SS[14:7] not used in Alarm
439                                                                                                                           comparison. Only SS[6:0] are compared  */
440 #define RTC_ALARMSUBSECONDMASK_SS14_8       RTC_ALRMASSR_MASKSS_3                                                    /*!< SS[14:8] not used in Alarm
441                                                                                                                           comparison. Only SS[7:0] are compared  */
442 #define RTC_ALARMSUBSECONDMASK_SS14_9       (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:9] not used in Alarm
443                                                                                                                           comparison. Only SS[8:0] are compared  */
444 #define RTC_ALARMSUBSECONDMASK_SS14_10      (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:10] not used in Alarm
445                                                                                                                           comparison. Only SS[9:0] are compared  */
446 #define RTC_ALARMSUBSECONDMASK_SS14_11      (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14:11] not used in Alarm
447                                                                                                                           comparison. Only SS[10:0] are compared */
448 #define RTC_ALARMSUBSECONDMASK_SS14_12      (RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)                          /*!< SS[14:12] not used in Alarm
449                                                                                                                           comparison.Only SS[11:0] are compared  */
450 #define RTC_ALARMSUBSECONDMASK_SS14_13      (RTC_ALRMASSR_MASKSS_0 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14:13] not used in Alarm
451                                                                                                                           comparison. Only SS[12:0] are compared */
452 #define RTC_ALARMSUBSECONDMASK_SS14         (RTC_ALRMASSR_MASKSS_1 | RTC_ALRMASSR_MASKSS_2 | RTC_ALRMASSR_MASKSS_3)  /*!< SS[14] not used in Alarm
453                                                                                                                           comparison. Only SS[13:0] are compared  */
454 #define RTC_ALARMSUBSECONDMASK_NONE         RTC_ALRMASSR_MASKSS                                                      /*!< SS[14:0] are compared and must match
455                                                                                                                           to activate alarm. */
456 /**
457   * @}
458   */
459 
460 /** @defgroup RTC_Interrupts_Definitions RTC Interrupts Definitions
461   * @{
462   */
463 #define RTC_IT_TS                           RTC_CR_TSIE        /*!< Enable Timestamp Interrupt    */
464 #define RTC_IT_WUT                          RTC_CR_WUTIE       /*!< Enable Wakeup timer Interrupt */
465 #define RTC_IT_ALRA                         RTC_CR_ALRAIE      /*!< Enable Alarm A Interrupt      */
466 #define RTC_IT_ALRB                         RTC_CR_ALRBIE      /*!< Enable Alarm B Interrupt      */
467 /**
468   * @}
469   */
470 
471 /** @defgroup RTC_Flag_Mask    RTC Flag Mask (5bits) describe in RTC_Flags_Definitions
472   * @{
473   */
474 #define RTC_FLAG_MASK                       0x001FU            /*!< RTC flags mask (5bits) */
475 /**
476   * @}
477   */
478 
479 /** @defgroup RTC_Flags_Definitions RTC Flags Definitions
480   *        Elements values convention: 000000XX000YYYYYb
481   *           - YYYYY  : Interrupt flag position in the XX register (5bits)
482   *           - XX  : Interrupt status register (2bits)
483   *                 - 01: ICSR register
484   *                 - 10: SR or SCR or MISR registers
485   * @{
486   */
487 #define RTC_FLAG_RECALPF                    (0x00000100U | RTC_ICSR_RECALPF_Pos) /*!< Recalibration pending Flag */
488 #define RTC_FLAG_INITF                      (0x00000100U | RTC_ICSR_INITF_Pos)   /*!< Initialization flag */
489 #define RTC_FLAG_RSF                        (0x00000100U | RTC_ICSR_RSF_Pos)     /*!< Registers synchronization flag */
490 #define RTC_FLAG_INITS                      (0x00000100U | RTC_ICSR_INITS_Pos)   /*!< Initialization status flag */
491 #define RTC_FLAG_SHPF                       (0x00000100U | RTC_ICSR_SHPF_Pos)    /*!< Shift operation pending flag */
492 #define RTC_FLAG_WUTWF                      (0x00000100U | RTC_ICSR_WUTWF_Pos)   /*!< Wakeup timer write flag */
493 #define RTC_FLAG_ALRBWF                     (0x00000100U | RTC_ICSR_ALRBWF_Pos)  /*!< Alarm B write flag */
494 #define RTC_FLAG_ALRAWF                     (0x00000100U | RTC_ICSR_ALRAWF_Pos)  /*!< Alarm A write flag */
495 #define RTC_FLAG_ITSF                       (0x00000200U | RTC_SR_ITSF_Pos)      /*!< Internal Time-stamp flag */
496 #define RTC_FLAG_TSOVF                      (0x00000200U | RTC_SR_TSOVF_Pos)     /*!< Time-stamp overflow flag */
497 #define RTC_FLAG_TSF                        (0x00000200U | RTC_SR_TSF_Pos)       /*!< Time-stamp flag */
498 #define RTC_FLAG_WUTF                       (0x00000200U | RTC_SR_WUTF_Pos)      /*!< Wakeup timer flag */
499 #define RTC_FLAG_ALRBF                      (0x00000200U | RTC_SR_ALRBF_Pos)     /*!< Alarm B flag */
500 #define RTC_FLAG_ALRAF                      (0x00000200U | RTC_SR_ALRAF_Pos)     /*!< Alarm A flag */
501  /**
502   * @}
503   */
504 
505 /** @defgroup RTC_Clear_Flags_Definitions RTC Clear Flags Definitions
506   * @{
507   */
508 #define RTC_CLEAR_ITSF                      RTC_SCR_CITSF    /*!< Clear Internal Time-stamp flag */
509 #define RTC_CLEAR_TSOVF                     RTC_SCR_CTSOVF   /*!< Clear Time-stamp overflow flag */
510 #define RTC_CLEAR_TSF                       RTC_SCR_CTSF     /*!< Clear Time-stamp flag */
511 #define RTC_CLEAR_WUTF                      RTC_SCR_CWUTF    /*!< Clear Wakeup timer flag */
512 #define RTC_CLEAR_ALRBF                     RTC_SCR_CALRBF   /*!< Clear Alarm B flag */
513 #define RTC_CLEAR_ALRAF                     RTC_SCR_CALRAF   /*!< Clear Alarm A flag */
514 /**
515   * @}
516   */
517 
518 /**
519   * @}
520   */
521 
522 /* Exported macros -----------------------------------------------------------*/
523 /** @defgroup RTC_Exported_Macros RTC Exported Macros
524   * @{
525   */
526 
527 /** @brief Reset RTC handle state
528   * @param  __HANDLE__ RTC handle.
529   * @retval None
530   */
531 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
532 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) do{\
533                                                       (__HANDLE__)->State = HAL_RTC_STATE_RESET;\
534                                                       (__HANDLE__)->MspInitCallback = NULL;\
535                                                       (__HANDLE__)->MspDeInitCallback = NULL;\
536                                                      }while(0)
537 #else
538 #define __HAL_RTC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_RTC_STATE_RESET)
539 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
540 
541 /**
542   * @brief  Disable the write protection for RTC registers.
543   * @param  __HANDLE__ specifies the RTC handle.
544   * @retval None
545   */
546 #define __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__)             \
547   do{                                       \
548     (__HANDLE__)->Instance->WPR = 0xCAU;   \
549     (__HANDLE__)->Instance->WPR = 0x53U;   \
550   } while(0U)
551 
552 /**
553   * @brief  Enable the write protection for RTC registers.
554   * @param  __HANDLE__ specifies the RTC handle.
555   * @retval None
556   */
557 #define __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__)              \
558   do{                                       \
559     (__HANDLE__)->Instance->WPR = 0xFFU;   \
560   } while(0U)
561 
562 /**
563   * @brief  Add 1 hour (summer time change).
564   * @note   This interface is deprecated.
565   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
566   * @param  __HANDLE__ specifies the RTC handle.
567   * @param  __BKP__ Backup
568   *         This parameter can be:
569   *            @arg @ref RTC_STOREOPERATION_RESET
570   *            @arg @ref RTC_STOREOPERATION_SET
571   * @retval None
572   */
573 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_ADD1H(__HANDLE__, __BKP__)                         \
574   do {                                                              \
575     __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
576     SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_ADD1H);            \
577     MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
578     __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
579   } while(0);
580 
581 /**
582   * @brief  Subtract 1 hour (winter time change).
583   * @note   This interface is deprecated.
584   *         To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions
585   * @param  __HANDLE__ specifies the RTC handle.
586   * @param  __BKP__ Backup
587   *         This parameter can be:
588   *            @arg @ref RTC_STOREOPERATION_RESET
589   *            @arg @ref RTC_STOREOPERATION_SET
590   * @retval None
591   */
592 #define __HAL_RTC_DAYLIGHT_SAVING_TIME_SUB1H(__HANDLE__, __BKP__)                         \
593   do {                                                              \
594     __HAL_RTC_WRITEPROTECTION_DISABLE(__HANDLE__);                \
595     SET_BIT((__HANDLE__)->Instance->CR, RTC_CR_SUB1H);            \
596     MODIFY_REG((__HANDLE__)->Instance->CR, RTC_CR_BKP , (__BKP__)); \
597     __HAL_RTC_WRITEPROTECTION_ENABLE(__HANDLE__);                 \
598   } while(0);
599 
600 /**
601   * @brief  Enable the RTC ALARMA peripheral.
602   * @param  __HANDLE__ specifies the RTC handle.
603   * @retval None
604   */
605 #define __HAL_RTC_ALARMA_ENABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRAE))
606 
607 /**
608   * @brief  Disable the RTC ALARMA peripheral.
609   * @param  __HANDLE__ specifies the RTC handle.
610   * @retval None
611   */
612 #define __HAL_RTC_ALARMA_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRAE))
613 
614 /**
615   * @brief  Enable the RTC ALARMB peripheral.
616   * @param  __HANDLE__ specifies the RTC handle.
617   * @retval None
618   */
619 #define __HAL_RTC_ALARMB_ENABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR |= (RTC_CR_ALRBE))
620 
621 /**
622   * @brief  Disable the RTC ALARMB peripheral.
623   * @param  __HANDLE__ specifies the RTC handle.
624   * @retval None
625   */
626 #define __HAL_RTC_ALARMB_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &= ~(RTC_CR_ALRBE))
627 
628 /**
629   * @brief  Enable the RTC Alarm interrupt.
630   * @param  __HANDLE__ specifies the RTC handle.
631   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
632   *          This parameter can be any combination of the following values:
633   *             @arg @ref RTC_IT_ALRA Alarm A interrupt
634   *             @arg @ref RTC_IT_ALRB Alarm B interrupt
635   * @retval None
636   */
637 #define __HAL_RTC_ALARM_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->CR |= (__INTERRUPT__))
638 
639 /**
640   * @brief  Disable the RTC Alarm interrupt.
641   * @param  __HANDLE__ specifies the RTC handle.
642   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to be enabled or disabled.
643   *         This parameter can be any combination of the following values:
644   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
645   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
646   * @retval None
647   */
648 #define __HAL_RTC_ALARM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->CR &= ~(__INTERRUPT__))
649 
650 /**
651   * @brief  Check whether the specified RTC Alarm interrupt has occurred or not.
652   * @param  __HANDLE__ specifies the RTC handle.
653   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
654   *         This parameter can be:
655   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
656   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
657   * @retval None
658   */
659 #define __HAL_RTC_ALARM_GET_IT(__HANDLE__, __INTERRUPT__) (((((__HANDLE__)->Instance->MISR)& ((__INTERRUPT__)>> 12U)) != 0U) ? 1UL : 0UL)
660 
661 /**
662   * @brief  Check whether the specified RTC Alarm interrupt has been enabled or not.
663   * @param  __HANDLE__ specifies the RTC handle.
664   * @param  __INTERRUPT__ specifies the RTC Alarm interrupt sources to check.
665   *         This parameter can be:
666   *            @arg @ref RTC_IT_ALRA Alarm A interrupt
667   *            @arg @ref RTC_IT_ALRB Alarm B interrupt
668   * @retval None
669   */
670 #define __HAL_RTC_ALARM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__)     (((((__HANDLE__)->Instance->CR) & (__INTERRUPT__)) != 0U) ? 1UL : 0UL)
671 
672 /**
673   * @brief  Get the selected RTC Alarms flag status.
674   * @param  __HANDLE__ specifies the RTC handle.
675   * @param  __FLAG__ specifies the RTC Alarm Flag sources to check.
676   *         This parameter can be:
677   *            @arg @ref RTC_FLAG_ALRAF
678   *            @arg @ref RTC_FLAG_ALRBF
679   *            @arg @ref RTC_FLAG_ALRAWF
680   *            @arg @ref RTC_FLAG_ALRBWF
681   * @retval None
682   */
683 #define __HAL_RTC_ALARM_GET_FLAG(__HANDLE__, __FLAG__)   (__HAL_RTC_GET_FLAG((__HANDLE__), (__FLAG__)))
684 
685 /**
686   * @brief  Clear the RTC Alarms pending flags.
687   * @param  __HANDLE__ specifies the RTC handle.
688   * @param  __FLAG__ specifies the RTC Alarm Flag sources to clear.
689   *          This parameter can be:
690   *             @arg @ref RTC_FLAG_ALRAF
691   *             @arg @ref RTC_FLAG_ALRBF
692   * @retval None
693   */
694 #define __HAL_RTC_ALARM_CLEAR_FLAG(__HANDLE__, __FLAG__)   (((__FLAG__) == RTC_FLAG_ALRAF) ? (((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRAF))) : \
695                                                             ((__HANDLE__)->Instance->SCR = (RTC_CLEAR_ALRBF)))
696 /**
697   * @brief  Enable interrupt on the RTC Alarm associated Exti line.
698   * @retval None
699   */
700 #define __HAL_RTC_ALARM_EXTI_ENABLE_IT()            (EXTI->IMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
701 
702 /**
703   * @brief  Disable interrupt on the RTC Alarm associated Exti line.
704   * @retval None
705   */
706 #define __HAL_RTC_ALARM_EXTI_DISABLE_IT()           (EXTI->IMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
707 
708 /**
709   * @brief  Enable event on the RTC Alarm associated Exti line.
710   * @retval None
711   */
712 #define __HAL_RTC_ALARM_EXTI_ENABLE_EVENT()         (EXTI->EMR1 |= RTC_EXTI_LINE_ALARM_EVENT)
713 
714 /**
715   * @brief  Disable event on the RTC Alarm associated Exti line.
716   * @retval None
717   */
718 #define __HAL_RTC_ALARM_EXTI_DISABLE_EVENT()         (EXTI->EMR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
719 
720 /**
721   * @brief  Enable falling edge trigger on the RTC Alarm associated Exti line.
722   * @retval None
723   */
724 #define __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
725 
726 /**
727   * @brief  Disable falling edge trigger on the RTC Alarm associated Exti line.
728   * @retval None
729   */
730 #define __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
731 
732 /**
733   * @brief  Enable rising edge trigger on the RTC Alarm associated Exti line.
734   * @retval None
735   */
736 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
737 
738 /**
739   * @brief  Disable rising edge trigger on the RTC Alarm associated Exti line.
740   * @retval None
741   */
742 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR1 &= ~(RTC_EXTI_LINE_ALARM_EVENT))
743 
744 /**
745   * @brief  Enable rising & falling edge trigger on the RTC Alarm associated Exti line.
746   * @retval None
747   */
748 #define __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING_EDGE()  do { \
749                                                                 __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE();  \
750                                                                 __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE(); \
751                                                               } while(0)
752 
753 /**
754   * @brief  Disable rising & falling edge trigger on the RTC Alarm associated Exti line.
755   * @retval None
756   */
757 #define __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
758                                                                 __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE();  \
759                                                                 __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE(); \
760                                                               } while(0)
761 
762 /**
763   * @brief  set rising edge interrupt on the RTC Alarm associated Exti line.
764   * @retval None
765   */
766 #define __HAL_RTC_ALARM_EXTI_RISING_IT()            (EXTI->RTSR1 |= RTC_EXTI_LINE_ALARM_EVENT)
767 
768 /**
769   * @brief  set rising edge interrupt on the RTC Alarm associated Exti line.
770   * @retval None
771   */
772 #define __HAL_RTC_ALARM_EXTI_FALLING_IT()            (EXTI->FSTR1 |= RTC_EXTI_LINE_ALARM_EVENT)
773 
774 /**
775   * @brief  clear interrupt on the RTC Alarm associated Exti line.
776   * @retval None
777   */
778 #define __HAL_RTC_ALARM_EXTI_CLEAR_IT()              (EXTI->PR1 = RTC_EXTI_LINE_ALARM_EVENT)
779 
780 
781 /**
782   * @}
783   */
784 
785 /* Include RTC HAL Extended module */
786 #include "stm32g4xx_hal_rtc_ex.h"
787 
788 /* Exported functions --------------------------------------------------------*/
789 /** @defgroup RTC_Exported_Functions RTC Exported Functions
790   * @{
791   */
792 
793 /** @defgroup RTC_Exported_Functions_Group1 Initialization and de-initialization functions
794   * @{
795   */
796 /* Initialization and de-initialization functions  ****************************/
797 HAL_StatusTypeDef HAL_RTC_Init(RTC_HandleTypeDef *hrtc);
798 HAL_StatusTypeDef HAL_RTC_DeInit(RTC_HandleTypeDef *hrtc);
799 
800 void HAL_RTC_MspInit(RTC_HandleTypeDef *hrtc);
801 void HAL_RTC_MspDeInit(RTC_HandleTypeDef *hrtc);
802 #if (USE_HAL_RTC_REGISTER_CALLBACKS == 1)
803 
804 /* Callbacks Register/UnRegister functions  ***********************************/
805 HAL_StatusTypeDef HAL_RTC_RegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID,
806                                            pRTC_CallbackTypeDef pCallback);
807 HAL_StatusTypeDef HAL_RTC_UnRegisterCallback(RTC_HandleTypeDef *hrtc, HAL_RTC_CallbackIDTypeDef CallbackID);
808 #endif /* USE_HAL_RTC_REGISTER_CALLBACKS */
809 /**
810   * @}
811   */
812 
813 /** @defgroup RTC_Exported_Functions_Group2 RTC Time and Date functions
814   * @{
815   */
816 /* RTC Time and Date functions ************************************************/
817 HAL_StatusTypeDef HAL_RTC_SetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
818 HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format);
819 HAL_StatusTypeDef HAL_RTC_SetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
820 HAL_StatusTypeDef HAL_RTC_GetDate(RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format);
821 void              HAL_RTC_DST_Add1Hour(RTC_HandleTypeDef *hrtc);
822 void              HAL_RTC_DST_Sub1Hour(RTC_HandleTypeDef *hrtc);
823 void              HAL_RTC_DST_SetStoreOperation(RTC_HandleTypeDef *hrtc);
824 void              HAL_RTC_DST_ClearStoreOperation(RTC_HandleTypeDef *hrtc);
825 uint32_t          HAL_RTC_DST_ReadStoreOperation(RTC_HandleTypeDef *hrtc);
826 /**
827   * @}
828   */
829 
830 /** @defgroup RTC_Exported_Functions_Group3 RTC Alarm functions
831   * @{
832   */
833 /* RTC Alarm functions ********************************************************/
834 HAL_StatusTypeDef HAL_RTC_SetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
835 HAL_StatusTypeDef HAL_RTC_SetAlarm_IT(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Format);
836 HAL_StatusTypeDef HAL_RTC_DeactivateAlarm(RTC_HandleTypeDef *hrtc, uint32_t Alarm);
837 HAL_StatusTypeDef HAL_RTC_GetAlarm(RTC_HandleTypeDef *hrtc, RTC_AlarmTypeDef *sAlarm, uint32_t Alarm, uint32_t Format);
838 void              HAL_RTC_AlarmIRQHandler(RTC_HandleTypeDef *hrtc);
839 HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent(RTC_HandleTypeDef *hrtc, uint32_t Timeout);
840 void              HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc);
841 /**
842   * @}
843   */
844 
845 /** @defgroup  RTC_Exported_Functions_Group4 Peripheral Control functions
846   * @{
847   */
848 /* Peripheral Control functions ***********************************************/
849 HAL_StatusTypeDef   HAL_RTC_WaitForSynchro(RTC_HandleTypeDef *hrtc);
850 /**
851   * @}
852   */
853 
854 /** @defgroup RTC_Exported_Functions_Group5 Peripheral State functions
855   * @{
856   */
857 /* Peripheral State functions *************************************************/
858 HAL_RTCStateTypeDef HAL_RTC_GetState(RTC_HandleTypeDef *hrtc);
859 /**
860   * @}
861   */
862 
863 /**
864   * @}
865   */
866 
867 /* Private types -------------------------------------------------------------*/
868 /* Private variables ---------------------------------------------------------*/
869 /* Private constants ---------------------------------------------------------*/
870 /** @defgroup RTC_Private_Constants RTC Private Constants
871   * @{
872   */
873 /* Masks Definition */
874 #define RTC_TR_RESERVED_MASK                (RTC_TR_PM | RTC_TR_HT | RTC_TR_HU | \
875                                              RTC_TR_MNT | RTC_TR_MNU| RTC_TR_ST | \
876                                              RTC_TR_SU)
877 #define RTC_DR_RESERVED_MASK                (RTC_DR_YT | RTC_DR_YU | RTC_DR_WDU | \
878                                              RTC_DR_MT | RTC_DR_MU | RTC_DR_DT  | \
879                                              RTC_DR_DU)
880 #define RTC_INIT_MASK                       0xFFFFFFFFU
881 
882 #define RTC_TIMEOUT_VALUE                   1000U
883 
884 /**
885   * @}
886   */
887 
888 /* Private macros ------------------------------------------------------------*/
889 /** @defgroup RTC_Private_Macros RTC Private Macros
890   * @{
891   */
892 
893 /** @defgroup RTC_IS_RTC_Definitions RTC Private macros to check input parameters
894   * @{
895   */
896 #define IS_RTC_OUTPUT(OUTPUT) (((OUTPUT) == RTC_OUTPUT_DISABLE) || \
897                                ((OUTPUT) == RTC_OUTPUT_ALARMA)  || \
898                                ((OUTPUT) == RTC_OUTPUT_ALARMB)  || \
899                                ((OUTPUT) == RTC_OUTPUT_WAKEUP)  || \
900                                ((OUTPUT) == RTC_OUTPUT_TAMPER))
901 
902 #define IS_RTC_HOUR_FORMAT(FORMAT)     (((FORMAT) == RTC_HOURFORMAT_12) || \
903                                         ((FORMAT) == RTC_HOURFORMAT_24))
904 
905 #define IS_RTC_OUTPUT_POL(POL) (((POL) == RTC_OUTPUT_POLARITY_HIGH) || \
906                                 ((POL) == RTC_OUTPUT_POLARITY_LOW))
907 
908 #define IS_RTC_OUTPUT_TYPE(TYPE) (((TYPE) == RTC_OUTPUT_TYPE_OPENDRAIN) || \
909                                   ((TYPE) == RTC_OUTPUT_TYPE_PUSHPULL))
910 
911 #define IS_RTC_OUTPUT_PULLUP(TYPE) (((TYPE) == RTC_OUTPUT_PULLUP_NONE) || \
912                                     ((TYPE) == RTC_OUTPUT_PULLUP_ON))
913 
914 #define IS_RTC_OUTPUT_REMAP(REMAP)   (((REMAP) == RTC_OUTPUT_REMAP_NONE) || \
915                                       ((REMAP) == RTC_OUTPUT_REMAP_POS1))
916 
917 #define IS_RTC_HOURFORMAT12(PM)  (((PM) == RTC_HOURFORMAT12_AM) || \
918                                   ((PM) == RTC_HOURFORMAT12_PM))
919 
920 #define IS_RTC_DAYLIGHT_SAVING(SAVE) (((SAVE) == RTC_DAYLIGHTSAVING_SUB1H) || \
921                                       ((SAVE) == RTC_DAYLIGHTSAVING_ADD1H) || \
922                                       ((SAVE) == RTC_DAYLIGHTSAVING_NONE))
923 
924 #define IS_RTC_STORE_OPERATION(OPERATION) (((OPERATION) == RTC_STOREOPERATION_RESET) || \
925                                            ((OPERATION) == RTC_STOREOPERATION_SET))
926 
927 #define IS_RTC_FORMAT(FORMAT) (((FORMAT) == RTC_FORMAT_BIN) || \
928                                ((FORMAT) == RTC_FORMAT_BCD))
929 
930 #define IS_RTC_YEAR(YEAR)              ((YEAR) <= 99u)
931 
932 #define IS_RTC_MONTH(MONTH)            (((MONTH) >= 1u) && ((MONTH) <= 12u))
933 
934 #define IS_RTC_DATE(DATE)              (((DATE) >= 1u) && ((DATE) <= 31u))
935 
936 #define IS_RTC_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
937                                  ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
938                                  ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
939                                  ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
940                                  ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
941                                  ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
942                                  ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
943 
944 #define IS_RTC_ALARM_DATE_WEEKDAY_DATE(DATE) (((DATE) >0u) && ((DATE) <= 31u))
945 
946 #define IS_RTC_ALARM_DATE_WEEKDAY_WEEKDAY(WEEKDAY) (((WEEKDAY) == RTC_WEEKDAY_MONDAY)    || \
947                                                     ((WEEKDAY) == RTC_WEEKDAY_TUESDAY)   || \
948                                                     ((WEEKDAY) == RTC_WEEKDAY_WEDNESDAY) || \
949                                                     ((WEEKDAY) == RTC_WEEKDAY_THURSDAY)  || \
950                                                     ((WEEKDAY) == RTC_WEEKDAY_FRIDAY)    || \
951                                                     ((WEEKDAY) == RTC_WEEKDAY_SATURDAY)  || \
952                                                     ((WEEKDAY) == RTC_WEEKDAY_SUNDAY))
953 
954 #define IS_RTC_ALARM_DATE_WEEKDAY_SEL(SEL) (((SEL) == RTC_ALARMDATEWEEKDAYSEL_DATE) || \
955                                             ((SEL) == RTC_ALARMDATEWEEKDAYSEL_WEEKDAY))
956 
957 #define IS_RTC_ALARM_MASK(MASK)  (((MASK) & ~(RTC_ALARMMASK_ALL)) == 0UL)
958 
959 #define IS_RTC_ALARM(ALARM)      (((ALARM) == RTC_ALARM_A) || \
960                                   ((ALARM) == RTC_ALARM_B))
961 
962 #define IS_RTC_ALARM_SUB_SECOND_VALUE(VALUE) ((VALUE) <= RTC_ALRMASSR_SS)
963 
964 #define IS_RTC_ALARM_SUB_SECOND_MASK(MASK)          (((MASK) == 0UL) || \
965                                                      (((MASK) >= RTC_ALARMSUBSECONDMASK_SS14_1) && ((MASK) <= RTC_ALARMSUBSECONDMASK_NONE)))
966 
967 #define IS_RTC_ASYNCH_PREDIV(PREDIV)   ((PREDIV) <= (RTC_PRER_PREDIV_A >> RTC_PRER_PREDIV_A_Pos))
968 
969 #define IS_RTC_SYNCH_PREDIV(PREDIV)    ((PREDIV) <= (RTC_PRER_PREDIV_S >> RTC_PRER_PREDIV_S_Pos))
970 
971 #define IS_RTC_HOUR12(HOUR)            (((HOUR) > 0u) && ((HOUR) <= 12u))
972 
973 #define IS_RTC_HOUR24(HOUR)            ((HOUR) <= 23u)
974 
975 #define IS_RTC_MINUTES(MINUTES)        ((MINUTES) <= 59u)
976 
977 #define IS_RTC_SECONDS(SECONDS)        ((SECONDS) <= 59u)
978 
979 /**
980   * @}
981   */
982 
983 /**
984   * @}
985   */
986 
987 /* Private functions -------------------------------------------------------------*/
988 /** @defgroup RTC_Private_Functions RTC Private Functions
989   * @{
990   */
991 HAL_StatusTypeDef  RTC_EnterInitMode(RTC_HandleTypeDef *hrtc);
992 HAL_StatusTypeDef  RTC_ExitInitMode(RTC_HandleTypeDef *hrtc);
993 uint8_t            RTC_ByteToBcd2(uint8_t Value);
994 uint8_t            RTC_Bcd2ToByte(uint8_t Value);
995 /**
996   * @}
997   */
998 
999 
1000 /**
1001   * @}
1002   */
1003 
1004 /**
1005   * @}
1006   */
1007 
1008 #ifdef __cplusplus
1009 }
1010 #endif
1011 
1012 #endif /* STM32G4xx_HAL_RTC_H */
1013