Updated and Validated
[betaflight.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_lptim.c
blob1b9a0147042ec64f4db4593c57c713530aa4a4fe
1 /**
2 ******************************************************************************
3 * @file stm32f7xx_hal_lptim.c
4 * @author MCD Application Team
5 * @brief LPTIM HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Low Power Timer (LPTIM) peripheral:
8 * + Initialization and de-initialization functions.
9 * + Start/Stop operation functions in polling mode.
10 * + Start/Stop operation functions in interrupt mode.
11 * + Reading operation functions.
12 * + Peripheral State functions.
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 The LPTIM HAL driver can be used as follows:
21 (#)Initialize the LPTIM low level resources by implementing the
22 HAL_LPTIM_MspInit():
23 (##) Enable the LPTIM interface clock using __LPTIMx_CLK_ENABLE().
24 (##) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
25 (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
26 (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
27 (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
29 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
30 configures mainly:
31 (##) The instance: LPTIM1.
32 (##) Clock: the counter clock.
33 (+++) Source: it can be either the ULPTIM input (IN1) or one of
34 the internal clock; (APB, LSE, LSI or MSI).
35 (+++) Prescaler: select the clock divider.
36 (##) UltraLowPowerClock : To be used only if the ULPTIM is selected
37 as counter clock source.
38 (+++) Polarity: polarity of the active edge for the counter unit
39 if the ULPTIM input is selected.
40 (+++) SampleTime: clock sampling time to configure the clock glitch
41 filter.
42 (##) Trigger: How the counter start.
43 (+++) Source: trigger can be software or one of the hardware triggers.
44 (+++) ActiveEdge: only for hardware trigger.
45 (+++) SampleTime: trigger sampling time to configure the trigger
46 glitch filter.
47 (##) OutputPolarity: 2 opposite polarities are possibles.
48 (##) UpdateMode: specifies whether the update of the autoreload and
49 the compare values is done immediately or after the end of current
50 period.
52 (#)Six modes are available:
54 (##) PWM Mode: To generate a PWM signal with specified period and pulse,
55 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
56 mode.
58 (##) One Pulse Mode: To generate pulse with specified width in response
59 to a stimulus, call HAL_LPTIM_OnePulse_Start() or
60 HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
62 (##) Set once Mode: In this mode, the output changes the level (from
63 low level to high level if the output polarity is configured high, else
64 the opposite) when a compare match occurs. To start this mode, call
65 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
66 interruption mode.
68 (##) Encoder Mode: To use the encoder interface call
69 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
70 interruption mode.
72 (##) Time out Mode: an active edge on one selected trigger input rests
73 the counter. The first trigger event will start the timer, any
74 successive trigger event will reset the counter and the timer will
75 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
76 HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
78 (##) Counter Mode: counter can be used to count external events on
79 the LPTIM Input1 or it can be used to count internal clock cycles.
80 To start this mode, call HAL_LPTIM_Counter_Start() or
81 HAL_LPTIM_Counter_Start_IT() for interruption mode.
84 (#) User can stop any process by calling the corresponding API:
85 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
86 already started in interruption mode.
88 (#) Call HAL_LPTIM_DeInit() to deinitialize the LPTIM peripheral.
90 *** Callback registration ***
91 =============================================
93 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
94 allows the user to configure dynamically the driver callbacks.
96 Use Function @ref HAL_LPTIM_RegisterCallback() to register a callback.
97 @ref HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
98 the Callback ID and a pointer to the user callback function.
100 Use function @ref HAL_LPTIM_UnRegisterCallback() to reset a callback to the default
101 weak function.
102 @ref HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
103 and the Callback ID.
105 These functions allow to register/unregister following callbacks:
106 (+) MspInitCallback : LPTIM Msp Init Callback.
107 (+) MspDeInitCallback : LPTIM Msp DeInit Callback.
108 (+) CompareMatchCallback : LPTIM Compare Match Init Callback.
109 (+) AutoReloadMatchCallback : LPTIM Auto Reload Match Callback.
110 (+) TriggerCallback : LPTIM Trigger Callback.
111 (+) CompareWriteCallback : LPTIM Compare Write Callback.
112 (+) AutoReloadWriteCallback : LPTIM Auto Reload Write Callback.
113 (+) DirectionUpCallback : LPTIM Direction Up Callback.
114 (+) DirectionDownCallback : LPTIM Direction Down Callback.
116 By default, after the @ref HAL_LPTIM_Init and when the state is HAL_LPTIM_STATE_RESET
117 all interrupt callbacks are set to the corresponding weak functions:
118 examples @ref HAL_LPTIM_CompareMatchCallback(), @ref HAL_LPTIM_AutoReloadMatchCallback().
120 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
121 functionalities in the @ref HAL_LPTIM_Init/@ref HAL_LPTIM_DeInit only when these
122 callbacks are null (not registered beforehand). If not, MspInit or MspDeInit are not null,
123 the @ref HAL_LPTIM_Init/@ref HAL_LPTIM_DeInit keep and use the user MspInit/MspDeInit
124 callbacks (registered beforehand)
126 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
127 Exception done MspInit/MspDeInit that can be registered/unregistered
128 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state, thus registered (user)
129 MspInit/DeInit callbacks can be used during the @ref HAL_LPTIM_Init/@ref HAL_LPTIM_DeInit.
130 In that case first register the MspInit/MspDeInit user callbacks using
131 @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
133 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
134 not defined, the callback registration feature is not available and all callbacks
135 are set to the corresponding weak functions.
137 @endverbatim
138 ******************************************************************************
139 * @attention
141 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
142 * All rights reserved.</center></h2>
144 * This software component is licensed by ST under BSD 3-Clause license,
145 * the "License"; You may not use this file except in compliance with the
146 * License. You may obtain a copy of the License at:
147 * opensource.org/licenses/BSD-3-Clause
149 ******************************************************************************
152 /* Includes ------------------------------------------------------------------*/
153 #include "stm32f7xx_hal.h"
155 /** @addtogroup STM32F7xx_HAL_Driver
156 * @{
159 /** @defgroup LPTIM LPTIM
160 * @brief LPTIM HAL module driver.
161 * @{
164 #ifdef HAL_LPTIM_MODULE_ENABLED
165 /* Private types -------------------------------------------------------------*/
166 /** @defgroup LPTIM_Private_Types LPTIM Private Types
167 * @{
171 * @}
174 /* Private defines -----------------------------------------------------------*/
175 /** @defgroup LPTIM_Private_Defines LPTIM Private Defines
176 * @{
180 * @}
183 /* Private variables ---------------------------------------------------------*/
184 /** @addtogroup LPTIM_Private_Variables LPTIM Private Variables
185 * @{
189 * @}
192 /* Private constants ---------------------------------------------------------*/
193 /** @addtogroup LPTIM_Private_Constants LPTIM Private Constants
194 * @{
198 * @}
201 /* Private macros ------------------------------------------------------------*/
202 /** @addtogroup LPTIM_Private_Macros LPTIM Private Macros
203 * @{
207 * @}
210 /* Private function prototypes -----------------------------------------------*/
211 /** @addtogroup LPTIM_Private_Functions_Prototypes LPTIM Private Functions Prototypes
212 * @{
216 * @}
219 /* Private functions ---------------------------------------------------------*/
220 /** @addtogroup LPTIM_Private_Functions LPTIM Private Functions
221 * @{
225 * @}
228 /* Exported functions ---------------------------------------------------------*/
229 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
230 * @{
233 /** @defgroup LPTIM_Group1 Initialization/de-initialization functions
234 * @brief Initialization and Configuration functions.
236 @verbatim
237 ==============================================================================
238 ##### Initialization and de-initialization functions #####
239 ==============================================================================
240 [..] This section provides functions allowing to:
241 (+) Initialize the LPTIM according to the specified parameters in the
242 LPTIM_InitTypeDef and creates the associated handle.
243 (+) DeInitialize the LPTIM peripheral.
244 (+) Initialize the LPTIM MSP.
245 (+) DeInitialize LPTIM MSP.
247 @endverbatim
248 * @{
252 * @brief Initializes the LPTIM according to the specified parameters in the
253 * LPTIM_InitTypeDef and creates the associated handle.
254 * @param hlptim LPTIM handle
255 * @retval HAL status
257 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
259 uint32_t tmpcfgr = 0;
261 /* Check the LPTIM handle allocation */
262 if(hlptim == NULL)
264 return HAL_ERROR;
267 /* Check the parameters */
268 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
270 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
271 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
272 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
274 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
275 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
277 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
278 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
280 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
281 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
283 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
284 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
285 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
287 if(hlptim->State == HAL_LPTIM_STATE_RESET)
289 /* Allocate lock resource and initialize it */
290 hlptim->Lock = HAL_UNLOCKED;
292 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
293 /* Reset the LPTIM callback to the legacy weak callbacks */
294 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback;
295 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback;
296 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback;
297 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback;
298 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback;
299 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback;
300 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback;
302 if(hlptim->MspInitCallback == NULL)
304 hlptim->MspInitCallback = HAL_LPTIM_MspInit;
306 /* Init the low level hardware : GPIO, CLOCK, NVIC */
307 hlptim->MspInitCallback(hlptim);
308 #else
309 /* Init the low level hardware */
310 HAL_LPTIM_MspInit(hlptim);
311 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
313 /* Change the LPTIM state */
314 hlptim->State = HAL_LPTIM_STATE_BUSY;
316 /* Get the LPTIMx CFGR value */
317 tmpcfgr = hlptim->Instance->CFGR;
319 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
321 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
323 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
325 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
328 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
329 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
330 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
332 /* Set initialization parameters */
333 tmpcfgr |= (hlptim->Init.Clock.Source |
334 hlptim->Init.Clock.Prescaler |
335 hlptim->Init.OutputPolarity |
336 hlptim->Init.UpdateMode |
337 hlptim->Init.CounterSource);
339 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
341 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
342 hlptim->Init.UltraLowPowerClock.SampleTime);
345 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
347 /* Enable External trigger and set the trigger source */
348 tmpcfgr |= (hlptim->Init.Trigger.Source |
349 hlptim->Init.Trigger.ActiveEdge |
350 hlptim->Init.Trigger.SampleTime);
353 /* Write to LPTIMx CFGR */
354 hlptim->Instance->CFGR = tmpcfgr;
356 /* Change the LPTIM state */
357 hlptim->State = HAL_LPTIM_STATE_READY;
359 /* Return function status */
360 return HAL_OK;
364 * @brief DeInitializes the LPTIM peripheral.
365 * @param hlptim LPTIM handle
366 * @retval HAL status
368 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
370 /* Check the LPTIM handle allocation */
371 if(hlptim == NULL)
373 return HAL_ERROR;
376 /* Change the LPTIM state */
377 hlptim->State = HAL_LPTIM_STATE_BUSY;
379 /* Disable the LPTIM Peripheral Clock */
380 __HAL_LPTIM_DISABLE(hlptim);
382 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
383 if(hlptim->MspDeInitCallback == NULL)
385 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
387 /* DeInit the low level hardware */
388 hlptim->MspDeInitCallback(hlptim);
389 #else
390 /* DeInit the low level hardware: CLOCK, NVIC.*/
391 HAL_LPTIM_MspDeInit(hlptim);
392 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
394 /* Change the LPTIM state */
395 hlptim->State = HAL_LPTIM_STATE_RESET;
397 /* Release Lock */
398 __HAL_UNLOCK(hlptim);
400 /* Return function status */
401 return HAL_OK;
405 * @brief Initializes the LPTIM MSP.
406 * @param hlptim LPTIM handle
407 * @retval None
409 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
411 /* Prevent unused argument(s) compilation warning */
412 UNUSED(hlptim);
414 /* NOTE : This function Should not be modified, when the callback is needed,
415 the HAL_LPTIM_MspInit could be implemented in the user file
420 * @brief DeInitializes LPTIM MSP.
421 * @param hlptim LPTIM handle
422 * @retval None
424 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
426 /* Prevent unused argument(s) compilation warning */
427 UNUSED(hlptim);
429 /* NOTE : This function Should not be modified, when the callback is needed,
430 the HAL_LPTIM_MspDeInit could be implemented in the user file
435 * @}
438 /** @defgroup LPTIM_Group2 LPTIM Start-Stop operation functions
439 * @brief Start-Stop operation functions.
441 @verbatim
442 ==============================================================================
443 ##### LPTIM Start Stop operation functions #####
444 ==============================================================================
445 [..] This section provides functions allowing to:
446 (+) Start the PWM mode.
447 (+) Stop the PWM mode.
448 (+) Start the One pulse mode.
449 (+) Stop the One pulse mode.
450 (+) Start the Set once mode.
451 (+) Stop the Set once mode.
452 (+) Start the Encoder mode.
453 (+) Stop the Encoder mode.
454 (+) Start the Timeout mode.
455 (+) Stop the Timeout mode.
456 (+) Start the Counter mode.
457 (+) Stop the Counter mode.
460 @endverbatim
461 * @{
465 * @brief Starts the LPTIM PWM generation.
466 * @param hlptim LPTIM handle
467 * @param Period Specifies the Autoreload value.
468 * This parameter must be a value between 0x0000 and 0xFFFF.
469 * @param Pulse Specifies the compare value.
470 * This parameter must be a value between 0x0000 and 0xFFFF.
471 * @retval HAL status
473 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
475 /* Check the parameters */
476 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
477 assert_param(IS_LPTIM_PERIOD(Period));
478 assert_param(IS_LPTIM_PULSE(Pulse));
480 /* Set the LPTIM state */
481 hlptim->State= HAL_LPTIM_STATE_BUSY;
483 /* Reset WAVE bit to set PWM mode */
484 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
486 /* Enable the Peripheral */
487 __HAL_LPTIM_ENABLE(hlptim);
489 /* Load the period value in the autoreload register */
490 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
492 /* Load the pulse value in the compare register */
493 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
495 /* Start timer in continuous mode */
496 __HAL_LPTIM_START_CONTINUOUS(hlptim);
498 /* Change the TIM state*/
499 hlptim->State= HAL_LPTIM_STATE_READY;
501 /* Return function status */
502 return HAL_OK;
506 * @brief Stops the LPTIM PWM generation.
507 * @param hlptim LPTIM handle
508 * @retval HAL status
510 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
512 /* Check the parameters */
513 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
515 /* Set the LPTIM state */
516 hlptim->State= HAL_LPTIM_STATE_BUSY;
518 /* Disable the Peripheral */
519 __HAL_LPTIM_DISABLE(hlptim);
521 /* Change the TIM state*/
522 hlptim->State= HAL_LPTIM_STATE_READY;
524 /* Return function status */
525 return HAL_OK;
529 * @brief Starts the LPTIM PWM generation in interrupt mode.
530 * @param hlptim LPTIM handle
531 * @param Period Specifies the Autoreload value.
532 * This parameter must be a value between 0x0000 and 0xFFFF
533 * @param Pulse Specifies the compare value.
534 * This parameter must be a value between 0x0000 and 0xFFFF
535 * @retval HAL status
537 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
539 /* Check the parameters */
540 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
541 assert_param(IS_LPTIM_PERIOD(Period));
542 assert_param(IS_LPTIM_PULSE(Pulse));
544 /* Set the LPTIM state */
545 hlptim->State= HAL_LPTIM_STATE_BUSY;
547 /* Reset WAVE bit to set PWM mode */
548 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
550 /* Enable Autoreload write complete interrupt */
551 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
553 /* Enable Compare write complete interrupt */
554 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
556 /* Enable Autoreload match interrupt */
557 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
559 /* Enable Compare match interrupt */
560 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
562 /* If external trigger source is used, then enable external trigger interrupt */
563 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
565 /* Enable external trigger interrupt */
566 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
569 /* Enable the Peripheral */
570 __HAL_LPTIM_ENABLE(hlptim);
572 /* Load the period value in the autoreload register */
573 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
575 /* Load the pulse value in the compare register */
576 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
578 /* Start timer in continuous mode */
579 __HAL_LPTIM_START_CONTINUOUS(hlptim);
581 /* Change the TIM state*/
582 hlptim->State= HAL_LPTIM_STATE_READY;
584 /* Return function status */
585 return HAL_OK;
589 * @brief Stops the LPTIM PWM generation in interrupt mode.
590 * @param hlptim LPTIM handle
591 * @retval HAL status
593 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
595 /* Check the parameters */
596 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
598 /* Set the LPTIM state */
599 hlptim->State= HAL_LPTIM_STATE_BUSY;
601 /* Disable the Peripheral */
602 __HAL_LPTIM_DISABLE(hlptim);
604 /* Disable Autoreload write complete interrupt */
605 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
607 /* Disable Compare write complete interrupt */
608 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
610 /* Disable Autoreload match interrupt */
611 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
613 /* Disable Compare match interrupt */
614 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
616 /* If external trigger source is used, then disable external trigger interrupt */
617 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
619 /* Disable external trigger interrupt */
620 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
623 /* Change the TIM state*/
624 hlptim->State= HAL_LPTIM_STATE_READY;
626 /* Return function status */
627 return HAL_OK;
631 * @brief Starts the LPTIM One pulse generation.
632 * @param hlptim LPTIM handle
633 * @param Period Specifies the Autoreload value.
634 * This parameter must be a value between 0x0000 and 0xFFFF.
635 * @param Pulse Specifies the compare value.
636 * This parameter must be a value between 0x0000 and 0xFFFF.
637 * @retval HAL status
639 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
641 /* Check the parameters */
642 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
643 assert_param(IS_LPTIM_PERIOD(Period));
644 assert_param(IS_LPTIM_PULSE(Pulse));
646 /* Set the LPTIM state */
647 hlptim->State= HAL_LPTIM_STATE_BUSY;
649 /* Reset WAVE bit to set one pulse mode */
650 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
652 /* Enable the Peripheral */
653 __HAL_LPTIM_ENABLE(hlptim);
655 /* Load the period value in the autoreload register */
656 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
658 /* Load the pulse value in the compare register */
659 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
661 /* Start timer in continuous mode */
662 __HAL_LPTIM_START_SINGLE(hlptim);
664 /* Change the TIM state*/
665 hlptim->State= HAL_LPTIM_STATE_READY;
667 /* Return function status */
668 return HAL_OK;
672 * @brief Stops the LPTIM One pulse generation.
673 * @param hlptim LPTIM handle
674 * @retval HAL status
676 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
678 /* Check the parameters */
679 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
681 /* Set the LPTIM state */
682 hlptim->State= HAL_LPTIM_STATE_BUSY;
684 /* Disable the Peripheral */
685 __HAL_LPTIM_DISABLE(hlptim);
687 /* Change the TIM state*/
688 hlptim->State= HAL_LPTIM_STATE_READY;
690 /* Return function status */
691 return HAL_OK;
695 * @brief Starts the LPTIM One pulse generation in interrupt mode.
696 * @param hlptim LPTIM handle
697 * @param Period Specifies the Autoreload value.
698 * This parameter must be a value between 0x0000 and 0xFFFF.
699 * @param Pulse Specifies the compare value.
700 * This parameter must be a value between 0x0000 and 0xFFFF.
701 * @retval HAL status
703 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
705 /* Check the parameters */
706 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
707 assert_param(IS_LPTIM_PERIOD(Period));
708 assert_param(IS_LPTIM_PULSE(Pulse));
710 /* Set the LPTIM state */
711 hlptim->State= HAL_LPTIM_STATE_BUSY;
713 /* Reset WAVE bit to set one pulse mode */
714 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
716 /* Enable Autoreload write complete interrupt */
717 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
719 /* Enable Compare write complete interrupt */
720 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
722 /* Enable Autoreload match interrupt */
723 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
725 /* Enable Compare match interrupt */
726 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
728 /* If external trigger source is used, then enable external trigger interrupt */
729 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
731 /* Enable external trigger interrupt */
732 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
735 /* Enable the Peripheral */
736 __HAL_LPTIM_ENABLE(hlptim);
738 /* Load the period value in the autoreload register */
739 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
741 /* Load the pulse value in the compare register */
742 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
744 /* Start timer in continuous mode */
745 __HAL_LPTIM_START_SINGLE(hlptim);
747 /* Change the TIM state*/
748 hlptim->State= HAL_LPTIM_STATE_READY;
750 /* Return function status */
751 return HAL_OK;
755 * @brief Stops the LPTIM One pulse generation in interrupt mode.
756 * @param hlptim LPTIM handle
757 * @retval HAL status
759 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
761 /* Check the parameters */
762 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
764 /* Set the LPTIM state */
765 hlptim->State= HAL_LPTIM_STATE_BUSY;
767 /* Disable the Peripheral */
768 __HAL_LPTIM_DISABLE(hlptim);
770 /* Disable Autoreload write complete interrupt */
771 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
773 /* Disable Compare write complete interrupt */
774 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
776 /* Disable Autoreload match interrupt */
777 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
779 /* Disable Compare match interrupt */
780 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
782 /* If external trigger source is used, then disable external trigger interrupt */
783 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
785 /* Disable external trigger interrupt */
786 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
789 /* Change the TIM state*/
790 hlptim->State= HAL_LPTIM_STATE_READY;
792 /* Return function status */
793 return HAL_OK;
797 * @brief Starts the LPTIM in Set once mode.
798 * @param hlptim LPTIM handle
799 * @param Period Specifies the Autoreload value.
800 * This parameter must be a value between 0x0000 and 0xFFFF.
801 * @param Pulse Specifies the compare value.
802 * This parameter must be a value between 0x0000 and 0xFFFF.
803 * @retval HAL status
805 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
807 /* Check the parameters */
808 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
809 assert_param(IS_LPTIM_PERIOD(Period));
810 assert_param(IS_LPTIM_PULSE(Pulse));
812 /* Set the LPTIM state */
813 hlptim->State= HAL_LPTIM_STATE_BUSY;
815 /* Set WAVE bit to enable the set once mode */
816 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
818 /* Enable the Peripheral */
819 __HAL_LPTIM_ENABLE(hlptim);
821 /* Load the period value in the autoreload register */
822 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
824 /* Load the pulse value in the compare register */
825 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
827 /* Start timer in continuous mode */
828 __HAL_LPTIM_START_SINGLE(hlptim);
830 /* Change the TIM state*/
831 hlptim->State= HAL_LPTIM_STATE_READY;
833 /* Return function status */
834 return HAL_OK;
838 * @brief Stops the LPTIM Set once mode.
839 * @param hlptim LPTIM handle
840 * @retval HAL status
842 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
844 /* Check the parameters */
845 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
847 /* Set the LPTIM state */
848 hlptim->State= HAL_LPTIM_STATE_BUSY;
850 /* Disable the Peripheral */
851 __HAL_LPTIM_DISABLE(hlptim);
853 /* Change the TIM state*/
854 hlptim->State= HAL_LPTIM_STATE_READY;
856 /* Return function status */
857 return HAL_OK;
861 * @brief Starts the LPTIM Set once mode in interrupt mode.
862 * @param hlptim LPTIM handle
863 * @param Period Specifies the Autoreload value.
864 * This parameter must be a value between 0x0000 and 0xFFFF.
865 * @param Pulse Specifies the compare value.
866 * This parameter must be a value between 0x0000 and 0xFFFF.
867 * @retval HAL status
869 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
871 /* Check the parameters */
872 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
873 assert_param(IS_LPTIM_PERIOD(Period));
874 assert_param(IS_LPTIM_PULSE(Pulse));
876 /* Set the LPTIM state */
877 hlptim->State= HAL_LPTIM_STATE_BUSY;
879 /* Set WAVE bit to enable the set once mode */
880 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
882 /* Enable Autoreload write complete interrupt */
883 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
885 /* Enable Compare write complete interrupt */
886 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
888 /* Enable Autoreload match interrupt */
889 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
891 /* Enable Compare match interrupt */
892 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
894 /* If external trigger source is used, then enable external trigger interrupt */
895 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
897 /* Enable external trigger interrupt */
898 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
901 /* Enable the Peripheral */
902 __HAL_LPTIM_ENABLE(hlptim);
904 /* Load the period value in the autoreload register */
905 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
907 /* Load the pulse value in the compare register */
908 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
910 /* Start timer in continuous mode */
911 __HAL_LPTIM_START_SINGLE(hlptim);
913 /* Change the TIM state*/
914 hlptim->State= HAL_LPTIM_STATE_READY;
916 /* Return function status */
917 return HAL_OK;
921 * @brief Stops the LPTIM Set once mode in interrupt mode.
922 * @param hlptim LPTIM handle
923 * @retval HAL status
925 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
927 /* Check the parameters */
928 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
930 /* Set the LPTIM state */
931 hlptim->State= HAL_LPTIM_STATE_BUSY;
933 /* Disable the Peripheral */
934 __HAL_LPTIM_DISABLE(hlptim);
936 /* Disable Autoreload write complete interrupt */
937 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
939 /* Disable Compare write complete interrupt */
940 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
942 /* Disable Autoreload match interrupt */
943 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
945 /* Disable Compare match interrupt */
946 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
948 /* If external trigger source is used, then disable external trigger interrupt */
949 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
951 /* Disable external trigger interrupt */
952 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
955 /* Change the TIM state*/
956 hlptim->State= HAL_LPTIM_STATE_READY;
958 /* Return function status */
959 return HAL_OK;
963 * @brief Starts the Encoder interface.
964 * @param hlptim LPTIM handle
965 * @param Period Specifies the Autoreload value.
966 * This parameter must be a value between 0x0000 and 0xFFFF.
967 * @retval HAL status
969 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
971 uint32_t tmpcfgr = 0;
973 /* Check the parameters */
974 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
975 assert_param(IS_LPTIM_PERIOD(Period));
976 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
977 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
978 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
980 /* Set the LPTIM state */
981 hlptim->State= HAL_LPTIM_STATE_BUSY;
983 /* Get the LPTIMx CFGR value */
984 tmpcfgr = hlptim->Instance->CFGR;
986 /* Clear CKPOL bits */
987 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
989 /* Set Input polarity */
990 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
992 /* Write to LPTIMx CFGR */
993 hlptim->Instance->CFGR = tmpcfgr;
995 /* Set ENC bit to enable the encoder interface */
996 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
998 /* Enable the Peripheral */
999 __HAL_LPTIM_ENABLE(hlptim);
1001 /* Load the period value in the autoreload register */
1002 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1004 /* Start timer in continuous mode */
1005 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1007 /* Change the TIM state*/
1008 hlptim->State= HAL_LPTIM_STATE_READY;
1010 /* Return function status */
1011 return HAL_OK;
1015 * @brief Stops the Encoder interface.
1016 * @param hlptim LPTIM handle
1017 * @retval HAL status
1019 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
1021 /* Check the parameters */
1022 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1024 /* Set the LPTIM state */
1025 hlptim->State= HAL_LPTIM_STATE_BUSY;
1027 /* Disable the Peripheral */
1028 __HAL_LPTIM_DISABLE(hlptim);
1030 /* Reset ENC bit to disable the encoder interface */
1031 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1033 /* Change the TIM state*/
1034 hlptim->State= HAL_LPTIM_STATE_READY;
1036 /* Return function status */
1037 return HAL_OK;
1041 * @brief Starts the Encoder interface in interrupt mode.
1042 * @param hlptim LPTIM handle
1043 * @param Period Specifies the Autoreload value.
1044 * This parameter must be a value between 0x0000 and 0xFFFF.
1045 * @retval HAL status
1047 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1049 uint32_t tmpcfgr = 0;
1051 /* Check the parameters */
1052 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1053 assert_param(IS_LPTIM_PERIOD(Period));
1054 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
1055 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
1056 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
1058 /* Set the LPTIM state */
1059 hlptim->State= HAL_LPTIM_STATE_BUSY;
1061 /* Configure edge sensitivity for encoder mode */
1062 /* Get the LPTIMx CFGR value */
1063 tmpcfgr = hlptim->Instance->CFGR;
1065 /* Clear CKPOL bits */
1066 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
1068 /* Set Input polarity */
1069 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
1071 /* Write to LPTIMx CFGR */
1072 hlptim->Instance->CFGR = tmpcfgr;
1074 /* Set ENC bit to enable the encoder interface */
1075 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
1077 /* Enable "switch to down direction" interrupt */
1078 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
1080 /* Enable "switch to up direction" interrupt */
1081 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
1083 /* Enable the Peripheral */
1084 __HAL_LPTIM_ENABLE(hlptim);
1086 /* Load the period value in the autoreload register */
1087 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1089 /* Start timer in continuous mode */
1090 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1092 /* Change the TIM state*/
1093 hlptim->State= HAL_LPTIM_STATE_READY;
1095 /* Return function status */
1096 return HAL_OK;
1100 * @brief Stops the Encoder interface in interrupt mode.
1101 * @param hlptim LPTIM handle
1102 * @retval HAL status
1104 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1106 /* Check the parameters */
1107 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1109 /* Set the LPTIM state */
1110 hlptim->State= HAL_LPTIM_STATE_BUSY;
1112 /* Disable the Peripheral */
1113 __HAL_LPTIM_DISABLE(hlptim);
1115 /* Reset ENC bit to disable the encoder interface */
1116 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1118 /* Disable "switch to down direction" interrupt */
1119 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
1121 /* Disable "switch to up direction" interrupt */
1122 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
1124 /* Change the TIM state*/
1125 hlptim->State= HAL_LPTIM_STATE_READY;
1127 /* Return function status */
1128 return HAL_OK;
1132 * @brief Starts the Timeout function. The first trigger event will start the
1133 * timer, any successive trigger event will reset the counter and
1134 * the timer restarts.
1135 * @param hlptim LPTIM handle
1136 * @param Period Specifies the Autoreload value.
1137 * This parameter must be a value between 0x0000 and 0xFFFF.
1138 * @param Timeout Specifies the TimeOut value to rest the counter.
1139 * This parameter must be a value between 0x0000 and 0xFFFF.
1140 * @retval HAL status
1142 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1144 /* Check the parameters */
1145 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1146 assert_param(IS_LPTIM_PERIOD(Period));
1147 assert_param(IS_LPTIM_PULSE(Timeout));
1149 /* Set the LPTIM state */
1150 hlptim->State= HAL_LPTIM_STATE_BUSY;
1152 /* Set TIMOUT bit to enable the timeout function */
1153 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1155 /* Enable the Peripheral */
1156 __HAL_LPTIM_ENABLE(hlptim);
1158 /* Load the period value in the autoreload register */
1159 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1161 /* Load the Timeout value in the compare register */
1162 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1164 /* Start timer in continuous mode */
1165 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1167 /* Change the TIM state*/
1168 hlptim->State= HAL_LPTIM_STATE_READY;
1170 /* Return function status */
1171 return HAL_OK;
1175 * @brief Stops the Timeout function.
1176 * @param hlptim LPTIM handle
1177 * @retval HAL status
1179 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
1181 /* Check the parameters */
1182 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1184 /* Set the LPTIM state */
1185 hlptim->State= HAL_LPTIM_STATE_BUSY;
1187 /* Disable the Peripheral */
1188 __HAL_LPTIM_DISABLE(hlptim);
1190 /* Reset TIMOUT bit to enable the timeout function */
1191 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1193 /* Change the TIM state*/
1194 hlptim->State= HAL_LPTIM_STATE_READY;
1196 /* Return function status */
1197 return HAL_OK;
1201 * @brief Starts the Timeout function in interrupt mode. The first trigger
1202 * event will start the timer, any successive trigger event will reset
1203 * the counter and the timer restarts.
1204 * @param hlptim LPTIM handle
1205 * @param Period Specifies the Autoreload value.
1206 * This parameter must be a value between 0x0000 and 0xFFFF.
1207 * @param Timeout Specifies the TimeOut value to rest the counter.
1208 * This parameter must be a value between 0x0000 and 0xFFFF.
1209 * @retval HAL status
1211 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1213 /* Check the parameters */
1214 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1215 assert_param(IS_LPTIM_PERIOD(Period));
1216 assert_param(IS_LPTIM_PULSE(Timeout));
1218 /* Set the LPTIM state */
1219 hlptim->State= HAL_LPTIM_STATE_BUSY;
1221 /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
1222 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
1224 /* Enable rising edge trigger on the LPTIM Wake-up Timer Exti line */
1225 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
1227 /* Set TIMOUT bit to enable the timeout function */
1228 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1230 /* Enable Compare match interrupt */
1231 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
1233 /* Enable the Peripheral */
1234 __HAL_LPTIM_ENABLE(hlptim);
1236 /* Load the period value in the autoreload register */
1237 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1239 /* Load the Timeout value in the compare register */
1240 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1242 /* Start timer in continuous mode */
1243 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1245 /* Change the TIM state*/
1246 hlptim->State= HAL_LPTIM_STATE_READY;
1248 /* Return function status */
1249 return HAL_OK;
1253 * @brief Stops the Timeout function in interrupt mode.
1254 * @param hlptim LPTIM handle
1255 * @retval HAL status
1257 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1259 /* Check the parameters */
1260 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1262 /* Set the LPTIM state */
1263 hlptim->State= HAL_LPTIM_STATE_BUSY;
1265 /* Disable rising edge trigger on the LPTIM Wake-up Timer Exti line */
1266 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();
1268 /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
1269 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
1271 /* Disable the Peripheral */
1272 __HAL_LPTIM_DISABLE(hlptim);
1274 /* Reset TIMOUT bit to enable the timeout function */
1275 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1277 /* Disable Compare match interrupt */
1278 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1280 /* Change the TIM state*/
1281 hlptim->State= HAL_LPTIM_STATE_READY;
1283 /* Return function status */
1284 return HAL_OK;
1288 * @brief Starts the Counter mode.
1289 * @param hlptim LPTIM handle
1290 * @param Period Specifies the Autoreload value.
1291 * This parameter must be a value between 0x0000 and 0xFFFF.
1292 * @retval HAL status
1294 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1296 /* Check the parameters */
1297 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1298 assert_param(IS_LPTIM_PERIOD(Period));
1300 /* Set the LPTIM state */
1301 hlptim->State= HAL_LPTIM_STATE_BUSY;
1303 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1304 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1306 /* Check if clock is prescaled */
1307 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1308 /* Set clock prescaler to 0 */
1309 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1312 /* Enable the Peripheral */
1313 __HAL_LPTIM_ENABLE(hlptim);
1315 /* Load the period value in the autoreload register */
1316 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1318 /* Start timer in continuous mode */
1319 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1321 /* Change the TIM state*/
1322 hlptim->State= HAL_LPTIM_STATE_READY;
1324 /* Return function status */
1325 return HAL_OK;
1329 * @brief Stops the Counter mode.
1330 * @param hlptim LPTIM handle
1331 * @retval HAL status
1333 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
1335 /* Check the parameters */
1336 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1338 /* Set the LPTIM state */
1339 hlptim->State= HAL_LPTIM_STATE_BUSY;
1341 /* Disable the Peripheral */
1342 __HAL_LPTIM_DISABLE(hlptim);
1344 /* Change the TIM state*/
1345 hlptim->State= HAL_LPTIM_STATE_READY;
1347 /* Return function status */
1348 return HAL_OK;
1352 * @brief Starts the Counter mode in interrupt mode.
1353 * @param hlptim LPTIM handle
1354 * @param Period Specifies the Autoreload value.
1355 * This parameter must be a value between 0x0000 and 0xFFFF.
1356 * @retval HAL status
1358 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1360 /* Check the parameters */
1361 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1362 assert_param(IS_LPTIM_PERIOD(Period));
1364 /* Set the LPTIM state */
1365 hlptim->State= HAL_LPTIM_STATE_BUSY;
1367 /* Enable EXTI Line interrupt on the LPTIM Wake-up Timer */
1368 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
1370 /* Enable rising edge trigger on the LPTIM Wake-up Timer Exti line */
1371 __HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
1373 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1374 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1376 /* Check if clock is prescaled */
1377 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1378 /* Set clock prescaler to 0 */
1379 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1382 /* Enable Autoreload write complete interrupt */
1383 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
1385 /* Enable Autoreload match interrupt */
1386 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
1388 /* Enable the Peripheral */
1389 __HAL_LPTIM_ENABLE(hlptim);
1391 /* Load the period value in the autoreload register */
1392 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1394 /* Start timer in continuous mode */
1395 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1397 /* Change the TIM state*/
1398 hlptim->State= HAL_LPTIM_STATE_READY;
1400 /* Return function status */
1401 return HAL_OK;
1405 * @brief Stops the Counter mode in interrupt mode.
1406 * @param hlptim LPTIM handle
1407 * @retval HAL status
1409 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1411 /* Check the parameters */
1412 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1414 /* Set the LPTIM state */
1415 hlptim->State= HAL_LPTIM_STATE_BUSY;
1417 /* Disable rising edge trigger on the LPTIM Wake-up Timer Exti line */
1418 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_RISING_EDGE();
1420 /* Disable EXTI Line interrupt on the LPTIM Wake-up Timer */
1421 __HAL_LPTIM_WAKEUPTIMER_EXTI_DISABLE_IT();
1423 /* Disable the Peripheral */
1424 __HAL_LPTIM_DISABLE(hlptim);
1426 /* Disable Autoreload write complete interrupt */
1427 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1429 /* Disable Autoreload match interrupt */
1430 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1432 /* Change the TIM state*/
1433 hlptim->State= HAL_LPTIM_STATE_READY;
1435 /* Return function status */
1436 return HAL_OK;
1440 * @}
1443 /** @defgroup LPTIM_Group3 LPTIM Read operation functions
1444 * @brief Read operation functions.
1446 @verbatim
1447 ==============================================================================
1448 ##### LPTIM Read operation functions #####
1449 ==============================================================================
1450 [..] This section provides LPTIM Reading functions.
1451 (+) Read the counter value.
1452 (+) Read the period (Auto-reload) value.
1453 (+) Read the pulse (Compare)value.
1454 @endverbatim
1455 * @{
1459 * @brief This function returns the current counter value.
1460 * @param hlptim LPTIM handle
1461 * @retval Counter value.
1463 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
1465 /* Check the parameters */
1466 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1468 return (hlptim->Instance->CNT);
1472 * @brief This function return the current Autoreload (Period) value.
1473 * @param hlptim LPTIM handle
1474 * @retval Autoreload value.
1476 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
1478 /* Check the parameters */
1479 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1481 return (hlptim->Instance->ARR);
1485 * @brief This function return the current Compare (Pulse) value.
1486 * @param hlptim LPTIM handle
1487 * @retval Compare value.
1489 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
1491 /* Check the parameters */
1492 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1494 return (hlptim->Instance->CMP);
1498 * @}
1503 /** @defgroup LPTIM_Group4 LPTIM IRQ handler
1504 * @brief LPTIM IRQ handler.
1506 @verbatim
1507 ==============================================================================
1508 ##### LPTIM IRQ handler #####
1509 ==============================================================================
1510 [..] This section provides LPTIM IRQ handler function.
1512 @endverbatim
1513 * @{
1517 * @brief This function handles LPTIM interrupt request.
1518 * @param hlptim LPTIM handle
1519 * @retval None
1521 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
1523 /* Compare match interrupt */
1524 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
1526 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) !=RESET)
1528 /* Clear Compare match flag */
1529 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
1530 /* Compare match Callback */
1531 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1532 hlptim->CompareMatchCallback(hlptim);
1533 #else
1534 HAL_LPTIM_CompareMatchCallback(hlptim);
1535 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1539 /* Autoreload match interrupt */
1540 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
1542 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) !=RESET)
1544 /* Clear Autoreload match flag */
1545 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
1546 /* Autoreload match Callback */
1547 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1548 hlptim->AutoReloadMatchCallback(hlptim);
1549 #else
1550 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
1551 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1555 /* Trigger detected interrupt */
1556 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
1558 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) !=RESET)
1560 /* Clear Trigger detected flag */
1561 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
1562 /* Trigger detected callback */
1563 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1564 hlptim->TriggerCallback(hlptim);
1565 #else
1566 HAL_LPTIM_TriggerCallback(hlptim);
1567 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1571 /* Compare write interrupt */
1572 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
1574 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_FLAG_CMPM) !=RESET)
1576 /* Clear Compare write flag */
1577 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1578 /* Compare write Callback */
1579 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1580 hlptim->CompareWriteCallback(hlptim);
1581 #else
1582 HAL_LPTIM_CompareWriteCallback(hlptim);
1583 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1587 /* Autoreload write interrupt */
1588 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
1590 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) !=RESET)
1592 /* Clear Autoreload write flag */
1593 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1594 /* Autoreload write Callback */
1595 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1596 hlptim->AutoReloadWriteCallback(hlptim);
1597 #else
1598 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
1599 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1603 /* Direction counter changed from Down to Up interrupt */
1604 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
1606 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) !=RESET)
1608 /* Clear Direction counter changed from Down to Up flag */
1609 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
1610 /* Direction counter changed from Down to Up Callback */
1611 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1612 hlptim->DirectionUpCallback(hlptim);
1613 #else
1614 HAL_LPTIM_DirectionUpCallback(hlptim);
1615 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1619 /* Direction counter changed from Up to Down interrupt */
1620 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
1622 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) !=RESET)
1624 /* Clear Direction counter changed from Up to Down flag */
1625 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
1626 /* Direction counter changed from Up to Down Callback */
1627 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1628 hlptim->DirectionDownCallback(hlptim);
1629 #else
1630 HAL_LPTIM_DirectionDownCallback(hlptim);
1631 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1635 __HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
1639 * @brief Compare match callback in non blocking mode
1640 * @param hlptim LPTIM handle
1641 * @retval None
1643 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
1645 /* Prevent unused argument(s) compilation warning */
1646 UNUSED(hlptim);
1648 /* NOTE : This function Should not be modified, when the callback is needed,
1649 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
1654 * @brief Autoreload match callback in non blocking mode
1655 * @param hlptim LPTIM handle
1656 * @retval None
1658 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
1660 /* Prevent unused argument(s) compilation warning */
1661 UNUSED(hlptim);
1663 /* NOTE : This function Should not be modified, when the callback is needed,
1664 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
1669 * @brief Trigger detected callback in non blocking mode
1670 * @param hlptim LPTIM handle
1671 * @retval None
1673 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
1675 /* Prevent unused argument(s) compilation warning */
1676 UNUSED(hlptim);
1678 /* NOTE : This function Should not be modified, when the callback is needed,
1679 the HAL_LPTIM_TriggerCallback could be implemented in the user file
1684 * @brief Compare write callback in non blocking mode
1685 * @param hlptim LPTIM handle
1686 * @retval None
1688 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
1690 /* Prevent unused argument(s) compilation warning */
1691 UNUSED(hlptim);
1693 /* NOTE : This function Should not be modified, when the callback is needed,
1694 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
1699 * @brief Autoreload write callback in non blocking mode
1700 * @param hlptim LPTIM handle
1701 * @retval None
1703 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
1705 /* Prevent unused argument(s) compilation warning */
1706 UNUSED(hlptim);
1708 /* NOTE : This function Should not be modified, when the callback is needed,
1709 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
1714 * @brief Direction counter changed from Down to Up callback in non blocking mode
1715 * @param hlptim LPTIM handle
1716 * @retval None
1718 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
1720 /* Prevent unused argument(s) compilation warning */
1721 UNUSED(hlptim);
1723 /* NOTE : This function Should not be modified, when the callback is needed,
1724 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
1729 * @brief Direction counter changed from Up to Down callback in non blocking mode
1730 * @param hlptim LPTIM handle
1731 * @retval None
1733 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
1735 /* Prevent unused argument(s) compilation warning */
1736 UNUSED(hlptim);
1738 /* NOTE : This function Should not be modified, when the callback is needed,
1739 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
1743 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1745 * @brief Register user LPTIM callback to be used instead of the weak predefined callback
1746 * @param hlptim lptim handle
1747 * @param CallbackID ID of the callback to be registered
1748 * This parameter can be one of the following values:
1749 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID MspInit Callback ID
1750 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID MspDeInit Callback ID
1751 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare Match Callback ID
1752 * @arg @ref HAL_LPTIM_AUTO_RELOAD_MATCH_CB_ID Auto Reload Match Callback ID
1753 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID Trigger Callback ID
1754 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare Write Callback ID
1755 * @arg @ref HAL_LPTIM_AUTO_RELOAD_WRITE_CB_ID Auto Reload Write Callback ID
1756 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Direction UP Callback ID
1757 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Direction Down Callback ID
1758 * @param pCallback pointer to the callback function
1759 * @retval status
1761 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim, HAL_LPTIM_CallbackIDTypeDef CallbackID, pLPTIM_CallbackTypeDef pCallback)
1763 HAL_StatusTypeDef status = HAL_OK;
1765 if(pCallback == NULL)
1767 return HAL_ERROR;
1769 /* Process locked */
1770 __HAL_LOCK(hlptim);
1772 if(hlptim->State == HAL_LPTIM_STATE_READY)
1774 switch (CallbackID)
1776 case HAL_LPTIM_MSPINIT_CB_ID :
1777 hlptim->MspInitCallback = pCallback;
1778 break;
1780 case HAL_LPTIM_MSPDEINIT_CB_ID :
1781 hlptim->MspDeInitCallback = pCallback;
1782 break;
1784 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
1785 hlptim->CompareMatchCallback = pCallback;
1786 break;
1788 case HAL_LPTIM_AUTO_RELOAD_MATCH_CB_ID :
1789 hlptim->AutoReloadMatchCallback = pCallback;
1790 break;
1792 case HAL_LPTIM_TRIGGER_CB_ID :
1793 hlptim->TriggerCallback = pCallback;
1794 break;
1796 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
1797 hlptim->CompareWriteCallback = pCallback;
1798 break;
1800 case HAL_LPTIM_AUTO_RELOAD_WRITE_CB_ID :
1801 hlptim->AutoReloadWriteCallback = pCallback;
1802 break;
1804 case HAL_LPTIM_DIRECTION_UP_CB_ID :
1805 hlptim->DirectionUpCallback = pCallback;
1806 break;
1808 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
1809 hlptim->DirectionDownCallback = pCallback;
1810 break;
1812 default :
1813 /* Return error status */
1814 status = HAL_ERROR;
1815 break;
1818 else if(hlptim->State == HAL_LPTIM_STATE_RESET)
1820 switch (CallbackID)
1822 case HAL_LPTIM_MSPINIT_CB_ID :
1823 hlptim->MspInitCallback = pCallback;
1824 break;
1826 case HAL_LPTIM_MSPDEINIT_CB_ID :
1827 hlptim->MspDeInitCallback = pCallback;
1828 break;
1830 default :
1831 /* Return error status */
1832 status = HAL_ERROR;
1833 break;
1836 else
1838 /* Return error status */
1839 status = HAL_ERROR;
1842 /* Release Lock */
1843 __HAL_UNLOCK(hlptim);
1845 return status;
1849 * @brief UnRegister user LPTIM callback
1850 * LPTIM callback is redirected to the weak predefined callback
1851 * @param hlptim lptim handle
1852 * @param CallbackID ID of the callback to be unregistered
1853 + * This parameter can be one of the following values:
1854 + * @arg @ref HAL_LPTIM_MSPINIT_CB_ID MspInit Callback ID
1855 + * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID MspDeInit Callback ID
1856 + * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare Match Callback ID
1857 + * @arg @ref HAL_LPTIM_AUTO_RELOAD_MATCH_CB_ID Auto Reload Match Callback ID
1858 + * @arg @ref HAL_LPTIM_TRIGGER_CB_ID Trigger Callback ID
1859 + * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare Write Callback ID
1860 + * @arg @ref HAL_LPTIM_AUTO_RELOAD_WRITE_CB_ID Auto Reload Write Callback ID
1861 + * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Direction UP Callback ID
1862 + * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Direction Down Callback ID
1863 * @retval status
1865 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim, HAL_LPTIM_CallbackIDTypeDef CallbackID)
1867 HAL_StatusTypeDef status = HAL_OK;
1869 /* Process locked */
1870 __HAL_LOCK(hlptim);
1872 if(hlptim->State == HAL_LPTIM_STATE_READY)
1874 switch (CallbackID)
1876 case HAL_LPTIM_MSPINIT_CB_ID :
1877 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
1878 break;
1880 case HAL_LPTIM_MSPDEINIT_CB_ID :
1881 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak MspDeInit Callback */
1882 break;
1884 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
1885 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Legacy weak Compare Match Callback */
1886 break;
1888 case HAL_LPTIM_AUTO_RELOAD_MATCH_CB_ID :
1889 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Legacy weak Auto Reload Match Callback */
1890 break;
1892 case HAL_LPTIM_TRIGGER_CB_ID :
1893 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* Legacy weak Trigger Callback */
1894 break;
1896 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
1897 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Legacy weak Compare Write Callback */
1898 break;
1900 case HAL_LPTIM_AUTO_RELOAD_WRITE_CB_ID :
1901 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Legacy weak Auto Reload Write Callback */
1902 break;
1904 case HAL_LPTIM_DIRECTION_UP_CB_ID :
1905 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Legacy weak Direction Up Callback */
1906 break;
1908 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
1909 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Legacy weak Direction Down Callback */
1910 break;
1912 default :
1913 /* Return error status */
1914 status = HAL_ERROR;
1915 break;
1918 else if(hlptim->State == HAL_LPTIM_STATE_RESET)
1920 switch (CallbackID)
1922 case HAL_LPTIM_MSPINIT_CB_ID :
1923 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
1924 break;
1926 case HAL_LPTIM_MSPDEINIT_CB_ID :
1927 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak MspDeInit Callback */
1928 break;
1930 default :
1931 /* Return error status */
1932 status = HAL_ERROR;
1933 break;
1936 else
1938 /* Return error status */
1939 status = HAL_ERROR;
1942 /* Release Lock */
1943 __HAL_UNLOCK(hlptim);
1945 return status;
1947 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1950 * @}
1953 /** @defgroup LPTIM_Group5 Peripheral State functions
1954 * @brief Peripheral State functions.
1956 @verbatim
1957 ==============================================================================
1958 ##### Peripheral State functions #####
1959 ==============================================================================
1960 [..]
1961 This subsection permits to get in run-time the status of the peripheral.
1963 @endverbatim
1964 * @{
1968 * @brief Returns the LPTIM state.
1969 * @param hlptim LPTIM handle
1970 * @retval HAL state
1972 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
1974 return hlptim->State;
1978 * @}
1983 * @}
1986 #endif /* HAL_LPTIM_MODULE_ENABLED */
1988 * @}
1992 * @}
1995 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/