1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_hal_lptim.h
4   * @author  MCD Application Team
5   * @brief   Header file of LPTIM HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L4xx_HAL_LPTIM_H
38 #define __STM32L4xx_HAL_LPTIM_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l4xx_hal_def.h"
46 
47 /** @addtogroup STM32L4xx_HAL_Driver
48   * @{
49   */
50 
51 /** @addtogroup LPTIM
52   * @{
53   */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup LPTIM_Exported_Types LPTIM Exported Types
57   * @{
58   */
59 
60 /**
61   * @brief  LPTIM Clock configuration definition
62   */
63 typedef struct
64 {
65   uint32_t Source;         /*!< Selects the clock source.
66                            This parameter can be a value of @ref LPTIM_Clock_Source   */
67 
68   uint32_t Prescaler;      /*!< Specifies the counter clock Prescaler.
69                            This parameter can be a value of @ref LPTIM_Clock_Prescaler */
70 
71 }LPTIM_ClockConfigTypeDef;
72 
73 /**
74   * @brief  LPTIM Clock configuration definition
75   */
76 typedef struct
77 {
78   uint32_t Polarity;      /*!< Selects the polarity of the active edge for the counter unit
79                            if the ULPTIM input is selected.
80                            Note: This parameter is used only when Ultra low power clock source is used.
81                            Note: If the polarity is configured on 'both edges', an auxiliary clock
82                            (one of the Low power oscillator) must be active.
83                            This parameter can be a value of @ref LPTIM_Clock_Polarity */
84 
85   uint32_t SampleTime;     /*!< Selects the clock sampling time to configure the clock glitch filter.
86                            Note: This parameter is used only when Ultra low power clock source is used.
87                            This parameter can be a value of @ref LPTIM_Clock_Sample_Time */
88 
89 }LPTIM_ULPClockConfigTypeDef;
90 
91 /**
92   * @brief  LPTIM Trigger configuration definition
93   */
94 typedef struct
95 {
96   uint32_t Source;        /*!< Selects the Trigger source.
97                           This parameter can be a value of @ref LPTIM_Trigger_Source */
98 
99   uint32_t ActiveEdge;    /*!< Selects the Trigger active edge.
100                           Note: This parameter is used only when an external trigger is used.
101                           This parameter can be a value of @ref LPTIM_External_Trigger_Polarity */
102 
103   uint32_t SampleTime;    /*!< Selects the trigger sampling time to configure the clock glitch filter.
104                           Note: This parameter is used only when an external trigger is used.
105                           This parameter can be a value of @ref LPTIM_Trigger_Sample_Time  */
106 }LPTIM_TriggerConfigTypeDef;
107 
108 /**
109   * @brief  LPTIM Initialization Structure definition
110   */
111 typedef struct
112 {
113   LPTIM_ClockConfigTypeDef     Clock;               /*!< Specifies the clock parameters */
114 
115   LPTIM_ULPClockConfigTypeDef  UltraLowPowerClock;  /*!< Specifies the Ultra Low Power clock parameters */
116 
117   LPTIM_TriggerConfigTypeDef   Trigger;             /*!< Specifies the Trigger parameters */
118 
119   uint32_t                     OutputPolarity;      /*!< Specifies the Output polarity.
120                                                     This parameter can be a value of @ref LPTIM_Output_Polarity */
121 
122   uint32_t                     UpdateMode;          /*!< Specifies whether the update of the autoreload and the compare
123                                                     values is done immediately or after the end of current period.
124                                                     This parameter can be a value of @ref LPTIM_Updating_Mode */
125 
126   uint32_t                     CounterSource;       /*!< Specifies whether the counter is incremented each internal event
127                                                     or each external event.
128                                                     This parameter can be a value of @ref LPTIM_Counter_Source */
129 
130   uint32_t                     Input1Source;        /*!< Specifies source selected for input1 (GPIO or comparator output).
131                                                     This parameter can be a value of @ref LPTIM_Input1_Source */
132 
133   uint32_t                     Input2Source;        /*!< Specifies source selected for input2 (GPIO or comparator output).
134                                                     Note: This parameter is used only for encoder feature so is used only
135                                                     for LPTIM1 instance.
136                                                     This parameter can be a value of @ref LPTIM_Input2_Source */
137 
138 #if defined(LPTIM_RCR_REP)
139   uint32_t                     RepetitionCounter;  /*!< Specifies the repetition counter value. Each time the RCR downcounter
140                                                     reaches zero, an update event is generated and counting restarts
141                                                     from the RCR value (N).
142                                                     Note: When using repetition counter the UpdateMode field must be set to
143                                                           LPTIM_UPDATE_ENDOFPERIOD otherwise unpredictable bahavior may occur.
144                                                     This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF. */
145 #endif
146 
147 }LPTIM_InitTypeDef;
148 
149 /**
150   * @brief  HAL LPTIM State structure definition
151   */
152 typedef enum __HAL_LPTIM_StateTypeDef
153 {
154   HAL_LPTIM_STATE_RESET            = 0x00,    /*!< Peripheral not yet initialized or disabled  */
155   HAL_LPTIM_STATE_READY            = 0x01,    /*!< Peripheral Initialized and ready for use    */
156   HAL_LPTIM_STATE_BUSY             = 0x02,    /*!< An internal process is ongoing              */
157   HAL_LPTIM_STATE_TIMEOUT          = 0x03,    /*!< Timeout state                               */
158   HAL_LPTIM_STATE_ERROR            = 0x04     /*!< Internal Process is ongoing                */
159 }HAL_LPTIM_StateTypeDef;
160 
161 /**
162   * @brief  LPTIM handle Structure definition
163   */
164 typedef struct __LPTIM_HandleTypeDef
165 {
166       LPTIM_TypeDef              *Instance;         /*!< Register base address     */
167 
168       LPTIM_InitTypeDef           Init;             /*!< LPTIM required parameters */
169 
170       HAL_StatusTypeDef           Status;           /*!< LPTIM peripheral status   */
171 
172       HAL_LockTypeDef             Lock;             /*!< LPTIM locking object      */
173 
174    __IO  HAL_LPTIM_StateTypeDef   State;            /*!< LPTIM peripheral state    */
175 
176 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
177   void (* MspInitCallback)(struct __LPTIM_HandleTypeDef *hlptim);            /*!< LPTIM Base Msp Init Callback                 */
178   void (* MspDeInitCallback)(struct __LPTIM_HandleTypeDef *hlptim);          /*!< LPTIM Base Msp DeInit Callback               */
179   void (* CompareMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim);       /*!< Compare match Callback                       */
180   void (* AutoReloadMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim);    /*!< Auto-reload match Callback                   */
181   void (* TriggerCallback)(struct __LPTIM_HandleTypeDef *hlptim);            /*!< External trigger event detection Callback    */
182   void (* CompareWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim);       /*!< Compare register write complete Callback     */
183   void (* AutoReloadWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim);    /*!< Auto-reload register write complete Callback */
184   void (* DirectionUpCallback)(struct __LPTIM_HandleTypeDef *hlptim);        /*!< Up-counting direction change Callback        */
185   void (* DirectionDownCallback)(struct __LPTIM_HandleTypeDef *hlptim);      /*!< Down-counting direction change Callback      */
186 #if defined(LPTIM_RCR_REP)
187   void (* UpdateEventCallback)(struct __LPTIM_HandleTypeDef *hlptim);        /*!< Repetition counter underflow Callback        */
188   void (* RepCounterWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim);    /*!< Repetition counter successful write Callback */
189 #endif /* LPTIM_RCR_REP */
190 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
191 }LPTIM_HandleTypeDef;
192 
193 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
194 /**
195   * @brief  HAL LPTIM Callback ID enumeration definition
196   */
197 typedef enum
198 {
199   HAL_LPTIM_MSPINIT_CB_ID          = 0x00U,    /*!< LPTIM Base Msp Init Callback ID                  */
200   HAL_LPTIM_MSPDEINIT_CB_ID        = 0x01U,    /*!< LPTIM Base Msp DeInit Callback ID                */
201   HAL_LPTIM_COMPARE_MATCH_CB_ID    = 0x02U,    /*!< Compare match Callback ID                        */
202   HAL_LPTIM_AUTORELOAD_MATCH_CB_ID = 0x03U,    /*!< Auto-reload match Callback ID                    */
203   HAL_LPTIM_TRIGGER_CB_ID          = 0x04U,    /*!< External trigger event detection Callback ID     */
204   HAL_LPTIM_COMPARE_WRITE_CB_ID    = 0x05U,    /*!< Compare register write complete Callback ID      */
205   HAL_LPTIM_AUTORELOAD_WRITE_CB_ID = 0x06U,    /*!< Auto-reload register write complete Callback ID  */
206   HAL_LPTIM_DIRECTION_UP_CB_ID     = 0x07U,    /*!< Up-counting direction change Callback ID         */
207   HAL_LPTIM_DIRECTION_DOWN_CB_ID   = 0x08U,    /*!< Down-counting direction change Callback ID       */
208 #if defined(LPTIM_RCR_REP)
209   HAL_LPTIM_UPDATE_EVENT_CB_ID     = 0x09U,    /*!< Repetition counter underflow Callback ID         */
210   HAL_LPTIM_REPETITION_WRITE_CB_ID = 0x0AU,    /*!< Repetition counter successful write Callback ID  */
211 #endif /* LPTIM_RCR_REP */
212 } HAL_LPTIM_CallbackIDTypeDef;
213 
214 /**
215   * @brief  HAL TIM Callback pointer definition
216   */
217 typedef  void (*pLPTIM_CallbackTypeDef)(LPTIM_HandleTypeDef *hlptim);  /*!< pointer to the LPTIM callback function */
218 
219 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
220 /**
221   * @}
222   */
223 
224 /* Exported constants --------------------------------------------------------*/
225 /** @defgroup LPTIM_Exported_Constants LPTIM Exported Constants
226   * @{
227   */
228 
229 /** @defgroup LPTIM_Clock_Source LPTIM Clock Source
230   * @{
231   */
232 #define LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC        ((uint32_t)0x00)
233 #define LPTIM_CLOCKSOURCE_ULPTIM                LPTIM_CFGR_CKSEL
234 /**
235   * @}
236   */
237 
238 /** @defgroup LPTIM_Clock_Prescaler LPTIM Clock Prescaler
239   * @{
240   */
241 #define LPTIM_PRESCALER_DIV1                    ((uint32_t)0x000000)
242 #define LPTIM_PRESCALER_DIV2                    LPTIM_CFGR_PRESC_0
243 #define LPTIM_PRESCALER_DIV4                    LPTIM_CFGR_PRESC_1
244 #define LPTIM_PRESCALER_DIV8                    ((uint32_t)(LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_1))
245 #define LPTIM_PRESCALER_DIV16                   LPTIM_CFGR_PRESC_2
246 #define LPTIM_PRESCALER_DIV32                   ((uint32_t)(LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_2))
247 #define LPTIM_PRESCALER_DIV64                   ((uint32_t)(LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_2))
248 #define LPTIM_PRESCALER_DIV128                  ((uint32_t)LPTIM_CFGR_PRESC)
249 /**
250   * @}
251   */
252 
253 /** @defgroup LPTIM_Output_Polarity LPTIM Output Polarity
254   * @{
255   */
256 
257 #define LPTIM_OUTPUTPOLARITY_HIGH               ((uint32_t)0x00000000)
258 #define LPTIM_OUTPUTPOLARITY_LOW                (LPTIM_CFGR_WAVPOL)
259 /**
260   * @}
261   */
262 
263 /** @defgroup LPTIM_Clock_Sample_Time LPTIM Clock Sample Time
264   * @{
265   */
266 #define LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION  ((uint32_t)0x00000000)
267 #define LPTIM_CLOCKSAMPLETIME_2TRANSITIONS      LPTIM_CFGR_CKFLT_0
268 #define LPTIM_CLOCKSAMPLETIME_4TRANSITIONS      LPTIM_CFGR_CKFLT_1
269 #define LPTIM_CLOCKSAMPLETIME_8TRANSITIONS      LPTIM_CFGR_CKFLT
270 /**
271   * @}
272   */
273 
274 /** @defgroup LPTIM_Clock_Polarity LPTIM Clock Polarity
275   * @{
276   */
277 #define LPTIM_CLOCKPOLARITY_RISING              ((uint32_t)0x00000000)
278 #define LPTIM_CLOCKPOLARITY_FALLING             LPTIM_CFGR_CKPOL_0
279 #define LPTIM_CLOCKPOLARITY_RISING_FALLING      LPTIM_CFGR_CKPOL_1
280 /**
281   * @}
282   */
283 
284 /** @defgroup LPTIM_Trigger_Source LPTIM Trigger Source
285   * @{
286   */
287 #define LPTIM_TRIGSOURCE_SOFTWARE               ((uint32_t)0x0000FFFF)
288 #define LPTIM_TRIGSOURCE_0                      ((uint32_t)0x00000000)
289 #define LPTIM_TRIGSOURCE_1                      ((uint32_t)LPTIM_CFGR_TRIGSEL_0)
290 #define LPTIM_TRIGSOURCE_2                      LPTIM_CFGR_TRIGSEL_1
291 #define LPTIM_TRIGSOURCE_3                      ((uint32_t)LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_1)
292 #define LPTIM_TRIGSOURCE_4                      LPTIM_CFGR_TRIGSEL_2
293 #define LPTIM_TRIGSOURCE_5                      ((uint32_t)LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_2)
294 #define LPTIM_TRIGSOURCE_6                      ((uint32_t)LPTIM_CFGR_TRIGSEL_1 | LPTIM_CFGR_TRIGSEL_2)
295 #define LPTIM_TRIGSOURCE_7                      LPTIM_CFGR_TRIGSEL
296 /**
297   * @}
298   */
299 
300 /** @defgroup LPTIM_External_Trigger_Polarity LPTIM External Trigger Polarity
301   * @{
302   */
303 #define LPTIM_ACTIVEEDGE_RISING                LPTIM_CFGR_TRIGEN_0
304 #define LPTIM_ACTIVEEDGE_FALLING               LPTIM_CFGR_TRIGEN_1
305 #define LPTIM_ACTIVEEDGE_RISING_FALLING        LPTIM_CFGR_TRIGEN
306 /**
307   * @}
308   */
309 
310 /** @defgroup LPTIM_Trigger_Sample_Time LPTIM Trigger Sample Time
311   * @{
312   */
313 #define LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION  ((uint32_t)0x00000000)
314 #define LPTIM_TRIGSAMPLETIME_2TRANSITIONS      LPTIM_CFGR_TRGFLT_0
315 #define LPTIM_TRIGSAMPLETIME_4TRANSITIONS      LPTIM_CFGR_TRGFLT_1
316 #define LPTIM_TRIGSAMPLETIME_8TRANSITIONS      LPTIM_CFGR_TRGFLT
317 /**
318   * @}
319   */
320 
321 /** @defgroup LPTIM_Updating_Mode LPTIM Updating Mode
322   * @{
323   */
324 
325 #define LPTIM_UPDATE_IMMEDIATE                  ((uint32_t)0x00000000)
326 #define LPTIM_UPDATE_ENDOFPERIOD                LPTIM_CFGR_PRELOAD
327 /**
328   * @}
329   */
330 
331 /** @defgroup LPTIM_Counter_Source LPTIM Counter Source
332   * @{
333   */
334 
335 #define LPTIM_COUNTERSOURCE_INTERNAL            ((uint32_t)0x00000000)
336 #define LPTIM_COUNTERSOURCE_EXTERNAL            LPTIM_CFGR_COUNTMODE
337 /**
338   * @}
339   */
340 
341 /** @defgroup LPTIM_Input1_Source LPTIM Input1 Source
342   * @{
343   */
344 
345 #define LPTIM_INPUT1SOURCE_GPIO         ((uint32_t)0x00000000) /*!< For LPTIM1 and LPTIM2 */
346 #define LPTIM_INPUT1SOURCE_COMP1        LPTIM_OR_OR_0          /*!< For LPTIM1 and LPTIM2 */
347 #define LPTIM_INPUT1SOURCE_COMP2        LPTIM_OR_OR_1          /*!< For LPTIM2 */
348 #define LPTIM_INPUT1SOURCE_COMP1_COMP2  LPTIM_OR_OR            /*!< For LPTIM2 */
349 /**
350   * @}
351   */
352 
353 /** @defgroup LPTIM_Input2_Source LPTIM Input2 Source
354   * @{
355   */
356 
357 #define LPTIM_INPUT2SOURCE_GPIO         ((uint32_t)0x00000000) /*!< For LPTIM1 */
358 #define LPTIM_INPUT2SOURCE_COMP2        LPTIM_OR_OR_1          /*!< For LPTIM1 */
359 /**
360   * @}
361   */
362 
363 /** @defgroup LPTIM_Flag_Definition LPTIM Flags Definition
364   * @{
365   */
366 #if defined(LPTIM_RCR_REP)
367 #define LPTIM_FLAG_REPOK                         LPTIM_ISR_REPOK
368 #define LPTIM_FLAG_UPDATE                        LPTIM_ISR_UE
369 #endif
370 #define LPTIM_FLAG_DOWN                          LPTIM_ISR_DOWN
371 #define LPTIM_FLAG_UP                            LPTIM_ISR_UP
372 #define LPTIM_FLAG_ARROK                         LPTIM_ISR_ARROK
373 #define LPTIM_FLAG_CMPOK                         LPTIM_ISR_CMPOK
374 #define LPTIM_FLAG_EXTTRIG                       LPTIM_ISR_EXTTRIG
375 #define LPTIM_FLAG_ARRM                          LPTIM_ISR_ARRM
376 #define LPTIM_FLAG_CMPM                          LPTIM_ISR_CMPM
377 /**
378   * @}
379   */
380 
381 /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition
382   * @{
383   */
384 #if defined(LPTIM_RCR_REP)
385 #define LPTIM_IT_REPOK                           LPTIM_IER_REPOKIE
386 #define LPTIM_IT_UPDATE                          LPTIM_IER_UEIE
387 #endif
388 #define LPTIM_IT_DOWN                            LPTIM_IER_DOWNIE
389 #define LPTIM_IT_UP                              LPTIM_IER_UPIE
390 #define LPTIM_IT_ARROK                           LPTIM_IER_ARROKIE
391 #define LPTIM_IT_CMPOK                           LPTIM_IER_CMPOKIE
392 #define LPTIM_IT_EXTTRIG                         LPTIM_IER_EXTTRIGIE
393 #define LPTIM_IT_ARRM                            LPTIM_IER_ARRMIE
394 #define LPTIM_IT_CMPM                            LPTIM_IER_CMPMIE
395 /**
396   * @}
397   */
398 
399 /**
400   * @}
401   */
402 
403 /* Exported macros -----------------------------------------------------------*/
404 /** @defgroup LPTIM_Exported_Macros LPTIM Exported Macros
405   * @{
406   */
407 
408 /** @brief Reset LPTIM handle state.
409   * @param  __HANDLE__: LPTIM handle
410   * @retval None
411   */
412 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
413 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do {                                                        \
414                                                       (__HANDLE__)->State             = HAL_LPTIM_STATE_RESET; \
415                                                       (__HANDLE__)->MspInitCallback   = NULL;                  \
416                                                       (__HANDLE__)->MspDeInitCallback = NULL;                  \
417                                                      } while(0)
418 #else
419 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET)
420 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
421 
422 /**
423   * @brief  Enable the LPTIM peripheral.
424   * @param  __HANDLE__: LPTIM handle
425   * @retval None
426   */
427 #define __HAL_LPTIM_ENABLE(__HANDLE__)   ((__HANDLE__)->Instance->CR |=  (LPTIM_CR_ENABLE))
428 
429 /**
430   * @brief  Disable the LPTIM peripheral.
431   * @param  __HANDLE__: LPTIM handle
432   * @retval None
433   */
434 #define __HAL_LPTIM_DISABLE(__HANDLE__)  ((__HANDLE__)->Instance->CR &=  ~(LPTIM_CR_ENABLE))
435 
436 /**
437   * @brief  Start the LPTIM peripheral in Continuous or in single mode.
438   * @param  __HANDLE__: LPTIM handle
439   * @retval None
440   */
441 #define __HAL_LPTIM_START_CONTINUOUS(__HANDLE__)  ((__HANDLE__)->Instance->CR |=  LPTIM_CR_CNTSTRT)
442 #define __HAL_LPTIM_START_SINGLE(__HANDLE__)      ((__HANDLE__)->Instance->CR |=  LPTIM_CR_SNGSTRT)
443 
444 
445 /**
446   * @brief  Write the passed parameter in the Autoreload register.
447   * @param  __HANDLE__: LPTIM handle
448   * @param  __VALUE__: Autoreload value
449   * @retval None
450   */
451 #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__)  ((__HANDLE__)->Instance->ARR =  (__VALUE__))
452 
453 /**
454   * @brief  Write the passed parameter in the Compare register.
455   * @param  __HANDLE__: LPTIM handle
456   * @param  __VALUE__: Compare value
457   * @retval None
458   */
459 #define __HAL_LPTIM_COMPARE_SET(__HANDLE__ , __VALUE__)     ((__HANDLE__)->Instance->CMP =  (__VALUE__))
460 
461 #if defined(LPTIM_RCR_REP)
462 /**
463   * @brief  Write the passed parameter in the Repetition register.
464   * @param  __HANDLE__: LPTIM handle
465   * @param  __VALUE__: Repetition value
466   * @retval None
467   */
468 #define __HAL_LPTIM_REPETITIONCOUNTER_SET(__HANDLE__ , __VALUE__) \
469   do {                                                            \
470        (__HANDLE__)->Instance->RCR =  (__VALUE__);                \
471        (__HANDLE__)->Init.RepetitionCounter = (__VALUE__);        \
472   } while(0)
473 
474 /**
475   * @brief  Return the current Repetition value.
476   * @param  __HANDLE__: LPTIM handle
477   * @retval Repetition register value
478   */
479 #define __HAL_LPTIM_REPETITIONCOUNTER_GET(__HANDLE__)  ((__HANDLE__)->Instance->RCR)
480 #endif
481 
482 /**
483   * @brief  Check whether the specified LPTIM flag is set or not.
484   * @param  __HANDLE__: LPTIM handle
485   * @param  __FLAG__: LPTIM flag to check
486   *            This parameter can be a value of:
487   *            @arg LPTIM_FLAG_REPOK   : Repetition register update OK Flag (when available).
488   *            @arg LPTIM_FLAG_UPDATE  : Update event Flag (when available).
489   *            @arg LPTIM_FLAG_DOWN    : Counter direction change up Flag.
490   *            @arg LPTIM_FLAG_UP      : Counter direction change down to up Flag.
491   *            @arg LPTIM_FLAG_ARROK   : Autoreload register update OK Flag.
492   *            @arg LPTIM_FLAG_CMPOK   : Compare register update OK Flag.
493   *            @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag.
494   *            @arg LPTIM_FLAG_ARRM    : Autoreload match Flag.
495   *            @arg LPTIM_FLAG_CMPM    : Compare match Flag.
496   * @retval The state of the specified flag (SET or RESET).
497   */
498 #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__)          (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__))
499 
500 /**
501   * @brief  Clear the specified LPTIM flag.
502   * @param  __HANDLE__: LPTIM handle.
503   * @param  __FLAG__: LPTIM flag to clear.
504   *            This parameter can be a value of:
505   *            @arg LPTIM_FLAG_REPOK   : Repetition register update OK Flag (when available).
506   *            @arg LPTIM_FLAG_UPDATE  : Update event Flag (when available).
507   *            @arg LPTIM_FLAG_DOWN    : Counter direction change up Flag.
508   *            @arg LPTIM_FLAG_UP      : Counter direction change down to up Flag.
509   *            @arg LPTIM_FLAG_ARROK   : Autoreload register update OK Flag.
510   *            @arg LPTIM_FLAG_CMPOK   : Compare register update OK Flag.
511   *            @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag.
512   *            @arg LPTIM_FLAG_ARRM    : Autoreload match Flag.
513   *            @arg LPTIM_FLAG_CMPM    : Compare match Flag.
514   * @retval None
515   */
516 #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__)        ((__HANDLE__)->Instance->ICR  = (__FLAG__))
517 
518 /**
519   * @brief  Enable the specified LPTIM interrupt.
520   * @param  __HANDLE__: LPTIM handle.
521   * @param  __INTERRUPT__: LPTIM interrupt to set.
522   *            This parameter can be a value of:
523   *            @arg LPTIM_IT_REPOK   : Repetition register update Interrupt (when available).
524   *            @arg LPTIM_IT_UPDATE  : Update event Interrupt (when available).
525   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
526   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
527   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
528   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
529   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
530   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
531   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
532   * @retval None
533   */
534 #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)    ((__HANDLE__)->Instance->IER  |= (__INTERRUPT__))
535 
536  /**
537   * @brief  Disable the specified LPTIM interrupt.
538   * @param  __HANDLE__: LPTIM handle.
539   * @param  __INTERRUPT__: LPTIM interrupt to set.
540   *            This parameter can be a value of:
541   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
542   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
543   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
544   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
545   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
546   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
547   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
548   * @retval None
549   */
550 #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)   ((__HANDLE__)->Instance->IER  &= (~(__INTERRUPT__)))
551 
552     /**
553   * @brief  Check whether the specified LPTIM interrupt source is enabled or not.
554   * @param  __HANDLE__: LPTIM handle.
555   * @param  __INTERRUPT__: LPTIM interrupt to check.
556   *            This parameter can be a value of:
557   *            @arg LPTIM_IT_DOWN    : Counter direction change up Interrupt.
558   *            @arg LPTIM_IT_UP      : Counter direction change down to up Interrupt.
559   *            @arg LPTIM_IT_ARROK   : Autoreload register update OK Interrupt.
560   *            @arg LPTIM_IT_CMPOK   : Compare register update OK Interrupt.
561   *            @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt.
562   *            @arg LPTIM_IT_ARRM    : Autoreload match Interrupt.
563   *            @arg LPTIM_IT_CMPM    : Compare match Interrupt.
564   * @retval Interrupt status.
565   */
566 
567 #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
568 
569 /**
570   * @}
571   */
572 
573 /* Exported functions --------------------------------------------------------*/
574 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
575   * @{
576   */
577 
578 /* Initialization/de-initialization functions  ********************************/
579 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim);
580 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim);
581 
582 /* MSP functions  *************************************************************/
583 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim);
584 void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim);
585 
586 /* Start/Stop operation functions  *********************************************/
587 /* ################################# PWM Mode ################################*/
588 /* Blocking mode: Polling */
589 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
590 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim);
591 /* Non-Blocking mode: Interrupt */
592 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
593 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim);
594 
595 /* ############################# One Pulse Mode ##############################*/
596 /* Blocking mode: Polling */
597 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
598 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim);
599 /* Non-Blocking mode: Interrupt */
600 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
601 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim);
602 
603 /* ############################## Set once Mode ##############################*/
604 /* Blocking mode: Polling */
605 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
606 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim);
607 /* Non-Blocking mode: Interrupt */
608 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse);
609 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim);
610 
611 /* ############################### Encoder Mode ##############################*/
612 /* Blocking mode: Polling */
613 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
614 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim);
615 /* Non-Blocking mode: Interrupt */
616 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
617 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim);
618 
619 /* ############################# Time out  Mode ##############################*/
620 /* Blocking mode: Polling */
621 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
622 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim);
623 /* Non-Blocking mode: Interrupt */
624 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout);
625 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim);
626 
627 /* ############################## Counter Mode ###############################*/
628 /* Blocking mode: Polling */
629 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
630 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim);
631 /* Non-Blocking mode: Interrupt */
632 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
633 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim);
634 
635 /* Reading operation functions ************************************************/
636 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim);
637 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim);
638 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim);
639 
640 /* LPTIM IRQ functions  *******************************************************/
641 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim);
642 
643 /* CallBack functions  ********************************************************/
644 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim);
645 void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim);
646 void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim);
647 void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim);
648 void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim);
649 void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim);
650 void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim);
651 #if defined(LPTIM_RCR_REP)
652 void HAL_LPTIM_UpdateEventCallback(LPTIM_HandleTypeDef *hlptim);
653 void HAL_LPTIM_RepCounterWriteCallback(LPTIM_HandleTypeDef *hlptim);
654 #endif /* LPTIM_RCR_REP */
655 
656 /* Callbacks Register/UnRegister functions  ***********************************/
657 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
658 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID, pLPTIM_CallbackTypeDef pCallback);
659 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID);
660 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
661 
662 /* Peripheral State functions  ************************************************/
663 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim);
664 
665 /**
666   * @}
667   */
668 
669 /* Private types -------------------------------------------------------------*/
670 /** @defgroup LPTIM_Private_Types LPTIM Private Types
671   * @{
672   */
673 
674 /**
675   * @}
676   */
677 
678 /* Private variables ---------------------------------------------------------*/
679 /** @defgroup LPTIM_Private_Variables LPTIM Private Variables
680   * @{
681   */
682 
683 /**
684   * @}
685   */
686 
687 /* Private constants ---------------------------------------------------------*/
688 /** @defgroup LPTIM_Private_Constants LPTIM Private Constants
689   * @{
690   */
691 
692 /**
693   * @}
694   */
695 
696 /* Private macros ------------------------------------------------------------*/
697 /** @defgroup LPTIM_Private_Macros LPTIM Private Macros
698   * @{
699   */
700 
701 #define IS_LPTIM_CLOCK_SOURCE(__SOURCE__)       (((__SOURCE__) == LPTIM_CLOCKSOURCE_ULPTIM) || \
702                                                  ((__SOURCE__) == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC))
703 
704 
705 #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) ==  LPTIM_PRESCALER_DIV1  ) || \
706                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV2  ) || \
707                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV4  ) || \
708                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV8  ) || \
709                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV16 ) || \
710                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV32 ) || \
711                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV64 ) || \
712                                                  ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV128))
713 
714 #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) ==  LPTIM_PRESCALER_DIV1)
715 
716 #define IS_LPTIM_OUTPUT_POLARITY(__POLARITY__)  (((__POLARITY__) == LPTIM_OUTPUTPOLARITY_LOW ) || \
717                                                  ((__POLARITY__) == LPTIM_OUTPUTPOLARITY_HIGH))
718 
719 #define IS_LPTIM_CLOCK_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION) || \
720                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_2TRANSITIONS)     || \
721                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_4TRANSITIONS)     || \
722                                                     ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_8TRANSITIONS))
723 
724 #define IS_LPTIM_CLOCK_POLARITY(__POLARITY__)   (((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING)  || \
725                                                  ((__POLARITY__) == LPTIM_CLOCKPOLARITY_FALLING) || \
726                                                  ((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING_FALLING))
727 
728 #define IS_LPTIM_TRG_SOURCE(__TRIG__)           (((__TRIG__) == LPTIM_TRIGSOURCE_SOFTWARE) || \
729                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_0) || \
730                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_1) || \
731                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_2) || \
732                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_3) || \
733                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_4) || \
734                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_5) || \
735                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_6) || \
736                                                  ((__TRIG__) == LPTIM_TRIGSOURCE_7))
737 
738 #define IS_LPTIM_EXT_TRG_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING         ) || \
739                                                  ((__POLARITY__) == LPTIM_ACTIVEEDGE_FALLING        ) || \
740                                                  ((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING_FALLING ))
741 
742 #define IS_LPTIM_TRIG_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION) || \
743                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_2TRANSITIONS    ) || \
744                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_4TRANSITIONS    ) || \
745                                                    ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_8TRANSITIONS    ))
746 
747 #define IS_LPTIM_UPDATE_MODE(__MODE__)          (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \
748                                                  ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD))
749 
750 #define IS_LPTIM_COUNTER_SOURCE(__SOURCE__)     (((__SOURCE__) == LPTIM_COUNTERSOURCE_INTERNAL) || \
751                                                  ((__SOURCE__) == LPTIM_COUNTERSOURCE_EXTERNAL))
752 
753 #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__)     ((__AUTORELOAD__) <= 0x0000FFFF)
754 
755 #define IS_LPTIM_COMPARE(__COMPARE__)           ((__COMPARE__) <= 0x0000FFFF)
756 
757 #define IS_LPTIM_PERIOD(__PERIOD__)             ((__PERIOD__) <= 0x0000FFFF)
758 
759 #define IS_LPTIM_PULSE(__PULSE__)               ((__PULSE__) <= 0x0000FFFF)
760 
761 #if defined(LPTIM_RCR_REP)
762 #define IS_LPTIM_REPETITION(__REPETITION__)     ((__REPETITION__) <= 0x000000FF)
763 #endif
764 
765 #define IS_LPTIM_INPUT1_SOURCE(__INSTANCE__, __SOURCE__)  \
766     ((((__INSTANCE__) == LPTIM1) &&                       \
767      (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) ||        \
768       ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1)))        \
769      ||                                                   \
770      (((__INSTANCE__) == LPTIM2) &&                       \
771      (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) ||        \
772       ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1) ||       \
773       ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP2) ||       \
774       ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1_COMP2))))
775 
776 #define IS_LPTIM_INPUT2_SOURCE(__INSTANCE__, __SOURCE__)  \
777      (((__INSTANCE__) == LPTIM1) &&                       \
778      (((__SOURCE__) == LPTIM_INPUT2SOURCE_GPIO) ||        \
779       ((__SOURCE__) == LPTIM_INPUT2SOURCE_COMP2)))
780 
781 /**
782   * @}
783   */
784 
785 /* Private functions ---------------------------------------------------------*/
786 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
787   * @{
788   */
789 
790 /**
791   * @}
792   */
793 
794 /**
795   * @}
796   */
797 
798 /**
799   * @}
800   */
801 
802 #ifdef __cplusplus
803 }
804 #endif
805 
806 #endif /* __STM32L4xx_HAL_LPTIM_H */
807 
808 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
809