1 /**
2 ******************************************************************************
3 * @file stm32l4xx_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.
13 *
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 The LPTIM HAL driver can be used as follows:
20
21 (#)Initialize the LPTIM low level resources by implementing the
22 HAL_LPTIM_MspInit():
23 (++) Enable the LPTIM interface clock using __HAL_RCC_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().
28
29 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
30 configures mainly:
31 (++) The instance: LPTIM1 or LPTIM2.
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 possible.
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.
51 (++) Input1Source: Source selected for input1 (GPIO or comparator output).
52 (++) Input2Source: Source selected for input2 (GPIO or comparator output).
53 Input2 is used only for encoder feature so is used only for LPTIM1 instance.
54
55 (#)Six modes are available:
56
57 (++) PWM Mode: To generate a PWM signal with specified period and pulse,
58 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
59 mode.
60
61 (++) One Pulse Mode: To generate pulse with specified width in response
62 to a stimulus, call HAL_LPTIM_OnePulse_Start() or
63 HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
64
65 (++) Set once Mode: In this mode, the output changes the level (from
66 low level to high level if the output polarity is configured high, else
67 the opposite) when a compare match occurs. To start this mode, call
68 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
69 interruption mode.
70
71 (++) Encoder Mode: To use the encoder interface call
72 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
73 interruption mode. Only available for LPTIM1 instance.
74
75 (++) Time out Mode: an active edge on one selected trigger input rests
76 the counter. The first trigger event will start the timer, any
77 successive trigger event will reset the counter and the timer will
78 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
79 HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
80
81 (++) Counter Mode: counter can be used to count external events on
82 the LPTIM Input1 or it can be used to count internal clock cycles.
83 To start this mode, call HAL_LPTIM_Counter_Start() or
84 HAL_LPTIM_Counter_Start_IT() for interruption mode.
85
86
87 (#) User can stop any process by calling the corresponding API:
88 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
89 already started in interruption mode.
90
91 (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
92
93 *** Callback registration ***
94 =============================================
95
96 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1
97 allows the user to configure dynamically the driver callbacks.
98
99 Use Function @ref HAL_LPTIM_RegisterCallback() to register a callback.
100 @ref HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle,
101 the Callback ID and a pointer to the user callback function.
102
103 Use function @ref HAL_LPTIM_UnRegisterCallback() to reset a callback to the
104 default weak function.
105 @ref HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
106 and the Callback ID.
107
108 These functions allow to register/unregister following callbacks:
109
110 (+) MspInitCallback : LPTIM Base Msp Init Callback.
111 (+) MspDeInitCallback : LPTIM Base Msp DeInit Callback.
112 (+) CompareMatchCallback : Compare match Callback.
113 (+) AutoReloadMatchCallback : Auto-reload match Callback.
114 (+) TriggerCallback : External trigger event detection Callback.
115 (+) CompareWriteCallback : Compare register write complete Callback.
116 (+) AutoReloadWriteCallback : Auto-reload register write complete Callback.
117 (+) DirectionUpCallback : Up-counting direction change Callback.
118 (+) DirectionDownCallback : Down-counting direction change Callback.
119
120 By default, after the Init and when the state is HAL_LPTIM_STATE_RESET
121 all interrupt callbacks are set to the corresponding weak functions:
122 examples @ref HAL_LPTIM_TriggerCallback(), @ref HAL_LPTIM_CompareMatchCallback().
123
124 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
125 functionalities in the Init/DeInit only when these callbacks are null
126 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit
127 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
128
129 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only.
130 Exception done MspInit/MspDeInit that can be registered/unregistered
131 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state,
132 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
133 In that case first register the MspInit/MspDeInit user callbacks
134 using @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function.
135
136 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or
137 not defined, the callback registration feature is not available and all callbacks
138 are set to the corresponding weak functions.
139 @endverbatim
140 ******************************************************************************
141 * @attention
142 *
143 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
144 *
145 * Redistribution and use in source and binary forms, with or without modification,
146 * are permitted provided that the following conditions are met:
147 * 1. Redistributions of source code must retain the above copyright notice,
148 * this list of conditions and the following disclaimer.
149 * 2. Redistributions in binary form must reproduce the above copyright notice,
150 * this list of conditions and the following disclaimer in the documentation
151 * and/or other materials provided with the distribution.
152 * 3. Neither the name of STMicroelectronics nor the names of its contributors
153 * may be used to endorse or promote products derived from this software
154 * without specific prior written permission.
155 *
156 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
157 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
159 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
160 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
161 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
162 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
163 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
164 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
165 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
166 *
167 ******************************************************************************
168 */
169
170 /* Includes ------------------------------------------------------------------*/
171 #include "stm32l4xx_hal.h"
172
173 /** @addtogroup STM32L4xx_HAL_Driver
174 * @{
175 */
176
177 /** @defgroup LPTIM LPTIM
178 * @brief LPTIM HAL module driver.
179 * @{
180 */
181
182 #ifdef HAL_LPTIM_MODULE_ENABLED
183 /* Private typedef -----------------------------------------------------------*/
184 /* Private define ------------------------------------------------------------*/
185 /* Private macro -------------------------------------------------------------*/
186 /* Private variables ---------------------------------------------------------*/
187 /* Private function prototypes -----------------------------------------------*/
188 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
189 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim);
190 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
191
192 /* Exported functions --------------------------------------------------------*/
193
194 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
195 * @{
196 */
197
198 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
199 * @brief Initialization and Configuration functions.
200 *
201 @verbatim
202 ==============================================================================
203 ##### Initialization and de-initialization functions #####
204 ==============================================================================
205 [..] This section provides functions allowing to:
206 (+) Initialize the LPTIM according to the specified parameters in the
207 LPTIM_InitTypeDef and initialize the associated handle.
208 (+) DeInitialize the LPTIM peripheral.
209 (+) Initialize the LPTIM MSP.
210 (+) DeInitialize the LPTIM MSP.
211
212 @endverbatim
213 * @{
214 */
215
216 /**
217 * @brief Initialize the LPTIM according to the specified parameters in the
218 * LPTIM_InitTypeDef and initialize the associated handle.
219 * @param hlptim: LPTIM handle
220 * @retval HAL status
221 */
HAL_LPTIM_Init(LPTIM_HandleTypeDef * hlptim)222 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
223 {
224 uint32_t tmpcfgr = 0;
225
226 /* Check the LPTIM handle allocation */
227 if(hlptim == NULL)
228 {
229 return HAL_ERROR;
230 }
231
232 /* Check the parameters */
233 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
234
235 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
236 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
237 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
238 {
239 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
240 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
241 }
242 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
243 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
244 {
245 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
246 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
247 }
248 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
249 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
250 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
251
252 #if defined(LPTIM_RCR_REP)
253 assert_param(IS_LPTIM_REPETITION(hlptim->Init.RepetitionCounter));
254 #endif
255
256 if(hlptim->State == HAL_LPTIM_STATE_RESET)
257 {
258 /* Allocate lock resource and initialize it */
259 hlptim->Lock = HAL_UNLOCKED;
260
261 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
262 /* Reset interrupt callbacks to legacy weak callbacks */
263 LPTIM_ResetCallback(hlptim);
264
265 if (hlptim->MspInitCallback == NULL)
266 {
267 hlptim->MspInitCallback = HAL_LPTIM_MspInit;
268 }
269
270 /* Init the low level hardware : GPIO, CLOCK, NVIC */
271 hlptim->MspInitCallback(hlptim);
272 #else
273 /* Init the low level hardware : GPIO, CLOCK, NVIC */
274 HAL_LPTIM_MspInit(hlptim);
275 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
276 }
277
278 /* Change the LPTIM state */
279 hlptim->State = HAL_LPTIM_STATE_BUSY;
280
281 /* Get the LPTIMx CFGR value */
282 tmpcfgr = hlptim->Instance->CFGR;
283
284 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
285 {
286 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
287 }
288 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
289 {
290 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
291 }
292
293 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
294 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
295 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
296
297 /* Set initialization parameters */
298 tmpcfgr |= (hlptim->Init.Clock.Source |
299 hlptim->Init.Clock.Prescaler |
300 hlptim->Init.OutputPolarity |
301 hlptim->Init.UpdateMode |
302 hlptim->Init.CounterSource);
303
304 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
305 {
306 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
307 hlptim->Init.UltraLowPowerClock.SampleTime);
308 }
309
310 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
311 {
312 /* Enable External trigger and set the trigger source */
313 tmpcfgr |= (hlptim->Init.Trigger.Source |
314 hlptim->Init.Trigger.ActiveEdge |
315 hlptim->Init.Trigger.SampleTime);
316 }
317
318 /* Write to LPTIMx CFGR */
319 hlptim->Instance->CFGR = tmpcfgr;
320
321 /* Configure LPTIM input sources */
322 if(hlptim->Instance == LPTIM1)
323 {
324 /* Check LPTIM1 Input1 and Input2 sources */
325 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
326 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance,hlptim->Init.Input2Source));
327
328 /* Configure LPTIM1 Input1 and Input2 sources */
329 hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
330 }
331 else
332 {
333 /* Check LPTIM2 Input1 source */
334 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
335
336 /* Configure LPTIM2 Input1 source */
337 hlptim->Instance->OR = hlptim->Init.Input1Source;
338 }
339
340 /* Change the LPTIM state */
341 hlptim->State = HAL_LPTIM_STATE_READY;
342
343 /* Return function status */
344 return HAL_OK;
345 }
346
347 /**
348 * @brief DeInitialize the LPTIM peripheral.
349 * @param hlptim: LPTIM handle
350 * @retval HAL status
351 */
HAL_LPTIM_DeInit(LPTIM_HandleTypeDef * hlptim)352 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
353 {
354 /* Check the LPTIM handle allocation */
355 if(hlptim == NULL)
356 {
357 return HAL_ERROR;
358 }
359
360 /* Change the LPTIM state */
361 hlptim->State = HAL_LPTIM_STATE_BUSY;
362
363 /* Disable the LPTIM Peripheral Clock */
364 __HAL_LPTIM_DISABLE(hlptim);
365
366 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
367 if (hlptim->MspDeInitCallback == NULL)
368 {
369 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit;
370 }
371
372 /* DeInit the low level hardware: CLOCK, NVIC.*/
373 hlptim->MspDeInitCallback(hlptim);
374 #else
375 /* DeInit the low level hardware: CLOCK, NVIC.*/
376 HAL_LPTIM_MspDeInit(hlptim);
377 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
378
379 /* Change the LPTIM state */
380 hlptim->State = HAL_LPTIM_STATE_RESET;
381
382 /* Release Lock */
383 __HAL_UNLOCK(hlptim);
384
385 /* Return function status */
386 return HAL_OK;
387 }
388
389 /**
390 * @brief Initialize the LPTIM MSP.
391 * @param hlptim: LPTIM handle
392 * @retval None
393 */
HAL_LPTIM_MspInit(LPTIM_HandleTypeDef * hlptim)394 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
395 {
396 /* Prevent unused argument(s) compilation warning */
397 UNUSED(hlptim);
398
399 /* NOTE : This function should not be modified, when the callback is needed,
400 the HAL_LPTIM_MspInit could be implemented in the user file
401 */
402 }
403
404 /**
405 * @brief DeInitialize LPTIM MSP.
406 * @param hlptim: LPTIM handle
407 * @retval None
408 */
HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef * hlptim)409 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
410 {
411 /* Prevent unused argument(s) compilation warning */
412 UNUSED(hlptim);
413
414 /* NOTE : This function should not be modified, when the callback is needed,
415 the HAL_LPTIM_MspDeInit could be implemented in the user file
416 */
417 }
418
419 /**
420 * @}
421 */
422
423 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
424 * @brief Start-Stop operation functions.
425 *
426 @verbatim
427 ==============================================================================
428 ##### LPTIM Start Stop operation functions #####
429 ==============================================================================
430 [..] This section provides functions allowing to:
431 (+) Start the PWM mode.
432 (+) Stop the PWM mode.
433 (+) Start the One pulse mode.
434 (+) Stop the One pulse mode.
435 (+) Start the Set once mode.
436 (+) Stop the Set once mode.
437 (+) Start the Encoder mode.
438 (+) Stop the Encoder mode.
439 (+) Start the Timeout mode.
440 (+) Stop the Timeout mode.
441 (+) Start the Counter mode.
442 (+) Stop the Counter mode.
443
444
445 @endverbatim
446 * @{
447 */
448
449 /**
450 * @brief Start the LPTIM PWM generation.
451 * @param hlptim : LPTIM handle
452 * @param Period : Specifies the Autoreload value.
453 * This parameter must be a value between 0x0000 and 0xFFFF.
454 * @param Pulse : Specifies the compare value.
455 * This parameter must be a value between 0x0000 and 0xFFFF.
456 * @retval HAL status
457 */
HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)458 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
459 {
460 /* Check the parameters */
461 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
462 assert_param(IS_LPTIM_PERIOD(Period));
463 assert_param(IS_LPTIM_PULSE(Pulse));
464
465 /* Set the LPTIM state */
466 hlptim->State= HAL_LPTIM_STATE_BUSY;
467
468 /* Reset WAVE bit to set PWM mode */
469 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
470
471 /* Enable the Peripheral */
472 __HAL_LPTIM_ENABLE(hlptim);
473
474 /* Load the period value in the autoreload register */
475 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
476
477 /* Load the pulse value in the compare register */
478 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
479
480 #if defined(LPTIM_RCR_REP)
481 /* Load the repetition value in the repetition counter */
482 if (hlptim->Init.RepetitionCounter != 0)
483 {
484 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
485 }
486 #endif
487
488 /* Start timer in continuous mode */
489 __HAL_LPTIM_START_CONTINUOUS(hlptim);
490
491 /* Change the TIM state*/
492 hlptim->State= HAL_LPTIM_STATE_READY;
493
494 /* Return function status */
495 return HAL_OK;
496 }
497
498 /**
499 * @brief Stop the LPTIM PWM generation.
500 * @param hlptim : LPTIM handle
501 * @retval HAL status
502 */
HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef * hlptim)503 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
504 {
505 /* Check the parameters */
506 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
507
508 /* Set the LPTIM state */
509 hlptim->State= HAL_LPTIM_STATE_BUSY;
510
511 /* Disable the Peripheral */
512 __HAL_LPTIM_DISABLE(hlptim);
513
514 /* Change the TIM state*/
515 hlptim->State= HAL_LPTIM_STATE_READY;
516
517 /* Return function status */
518 return HAL_OK;
519 }
520
521 /**
522 * @brief Start the LPTIM PWM generation in interrupt mode.
523 * @param hlptim : LPTIM handle
524 * @param Period : Specifies the Autoreload value.
525 * This parameter must be a value between 0x0000 and 0xFFFF
526 * @param Pulse : Specifies the compare value.
527 * This parameter must be a value between 0x0000 and 0xFFFF
528 * @retval HAL status
529 */
HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)530 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
531 {
532 /* Check the parameters */
533 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
534 assert_param(IS_LPTIM_PERIOD(Period));
535 assert_param(IS_LPTIM_PULSE(Pulse));
536
537 /* Set the LPTIM state */
538 hlptim->State= HAL_LPTIM_STATE_BUSY;
539
540 /* Reset WAVE bit to set PWM mode */
541 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
542
543 /* Enable Autoreload write complete interrupt */
544 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
545
546 /* Enable Compare write complete interrupt */
547 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
548
549 /* Enable Autoreload match interrupt */
550 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
551
552 /* Enable Compare match interrupt */
553 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
554
555 /* If external trigger source is used, then enable external trigger interrupt */
556 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
557 {
558 /* Enable external trigger interrupt */
559 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
560 }
561
562 #if defined(LPTIM_RCR_REP)
563 /* Enable the update event and the repetition register update OK interrupts */
564 if ((hlptim->Init.RepetitionCounter) != 0)
565 {
566 __HAL_LPTIM_ENABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
567 }
568 #endif
569
570 /* Enable the Peripheral */
571 __HAL_LPTIM_ENABLE(hlptim);
572
573 /* Load the period value in the autoreload register */
574 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
575
576 /* Load the pulse value in the compare register */
577 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
578
579 #if defined(LPTIM_RCR_REP)
580 /* Load the repetition value in the repetition counter */
581 if (hlptim->Init.RepetitionCounter != 0)
582 {
583 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
584 }
585 #endif
586
587 /* Start timer in continuous mode */
588 __HAL_LPTIM_START_CONTINUOUS(hlptim);
589
590 /* Change the TIM state*/
591 hlptim->State= HAL_LPTIM_STATE_READY;
592
593 /* Return function status */
594 return HAL_OK;
595 }
596
597 /**
598 * @brief Stop the LPTIM PWM generation in interrupt mode.
599 * @param hlptim : LPTIM handle
600 * @retval HAL status
601 */
HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef * hlptim)602 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
603 {
604 /* Check the parameters */
605 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
606
607 /* Set the LPTIM state */
608 hlptim->State= HAL_LPTIM_STATE_BUSY;
609
610 /* Disable the Peripheral */
611 __HAL_LPTIM_DISABLE(hlptim);
612
613 /* Disable Autoreload write complete interrupt */
614 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
615
616 /* Disable Compare write complete interrupt */
617 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
618
619 /* Disable Autoreload match interrupt */
620 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
621
622 /* Disable Compare match interrupt */
623 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
624
625 /* If external trigger source is used, then disable external trigger interrupt */
626 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
627 {
628 /* Disable external trigger interrupt */
629 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
630 }
631
632 #if defined(LPTIM_RCR_REP)
633 /* Disable the update event and the repetition register update OK interrupts */
634 if ((hlptim->Init.RepetitionCounter) != 0)
635 {
636 __HAL_LPTIM_DISABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
637 }
638 #endif
639
640 /* Change the TIM state*/
641 hlptim->State= HAL_LPTIM_STATE_READY;
642
643 /* Return function status */
644 return HAL_OK;
645 }
646
647 /**
648 * @brief Start the LPTIM One pulse generation.
649 * @param hlptim : LPTIM handle
650 * @param Period : Specifies the Autoreload value.
651 * This parameter must be a value between 0x0000 and 0xFFFF.
652 * @param Pulse : Specifies the compare value.
653 * This parameter must be a value between 0x0000 and 0xFFFF.
654 * @retval HAL status
655 */
HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)656 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
657 {
658 /* Check the parameters */
659 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
660 assert_param(IS_LPTIM_PERIOD(Period));
661 assert_param(IS_LPTIM_PULSE(Pulse));
662
663 /* Set the LPTIM state */
664 hlptim->State= HAL_LPTIM_STATE_BUSY;
665
666 /* Reset WAVE bit to set one pulse mode */
667 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
668
669 /* Enable the Peripheral */
670 __HAL_LPTIM_ENABLE(hlptim);
671
672 /* Load the period value in the autoreload register */
673 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
674
675 /* Load the pulse value in the compare register */
676 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
677
678 /* Start timer in continuous mode */
679 __HAL_LPTIM_START_SINGLE(hlptim);
680
681 #if defined(LPTIM_RCR_REP)
682 /* Load the repetition value in the repetition counter */
683 if (hlptim->Init.RepetitionCounter != 0)
684 {
685 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
686 }
687 #endif
688
689 /* Change the TIM state*/
690 hlptim->State= HAL_LPTIM_STATE_READY;
691
692 /* Return function status */
693 return HAL_OK;
694 }
695
696 /**
697 * @brief Stop the LPTIM One pulse generation.
698 * @param hlptim : LPTIM handle
699 * @retval HAL status
700 */
HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef * hlptim)701 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
702 {
703 /* Check the parameters */
704 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
705
706 /* Set the LPTIM state */
707 hlptim->State= HAL_LPTIM_STATE_BUSY;
708
709 /* Disable the Peripheral */
710 __HAL_LPTIM_DISABLE(hlptim);
711
712 /* Change the TIM state*/
713 hlptim->State= HAL_LPTIM_STATE_READY;
714
715 /* Return function status */
716 return HAL_OK;
717 }
718
719 /**
720 * @brief Start the LPTIM One pulse generation in interrupt mode.
721 * @param hlptim : LPTIM handle
722 * @param Period : Specifies the Autoreload value.
723 * This parameter must be a value between 0x0000 and 0xFFFF.
724 * @param Pulse : Specifies the compare value.
725 * This parameter must be a value between 0x0000 and 0xFFFF.
726 * @retval HAL status
727 */
HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)728 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
729 {
730 /* Check the parameters */
731 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
732 assert_param(IS_LPTIM_PERIOD(Period));
733 assert_param(IS_LPTIM_PULSE(Pulse));
734
735 /* Set the LPTIM state */
736 hlptim->State= HAL_LPTIM_STATE_BUSY;
737
738 /* Reset WAVE bit to set one pulse mode */
739 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
740
741 /* Enable Autoreload write complete interrupt */
742 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
743
744 /* Enable Compare write complete interrupt */
745 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
746
747 /* Enable Autoreload match interrupt */
748 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
749
750 /* Enable Compare match interrupt */
751 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
752
753 /* If external trigger source is used, then enable external trigger interrupt */
754 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
755 {
756 /* Enable external trigger interrupt */
757 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
758 }
759
760 #if defined(LPTIM_RCR_REP)
761 /* Enable the update event and the repetition register update OK interrupts */
762 if ((hlptim->Init.RepetitionCounter) != 0)
763 {
764 __HAL_LPTIM_ENABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
765 }
766 #endif
767
768 /* Enable the Peripheral */
769 __HAL_LPTIM_ENABLE(hlptim);
770
771 /* Load the period value in the autoreload register */
772 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
773
774 /* Load the pulse value in the compare register */
775 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
776
777 #if defined(LPTIM_RCR_REP)
778 /* Load the repetition value in the repetition counter */
779 if (hlptim->Init.RepetitionCounter != 0)
780 {
781 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
782 }
783 #endif
784
785 /* Start timer in continuous mode */
786 __HAL_LPTIM_START_SINGLE(hlptim);
787
788 /* Change the TIM state*/
789 hlptim->State= HAL_LPTIM_STATE_READY;
790
791 /* Return function status */
792 return HAL_OK;
793 }
794
795 /**
796 * @brief Stop the LPTIM One pulse generation in interrupt mode.
797 * @param hlptim : LPTIM handle
798 * @retval HAL status
799 */
HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef * hlptim)800 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
801 {
802 /* Check the parameters */
803 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
804
805 /* Set the LPTIM state */
806 hlptim->State= HAL_LPTIM_STATE_BUSY;
807
808 /* Disable the Peripheral */
809 __HAL_LPTIM_DISABLE(hlptim);
810
811 /* Disable Autoreload write complete interrupt */
812 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
813
814 /* Disable Compare write complete interrupt */
815 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
816
817 /* Disable Autoreload match interrupt */
818 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
819
820 /* Disable Compare match interrupt */
821 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
822
823 /* If external trigger source is used, then disable external trigger interrupt */
824 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
825 {
826 /* Disable external trigger interrupt */
827 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
828 }
829
830 #if defined(LPTIM_RCR_REP)
831 /* Disable the update event and the repetition register update OK interrupts */
832 if ((hlptim->Init.RepetitionCounter) != 0)
833 {
834 __HAL_LPTIM_DISABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
835 }
836 #endif
837
838 /* Change the TIM state*/
839 hlptim->State= HAL_LPTIM_STATE_READY;
840
841 /* Return function status */
842 return HAL_OK;
843 }
844
845 /**
846 * @brief Start the LPTIM in Set once mode.
847 * @param hlptim : LPTIM handle
848 * @param Period : Specifies the Autoreload value.
849 * This parameter must be a value between 0x0000 and 0xFFFF.
850 * @param Pulse : Specifies the compare value.
851 * This parameter must be a value between 0x0000 and 0xFFFF.
852 * @retval HAL status
853 */
HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)854 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
855 {
856 /* Check the parameters */
857 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
858 assert_param(IS_LPTIM_PERIOD(Period));
859 assert_param(IS_LPTIM_PULSE(Pulse));
860
861 /* Set the LPTIM state */
862 hlptim->State= HAL_LPTIM_STATE_BUSY;
863
864 /* Set WAVE bit to enable the set once mode */
865 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
866
867 /* Enable the Peripheral */
868 __HAL_LPTIM_ENABLE(hlptim);
869
870 /* Load the period value in the autoreload register */
871 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
872
873 /* Load the pulse value in the compare register */
874 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
875
876 #if defined(LPTIM_RCR_REP)
877 /* Load the repetition value in the repetition counter */
878 if (hlptim->Init.RepetitionCounter != 0)
879 {
880 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
881 }
882 #endif
883
884 /* Start timer in continuous mode */
885 __HAL_LPTIM_START_SINGLE(hlptim);
886
887 /* Change the TIM state*/
888 hlptim->State= HAL_LPTIM_STATE_READY;
889
890 /* Return function status */
891 return HAL_OK;
892 }
893
894 /**
895 * @brief Stop the LPTIM Set once mode.
896 * @param hlptim : LPTIM handle
897 * @retval HAL status
898 */
HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef * hlptim)899 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
900 {
901 /* Check the parameters */
902 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
903
904 /* Set the LPTIM state */
905 hlptim->State= HAL_LPTIM_STATE_BUSY;
906
907 /* Disable the Peripheral */
908 __HAL_LPTIM_DISABLE(hlptim);
909
910 /* Change the TIM state*/
911 hlptim->State= HAL_LPTIM_STATE_READY;
912
913 /* Return function status */
914 return HAL_OK;
915 }
916
917 /**
918 * @brief Start the LPTIM Set once mode in interrupt mode.
919 * @param hlptim : LPTIM handle
920 * @param Period : Specifies the Autoreload value.
921 * This parameter must be a value between 0x0000 and 0xFFFF.
922 * @param Pulse : Specifies the compare value.
923 * This parameter must be a value between 0x0000 and 0xFFFF.
924 * @retval HAL status
925 */
HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Pulse)926 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
927 {
928 /* Check the parameters */
929 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
930 assert_param(IS_LPTIM_PERIOD(Period));
931 assert_param(IS_LPTIM_PULSE(Pulse));
932
933 /* Set the LPTIM state */
934 hlptim->State= HAL_LPTIM_STATE_BUSY;
935
936 /* Set WAVE bit to enable the set once mode */
937 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
938
939 /* Enable Autoreload write complete interrupt */
940 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
941
942 /* Enable Compare write complete interrupt */
943 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
944
945 /* Enable Autoreload match interrupt */
946 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
947
948 /* Enable Compare match interrupt */
949 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
950
951 /* If external trigger source is used, then enable external trigger interrupt */
952 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
953 {
954 /* Enable external trigger interrupt */
955 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
956 }
957
958 #if defined(LPTIM_RCR_REP)
959 /* Enable the update event and the repetition register update OK interrupts */
960 if ((hlptim->Init.RepetitionCounter) != 0)
961 {
962 __HAL_LPTIM_ENABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
963 }
964 #endif
965
966 /* Enable the Peripheral */
967 __HAL_LPTIM_ENABLE(hlptim);
968
969 /* Load the period value in the autoreload register */
970 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
971
972 /* Load the pulse value in the compare register */
973 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
974
975 #if defined(LPTIM_RCR_REP)
976 /* Load the repetition value in the repetition counter */
977 if (hlptim->Init.RepetitionCounter != 0)
978 {
979 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
980 }
981 #endif
982
983 /* Start timer in continuous mode */
984 __HAL_LPTIM_START_SINGLE(hlptim);
985
986 /* Change the TIM state*/
987 hlptim->State= HAL_LPTIM_STATE_READY;
988
989 /* Return function status */
990 return HAL_OK;
991 }
992
993 /**
994 * @brief Stop the LPTIM Set once mode in interrupt mode.
995 * @param hlptim : LPTIM handle
996 * @retval HAL status
997 */
HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef * hlptim)998 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
999 {
1000 /* Check the parameters */
1001 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1002
1003 /* Set the LPTIM state */
1004 hlptim->State= HAL_LPTIM_STATE_BUSY;
1005
1006 /* Disable the Peripheral */
1007 __HAL_LPTIM_DISABLE(hlptim);
1008
1009 /* Disable Autoreload write complete interrupt */
1010 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1011
1012 /* Disable Compare write complete interrupt */
1013 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
1014
1015 /* Disable Autoreload match interrupt */
1016 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1017
1018 /* Disable Compare match interrupt */
1019 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1020
1021 /* If external trigger source is used, then disable external trigger interrupt */
1022 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
1023 {
1024 /* Disable external trigger interrupt */
1025 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
1026 }
1027
1028 #if defined(LPTIM_RCR_REP)
1029 /* Disable the update event and the repetition register update OK interrupts */
1030 if ((hlptim->Init.RepetitionCounter) != 0)
1031 {
1032 __HAL_LPTIM_DISABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
1033 }
1034 #endif
1035
1036 /* Change the TIM state*/
1037 hlptim->State= HAL_LPTIM_STATE_READY;
1038
1039 /* Return function status */
1040 return HAL_OK;
1041 }
1042
1043 /**
1044 * @brief Start the Encoder interface.
1045 * @param hlptim : LPTIM handle
1046 * @param Period : Specifies the Autoreload value.
1047 * This parameter must be a value between 0x0000 and 0xFFFF.
1048 * @retval HAL status
1049 */
HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period)1050 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1051 {
1052 HAL_StatusTypeDef status = HAL_OK;
1053 uint32_t tmpcfgr;
1054
1055 /* Check the parameters */
1056 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1057 assert_param(IS_LPTIM_PERIOD(Period));
1058 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
1059 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
1060 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
1061
1062 /* Encoder feature is only available for LPTIM1 instance */
1063 if (hlptim->Instance == LPTIM1)
1064 {
1065 /* Set the LPTIM state */
1066 hlptim->State= HAL_LPTIM_STATE_BUSY;
1067
1068 /* Get the LPTIMx CFGR value */
1069 tmpcfgr = hlptim->Instance->CFGR;
1070
1071 /* Clear CKPOL bits */
1072 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
1073
1074 /* Set Input polarity */
1075 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
1076
1077 /* Write to LPTIMx CFGR */
1078 hlptim->Instance->CFGR = tmpcfgr;
1079
1080 /* Set ENC bit to enable the encoder interface */
1081 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
1082
1083 /* Enable the Peripheral */
1084 __HAL_LPTIM_ENABLE(hlptim);
1085
1086 /* Load the period value in the autoreload register */
1087 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1088
1089 /* Start timer in continuous mode */
1090 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1091
1092 /* Change the TIM state*/
1093 hlptim->State= HAL_LPTIM_STATE_READY;
1094 }
1095 else
1096 {
1097 status = HAL_ERROR;
1098 }
1099
1100 /* Return function status */
1101 return status;
1102 }
1103
1104 /**
1105 * @brief Stop the Encoder interface.
1106 * @param hlptim : LPTIM handle
1107 * @retval HAL status
1108 */
HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef * hlptim)1109 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
1110 {
1111 /* Check the parameters */
1112 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1113
1114 /* Set the LPTIM state */
1115 hlptim->State= HAL_LPTIM_STATE_BUSY;
1116
1117 /* Disable the Peripheral */
1118 __HAL_LPTIM_DISABLE(hlptim);
1119
1120 /* Reset ENC bit to disable the encoder interface */
1121 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1122
1123 /* Change the TIM state*/
1124 hlptim->State= HAL_LPTIM_STATE_READY;
1125
1126 /* Return function status */
1127 return HAL_OK;
1128 }
1129
1130 /**
1131 * @brief Start the Encoder interface in interrupt mode.
1132 * @param hlptim : LPTIM handle
1133 * @param Period : Specifies the Autoreload value.
1134 * This parameter must be a value between 0x0000 and 0xFFFF.
1135 * @retval HAL status
1136 */
HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period)1137 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1138 {
1139 HAL_StatusTypeDef status = HAL_OK;
1140 uint32_t tmpcfgr;
1141
1142 /* Check the parameters */
1143 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1144 assert_param(IS_LPTIM_PERIOD(Period));
1145 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
1146 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
1147 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
1148
1149 /* Encoder feature is only available for LPTIM1 instance */
1150 if (hlptim->Instance == LPTIM1)
1151 {
1152 /* Set the LPTIM state */
1153 hlptim->State= HAL_LPTIM_STATE_BUSY;
1154
1155 /* Configure edge sensitivity for encoder mode */
1156 /* Get the LPTIMx CFGR value */
1157 tmpcfgr = hlptim->Instance->CFGR;
1158
1159 /* Clear CKPOL bits */
1160 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
1161
1162 /* Set Input polarity */
1163 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
1164
1165 /* Write to LPTIMx CFGR */
1166 hlptim->Instance->CFGR = tmpcfgr;
1167
1168 /* Set ENC bit to enable the encoder interface */
1169 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
1170
1171 /* Enable "switch to down direction" interrupt */
1172 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
1173
1174 /* Enable "switch to up direction" interrupt */
1175 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
1176
1177 /* Enable the Peripheral */
1178 __HAL_LPTIM_ENABLE(hlptim);
1179
1180 /* Load the period value in the autoreload register */
1181 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1182
1183 /* Start timer in continuous mode */
1184 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1185
1186 /* Change the TIM state*/
1187 hlptim->State= HAL_LPTIM_STATE_READY;
1188 }
1189 else
1190 {
1191 status = HAL_ERROR;
1192 }
1193
1194 /* Return function status */
1195 return status;
1196 }
1197
1198 /**
1199 * @brief Stop the Encoder interface in interrupt mode.
1200 * @param hlptim : LPTIM handle
1201 * @retval HAL status
1202 */
HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef * hlptim)1203 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1204 {
1205 /* Check the parameters */
1206 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1207
1208 /* Set the LPTIM state */
1209 hlptim->State= HAL_LPTIM_STATE_BUSY;
1210
1211 /* Disable the Peripheral */
1212 __HAL_LPTIM_DISABLE(hlptim);
1213
1214 /* Reset ENC bit to disable the encoder interface */
1215 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
1216
1217 /* Disable "switch to down direction" interrupt */
1218 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
1219
1220 /* Disable "switch to up direction" interrupt */
1221 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
1222
1223 /* Change the TIM state*/
1224 hlptim->State= HAL_LPTIM_STATE_READY;
1225
1226 /* Return function status */
1227 return HAL_OK;
1228 }
1229
1230 /**
1231 * @brief Start the Timeout function.
1232 * @note The first trigger event will start the timer, any successive
1233 * trigger event will reset the counter and the timer restarts.
1234 * @param hlptim : LPTIM handle
1235 * @param Period : Specifies the Autoreload value.
1236 * This parameter must be a value between 0x0000 and 0xFFFF.
1237 * @param Timeout : Specifies the TimeOut value to rest the counter.
1238 * This parameter must be a value between 0x0000 and 0xFFFF.
1239 * @retval HAL status
1240 */
HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Timeout)1241 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1242 {
1243 /* Check the parameters */
1244 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1245 assert_param(IS_LPTIM_PERIOD(Period));
1246 assert_param(IS_LPTIM_PULSE(Timeout));
1247
1248 /* Set the LPTIM state */
1249 hlptim->State= HAL_LPTIM_STATE_BUSY;
1250
1251 /* Set TIMOUT bit to enable the timeout function */
1252 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1253
1254 /* Enable the Peripheral */
1255 __HAL_LPTIM_ENABLE(hlptim);
1256
1257 /* Load the period value in the autoreload register */
1258 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1259
1260 /* Load the Timeout value in the compare register */
1261 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1262
1263 /* Start timer in continuous mode */
1264 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1265
1266 /* Change the TIM state*/
1267 hlptim->State= HAL_LPTIM_STATE_READY;
1268
1269 /* Return function status */
1270 return HAL_OK;
1271 }
1272
1273 /**
1274 * @brief Stop the Timeout function.
1275 * @param hlptim : LPTIM handle
1276 * @retval HAL status
1277 */
HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef * hlptim)1278 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
1279 {
1280 /* Check the parameters */
1281 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1282
1283 /* Set the LPTIM state */
1284 hlptim->State= HAL_LPTIM_STATE_BUSY;
1285
1286 /* Disable the Peripheral */
1287 __HAL_LPTIM_DISABLE(hlptim);
1288
1289 /* Reset TIMOUT bit to enable the timeout function */
1290 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1291
1292 /* Change the TIM state*/
1293 hlptim->State= HAL_LPTIM_STATE_READY;
1294
1295 /* Return function status */
1296 return HAL_OK;
1297 }
1298
1299 /**
1300 * @brief Start the Timeout function in interrupt mode.
1301 * @note The first trigger event will start the timer, any successive
1302 * trigger event will reset the counter and the timer restarts.
1303 * @param hlptim : LPTIM handle
1304 * @param Period : Specifies the Autoreload value.
1305 * This parameter must be a value between 0x0000 and 0xFFFF.
1306 * @param Timeout : Specifies the TimeOut value to rest the counter.
1307 * This parameter must be a value between 0x0000 and 0xFFFF.
1308 * @retval HAL status
1309 */
HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period,uint32_t Timeout)1310 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
1311 {
1312 /* Check the parameters */
1313 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1314 assert_param(IS_LPTIM_PERIOD(Period));
1315 assert_param(IS_LPTIM_PULSE(Timeout));
1316
1317 /* Set the LPTIM state */
1318 hlptim->State= HAL_LPTIM_STATE_BUSY;
1319
1320 /* Set TIMOUT bit to enable the timeout function */
1321 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
1322
1323 /* Enable Compare match interrupt */
1324 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
1325
1326 /* Enable the Peripheral */
1327 __HAL_LPTIM_ENABLE(hlptim);
1328
1329 /* Load the period value in the autoreload register */
1330 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1331
1332 /* Load the Timeout value in the compare register */
1333 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
1334
1335 /* Start timer in continuous mode */
1336 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1337
1338 /* Change the TIM state*/
1339 hlptim->State= HAL_LPTIM_STATE_READY;
1340
1341 /* Return function status */
1342 return HAL_OK;
1343 }
1344
1345 /**
1346 * @brief Stop the Timeout function in interrupt mode.
1347 * @param hlptim : LPTIM handle
1348 * @retval HAL status
1349 */
HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef * hlptim)1350 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1351 {
1352 /* Check the parameters */
1353 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1354
1355 /* Set the LPTIM state */
1356 hlptim->State= HAL_LPTIM_STATE_BUSY;
1357
1358 /* Disable the Peripheral */
1359 __HAL_LPTIM_DISABLE(hlptim);
1360
1361 /* Reset TIMOUT bit to enable the timeout function */
1362 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
1363
1364 /* Disable Compare match interrupt */
1365 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
1366
1367 /* Change the TIM state*/
1368 hlptim->State= HAL_LPTIM_STATE_READY;
1369
1370 /* Return function status */
1371 return HAL_OK;
1372 }
1373
1374 /**
1375 * @brief Start the Counter mode.
1376 * @param hlptim : LPTIM handle
1377 * @param Period : Specifies the Autoreload value.
1378 * This parameter must be a value between 0x0000 and 0xFFFF.
1379 * @retval HAL status
1380 */
HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef * hlptim,uint32_t Period)1381 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1382 {
1383 /* Check the parameters */
1384 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1385 assert_param(IS_LPTIM_PERIOD(Period));
1386
1387 /* Set the LPTIM state */
1388 hlptim->State= HAL_LPTIM_STATE_BUSY;
1389
1390 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1391 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1392 {
1393 /* Check if clock is prescaled */
1394 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1395 /* Set clock prescaler to 0 */
1396 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1397 }
1398
1399 /* Enable the Peripheral */
1400 __HAL_LPTIM_ENABLE(hlptim);
1401
1402 /* Load the period value in the autoreload register */
1403 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1404
1405 #if defined(LPTIM_RCR_REP)
1406 /* Load the repetition value in the repetition counter */
1407 if (hlptim->Init.RepetitionCounter != 0)
1408 {
1409 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
1410 }
1411 #endif
1412
1413 /* Start timer in continuous mode */
1414 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1415
1416 /* Change the TIM state*/
1417 hlptim->State= HAL_LPTIM_STATE_READY;
1418
1419 /* Return function status */
1420 return HAL_OK;
1421 }
1422
1423 /**
1424 * @brief Stop the Counter mode.
1425 * @param hlptim : LPTIM handle
1426 * @retval HAL status
1427 */
HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef * hlptim)1428 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
1429 {
1430 /* Check the parameters */
1431 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1432
1433 /* Set the LPTIM state */
1434 hlptim->State= HAL_LPTIM_STATE_BUSY;
1435
1436 /* Disable the Peripheral */
1437 __HAL_LPTIM_DISABLE(hlptim);
1438
1439 /* Change the TIM state*/
1440 hlptim->State= HAL_LPTIM_STATE_READY;
1441
1442 /* Return function status */
1443 return HAL_OK;
1444 }
1445
1446 /**
1447 * @brief Start the Counter mode in interrupt mode.
1448 * @param hlptim : LPTIM handle
1449 * @param Period : Specifies the Autoreload value.
1450 * This parameter must be a value between 0x0000 and 0xFFFF.
1451 * @retval HAL status
1452 */
HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef * hlptim,uint32_t Period)1453 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
1454 {
1455 /* Check the parameters */
1456 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1457 assert_param(IS_LPTIM_PERIOD(Period));
1458
1459 /* Set the LPTIM state */
1460 hlptim->State= HAL_LPTIM_STATE_BUSY;
1461
1462 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
1463 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
1464 {
1465 /* Check if clock is prescaled */
1466 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
1467 /* Set clock prescaler to 0 */
1468 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
1469 }
1470
1471 /* Enable Autoreload write complete interrupt */
1472 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
1473
1474 /* Enable Autoreload match interrupt */
1475 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
1476
1477 #if defined(LPTIM_RCR_REP)
1478 /* Enable the update event and the repetition register update OK interrupts */
1479 if ((hlptim->Init.RepetitionCounter) != 0)
1480 {
1481 __HAL_LPTIM_ENABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
1482 }
1483 #endif
1484
1485 /* Enable the Peripheral */
1486 __HAL_LPTIM_ENABLE(hlptim);
1487
1488 /* Load the period value in the autoreload register */
1489 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
1490
1491 #if defined(LPTIM_RCR_REP)
1492 /* Load the repetition value in the repetition counter */
1493 if (hlptim->Init.RepetitionCounter != 0)
1494 {
1495 __HAL_LPTIM_REPETITIONCOUNTER_SET(hlptim, hlptim->Init.RepetitionCounter);
1496 }
1497 #endif
1498
1499 /* Start timer in continuous mode */
1500 __HAL_LPTIM_START_CONTINUOUS(hlptim);
1501
1502 /* Change the TIM state*/
1503 hlptim->State= HAL_LPTIM_STATE_READY;
1504
1505 /* Return function status */
1506 return HAL_OK;
1507 }
1508
1509 /**
1510 * @brief Stop the Counter mode in interrupt mode.
1511 * @param hlptim : LPTIM handle
1512 * @retval HAL status
1513 */
HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef * hlptim)1514 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
1515 {
1516 /* Check the parameters */
1517 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1518
1519 /* Set the LPTIM state */
1520 hlptim->State= HAL_LPTIM_STATE_BUSY;
1521
1522 /* Disable the Peripheral */
1523 __HAL_LPTIM_DISABLE(hlptim);
1524
1525 /* Disable Autoreload write complete interrupt */
1526 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
1527
1528 /* Disable Autoreload match interrupt */
1529 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
1530
1531 #if defined(LPTIM_RCR_REP)
1532 /* Disable the update event and the repetition register update OK interrupts */
1533 if ((hlptim->Init.RepetitionCounter) != 0)
1534 {
1535 __HAL_LPTIM_DISABLE_IT(hlptim, (LPTIM_IT_UPDATE | LPTIM_IT_REPOK));
1536 }
1537 #endif
1538
1539 /* Change the TIM state*/
1540 hlptim->State= HAL_LPTIM_STATE_READY;
1541
1542 /* Return function status */
1543 return HAL_OK;
1544 }
1545
1546 /**
1547 * @}
1548 */
1549
1550 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
1551 * @brief Read operation functions.
1552 *
1553 @verbatim
1554 ==============================================================================
1555 ##### LPTIM Read operation functions #####
1556 ==============================================================================
1557 [..] This section provides LPTIM Reading functions.
1558 (+) Read the counter value.
1559 (+) Read the period (Auto-reload) value.
1560 (+) Read the pulse (Compare)value.
1561 @endverbatim
1562 * @{
1563 */
1564
1565 /**
1566 * @brief Return the current counter value.
1567 * @param hlptim: LPTIM handle
1568 * @retval Counter value.
1569 */
HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef * hlptim)1570 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
1571 {
1572 /* Check the parameters */
1573 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1574
1575 return (hlptim->Instance->CNT);
1576 }
1577
1578 /**
1579 * @brief Return the current Autoreload (Period) value.
1580 * @param hlptim: LPTIM handle
1581 * @retval Autoreload value.
1582 */
HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef * hlptim)1583 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
1584 {
1585 /* Check the parameters */
1586 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1587
1588 return (hlptim->Instance->ARR);
1589 }
1590
1591 /**
1592 * @brief Return the current Compare (Pulse) value.
1593 * @param hlptim: LPTIM handle
1594 * @retval Compare value.
1595 */
HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef * hlptim)1596 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
1597 {
1598 /* Check the parameters */
1599 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
1600
1601 return (hlptim->Instance->CMP);
1602 }
1603
1604 /**
1605 * @}
1606 */
1607
1608
1609
1610 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
1611 * @brief LPTIM IRQ handler.
1612 *
1613 @verbatim
1614 ==============================================================================
1615 ##### LPTIM IRQ handler and callbacks #####
1616 ==============================================================================
1617 [..] This section provides LPTIM IRQ handler and callback functions called within
1618 the IRQ handler.
1619
1620 @endverbatim
1621 * @{
1622 */
1623
1624 /**
1625 * @brief Handle LPTIM interrupt request.
1626 * @param hlptim: LPTIM handle
1627 * @retval None
1628 */
HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef * hlptim)1629 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
1630 {
1631 /* Compare match interrupt */
1632 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
1633 {
1634 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
1635 {
1636 /* Clear Compare match flag */
1637 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
1638
1639 /* Compare match Callback */
1640 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1641 hlptim->CompareMatchCallback(hlptim);
1642 #else
1643 HAL_LPTIM_CompareMatchCallback(hlptim);
1644 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1645 }
1646 }
1647
1648 /* Autoreload match interrupt */
1649 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
1650 {
1651 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
1652 {
1653 /* Clear Autoreload match flag */
1654 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
1655
1656 /* Autoreload match Callback */
1657 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1658 hlptim->AutoReloadMatchCallback(hlptim);
1659 #else
1660 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
1661 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1662 }
1663 }
1664
1665 /* Trigger detected interrupt */
1666 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
1667 {
1668 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
1669 {
1670 /* Clear Trigger detected flag */
1671 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
1672
1673 /* Trigger detected callback */
1674 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1675 hlptim->TriggerCallback(hlptim);
1676 #else
1677 HAL_LPTIM_TriggerCallback(hlptim);
1678 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1679 }
1680 }
1681
1682 /* Compare write interrupt */
1683 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
1684 {
1685 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
1686 {
1687 /* Clear Compare write flag */
1688 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
1689
1690 /* Compare write Callback */
1691 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1692 hlptim->CompareWriteCallback(hlptim);
1693 #else
1694 HAL_LPTIM_CompareWriteCallback(hlptim);
1695 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1696 }
1697 }
1698
1699 /* Autoreload write interrupt */
1700 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
1701 {
1702 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
1703 {
1704 /* Clear Autoreload write flag */
1705 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
1706
1707 /* Autoreload write Callback */
1708 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1709 hlptim->AutoReloadWriteCallback(hlptim);
1710 #else
1711 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
1712 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1713 }
1714 }
1715
1716 /* Direction counter changed from Down to Up interrupt */
1717 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
1718 {
1719 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
1720 {
1721 /* Clear Direction counter changed from Down to Up flag */
1722 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
1723
1724 /* Direction counter changed from Down to Up Callback */
1725 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1726 hlptim->DirectionUpCallback(hlptim);
1727 #else
1728 HAL_LPTIM_DirectionUpCallback(hlptim);
1729 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1730 }
1731 }
1732
1733 /* Direction counter changed from Up to Down interrupt */
1734 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
1735 {
1736 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
1737 {
1738 /* Clear Direction counter changed from Up to Down flag */
1739 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
1740
1741 /* Direction counter changed from Up to Down Callback */
1742 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1743 hlptim->DirectionDownCallback(hlptim);
1744 #else
1745 HAL_LPTIM_DirectionDownCallback(hlptim);
1746 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1747 }
1748 }
1749
1750 #if defined(LPTIM_RCR_REP)
1751 /* Repetition counter underflowed (or contains zero) and the LPTIM counter
1752 overflowed */
1753 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UPDATE) != RESET)
1754 {
1755 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UPDATE) != RESET)
1756 {
1757 /* Clear update event flag */
1758 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UPDATE);
1759
1760 /* Update event Callback */
1761 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1762 hlptim->UpdateEventCallback(hlptim);
1763 #else
1764 HAL_LPTIM_UpdateEventCallback(hlptim);
1765 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1766 }
1767 }
1768
1769 /* Successful APB bus write to repetition counter register */
1770 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_REPOK) != RESET)
1771 {
1772 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_REPOK) != RESET)
1773 {
1774 /* Clear successful APB bus write to repetition counter flag */
1775 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_REPOK);
1776
1777 /* Successful APB bus write to repetition counter Callback */
1778 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1779 hlptim->RepCounterWriteCallback(hlptim);
1780 #else
1781 HAL_LPTIM_RepCounterWriteCallback(hlptim);
1782 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
1783 }
1784 }
1785 #endif
1786 }
1787
1788 /**
1789 * @brief Compare match callback in non-blocking mode.
1790 * @param hlptim : LPTIM handle
1791 * @retval None
1792 */
HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef * hlptim)1793 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
1794 {
1795 /* Prevent unused argument(s) compilation warning */
1796 UNUSED(hlptim);
1797
1798 /* NOTE : This function should not be modified, when the callback is needed,
1799 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
1800 */
1801 }
1802
1803 /**
1804 * @brief Autoreload match callback in non-blocking mode.
1805 * @param hlptim : LPTIM handle
1806 * @retval None
1807 */
HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef * hlptim)1808 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
1809 {
1810 /* Prevent unused argument(s) compilation warning */
1811 UNUSED(hlptim);
1812
1813 /* NOTE : This function should not be modified, when the callback is needed,
1814 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
1815 */
1816 }
1817
1818 /**
1819 * @brief Trigger detected callback in non-blocking mode.
1820 * @param hlptim : LPTIM handle
1821 * @retval None
1822 */
HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef * hlptim)1823 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
1824 {
1825 /* Prevent unused argument(s) compilation warning */
1826 UNUSED(hlptim);
1827
1828 /* NOTE : This function should not be modified, when the callback is needed,
1829 the HAL_LPTIM_TriggerCallback could be implemented in the user file
1830 */
1831 }
1832
1833 /**
1834 * @brief Compare write callback in non-blocking mode.
1835 * @param hlptim : LPTIM handle
1836 * @retval None
1837 */
HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef * hlptim)1838 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
1839 {
1840 /* Prevent unused argument(s) compilation warning */
1841 UNUSED(hlptim);
1842
1843 /* NOTE : This function should not be modified, when the callback is needed,
1844 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
1845 */
1846 }
1847
1848 /**
1849 * @brief Autoreload write callback in non-blocking mode.
1850 * @param hlptim : LPTIM handle
1851 * @retval None
1852 */
HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef * hlptim)1853 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
1854 {
1855 /* Prevent unused argument(s) compilation warning */
1856 UNUSED(hlptim);
1857
1858 /* NOTE : This function should not be modified, when the callback is needed,
1859 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
1860 */
1861 }
1862
1863 /**
1864 * @brief Direction counter changed from Down to Up callback in non-blocking mode.
1865 * @param hlptim : LPTIM handle
1866 * @retval None
1867 */
HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef * hlptim)1868 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
1869 {
1870 /* Prevent unused argument(s) compilation warning */
1871 UNUSED(hlptim);
1872
1873 /* NOTE : This function should not be modified, when the callback is needed,
1874 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
1875 */
1876 }
1877
1878 /**
1879 * @brief Direction counter changed from Up to Down callback in non-blocking mode.
1880 * @param hlptim : LPTIM handle
1881 * @retval None
1882 */
HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef * hlptim)1883 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
1884 {
1885 /* Prevent unused argument(s) compilation warning */
1886 UNUSED(hlptim);
1887
1888 /* NOTE : This function should not be modified, when the callback is needed,
1889 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
1890 */
1891 }
1892
1893 #if defined(LPTIM_RCR_REP)
1894 /**
1895 * @brief Repetition counter underflowed (or contains zero) and LPTIM counter overflowed callback in non-blocking mode.
1896 * @param hlptim : LPTIM handle
1897 * @retval None
1898 */
HAL_LPTIM_UpdateEventCallback(LPTIM_HandleTypeDef * hlptim)1899 __weak void HAL_LPTIM_UpdateEventCallback(LPTIM_HandleTypeDef *hlptim)
1900 {
1901 /* Prevent unused argument(s) compilation warning */
1902 UNUSED(hlptim);
1903
1904 /* NOTE : This function should not be modified, when the callback is needed,
1905 the HAL_LPTIM_UpdateEventCallback could be implemented in the user file
1906 */
1907 }
1908
1909 /**
1910 * @brief Successful APB bus write to repetition counter register callback in non-blocking mode.
1911 * @param hlptim : LPTIM handle
1912 * @retval None
1913 */
HAL_LPTIM_RepCounterWriteCallback(LPTIM_HandleTypeDef * hlptim)1914 __weak void HAL_LPTIM_RepCounterWriteCallback(LPTIM_HandleTypeDef *hlptim)
1915 {
1916 /* Prevent unused argument(s) compilation warning */
1917 UNUSED(hlptim);
1918
1919 /* NOTE : This function should not be modified, when the callback is needed,
1920 the HAL_LPTIM_RepCounterWriteCallback could be implemented in the user file
1921 */
1922 }
1923 #endif /* LPTIM_RCR_REP */
1924
1925 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
1926 /**
1927 * @brief Register a User LPTIM callback to be used instead of the weak predefined callback
1928 * @param hlptim LPTIM handle
1929 * @param CallbackID ID of the callback to be registered
1930 * This parameter can be one of the following values:
1931 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
1932 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
1933 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
1934 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
1935 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
1936 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
1937 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
1938 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
1939 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
1940 * @param pCallback pointer to the callback function
1941 * @retval status
1942 */
HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef * hlptim,HAL_LPTIM_CallbackIDTypeDef CallbackID,pLPTIM_CallbackTypeDef pCallback)1943 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim,
1944 HAL_LPTIM_CallbackIDTypeDef CallbackID,
1945 pLPTIM_CallbackTypeDef pCallback)
1946 {
1947 HAL_StatusTypeDef status = HAL_OK;
1948
1949 if (pCallback == NULL)
1950 {
1951 return HAL_ERROR;
1952 }
1953
1954 /* Process locked */
1955 __HAL_LOCK(hlptim);
1956
1957 if (hlptim->State == HAL_LPTIM_STATE_READY)
1958 {
1959 switch (CallbackID)
1960 {
1961 case HAL_LPTIM_MSPINIT_CB_ID :
1962 hlptim->MspInitCallback = pCallback;
1963 break;
1964
1965 case HAL_LPTIM_MSPDEINIT_CB_ID :
1966 hlptim->MspDeInitCallback = pCallback;
1967 break;
1968
1969 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
1970 hlptim->CompareMatchCallback = pCallback;
1971 break;
1972
1973 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
1974 hlptim->AutoReloadMatchCallback = pCallback;
1975 break;
1976
1977 case HAL_LPTIM_TRIGGER_CB_ID :
1978 hlptim->TriggerCallback = pCallback;
1979 break;
1980
1981 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
1982 hlptim->CompareWriteCallback = pCallback;
1983 break;
1984
1985 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
1986 hlptim->AutoReloadWriteCallback = pCallback;
1987 break;
1988
1989 case HAL_LPTIM_DIRECTION_UP_CB_ID :
1990 hlptim->DirectionUpCallback = pCallback;
1991 break;
1992
1993 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
1994 hlptim->DirectionDownCallback = pCallback;
1995 break;
1996
1997 #if defined(LPTIM_RCR_REP)
1998 case HAL_LPTIM_UPDATE_EVENT_CB_ID :
1999 hlptim->UpdateEventCallback = pCallback;
2000 break;
2001
2002 case HAL_LPTIM_REPETITION_WRITE_CB_ID :
2003 hlptim->RepCounterWriteCallback = pCallback;
2004 break;
2005 #endif /* LPTIM_RCR_REP */
2006
2007 default :
2008 /* Return error status */
2009 status = HAL_ERROR;
2010 break;
2011 }
2012 }
2013 else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2014 {
2015 switch (CallbackID)
2016 {
2017 case HAL_LPTIM_MSPINIT_CB_ID :
2018 hlptim->MspInitCallback = pCallback;
2019 break;
2020
2021 case HAL_LPTIM_MSPDEINIT_CB_ID :
2022 hlptim->MspDeInitCallback = pCallback;
2023 break;
2024
2025 default :
2026 /* Return error status */
2027 status = HAL_ERROR;
2028 break;
2029 }
2030 }
2031 else
2032 {
2033 /* Return error status */
2034 status = HAL_ERROR;
2035 }
2036
2037 /* Release Lock */
2038 __HAL_UNLOCK(hlptim);
2039
2040 return status;
2041 }
2042
2043 /**
2044 * @brief Unregister a LPTIM callback
2045 * LLPTIM callback is redirected to the weak predefined callback
2046 * @param hlptim LPTIM handle
2047 * @param CallbackID ID of the callback to be unregistered
2048 * This parameter can be one of the following values:
2049 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID
2050 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID
2051 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID
2052 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID
2053 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID
2054 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID
2055 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID
2056 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID
2057 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID
2058 * @retval status
2059 */
HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef * hlptim,HAL_LPTIM_CallbackIDTypeDef CallbackID)2060 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim,
2061 HAL_LPTIM_CallbackIDTypeDef CallbackID)
2062 {
2063 HAL_StatusTypeDef status = HAL_OK;
2064
2065 /* Process locked */
2066 __HAL_LOCK(hlptim);
2067
2068 if (hlptim->State == HAL_LPTIM_STATE_READY)
2069 {
2070 switch (CallbackID)
2071 {
2072 case HAL_LPTIM_MSPINIT_CB_ID :
2073 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
2074 break;
2075
2076 case HAL_LPTIM_MSPDEINIT_CB_ID :
2077 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
2078 break;
2079
2080 case HAL_LPTIM_COMPARE_MATCH_CB_ID :
2081 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Legacy weak IC Msp Init Callback */
2082 break;
2083
2084 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID :
2085 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Legacy weak IC Msp DeInit Callback */
2086 break;
2087
2088 case HAL_LPTIM_TRIGGER_CB_ID :
2089 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* Legacy weak OC Msp Init Callback */
2090 break;
2091
2092 case HAL_LPTIM_COMPARE_WRITE_CB_ID :
2093 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Legacy weak OC Msp DeInit Callback */
2094 break;
2095
2096 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID :
2097 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Legacy weak PWM Msp Init Callback */
2098 break;
2099
2100 case HAL_LPTIM_DIRECTION_UP_CB_ID :
2101 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Legacy weak PWM Msp DeInit Callback */
2102 break;
2103
2104 case HAL_LPTIM_DIRECTION_DOWN_CB_ID :
2105 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Legacy weak One Pulse Msp Init Callback */
2106 break;
2107
2108 #if defined(LPTIM_RCR_REP)
2109 case HAL_LPTIM_UPDATE_EVENT_CB_ID :
2110 hlptim->UpdateEventCallback = HAL_LPTIM_UpdateEventCallback; /* Legacy weak Update Event Callback */
2111 break;
2112
2113 case HAL_LPTIM_REPETITION_WRITE_CB_ID :
2114 hlptim->RepCounterWriteCallback = HAL_LPTIM_RepCounterWriteCallback; /* Legacy weak Repetition counter successful write Callback */
2115 break;
2116 #endif /* LPTIM_RCR_REP */
2117
2118 default :
2119 /* Return error status */
2120 status = HAL_ERROR;
2121 break;
2122 }
2123 }
2124 else if (hlptim->State == HAL_LPTIM_STATE_RESET)
2125 {
2126 switch (CallbackID)
2127 {
2128 case HAL_LPTIM_MSPINIT_CB_ID :
2129 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */
2130 break;
2131
2132 case HAL_LPTIM_MSPDEINIT_CB_ID :
2133 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */
2134 break;
2135
2136 default :
2137 /* Return error status */
2138 status = HAL_ERROR;
2139 break;
2140 }
2141 }
2142 else
2143 {
2144 /* Return error status */
2145 status = HAL_ERROR;
2146 }
2147
2148 /* Release Lock */
2149 __HAL_UNLOCK(hlptim);
2150
2151 return status;
2152 }
2153 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
2154
2155 /**
2156 * @}
2157 */
2158
2159 /** @defgroup LPTIM_Exported_Functions_Group5 Peripheral State functions
2160 * @brief Peripheral State functions.
2161 *
2162 @verbatim
2163 ==============================================================================
2164 ##### Peripheral State functions #####
2165 ==============================================================================
2166 [..]
2167 This subsection permits to get in run-time the status of the peripheral.
2168
2169 @endverbatim
2170 * @{
2171 */
2172
2173 /**
2174 * @brief Return the LPTIM handle state.
2175 * @param hlptim: LPTIM handle
2176 * @retval HAL state
2177 */
HAL_LPTIM_GetState(LPTIM_HandleTypeDef * hlptim)2178 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
2179 {
2180 /* Return LPTIM handle state */
2181 return hlptim->State;
2182 }
2183
2184 /**
2185 * @}
2186 */
2187
2188
2189 /**
2190 * @}
2191 */
2192
2193 /* Private functions ---------------------------------------------------------*/
2194
2195 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
2196 * @{
2197 */
2198 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
2199 /**
2200 * @brief Reset interrupt callbacks to the legacy weak callbacks.
2201 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains
2202 * the configuration information for LPTIM module.
2203 * @retval None
2204 */
LPTIM_ResetCallback(LPTIM_HandleTypeDef * lptim)2205 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim)
2206 {
2207 /* Reset the LPTIM callback to the legacy weak callbacks */
2208 lptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Compare match Callback */
2209 lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Auto-reload match Callback */
2210 lptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* External trigger event detection Callback */
2211 lptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Compare register write complete Callback */
2212 lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Auto-reload register write complete Callback */
2213 lptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Up-counting direction change Callback */
2214 lptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Down-counting direction change Callback */
2215 #if defined(LPTIM_RCR_REP)
2216 lptim->UpdateEventCallback = HAL_LPTIM_UpdateEventCallback; /* Update Event Callback */
2217 lptim->RepCounterWriteCallback = HAL_LPTIM_RepCounterWriteCallback; /* Repetition counter successful write Callback */
2218 #endif /* LPTIM_RCR_REP */
2219 }
2220 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
2221
2222 /**
2223 * @}
2224 */
2225
2226 #endif /* HAL_LPTIM_MODULE_ENABLED */
2227 /**
2228 * @}
2229 */
2230
2231 /**
2232 * @}
2233 */
2234
2235 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
2236