source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_hal_lptim.c

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