1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_lptim.h
4   * @author  MCD Application Team
5   * @brief   Header file of LPTIM HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 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 STM32F4xx_HAL_LPTIM_H
21 #define STM32F4xx_HAL_LPTIM_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f4xx_hal_def.h"
29 
30 /** @addtogroup STM32F4xx_HAL_Driver
31   * @{
32   */
33 
34 #if defined (LPTIM1)
35 
36 /** @addtogroup LPTIM
37   * @{
38   */
39 
40 /* Exported types ------------------------------------------------------------*/
41 /** @defgroup LPTIM_Exported_Types LPTIM Exported Types
42   * @{
43   */
44 #define LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT  EXTI_IMR_MR23  /*!< External interrupt line 23 Connected to the LPTIM EXTI Line */
45 
46 /**
47   * @brief  LPTIM Clock configuration definition
48   */
49 typedef struct
50 {
51   uint32_t Source;         /*!< Selects the clock source.
52                            This parameter can be a value of @ref LPTIM_Clock_Source   */
53 
54   uint32_t Prescaler;      /*!< Specifies the counter clock Prescaler.
55                            This parameter can be a value of @ref LPTIM_Clock_Prescaler */
56 
57 } LPTIM_ClockConfigTypeDef;
58 
59 /**
60   * @brief  LPTIM Clock configuration definition
61   */
62 typedef struct
63 {
64   uint32_t Polarity;      /*!< Selects the polarity of the active edge for the counter unit
65                            if the ULPTIM input is selected.
66                            Note: This parameter is used only when Ultra low power clock source is used.
67                            Note: If the polarity is configured on 'both edges', an auxiliary clock
68                            (one of the Low power oscillator) must be active.
69                            This parameter can be a value of @ref LPTIM_Clock_Polarity */
70 
71   uint32_t SampleTime;     /*!< Selects the clock sampling time to configure the clock glitch filter.
72                            Note: This parameter is used only when Ultra low power clock source is used.
73                            This parameter can be a value of @ref LPTIM_Clock_Sample_Time */
74 
75 } LPTIM_ULPClockConfigTypeDef;
76 
77 /**
78   * @brief  LPTIM Trigger configuration definition
79   */
80 typedef struct
81 {
82   uint32_t Source;        /*!< Selects the Trigger source.
83                           This parameter can be a value of @ref LPTIM_Trigger_Source */
84 
85   uint32_t ActiveEdge;    /*!< Selects the Trigger active edge.
86                           Note: This parameter is used only when an external trigger is used.
87                           This parameter can be a value of @ref LPTIM_External_Trigger_Polarity */
88 
89   uint32_t SampleTime;    /*!< Selects the trigger sampling time to configure the clock glitch filter.
90                           Note: This parameter is used only when an external trigger is used.
91                           This parameter can be a value of @ref LPTIM_Trigger_Sample_Time  */
92 } LPTIM_TriggerConfigTypeDef;
93 
94 /**
95   * @brief  LPTIM Initialization Structure definition
96   */
97 typedef struct
98 {
99   LPTIM_ClockConfigTypeDef     Clock;             /*!< Specifies the clock parameters */
100 
101   LPTIM_ULPClockConfigTypeDef  UltraLowPowerClock;/*!< Specifies the Ultra Low Power clock parameters */
102 
103   LPTIM_TriggerConfigTypeDef   Trigger;           /*!< Specifies the Trigger parameters */
104 
105   uint32_t                     OutputPolarity;    /*!< Specifies the Output polarity.
106                                                   This parameter can be a value of @ref LPTIM_Output_Polarity */
107 
108   uint32_t                     UpdateMode;        /*!< Specifies whether the update of the autoreload and the compare
109                                                   values is done immediately or after the end of current period.
110                                                   This parameter can be a value of @ref LPTIM_Updating_Mode */
111 
112   uint32_t                     CounterSource;     /*!< Specifies whether the counter is incremented each internal event
113                                                   or each external event.
114                                                   This parameter can be a value of @ref LPTIM_Counter_Source */
115 } LPTIM_InitTypeDef;
116 
117 /**
118   * @brief  HAL LPTIM State structure definition
119   */
120 typedef enum
121 {
122   HAL_LPTIM_STATE_RESET            = 0x00U,    /*!< Peripheral not yet initialized or disabled  */
123   HAL_LPTIM_STATE_READY            = 0x01U,    /*!< Peripheral Initialized and ready for use    */
124   HAL_LPTIM_STATE_BUSY             = 0x02U,    /*!< An internal process is ongoing              */
125   HAL_LPTIM_STATE_TIMEOUT          = 0x03U,    /*!< Timeout state                               */
126   HAL_LPTIM_STATE_ERROR            = 0x04U     /*!< Internal Process is ongoing                 */
127 } HAL_LPTIM_StateTypeDef;
128 
129 /**
130   * @brief  LPTIM handle Structure definition
131   */
132 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
133 typedef struct __LPTIM_HandleTypeDef
134 #else
135 typedef struct
136 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
137 {
138   LPTIM_TypeDef                 *Instance;         /*!< Register base address     */
139 
140   LPTIM_InitTypeDef              Init;             /*!< LPTIM required parameters */
141 
142   HAL_StatusTypeDef              Status;           /*!< LPTIM peripheral status   */
143 
144   HAL_LockTypeDef                Lock;             /*!< LPTIM locking object      */
145 
146   __IO  HAL_LPTIM_StateTypeDef   State;            /*!< LPTIM peripheral state    */
147 
148 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
149   void (* MspInitCallback)(struct __LPTIM_HandleTypeDef *hlptim);            /*!< LPTIM Base Msp Init Callback                 */
150   void (* MspDeInitCallback)(struct __LPTIM_HandleTypeDef *hlptim);          /*!< LPTIM Base Msp DeInit Callback               */
151   void (* CompareMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim);       /*!< Compare match Callback                       */
152   void (* AutoReloadMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim);    /*!< Auto-reload match Callback                   */
153   void (* TriggerCallback)(struct __LPTIM_HandleTypeDef *hlptim);            /*!< External trigger event detection Callback    */
154   void (* CompareWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim);       /*!< Compare register write complete Callback     */
155   void (* AutoReloadWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim);    /*!< Auto-reload register write complete Callback */
156   void (* DirectionUpCallback)(struct __LPTIM_HandleTypeDef *hlptim);        /*!< Up-counting direction change Callback        */
157   void (* DirectionDownCallback)(struct __LPTIM_HandleTypeDef *hlptim);      /*!< Down-counting direction change Callback      */
158 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
159 } LPTIM_HandleTypeDef;
160 
161 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
162 /**
163   * @brief  HAL LPTIM Callback ID enumeration definition
164   */
165 typedef enum
166 {
167   HAL_LPTIM_MSPINIT_CB_ID          = 0x00U,    /*!< LPTIM Base Msp Init Callback ID                  */
168   HAL_LPTIM_MSPDEINIT_CB_ID        = 0x01U,    /*!< LPTIM Base Msp DeInit Callback ID                */
169   HAL_LPTIM_COMPARE_MATCH_CB_ID    = 0x02U,    /*!< Compare match Callback ID                        */
170   HAL_LPTIM_AUTORELOAD_MATCH_CB_ID = 0x03U,    /*!< Auto-reload match Callback ID                    */
171   HAL_LPTIM_TRIGGER_CB_ID          = 0x04U,    /*!< External trigger event detection Callback ID     */
172   HAL_LPTIM_COMPARE_WRITE_CB_ID    = 0x05U,    /*!< Compare register write complete Callback ID      */
173   HAL_LPTIM_AUTORELOAD_WRITE_CB_ID = 0x06U,    /*!< Auto-reload register write complete Callback ID  */
174   HAL_LPTIM_DIRECTION_UP_CB_ID     = 0x07U,    /*!< Up-counting direction change Callback ID         */
175   HAL_LPTIM_DIRECTION_DOWN_CB_ID   = 0x08U,    /*!< Down-counting direction change Callback ID       */
176 } HAL_LPTIM_CallbackIDTypeDef;
177 
178 /**
179   * @brief  HAL TIM Callback pointer definition
180   */
181 typedef  void (*pLPTIM_CallbackTypeDef)(LPTIM_HandleTypeDef *hlptim);  /*!< pointer to the LPTIM callback function */
182 
183 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
184 /**
185   * @}
186   */
187 
188 /* Exported constants --------------------------------------------------------*/
189 /** @defgroup LPTIM_Exported_Constants LPTIM Exported Constants
190   * @{
191   */
192 
193 /** @defgroup LPTIM_Clock_Source LPTIM Clock Source
194   * @{
195   */
196 #define LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC        0x00000000U
197 #define LPTIM_CLOCKSOURCE_ULPTIM                LPTIM_CFGR_CKSEL
198 /**
199   * @}
200   */
201 
202 /** @defgroup LPTIM_Clock_Prescaler LPTIM Clock Prescaler
203   * @{
204   */
205 #define LPTIM_PRESCALER_DIV1                    0x00000000U
206 #define LPTIM_PRESCALER_DIV2                    LPTIM_CFGR_PRESC_0
207 #define LPTIM_PRESCALER_DIV4                    LPTIM_CFGR_PRESC_1
208 #define LPTIM_PRESCALER_DIV8                    (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_1)
209 #define LPTIM_PRESCALER_DIV16                   LPTIM_CFGR_PRESC_2
210 #define LPTIM_PRESCALER_DIV32                   (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_2)
211 #define LPTIM_PRESCALER_DIV64                   (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_2)
212 #define LPTIM_PRESCALER_DIV128                  LPTIM_CFGR_PRESC
213 /**
214   * @}
215   */
216 
217 /** @defgroup LPTIM_Output_Polarity LPTIM Output Polarity
218   * @{
219   */
220 
221 #define LPTIM_OUTPUTPOLARITY_HIGH               0x00000000U
222 #define LPTIM_OUTPUTPOLARITY_LOW                LPTIM_CFGR_WAVPOL
223 /**
224   * @}
225   */
226 
227 /** @defgroup LPTIM_Clock_Sample_Time LPTIM Clock Sample Time
228   * @{
229   */
230 #define LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION  0x00000000U
231 #define LPTIM_CLOCKSAMPLETIME_2TRANSITIONS      LPTIM_CFGR_CKFLT_0
232 #define LPTIM_CLOCKSAMPLETIME_4TRANSITIONS      LPTIM_CFGR_CKFLT_1
233 #define LPTIM_CLOCKSAMPLETIME_8TRANSITIONS      LPTIM_CFGR_CKFLT
234 /**
235   * @}
236   */
237 
238 /** @defgroup LPTIM_Clock_Polarity LPTIM Clock Polarity
239   * @{
240   */
241 #define LPTIM_CLOCKPOLARITY_RISING              0x00000000U
242 #define LPTIM_CLOCKPOLARITY_FALLING             LPTIM_CFGR_CKPOL_0
243 #define LPTIM_CLOCKPOLARITY_RISING_FALLING      LPTIM_CFGR_CKPOL_1
244 /**
245   * @}
246   */
247 
248 /** @defgroup LPTIM_Trigger_Source LPTIM Trigger Source
249   * @{
250   */
251 #define LPTIM_TRIGSOURCE_SOFTWARE               0x0000FFFFU
252 #define LPTIM_TRIGSOURCE_0                      0x00000000U
253 #define LPTIM_TRIGSOURCE_1                      LPTIM_CFGR_TRIGSEL_0
254 #define LPTIM_TRIGSOURCE_2                      LPTIM_CFGR_TRIGSEL_1
255 #define LPTIM_TRIGSOURCE_3                      (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_1)
256 #define LPTIM_TRIGSOURCE_4                      LPTIM_CFGR_TRIGSEL_2
257 #define LPTIM_TRIGSOURCE_5                      (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_2)
258 /**
259   * @}
260   */
261 
262 /** @defgroup LPTIM_External_Trigger_Polarity LPTIM External Trigger Polarity
263   * @{
264   */
265 #define LPTIM_ACTIVEEDGE_RISING                LPTIM_CFGR_TRIGEN_0
266 #define LPTIM_ACTIVEEDGE_FALLING               LPTIM_CFGR_TRIGEN_1
267 #define LPTIM_ACTIVEEDGE_RISING_FALLING        LPTIM_CFGR_TRIGEN
268 /**
269   * @}
270   */
271 
272 /** @defgroup LPTIM_Trigger_Sample_Time LPTIM Trigger Sample Time
273   * @{
274   */
275 #define LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION  0x00000000U
276 #define LPTIM_TRIGSAMPLETIME_2TRANSITIONS      LPTIM_CFGR_TRGFLT_0
277 #define LPTIM_TRIGSAMPLETIME_4TRANSITIONS      LPTIM_CFGR_TRGFLT_1
278 #define LPTIM_TRIGSAMPLETIME_8TRANSITIONS      LPTIM_CFGR_TRGFLT
279 /**
280   * @}
281   */
282 
283 /** @defgroup LPTIM_Updating_Mode LPTIM Updating Mode
284   * @{
285   */
286 
287 #define LPTIM_UPDATE_IMMEDIATE                  0x00000000U
288 #define LPTIM_UPDATE_ENDOFPERIOD                LPTIM_CFGR_PRELOAD
289 /**
290   * @}
291   */
292 
293 /** @defgroup LPTIM_Counter_Source LPTIM Counter Source
294   * @{
295   */
296 
297 #define LPTIM_COUNTERSOURCE_INTERNAL            0x00000000U
298 #define LPTIM_COUNTERSOURCE_EXTERNAL            LPTIM_CFGR_COUNTMODE
299 /**
300   * @}
301   */
302 
303 /** @defgroup LPTIM_Flag_Definition LPTIM Flags Definition
304   * @{
305   */
306 
307 #define LPTIM_FLAG_DOWN                          LPTIM_ISR_DOWN
308 #define LPTIM_FLAG_UP                            LPTIM_ISR_UP
309 #define LPTIM_FLAG_ARROK                         LPTIM_ISR_ARROK
310 #define LPTIM_FLAG_CMPOK                         LPTIM_ISR_CMPOK
311 #define LPTIM_FLAG_EXTTRIG                       LPTIM_ISR_EXTTRIG
312 #define LPTIM_FLAG_ARRM                          LPTIM_ISR_ARRM
313 #define LPTIM_FLAG_CMPM                          LPTIM_ISR_CMPM
314 /**
315   * @}
316   */
317 
318 /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition
319   * @{
320   */
321 #define LPTIM_IT_DOWN                            LPTIM_IER_DOWNIE
322 #define LPTIM_IT_UP                              LPTIM_IER_UPIE
323 #define LPTIM_IT_ARROK                           LPTIM_IER_ARROKIE
324 #define LPTIM_IT_CMPOK                           LPTIM_IER_CMPOKIE
325 #define LPTIM_IT_EXTTRIG                         LPTIM_IER_EXTTRIGIE
326 #define LPTIM_IT_ARRM                            LPTIM_IER_ARRMIE
327 #define LPTIM_IT_CMPM                            LPTIM_IER_CMPMIE
328 /**
329   * @}
330   */
331 
332 /** @defgroup LPTIM_Option Register Definition
333   * @{
334   */
335 #define LPTIM_OP_PAD_AF                          0x00000000U
336 #define LPTIM_OP_PAD_PA4                         LPTIM_OR_LPT_IN1_RMP_0
337 #define LPTIM_OP_PAD_PB9                         LPTIM_OR_LPT_IN1_RMP_1
338 #define LPTIM_OP_TIM_DAC                         LPTIM_OR_LPT_IN1_RMP
339 /**
340   * @}
341   */
342 
343 /**
344   * @}
345   */
346 
347 /* Exported macros -----------------------------------------------------------*/
348 /** @defgroup LPTIM_Exported_Macros LPTIM Exported Macros
349   * @{
350   */
351 
352 /** @brief Reset LPTIM handle state.
353   * @param  __HANDLE__ LPTIM handle
354   * @retval None
355   */
356 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
357 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do {                                                        \
358                                                         (__HANDLE__)->State             = HAL_LPTIM_STATE_RESET; \
359                                                         (__HANDLE__)->MspInitCallback   = NULL;                  \
360                                                         (__HANDLE__)->MspDeInitCallback = NULL;                  \
361                                                       } while(0)
362 #else
363 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET)
364 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
365 
366 /**
367   * @brief  Enable the LPTIM peripheral.
368   * @param  __HANDLE__ LPTIM handle
369   * @retval None
370   */
371 #define __HAL_LPTIM_ENABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR |= (LPTIM_CR_ENABLE))
372 
373 /**
374   * @brief  Disable the LPTIM peripheral.
375   * @param  __HANDLE__ LPTIM handle
376   * @note   The following sequence is required to solve LPTIM disable HW limitation.
377   *         Please check Errata Sheet ES0335 for more details under "MCU may remain
378   *         stuck in LPTIM interrupt when entering Stop mode" section.
379   * @note   Please call @ref HAL_LPTIM_GetState() after a call to __HAL_LPTIM_DISABLE to
380   *         check for TIMEOUT.
381   * @retval None
382   */
383 #define __HAL_LPTIM_DISABLE(__HANDLE__)   LPTIM_Disable(__HANDLE__)
384 
385 /**
386   * @brief  Start the LPTIM peripheral in Continuous mode.
387   * @param  __HANDLE__ LPTIM handle
388   * @retval None
389   */
390 #define __HAL_LPTIM_START_CONTINUOUS(__HANDLE__)  ((__HANDLE__)->Instance->CR |=  LPTIM_CR_CNTSTRT)
391 /**
392   * @brief  Start the LPTIM peripheral in single mode.
393   * @param  __HANDLE__ LPTIM handle
394   * @retval None
395   */
396 #define __HAL_LPTIM_START_SINGLE(__HANDLE__)      ((__HANDLE__)->Instance->CR |=  LPTIM_CR_SNGSTRT)
397 
398 /**
399   * @brief  Write the passed parameter in the Autoreload register.
400   * @param  __HANDLE__ LPTIM handle
401   * @param  __VALUE__ Autoreload value
402   * @retval None
403   * @note   The ARR register can only be modified when the LPTIM instance is enabled.
404   */
405 #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__)  ((__HANDLE__)->Instance->ARR =  (__VALUE__))
406 
407 /**
408   * @brief  Write the passed parameter in the Compare register.
409   * @param  __HANDLE__ LPTIM handle
410   * @param  __VALUE__ Compare value
411   * @retval None
412   * @note   The CMP register can only be modified when the LPTIM instance is enabled.
413   */
414 #define __HAL_LPTIM_COMPARE_SET(__HANDLE__ , __VALUE__)     ((__HANDLE__)->Instance->CMP =  (__VALUE__))
415 
416 /**
417   * @brief  Check whether the specified LPTIM flag is set or not.
418   * @param  __HANDLE__ LPTIM handle
419   * @param  __FLAG__ LPTIM flag to check
420   *            This parameter can be a value of:
421   *            @arg LPTIM_FLAG_DOWN    : Counter direction change up Flag.
422   *            @arg LPTIM_FLAG_UP      : Counter direction change down to up Flag.
423   *            @arg LPTIM_FLAG_ARROK   : Autoreload register update OK Flag.
424   *            @arg LPTIM_FLAG_CMPOK   : Compare register update OK Flag.
425   *            @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag.
426   *            @arg LPTIM_FLAG_ARRM    : Autoreload match Flag.
427   *            @arg LPTIM_FLAG_CMPM    : Compare match Flag.
428   * @retval The state of the specified flag (SET or RESET).
429   */
430 #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__)          (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__))
431 
432 /**
433   * @brief  Clear the specified LPTIM flag.
434   * @param  __HANDLE__ LPTIM handle.
435   * @param  __FLAG__ LPTIM flag to clear.
436   *            This parameter can be a value of:
437   *            @arg LPTIM_FLAG_DOWN    : Counter direction change up Flag.
438   *            @arg LPTIM_FLAG_UP      : Counter direction change down to up Flag.
439   *            @arg LPTIM_FLAG_ARROK   : Autoreload register update OK Flag.
440   *            @arg LPTIM_FLAG_CMPOK   : Compare register update OK Flag.
441   *            @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag.
442   *            @arg LPTIM_FLAG_ARRM    : Autoreload match Flag.
443   *            @arg LPTIM_FLAG_CMPM    : Compare match Flag.
444   * @retval None.
445   */
446 #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__)        ((__HANDLE__)->Instance->ICR  = (__FLAG__))
447 
448 /**
449   * @brief  Enable the specified LPTIM interrupt.
450   * @param  __HANDLE__ LPTIM handle.
451   * @param  __INTERRUPT__ LPTIM interrupt to set.
452   *            This parameter can be a value of:
453   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
454   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
455   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
456   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
457   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
458   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
459   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
460   * @retval None.
461   * @note   The LPTIM interrupts can only be enabled when the LPTIM instance is disabled.
462   */
463 #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->IER  |= (__INTERRUPT__))
464 
465 /**
466   * @brief  Disable the specified LPTIM interrupt.
467   * @param  __HANDLE__ LPTIM handle.
468   * @param  __INTERRUPT__ LPTIM interrupt to set.
469   *            This parameter can be a value of:
470   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
471   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
472   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
473   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
474   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
475   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
476   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
477   * @retval None.
478   * @note   The LPTIM interrupts can only be disabled when the LPTIM instance is disabled.
479   */
480 #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IER  &= (~(__INTERRUPT__)))
481 
482 /**
483   * @brief  Check whether the specified LPTIM interrupt source is enabled or not.
484   * @param  __HANDLE__ LPTIM handle.
485   * @param  __INTERRUPT__ LPTIM interrupt to check.
486   *            This parameter can be a value of:
487   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
488   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
489   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
490   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
491   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
492   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
493   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
494   * @retval Interrupt status.
495   */
496 
497 #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER\
498                                                                 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
499 
500 /** @brief  LPTIM Option Register
501   * @param  __HANDLE__ LPTIM handle
502   * @param   __VALUE__ This parameter can be a value of :
503   *            @arg  LPTIM_OP_PAD_AF
504   *            @arg  LPTIM_OP_PAD_PA4
505   *            @arg  LPTIM_OP_PAD_PB9
506   *            @arg  LPTIM_OP_TIM_DAC
507   * @retval None
508   */
509 #define __HAL_LPTIM_OPTR_CONFIG(__HANDLE__ , __VALUE__)     ((__HANDLE__)->Instance->OR  =  (__VALUE__))
510 
511 
512 /**
513   * @brief  Enable interrupt on the LPTIM Wake-up Timer associated Exti line.
514   * @retval None
515   */
516 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT()       (EXTI->IMR\
517                                                         |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
518 
519 /**
520   * @brief  Disable interrupt on the LPTIM Wake-up Timer associated Exti line.
521   * @retval None
522   */
523 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT()      (EXTI->IMR\
524                                                         &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
525 
526 /**
527   * @brief  Enable event on the LPTIM Wake-up Timer associated Exti line.
528   * @retval None.
529   */
530 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_EVENT()    (EXTI->EMR\
531                                                         |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
532 
533 /**
534   * @brief  Disable event on the LPTIM Wake-up Timer associated Exti line.
535   * @retval None.
536   */
537 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_EVENT()   (EXTI->EMR\
538                                                         &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
539 #if defined(EXTI_IMR_MR23)
540 
541 /**
542   * @brief  Enable falling edge trigger on the LPTIM Wake-up Timer associated Exti line.
543   * @retval None.
544   */
545 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE()   (EXTI->FTSR\
546                                                               |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
547 
548 /**
549   * @brief  Disable falling edge trigger on the LPTIM Wake-up Timer associated Exti line.
550   * @retval None.
551   */
552 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE()  (EXTI->FTSR\
553                                                               &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
554 
555 /**
556   * @brief  Enable rising edge trigger on the LPTIM Wake-up Timer associated Exti line.
557   * @retval None.
558   */
559 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE()    (EXTI->RTSR\
560                                                               |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
561 
562 /**
563   * @brief  Disable rising edge trigger on the LPTIM Wake-up Timer associated Exti line.
564   * @retval None.
565   */
566 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE()   (EXTI->RTSR\
567                                                               &= ~(LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT))
568 
569 /**
570   * @brief  Enable rising & falling edge trigger on the LPTIM Wake-up Timer associated Exti line.
571   * @retval None.
572   */
573 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_FALLING_EDGE() do{__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();\
574                                                                      __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_FALLING_EDGE();\
575                                                                     }while(0)
576 
577 /**
578   * @brief  Disable rising & falling edge trigger on the LPTIM Wake-up Timer associated Exti line.
579   * @retval None.
580   */
581 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_FALLING_EDGE() do{__HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();\
582                                                                        __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_FALLING_EDGE();\
583                                                                      }while(0)
584 
585 /**
586   * @brief Check whether the LPTIM Wake-up Timer associated Exti line interrupt flag is set or not.
587   * @retval Line Status.
588   */
589 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_GET_FLAG()              (EXTI->PR\
590                                                               & LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
591 
592 /**
593   * @brief Clear the LPTIM Wake-up Timer associated Exti line flag.
594   * @retval None.
595   */
596 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG()            (EXTI->PR\
597                                                               = LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
598 
599 /**
600   * @brief Generate a Software interrupt on the LPTIM Wake-up Timer associated Exti line.
601   * @retval None.
602   */
603 #define __HAL_LPTIM_WAKEUPTIMER_EXTI_GENERATE_SWIT()         (EXTI->SWIER\
604                                                               |= LPTIM_EXTI_LINE_WAKEUPTIMER_EVENT)
605 #endif /* EXTI_IMR_MR23 */
606 
607 /**
608   * @}
609   */
610 
611 /* Exported functions --------------------------------------------------------*/
612 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
613   * @{
614   */
615 
616 /** @addtogroup LPTIM_Exported_Functions_Group1
617   *  @brief    Initialization and Configuration functions.
618   * @{
619   */
620 /* Initialization/de-initialization functions  ********************************/
621 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim);
622 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim);
623 
624 /* MSP functions  *************************************************************/
625 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim);
626 void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim);
627 /**
628   * @}
629   */
630 
631 /** @addtogroup LPTIM_Exported_Functions_Group2
632   *  @brief   Start-Stop operation functions.
633   * @{
634   */
635 /* Start/Stop operation functions  *********************************************/
636 /* ################################# PWM Mode ################################*/
637 /* Blocking mode: Polling */
638 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
639 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim);
640 /* Non-Blocking mode: Interrupt */
641 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
642 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim);
643 
644 /* ############################# One Pulse Mode ##############################*/
645 /* Blocking mode: Polling */
646 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
647 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim);
648 /* Non-Blocking mode: Interrupt */
649 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
650 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim);
651 
652 /* ############################## Set once Mode ##############################*/
653 /* Blocking mode: Polling */
654 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
655 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim);
656 /* Non-Blocking mode: Interrupt */
657 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
658 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim);
659 
660 /* ############################### Encoder Mode ##############################*/
661 /* Blocking mode: Polling */
662 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
663 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim);
664 /* Non-Blocking mode: Interrupt */
665 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
666 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim);
667 
668 /* ############################# Time out  Mode ##############################*/
669 /* Blocking mode: Polling */
670 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
671 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim);
672 /* Non-Blocking mode: Interrupt */
673 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
674 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim);
675 
676 /* ############################## Counter Mode ###############################*/
677 /* Blocking mode: Polling */
678 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
679 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim);
680 /* Non-Blocking mode: Interrupt */
681 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
682 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim);
683 /**
684   * @}
685   */
686 
687 /** @addtogroup LPTIM_Exported_Functions_Group3
688   *  @brief  Read operation functions.
689   * @{
690   */
691 /* Reading operation functions ************************************************/
692 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim);
693 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim);
694 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim);
695 /**
696   * @}
697   */
698 
699 /** @addtogroup LPTIM_Exported_Functions_Group4
700   *  @brief  LPTIM IRQ handler and callback functions.
701   * @{
702   */
703 /* LPTIM IRQ functions  *******************************************************/
704 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim);
705 
706 /* CallBack functions  ********************************************************/
707 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim);
708 void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim);
709 void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim);
710 void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim);
711 void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim);
712 void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim);
713 void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim);
714 
715 /* Callbacks Register/UnRegister functions  ***********************************/
716 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
717 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID,
718                                              pLPTIM_CallbackTypeDef pCallback);
719 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID);
720 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
721 /**
722   * @}
723   */
724 
725 /** @addtogroup LPTIM_Group5
726   *  @brief   Peripheral State functions.
727   * @{
728   */
729 /* Peripheral State functions  ************************************************/
730 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim);
731 /**
732   * @}
733   */
734 
735 /**
736   * @}
737   */
738 
739 /* Private types -------------------------------------------------------------*/
740 /** @defgroup LPTIM_Private_Types LPTIM Private Types
741   * @{
742   */
743 
744 /**
745   * @}
746   */
747 
748 /* Private variables ---------------------------------------------------------*/
749 /** @defgroup LPTIM_Private_Variables LPTIM Private Variables
750   * @{
751   */
752 
753 /**
754   * @}
755   */
756 
757 /* Private constants ---------------------------------------------------------*/
758 /** @defgroup LPTIM_Private_Constants LPTIM Private Constants
759   * @{
760   */
761 
762 /**
763   * @}
764   */
765 
766 /* Private macros ------------------------------------------------------------*/
767 /** @defgroup LPTIM_Private_Macros LPTIM Private Macros
768   * @{
769   */
770 
771 #define IS_LPTIM_CLOCK_SOURCE(__SOURCE__)       (((__SOURCE__) == LPTIM_CLOCKSOURCE_ULPTIM) || \
772                                                  ((__SOURCE__) == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC))
773 
774 
775 #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) ==  LPTIM_PRESCALER_DIV1  ) || \
776                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV2  ) || \
777                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV4  ) || \
778                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV8  ) || \
779                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV16 ) || \
780                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV32 ) || \
781                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV64 ) || \
782                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV128))
783 
784 #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV1)
785 
786 #define IS_LPTIM_OUTPUT_POLARITY(__POLARITY__)  (((__POLARITY__) == LPTIM_OUTPUTPOLARITY_LOW ) || \
787                                                  ((__POLARITY__) == LPTIM_OUTPUTPOLARITY_HIGH))
788 
789 #define IS_LPTIM_CLOCK_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION) || \
790                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_2TRANSITIONS)     || \
791                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_4TRANSITIONS)     || \
792                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_8TRANSITIONS))
793 
794 #define IS_LPTIM_CLOCK_POLARITY(__POLARITY__)   (((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING)  || \
795                                                  ((__POLARITY__) == LPTIM_CLOCKPOLARITY_FALLING) || \
796                                                  ((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING_FALLING))
797 
798 #define IS_LPTIM_TRG_SOURCE(__TRIG__)           (((__TRIG__) == LPTIM_TRIGSOURCE_SOFTWARE) || \
799                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_0) || \
800                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_1) || \
801                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_2) || \
802                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_3) || \
803                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_4) || \
804                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_5))
805 
806 #define IS_LPTIM_EXT_TRG_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING         ) || \
807                                                  ((__POLARITY__) == LPTIM_ACTIVEEDGE_FALLING        ) || \
808                                                  ((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING_FALLING ))
809 
810 #define IS_LPTIM_TRIG_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION) || \
811                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_2TRANSITIONS    ) || \
812                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_4TRANSITIONS    ) || \
813                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_8TRANSITIONS    ))
814 
815 #define IS_LPTIM_UPDATE_MODE(__MODE__)          (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \
816                                                  ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD))
817 
818 #define IS_LPTIM_COUNTER_SOURCE(__SOURCE__)     (((__SOURCE__) == LPTIM_COUNTERSOURCE_INTERNAL) || \
819                                                  ((__SOURCE__) == LPTIM_COUNTERSOURCE_EXTERNAL))
820 
821 #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__)     ((0x00000001UL <= (__AUTORELOAD__)) &&\
822                                                  ((__AUTORELOAD__) <= 0x0000FFFFUL))
823 
824 #define IS_LPTIM_COMPARE(__COMPARE__)           ((__COMPARE__) <= 0x0000FFFFUL)
825 
826 #define IS_LPTIM_PERIOD(__PERIOD__)             ((0x00000001UL <= (__PERIOD__)) &&\
827                                                  ((__PERIOD__) <= 0x0000FFFFUL))
828 
829 #define IS_LPTIM_PULSE(__PULSE__)               ((__PULSE__) <= 0x0000FFFFUL)
830 
831 /**
832   * @}
833   */
834 
835 /* Private functions ---------------------------------------------------------*/
836 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
837   * @{
838   */
839 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim);
840 /**
841   * @}
842   */
843 
844 /**
845   * @}
846   */
847 
848 #endif /* LPTIM1 */
849 /**
850   * @}
851   */
852 
853 #ifdef __cplusplus
854 }
855 #endif
856 
857 #endif /* STM32F4xx_HAL_LPTIM_H */
858