STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_lptim.c 00004 * @author MCD Application Team 00005 * @brief LPTIM HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Low Power Timer (LPTIM) peripheral: 00008 * + Initialization and de-initialization functions. 00009 * + Start/Stop operation functions in polling mode. 00010 * + Start/Stop operation functions in interrupt mode. 00011 * + Reading operation functions. 00012 * + Peripheral State functions. 00013 * 00014 @verbatim 00015 ============================================================================== 00016 ##### How to use this driver ##### 00017 ============================================================================== 00018 [..] 00019 The LPTIM HAL driver can be used as follows: 00020 00021 (#)Initialize the LPTIM low level resources by implementing the 00022 HAL_LPTIM_MspInit(): 00023 (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE(). 00024 (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()): 00025 (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority(). 00026 (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ(). 00027 (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler(). 00028 00029 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function 00030 configures mainly: 00031 (++) The instance: LPTIM1 or LPTIM2. 00032 (++) Clock: the counter clock. 00033 (+++) Source : it can be either the ULPTIM input (IN1) or one of 00034 the internal clock; (APB, LSE, LSI or MSI). 00035 (+++) Prescaler: select the clock divider. 00036 (++) UltraLowPowerClock : To be used only if the ULPTIM is selected 00037 as counter clock source. 00038 (+++) Polarity: polarity of the active edge for the counter unit 00039 if the ULPTIM input is selected. 00040 (+++) SampleTime: clock sampling time to configure the clock glitch 00041 filter. 00042 (++) Trigger: How the counter start. 00043 (+++) Source: trigger can be software or one of the hardware triggers. 00044 (+++) ActiveEdge : only for hardware trigger. 00045 (+++) SampleTime : trigger sampling time to configure the trigger 00046 glitch filter. 00047 (++) OutputPolarity : 2 opposite polarities are possible. 00048 (++) UpdateMode: specifies whether the update of the autoreload and 00049 the compare values is done immediately or after the end of current 00050 period. 00051 (++) Input1Source: Source selected for input1 (GPIO or comparator output). 00052 (++) Input2Source: Source selected for input2 (GPIO or comparator output). 00053 Input2 is used only for encoder feature so is used only for LPTIM1 instance. 00054 00055 (#)Six modes are available: 00056 00057 (++) PWM Mode: To generate a PWM signal with specified period and pulse, 00058 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption 00059 mode. 00060 00061 (++) One Pulse Mode: To generate pulse with specified width in response 00062 to a stimulus, call HAL_LPTIM_OnePulse_Start() or 00063 HAL_LPTIM_OnePulse_Start_IT() for interruption mode. 00064 00065 (++) Set once Mode: In this mode, the output changes the level (from 00066 low level to high level if the output polarity is configured high, else 00067 the opposite) when a compare match occurs. To start this mode, call 00068 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for 00069 interruption mode. 00070 00071 (++) Encoder Mode: To use the encoder interface call 00072 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for 00073 interruption mode. Only available for LPTIM1 instance. 00074 00075 (++) Time out Mode: an active edge on one selected trigger input rests 00076 the counter. The first trigger event will start the timer, any 00077 successive trigger event will reset the counter and the timer will 00078 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or 00079 HAL_LPTIM_TimeOut_Start_IT() for interruption mode. 00080 00081 (++) Counter Mode: counter can be used to count external events on 00082 the LPTIM Input1 or it can be used to count internal clock cycles. 00083 To start this mode, call HAL_LPTIM_Counter_Start() or 00084 HAL_LPTIM_Counter_Start_IT() for interruption mode. 00085 00086 00087 (#) User can stop any process by calling the corresponding API: 00088 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is 00089 already started in interruption mode. 00090 00091 (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit(). 00092 00093 *** Callback registration *** 00094 ============================================= 00095 00096 The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS when set to 1 00097 allows the user to configure dynamically the driver callbacks. 00098 00099 Use Function @ref HAL_LPTIM_RegisterCallback() to register a callback. 00100 @ref HAL_LPTIM_RegisterCallback() takes as parameters the HAL peripheral handle, 00101 the Callback ID and a pointer to the user callback function. 00102 00103 Use function @ref HAL_LPTIM_UnRegisterCallback() to reset a callback to the 00104 default weak function. 00105 @ref HAL_LPTIM_UnRegisterCallback takes as parameters the HAL peripheral handle, 00106 and the Callback ID. 00107 00108 These functions allow to register/unregister following callbacks: 00109 00110 (+) MspInitCallback : LPTIM Base Msp Init Callback. 00111 (+) MspDeInitCallback : LPTIM Base Msp DeInit Callback. 00112 (+) CompareMatchCallback : Compare match Callback. 00113 (+) AutoReloadMatchCallback : Auto-reload match Callback. 00114 (+) TriggerCallback : External trigger event detection Callback. 00115 (+) CompareWriteCallback : Compare register write complete Callback. 00116 (+) AutoReloadWriteCallback : Auto-reload register write complete Callback. 00117 (+) DirectionUpCallback : Up-counting direction change Callback. 00118 (+) DirectionDownCallback : Down-counting direction change Callback. 00119 00120 By default, after the Init and when the state is HAL_LPTIM_STATE_RESET 00121 all interrupt callbacks are set to the corresponding weak functions: 00122 examples @ref HAL_LPTIM_TriggerCallback(), @ref HAL_LPTIM_CompareMatchCallback(). 00123 00124 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak 00125 functionalities in the Init/DeInit only when these callbacks are null 00126 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init/DeInit 00127 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) 00128 00129 Callbacks can be registered/unregistered in HAL_LPTIM_STATE_READY state only. 00130 Exception done MspInit/MspDeInit that can be registered/unregistered 00131 in HAL_LPTIM_STATE_READY or HAL_LPTIM_STATE_RESET state, 00132 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. 00133 In that case first register the MspInit/MspDeInit user callbacks 00134 using @ref HAL_LPTIM_RegisterCallback() before calling DeInit or Init function. 00135 00136 When The compilation define USE_HAL_LPTIM_REGISTER_CALLBACKS is set to 0 or 00137 not defined, the callback registration feature is not available and all callbacks 00138 are set to the corresponding weak functions. 00139 @endverbatim 00140 ****************************************************************************** 00141 * @attention 00142 * 00143 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00144 * 00145 * Redistribution and use in source and binary forms, with or without modification, 00146 * are permitted provided that the following conditions are met: 00147 * 1. Redistributions of source code must retain the above copyright notice, 00148 * this list of conditions and the following disclaimer. 00149 * 2. Redistributions in binary form must reproduce the above copyright notice, 00150 * this list of conditions and the following disclaimer in the documentation 00151 * and/or other materials provided with the distribution. 00152 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00153 * may be used to endorse or promote products derived from this software 00154 * without specific prior written permission. 00155 * 00156 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00157 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00158 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00159 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00160 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00161 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00162 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00163 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00164 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00165 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00166 * 00167 ****************************************************************************** 00168 */ 00169 00170 /* Includes ------------------------------------------------------------------*/ 00171 #include "stm32l4xx_hal.h" 00172 00173 /** @addtogroup STM32L4xx_HAL_Driver 00174 * @{ 00175 */ 00176 00177 /** @defgroup LPTIM LPTIM 00178 * @brief LPTIM HAL module driver. 00179 * @{ 00180 */ 00181 00182 #ifdef HAL_LPTIM_MODULE_ENABLED 00183 /* Private typedef -----------------------------------------------------------*/ 00184 /* Private define ------------------------------------------------------------*/ 00185 /* Private macro -------------------------------------------------------------*/ 00186 /* Private variables ---------------------------------------------------------*/ 00187 /* Private function prototypes -----------------------------------------------*/ 00188 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00189 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim); 00190 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00191 00192 /* Exported functions --------------------------------------------------------*/ 00193 00194 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions 00195 * @{ 00196 */ 00197 00198 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions 00199 * @brief Initialization and Configuration functions. 00200 * 00201 @verbatim 00202 ============================================================================== 00203 ##### Initialization and de-initialization functions ##### 00204 ============================================================================== 00205 [..] This section provides functions allowing to: 00206 (+) Initialize the LPTIM according to the specified parameters in the 00207 LPTIM_InitTypeDef and initialize the associated handle. 00208 (+) DeInitialize the LPTIM peripheral. 00209 (+) Initialize the LPTIM MSP. 00210 (+) DeInitialize the LPTIM MSP. 00211 00212 @endverbatim 00213 * @{ 00214 */ 00215 00216 /** 00217 * @brief Initialize the LPTIM according to the specified parameters in the 00218 * LPTIM_InitTypeDef and initialize the associated handle. 00219 * @param hlptim: LPTIM handle 00220 * @retval HAL status 00221 */ 00222 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim) 00223 { 00224 uint32_t tmpcfgr = 0; 00225 00226 /* Check the LPTIM handle allocation */ 00227 if(hlptim == NULL) 00228 { 00229 return HAL_ERROR; 00230 } 00231 00232 /* Check the parameters */ 00233 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00234 00235 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source)); 00236 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler)); 00237 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) 00238 { 00239 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 00240 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime)); 00241 } 00242 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source)); 00243 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00244 { 00245 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime)); 00246 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge)); 00247 } 00248 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity)); 00249 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode)); 00250 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource)); 00251 00252 if(hlptim->State == HAL_LPTIM_STATE_RESET) 00253 { 00254 /* Allocate lock resource and initialize it */ 00255 hlptim->Lock = HAL_UNLOCKED; 00256 00257 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00258 /* Reset interrupt callbacks to legacy weak callbacks */ 00259 LPTIM_ResetCallback(hlptim); 00260 00261 if (hlptim->MspInitCallback == NULL) 00262 { 00263 hlptim->MspInitCallback = HAL_LPTIM_MspInit; 00264 } 00265 00266 /* Init the low level hardware : GPIO, CLOCK, NVIC */ 00267 hlptim->MspInitCallback(hlptim); 00268 #else 00269 /* Init the low level hardware : GPIO, CLOCK, NVIC */ 00270 HAL_LPTIM_MspInit(hlptim); 00271 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00272 } 00273 00274 /* Change the LPTIM state */ 00275 hlptim->State = HAL_LPTIM_STATE_BUSY; 00276 00277 /* Get the LPTIMx CFGR value */ 00278 tmpcfgr = hlptim->Instance->CFGR; 00279 00280 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) 00281 { 00282 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT)); 00283 } 00284 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00285 { 00286 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL)); 00287 } 00288 00289 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */ 00290 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD | 00291 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE )); 00292 00293 /* Set initialization parameters */ 00294 tmpcfgr |= (hlptim->Init.Clock.Source | 00295 hlptim->Init.Clock.Prescaler | 00296 hlptim->Init.OutputPolarity | 00297 hlptim->Init.UpdateMode | 00298 hlptim->Init.CounterSource); 00299 00300 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM) 00301 { 00302 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity | 00303 hlptim->Init.UltraLowPowerClock.SampleTime); 00304 } 00305 00306 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00307 { 00308 /* Enable External trigger and set the trigger source */ 00309 tmpcfgr |= (hlptim->Init.Trigger.Source | 00310 hlptim->Init.Trigger.ActiveEdge | 00311 hlptim->Init.Trigger.SampleTime); 00312 } 00313 00314 /* Write to LPTIMx CFGR */ 00315 hlptim->Instance->CFGR = tmpcfgr; 00316 00317 /* Configure LPTIM input sources */ 00318 if(hlptim->Instance == LPTIM1) 00319 { 00320 /* Check LPTIM1 Input1 and Input2 sources */ 00321 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source)); 00322 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance,hlptim->Init.Input2Source)); 00323 00324 /* Configure LPTIM1 Input1 and Input2 sources */ 00325 hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source); 00326 } 00327 else 00328 { 00329 /* Check LPTIM2 Input1 source */ 00330 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source)); 00331 00332 /* Configure LPTIM2 Input1 source */ 00333 hlptim->Instance->OR = hlptim->Init.Input1Source; 00334 } 00335 00336 /* Change the LPTIM state */ 00337 hlptim->State = HAL_LPTIM_STATE_READY; 00338 00339 /* Return function status */ 00340 return HAL_OK; 00341 } 00342 00343 /** 00344 * @brief DeInitialize the LPTIM peripheral. 00345 * @param hlptim: LPTIM handle 00346 * @retval HAL status 00347 */ 00348 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim) 00349 { 00350 /* Check the LPTIM handle allocation */ 00351 if(hlptim == NULL) 00352 { 00353 return HAL_ERROR; 00354 } 00355 00356 /* Change the LPTIM state */ 00357 hlptim->State = HAL_LPTIM_STATE_BUSY; 00358 00359 /* Disable the LPTIM Peripheral Clock */ 00360 __HAL_LPTIM_DISABLE(hlptim); 00361 00362 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 00363 if (hlptim->MspDeInitCallback == NULL) 00364 { 00365 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; 00366 } 00367 00368 /* DeInit the low level hardware: CLOCK, NVIC.*/ 00369 hlptim->MspDeInitCallback(hlptim); 00370 #else 00371 /* DeInit the low level hardware: CLOCK, NVIC.*/ 00372 HAL_LPTIM_MspDeInit(hlptim); 00373 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 00374 00375 /* Change the LPTIM state */ 00376 hlptim->State = HAL_LPTIM_STATE_RESET; 00377 00378 /* Release Lock */ 00379 __HAL_UNLOCK(hlptim); 00380 00381 /* Return function status */ 00382 return HAL_OK; 00383 } 00384 00385 /** 00386 * @brief Initialize the LPTIM MSP. 00387 * @param hlptim: LPTIM handle 00388 * @retval None 00389 */ 00390 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim) 00391 { 00392 /* Prevent unused argument(s) compilation warning */ 00393 UNUSED(hlptim); 00394 00395 /* NOTE : This function should not be modified, when the callback is needed, 00396 the HAL_LPTIM_MspInit could be implemented in the user file 00397 */ 00398 } 00399 00400 /** 00401 * @brief DeInitialize LPTIM MSP. 00402 * @param hlptim: LPTIM handle 00403 * @retval None 00404 */ 00405 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim) 00406 { 00407 /* Prevent unused argument(s) compilation warning */ 00408 UNUSED(hlptim); 00409 00410 /* NOTE : This function should not be modified, when the callback is needed, 00411 the HAL_LPTIM_MspDeInit could be implemented in the user file 00412 */ 00413 } 00414 00415 /** 00416 * @} 00417 */ 00418 00419 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions 00420 * @brief Start-Stop operation functions. 00421 * 00422 @verbatim 00423 ============================================================================== 00424 ##### LPTIM Start Stop operation functions ##### 00425 ============================================================================== 00426 [..] This section provides functions allowing to: 00427 (+) Start the PWM mode. 00428 (+) Stop the PWM mode. 00429 (+) Start the One pulse mode. 00430 (+) Stop the One pulse mode. 00431 (+) Start the Set once mode. 00432 (+) Stop the Set once mode. 00433 (+) Start the Encoder mode. 00434 (+) Stop the Encoder mode. 00435 (+) Start the Timeout mode. 00436 (+) Stop the Timeout mode. 00437 (+) Start the Counter mode. 00438 (+) Stop the Counter mode. 00439 00440 00441 @endverbatim 00442 * @{ 00443 */ 00444 00445 /** 00446 * @brief Start the LPTIM PWM generation. 00447 * @param hlptim : LPTIM handle 00448 * @param Period : Specifies the Autoreload value. 00449 * This parameter must be a value between 0x0000 and 0xFFFF. 00450 * @param Pulse : Specifies the compare value. 00451 * This parameter must be a value between 0x0000 and 0xFFFF. 00452 * @retval HAL status 00453 */ 00454 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00455 { 00456 /* Check the parameters */ 00457 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00458 assert_param(IS_LPTIM_PERIOD(Period)); 00459 assert_param(IS_LPTIM_PULSE(Pulse)); 00460 00461 /* Set the LPTIM state */ 00462 hlptim->State= HAL_LPTIM_STATE_BUSY; 00463 00464 /* Reset WAVE bit to set PWM mode */ 00465 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00466 00467 /* Enable the Peripheral */ 00468 __HAL_LPTIM_ENABLE(hlptim); 00469 00470 /* Load the period value in the autoreload register */ 00471 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00472 00473 /* Load the pulse value in the compare register */ 00474 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00475 00476 /* Start timer in continuous mode */ 00477 __HAL_LPTIM_START_CONTINUOUS(hlptim); 00478 00479 /* Change the TIM state*/ 00480 hlptim->State= HAL_LPTIM_STATE_READY; 00481 00482 /* Return function status */ 00483 return HAL_OK; 00484 } 00485 00486 /** 00487 * @brief Stop the LPTIM PWM generation. 00488 * @param hlptim : LPTIM handle 00489 * @retval HAL status 00490 */ 00491 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim) 00492 { 00493 /* Check the parameters */ 00494 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00495 00496 /* Set the LPTIM state */ 00497 hlptim->State= HAL_LPTIM_STATE_BUSY; 00498 00499 /* Disable the Peripheral */ 00500 __HAL_LPTIM_DISABLE(hlptim); 00501 00502 /* Change the TIM state*/ 00503 hlptim->State= HAL_LPTIM_STATE_READY; 00504 00505 /* Return function status */ 00506 return HAL_OK; 00507 } 00508 00509 /** 00510 * @brief Start the LPTIM PWM generation in interrupt mode. 00511 * @param hlptim : LPTIM handle 00512 * @param Period : Specifies the Autoreload value. 00513 * This parameter must be a value between 0x0000 and 0xFFFF 00514 * @param Pulse : Specifies the compare value. 00515 * This parameter must be a value between 0x0000 and 0xFFFF 00516 * @retval HAL status 00517 */ 00518 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00519 { 00520 /* Check the parameters */ 00521 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00522 assert_param(IS_LPTIM_PERIOD(Period)); 00523 assert_param(IS_LPTIM_PULSE(Pulse)); 00524 00525 /* Set the LPTIM state */ 00526 hlptim->State= HAL_LPTIM_STATE_BUSY; 00527 00528 /* Reset WAVE bit to set PWM mode */ 00529 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00530 00531 /* Enable Autoreload write complete interrupt */ 00532 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 00533 00534 /* Enable Compare write complete interrupt */ 00535 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 00536 00537 /* Enable Autoreload match interrupt */ 00538 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 00539 00540 /* Enable Compare match interrupt */ 00541 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 00542 00543 /* If external trigger source is used, then enable external trigger interrupt */ 00544 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00545 { 00546 /* Enable external trigger interrupt */ 00547 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00548 } 00549 00550 /* Enable the Peripheral */ 00551 __HAL_LPTIM_ENABLE(hlptim); 00552 00553 /* Load the period value in the autoreload register */ 00554 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00555 00556 /* Load the pulse value in the compare register */ 00557 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00558 00559 /* Start timer in continuous mode */ 00560 __HAL_LPTIM_START_CONTINUOUS(hlptim); 00561 00562 /* Change the TIM state*/ 00563 hlptim->State= HAL_LPTIM_STATE_READY; 00564 00565 /* Return function status */ 00566 return HAL_OK; 00567 } 00568 00569 /** 00570 * @brief Stop the LPTIM PWM generation in interrupt mode. 00571 * @param hlptim : LPTIM handle 00572 * @retval HAL status 00573 */ 00574 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim) 00575 { 00576 /* Check the parameters */ 00577 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00578 00579 /* Set the LPTIM state */ 00580 hlptim->State= HAL_LPTIM_STATE_BUSY; 00581 00582 /* Disable the Peripheral */ 00583 __HAL_LPTIM_DISABLE(hlptim); 00584 00585 /* Disable Autoreload write complete interrupt */ 00586 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 00587 00588 /* Disable Compare write complete interrupt */ 00589 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 00590 00591 /* Disable Autoreload match interrupt */ 00592 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 00593 00594 /* Disable Compare match interrupt */ 00595 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 00596 00597 /* If external trigger source is used, then disable external trigger interrupt */ 00598 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00599 { 00600 /* Disable external trigger interrupt */ 00601 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00602 } 00603 00604 /* Change the TIM state*/ 00605 hlptim->State= HAL_LPTIM_STATE_READY; 00606 00607 /* Return function status */ 00608 return HAL_OK; 00609 } 00610 00611 /** 00612 * @brief Start the LPTIM One pulse generation. 00613 * @param hlptim : LPTIM handle 00614 * @param Period : Specifies the Autoreload value. 00615 * This parameter must be a value between 0x0000 and 0xFFFF. 00616 * @param Pulse : Specifies the compare value. 00617 * This parameter must be a value between 0x0000 and 0xFFFF. 00618 * @retval HAL status 00619 */ 00620 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00621 { 00622 /* Check the parameters */ 00623 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00624 assert_param(IS_LPTIM_PERIOD(Period)); 00625 assert_param(IS_LPTIM_PULSE(Pulse)); 00626 00627 /* Set the LPTIM state */ 00628 hlptim->State= HAL_LPTIM_STATE_BUSY; 00629 00630 /* Reset WAVE bit to set one pulse mode */ 00631 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00632 00633 /* Enable the Peripheral */ 00634 __HAL_LPTIM_ENABLE(hlptim); 00635 00636 /* Load the period value in the autoreload register */ 00637 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00638 00639 /* Load the pulse value in the compare register */ 00640 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00641 00642 /* Start timer in continuous mode */ 00643 __HAL_LPTIM_START_SINGLE(hlptim); 00644 00645 /* Change the TIM state*/ 00646 hlptim->State= HAL_LPTIM_STATE_READY; 00647 00648 /* Return function status */ 00649 return HAL_OK; 00650 } 00651 00652 /** 00653 * @brief Stop the LPTIM One pulse generation. 00654 * @param hlptim : LPTIM handle 00655 * @retval HAL status 00656 */ 00657 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim) 00658 { 00659 /* Check the parameters */ 00660 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00661 00662 /* Set the LPTIM state */ 00663 hlptim->State= HAL_LPTIM_STATE_BUSY; 00664 00665 /* Disable the Peripheral */ 00666 __HAL_LPTIM_DISABLE(hlptim); 00667 00668 /* Change the TIM state*/ 00669 hlptim->State= HAL_LPTIM_STATE_READY; 00670 00671 /* Return function status */ 00672 return HAL_OK; 00673 } 00674 00675 /** 00676 * @brief Start the LPTIM One pulse generation in interrupt mode. 00677 * @param hlptim : LPTIM handle 00678 * @param Period : Specifies the Autoreload value. 00679 * This parameter must be a value between 0x0000 and 0xFFFF. 00680 * @param Pulse : Specifies the compare value. 00681 * This parameter must be a value between 0x0000 and 0xFFFF. 00682 * @retval HAL status 00683 */ 00684 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00685 { 00686 /* Check the parameters */ 00687 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00688 assert_param(IS_LPTIM_PERIOD(Period)); 00689 assert_param(IS_LPTIM_PULSE(Pulse)); 00690 00691 /* Set the LPTIM state */ 00692 hlptim->State= HAL_LPTIM_STATE_BUSY; 00693 00694 /* Reset WAVE bit to set one pulse mode */ 00695 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE; 00696 00697 /* Enable Autoreload write complete interrupt */ 00698 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 00699 00700 /* Enable Compare write complete interrupt */ 00701 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 00702 00703 /* Enable Autoreload match interrupt */ 00704 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 00705 00706 /* Enable Compare match interrupt */ 00707 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 00708 00709 /* If external trigger source is used, then enable external trigger interrupt */ 00710 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00711 { 00712 /* Enable external trigger interrupt */ 00713 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00714 } 00715 00716 /* Enable the Peripheral */ 00717 __HAL_LPTIM_ENABLE(hlptim); 00718 00719 /* Load the period value in the autoreload register */ 00720 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00721 00722 /* Load the pulse value in the compare register */ 00723 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00724 00725 /* Start timer in continuous mode */ 00726 __HAL_LPTIM_START_SINGLE(hlptim); 00727 00728 /* Change the TIM state*/ 00729 hlptim->State= HAL_LPTIM_STATE_READY; 00730 00731 /* Return function status */ 00732 return HAL_OK; 00733 } 00734 00735 /** 00736 * @brief Stop the LPTIM One pulse generation in interrupt mode. 00737 * @param hlptim : LPTIM handle 00738 * @retval HAL status 00739 */ 00740 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim) 00741 { 00742 /* Check the parameters */ 00743 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00744 00745 /* Set the LPTIM state */ 00746 hlptim->State= HAL_LPTIM_STATE_BUSY; 00747 00748 /* Disable the Peripheral */ 00749 __HAL_LPTIM_DISABLE(hlptim); 00750 00751 /* Disable Autoreload write complete interrupt */ 00752 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 00753 00754 /* Disable Compare write complete interrupt */ 00755 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 00756 00757 /* Disable Autoreload match interrupt */ 00758 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 00759 00760 /* Disable Compare match interrupt */ 00761 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 00762 00763 /* If external trigger source is used, then disable external trigger interrupt */ 00764 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00765 { 00766 /* Disable external trigger interrupt */ 00767 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00768 } 00769 00770 /* Change the TIM state*/ 00771 hlptim->State= HAL_LPTIM_STATE_READY; 00772 00773 /* Return function status */ 00774 return HAL_OK; 00775 } 00776 00777 /** 00778 * @brief Start the LPTIM in Set once mode. 00779 * @param hlptim : LPTIM handle 00780 * @param Period : Specifies the Autoreload value. 00781 * This parameter must be a value between 0x0000 and 0xFFFF. 00782 * @param Pulse : Specifies the compare value. 00783 * This parameter must be a value between 0x0000 and 0xFFFF. 00784 * @retval HAL status 00785 */ 00786 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00787 { 00788 /* Check the parameters */ 00789 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00790 assert_param(IS_LPTIM_PERIOD(Period)); 00791 assert_param(IS_LPTIM_PULSE(Pulse)); 00792 00793 /* Set the LPTIM state */ 00794 hlptim->State= HAL_LPTIM_STATE_BUSY; 00795 00796 /* Set WAVE bit to enable the set once mode */ 00797 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE; 00798 00799 /* Enable the Peripheral */ 00800 __HAL_LPTIM_ENABLE(hlptim); 00801 00802 /* Load the period value in the autoreload register */ 00803 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00804 00805 /* Load the pulse value in the compare register */ 00806 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00807 00808 /* Start timer in continuous mode */ 00809 __HAL_LPTIM_START_SINGLE(hlptim); 00810 00811 /* Change the TIM state*/ 00812 hlptim->State= HAL_LPTIM_STATE_READY; 00813 00814 /* Return function status */ 00815 return HAL_OK; 00816 } 00817 00818 /** 00819 * @brief Stop the LPTIM Set once mode. 00820 * @param hlptim : LPTIM handle 00821 * @retval HAL status 00822 */ 00823 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim) 00824 { 00825 /* Check the parameters */ 00826 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00827 00828 /* Set the LPTIM state */ 00829 hlptim->State= HAL_LPTIM_STATE_BUSY; 00830 00831 /* Disable the Peripheral */ 00832 __HAL_LPTIM_DISABLE(hlptim); 00833 00834 /* Change the TIM state*/ 00835 hlptim->State= HAL_LPTIM_STATE_READY; 00836 00837 /* Return function status */ 00838 return HAL_OK; 00839 } 00840 00841 /** 00842 * @brief Start the LPTIM Set once mode in interrupt mode. 00843 * @param hlptim : LPTIM handle 00844 * @param Period : Specifies the Autoreload value. 00845 * This parameter must be a value between 0x0000 and 0xFFFF. 00846 * @param Pulse : Specifies the compare value. 00847 * This parameter must be a value between 0x0000 and 0xFFFF. 00848 * @retval HAL status 00849 */ 00850 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse) 00851 { 00852 /* Check the parameters */ 00853 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00854 assert_param(IS_LPTIM_PERIOD(Period)); 00855 assert_param(IS_LPTIM_PULSE(Pulse)); 00856 00857 /* Set the LPTIM state */ 00858 hlptim->State= HAL_LPTIM_STATE_BUSY; 00859 00860 /* Set WAVE bit to enable the set once mode */ 00861 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE; 00862 00863 /* Enable Autoreload write complete interrupt */ 00864 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 00865 00866 /* Enable Compare write complete interrupt */ 00867 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK); 00868 00869 /* Enable Autoreload match interrupt */ 00870 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 00871 00872 /* Enable Compare match interrupt */ 00873 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 00874 00875 /* If external trigger source is used, then enable external trigger interrupt */ 00876 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00877 { 00878 /* Enable external trigger interrupt */ 00879 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00880 } 00881 00882 /* Enable the Peripheral */ 00883 __HAL_LPTIM_ENABLE(hlptim); 00884 00885 /* Load the period value in the autoreload register */ 00886 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00887 00888 /* Load the pulse value in the compare register */ 00889 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse); 00890 00891 /* Start timer in continuous mode */ 00892 __HAL_LPTIM_START_SINGLE(hlptim); 00893 00894 /* Change the TIM state*/ 00895 hlptim->State= HAL_LPTIM_STATE_READY; 00896 00897 /* Return function status */ 00898 return HAL_OK; 00899 } 00900 00901 /** 00902 * @brief Stop the LPTIM Set once mode in interrupt mode. 00903 * @param hlptim : LPTIM handle 00904 * @retval HAL status 00905 */ 00906 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim) 00907 { 00908 /* Check the parameters */ 00909 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00910 00911 /* Set the LPTIM state */ 00912 hlptim->State= HAL_LPTIM_STATE_BUSY; 00913 00914 /* Disable the Peripheral */ 00915 __HAL_LPTIM_DISABLE(hlptim); 00916 00917 /* Disable Autoreload write complete interrupt */ 00918 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 00919 00920 /* Disable Compare write complete interrupt */ 00921 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK); 00922 00923 /* Disable Autoreload match interrupt */ 00924 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 00925 00926 /* Disable Compare match interrupt */ 00927 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 00928 00929 /* If external trigger source is used, then disable external trigger interrupt */ 00930 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE) 00931 { 00932 /* Disable external trigger interrupt */ 00933 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG); 00934 } 00935 00936 /* Change the TIM state*/ 00937 hlptim->State= HAL_LPTIM_STATE_READY; 00938 00939 /* Return function status */ 00940 return HAL_OK; 00941 } 00942 00943 /** 00944 * @brief Start the Encoder interface. 00945 * @param hlptim : LPTIM handle 00946 * @param Period : Specifies the Autoreload value. 00947 * This parameter must be a value between 0x0000 and 0xFFFF. 00948 * @retval HAL status 00949 */ 00950 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 00951 { 00952 HAL_StatusTypeDef status = HAL_OK; 00953 uint32_t tmpcfgr; 00954 00955 /* Check the parameters */ 00956 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 00957 assert_param(IS_LPTIM_PERIOD(Period)); 00958 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC); 00959 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1); 00960 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 00961 00962 /* Encoder feature is only available for LPTIM1 instance */ 00963 if (hlptim->Instance == LPTIM1) 00964 { 00965 /* Set the LPTIM state */ 00966 hlptim->State= HAL_LPTIM_STATE_BUSY; 00967 00968 /* Get the LPTIMx CFGR value */ 00969 tmpcfgr = hlptim->Instance->CFGR; 00970 00971 /* Clear CKPOL bits */ 00972 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL); 00973 00974 /* Set Input polarity */ 00975 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity; 00976 00977 /* Write to LPTIMx CFGR */ 00978 hlptim->Instance->CFGR = tmpcfgr; 00979 00980 /* Set ENC bit to enable the encoder interface */ 00981 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC; 00982 00983 /* Enable the Peripheral */ 00984 __HAL_LPTIM_ENABLE(hlptim); 00985 00986 /* Load the period value in the autoreload register */ 00987 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 00988 00989 /* Start timer in continuous mode */ 00990 __HAL_LPTIM_START_CONTINUOUS(hlptim); 00991 00992 /* Change the TIM state*/ 00993 hlptim->State= HAL_LPTIM_STATE_READY; 00994 } 00995 else 00996 { 00997 status = HAL_ERROR; 00998 } 00999 01000 /* Return function status */ 01001 return status; 01002 } 01003 01004 /** 01005 * @brief Stop the Encoder interface. 01006 * @param hlptim : LPTIM handle 01007 * @retval HAL status 01008 */ 01009 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim) 01010 { 01011 /* Check the parameters */ 01012 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01013 01014 /* Set the LPTIM state */ 01015 hlptim->State= HAL_LPTIM_STATE_BUSY; 01016 01017 /* Disable the Peripheral */ 01018 __HAL_LPTIM_DISABLE(hlptim); 01019 01020 /* Reset ENC bit to disable the encoder interface */ 01021 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC; 01022 01023 /* Change the TIM state*/ 01024 hlptim->State= HAL_LPTIM_STATE_READY; 01025 01026 /* Return function status */ 01027 return HAL_OK; 01028 } 01029 01030 /** 01031 * @brief Start the Encoder interface in interrupt mode. 01032 * @param hlptim : LPTIM handle 01033 * @param Period : Specifies the Autoreload value. 01034 * This parameter must be a value between 0x0000 and 0xFFFF. 01035 * @retval HAL status 01036 */ 01037 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01038 { 01039 HAL_StatusTypeDef status = HAL_OK; 01040 uint32_t tmpcfgr; 01041 01042 /* Check the parameters */ 01043 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01044 assert_param(IS_LPTIM_PERIOD(Period)); 01045 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC); 01046 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1); 01047 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity)); 01048 01049 /* Encoder feature is only available for LPTIM1 instance */ 01050 if (hlptim->Instance == LPTIM1) 01051 { 01052 /* Set the LPTIM state */ 01053 hlptim->State= HAL_LPTIM_STATE_BUSY; 01054 01055 /* Configure edge sensitivity for encoder mode */ 01056 /* Get the LPTIMx CFGR value */ 01057 tmpcfgr = hlptim->Instance->CFGR; 01058 01059 /* Clear CKPOL bits */ 01060 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL); 01061 01062 /* Set Input polarity */ 01063 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity; 01064 01065 /* Write to LPTIMx CFGR */ 01066 hlptim->Instance->CFGR = tmpcfgr; 01067 01068 /* Set ENC bit to enable the encoder interface */ 01069 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC; 01070 01071 /* Enable "switch to down direction" interrupt */ 01072 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN); 01073 01074 /* Enable "switch to up direction" interrupt */ 01075 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP); 01076 01077 /* Enable the Peripheral */ 01078 __HAL_LPTIM_ENABLE(hlptim); 01079 01080 /* Load the period value in the autoreload register */ 01081 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01082 01083 /* Start timer in continuous mode */ 01084 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01085 01086 /* Change the TIM state*/ 01087 hlptim->State= HAL_LPTIM_STATE_READY; 01088 } 01089 else 01090 { 01091 status = HAL_ERROR; 01092 } 01093 01094 /* Return function status */ 01095 return status; 01096 } 01097 01098 /** 01099 * @brief Stop the Encoder interface in interrupt mode. 01100 * @param hlptim : LPTIM handle 01101 * @retval HAL status 01102 */ 01103 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01104 { 01105 /* Check the parameters */ 01106 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01107 01108 /* Set the LPTIM state */ 01109 hlptim->State= HAL_LPTIM_STATE_BUSY; 01110 01111 /* Disable the Peripheral */ 01112 __HAL_LPTIM_DISABLE(hlptim); 01113 01114 /* Reset ENC bit to disable the encoder interface */ 01115 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC; 01116 01117 /* Disable "switch to down direction" interrupt */ 01118 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN); 01119 01120 /* Disable "switch to up direction" interrupt */ 01121 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP); 01122 01123 /* Change the TIM state*/ 01124 hlptim->State= HAL_LPTIM_STATE_READY; 01125 01126 /* Return function status */ 01127 return HAL_OK; 01128 } 01129 01130 /** 01131 * @brief Start the Timeout function. 01132 * @note The first trigger event will start the timer, any successive 01133 * trigger event will reset the counter and the timer restarts. 01134 * @param hlptim : LPTIM handle 01135 * @param Period : Specifies the Autoreload value. 01136 * This parameter must be a value between 0x0000 and 0xFFFF. 01137 * @param Timeout : Specifies the TimeOut value to rest the counter. 01138 * This parameter must be a value between 0x0000 and 0xFFFF. 01139 * @retval HAL status 01140 */ 01141 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout) 01142 { 01143 /* Check the parameters */ 01144 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01145 assert_param(IS_LPTIM_PERIOD(Period)); 01146 assert_param(IS_LPTIM_PULSE(Timeout)); 01147 01148 /* Set the LPTIM state */ 01149 hlptim->State= HAL_LPTIM_STATE_BUSY; 01150 01151 /* Set TIMOUT bit to enable the timeout function */ 01152 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT; 01153 01154 /* Enable the Peripheral */ 01155 __HAL_LPTIM_ENABLE(hlptim); 01156 01157 /* Load the period value in the autoreload register */ 01158 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01159 01160 /* Load the Timeout value in the compare register */ 01161 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout); 01162 01163 /* Start timer in continuous mode */ 01164 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01165 01166 /* Change the TIM state*/ 01167 hlptim->State= HAL_LPTIM_STATE_READY; 01168 01169 /* Return function status */ 01170 return HAL_OK; 01171 } 01172 01173 /** 01174 * @brief Stop the Timeout function. 01175 * @param hlptim : LPTIM handle 01176 * @retval HAL status 01177 */ 01178 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim) 01179 { 01180 /* Check the parameters */ 01181 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01182 01183 /* Set the LPTIM state */ 01184 hlptim->State= HAL_LPTIM_STATE_BUSY; 01185 01186 /* Disable the Peripheral */ 01187 __HAL_LPTIM_DISABLE(hlptim); 01188 01189 /* Reset TIMOUT bit to enable the timeout function */ 01190 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT; 01191 01192 /* Change the TIM state*/ 01193 hlptim->State= HAL_LPTIM_STATE_READY; 01194 01195 /* Return function status */ 01196 return HAL_OK; 01197 } 01198 01199 /** 01200 * @brief Start the Timeout function in interrupt mode. 01201 * @note The first trigger event will start the timer, any successive 01202 * trigger event will reset the counter and the timer restarts. 01203 * @param hlptim : LPTIM handle 01204 * @param Period : Specifies the Autoreload value. 01205 * This parameter must be a value between 0x0000 and 0xFFFF. 01206 * @param Timeout : Specifies the TimeOut value to rest the counter. 01207 * This parameter must be a value between 0x0000 and 0xFFFF. 01208 * @retval HAL status 01209 */ 01210 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout) 01211 { 01212 /* Check the parameters */ 01213 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01214 assert_param(IS_LPTIM_PERIOD(Period)); 01215 assert_param(IS_LPTIM_PULSE(Timeout)); 01216 01217 /* Set the LPTIM state */ 01218 hlptim->State= HAL_LPTIM_STATE_BUSY; 01219 01220 /* Set TIMOUT bit to enable the timeout function */ 01221 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT; 01222 01223 /* Enable Compare match interrupt */ 01224 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM); 01225 01226 /* Enable the Peripheral */ 01227 __HAL_LPTIM_ENABLE(hlptim); 01228 01229 /* Load the period value in the autoreload register */ 01230 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01231 01232 /* Load the Timeout value in the compare register */ 01233 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout); 01234 01235 /* Start timer in continuous mode */ 01236 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01237 01238 /* Change the TIM state*/ 01239 hlptim->State= HAL_LPTIM_STATE_READY; 01240 01241 /* Return function status */ 01242 return HAL_OK; 01243 } 01244 01245 /** 01246 * @brief Stop the Timeout function in interrupt mode. 01247 * @param hlptim : LPTIM handle 01248 * @retval HAL status 01249 */ 01250 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01251 { 01252 /* Check the parameters */ 01253 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01254 01255 /* Set the LPTIM state */ 01256 hlptim->State= HAL_LPTIM_STATE_BUSY; 01257 01258 /* Disable the Peripheral */ 01259 __HAL_LPTIM_DISABLE(hlptim); 01260 01261 /* Reset TIMOUT bit to enable the timeout function */ 01262 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT; 01263 01264 /* Disable Compare match interrupt */ 01265 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM); 01266 01267 /* Change the TIM state*/ 01268 hlptim->State= HAL_LPTIM_STATE_READY; 01269 01270 /* Return function status */ 01271 return HAL_OK; 01272 } 01273 01274 /** 01275 * @brief Start the Counter mode. 01276 * @param hlptim : LPTIM handle 01277 * @param Period : Specifies the Autoreload value. 01278 * This parameter must be a value between 0x0000 and 0xFFFF. 01279 * @retval HAL status 01280 */ 01281 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01282 { 01283 /* Check the parameters */ 01284 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01285 assert_param(IS_LPTIM_PERIOD(Period)); 01286 01287 /* Set the LPTIM state */ 01288 hlptim->State= HAL_LPTIM_STATE_BUSY; 01289 01290 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */ 01291 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 01292 { 01293 /* Check if clock is prescaled */ 01294 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler)); 01295 /* Set clock prescaler to 0 */ 01296 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC; 01297 } 01298 01299 /* Enable the Peripheral */ 01300 __HAL_LPTIM_ENABLE(hlptim); 01301 01302 /* Load the period value in the autoreload register */ 01303 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01304 01305 /* Start timer in continuous mode */ 01306 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01307 01308 /* Change the TIM state*/ 01309 hlptim->State= HAL_LPTIM_STATE_READY; 01310 01311 /* Return function status */ 01312 return HAL_OK; 01313 } 01314 01315 /** 01316 * @brief Stop the Counter mode. 01317 * @param hlptim : LPTIM handle 01318 * @retval HAL status 01319 */ 01320 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim) 01321 { 01322 /* Check the parameters */ 01323 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01324 01325 /* Set the LPTIM state */ 01326 hlptim->State= HAL_LPTIM_STATE_BUSY; 01327 01328 /* Disable the Peripheral */ 01329 __HAL_LPTIM_DISABLE(hlptim); 01330 01331 /* Change the TIM state*/ 01332 hlptim->State= HAL_LPTIM_STATE_READY; 01333 01334 /* Return function status */ 01335 return HAL_OK; 01336 } 01337 01338 /** 01339 * @brief Start the Counter mode in interrupt mode. 01340 * @param hlptim : LPTIM handle 01341 * @param Period : Specifies the Autoreload value. 01342 * This parameter must be a value between 0x0000 and 0xFFFF. 01343 * @retval HAL status 01344 */ 01345 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period) 01346 { 01347 /* Check the parameters */ 01348 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01349 assert_param(IS_LPTIM_PERIOD(Period)); 01350 01351 /* Set the LPTIM state */ 01352 hlptim->State= HAL_LPTIM_STATE_BUSY; 01353 01354 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */ 01355 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL)) 01356 { 01357 /* Check if clock is prescaled */ 01358 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler)); 01359 /* Set clock prescaler to 0 */ 01360 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC; 01361 } 01362 01363 /* Enable Autoreload write complete interrupt */ 01364 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK); 01365 01366 /* Enable Autoreload match interrupt */ 01367 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM); 01368 01369 /* Enable the Peripheral */ 01370 __HAL_LPTIM_ENABLE(hlptim); 01371 01372 /* Load the period value in the autoreload register */ 01373 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period); 01374 01375 /* Start timer in continuous mode */ 01376 __HAL_LPTIM_START_CONTINUOUS(hlptim); 01377 01378 /* Change the TIM state*/ 01379 hlptim->State= HAL_LPTIM_STATE_READY; 01380 01381 /* Return function status */ 01382 return HAL_OK; 01383 } 01384 01385 /** 01386 * @brief Stop the Counter mode in interrupt mode. 01387 * @param hlptim : LPTIM handle 01388 * @retval HAL status 01389 */ 01390 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim) 01391 { 01392 /* Check the parameters */ 01393 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01394 01395 /* Set the LPTIM state */ 01396 hlptim->State= HAL_LPTIM_STATE_BUSY; 01397 01398 /* Disable the Peripheral */ 01399 __HAL_LPTIM_DISABLE(hlptim); 01400 01401 /* Disable Autoreload write complete interrupt */ 01402 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK); 01403 01404 /* Disable Autoreload match interrupt */ 01405 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM); 01406 01407 /* Change the TIM state*/ 01408 hlptim->State= HAL_LPTIM_STATE_READY; 01409 01410 /* Return function status */ 01411 return HAL_OK; 01412 } 01413 01414 /** 01415 * @} 01416 */ 01417 01418 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions 01419 * @brief Read operation functions. 01420 * 01421 @verbatim 01422 ============================================================================== 01423 ##### LPTIM Read operation functions ##### 01424 ============================================================================== 01425 [..] This section provides LPTIM Reading functions. 01426 (+) Read the counter value. 01427 (+) Read the period (Auto-reload) value. 01428 (+) Read the pulse (Compare)value. 01429 @endverbatim 01430 * @{ 01431 */ 01432 01433 /** 01434 * @brief Return the current counter value. 01435 * @param hlptim: LPTIM handle 01436 * @retval Counter value. 01437 */ 01438 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim) 01439 { 01440 /* Check the parameters */ 01441 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01442 01443 return (hlptim->Instance->CNT); 01444 } 01445 01446 /** 01447 * @brief Return the current Autoreload (Period) value. 01448 * @param hlptim: LPTIM handle 01449 * @retval Autoreload value. 01450 */ 01451 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim) 01452 { 01453 /* Check the parameters */ 01454 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01455 01456 return (hlptim->Instance->ARR); 01457 } 01458 01459 /** 01460 * @brief Return the current Compare (Pulse) value. 01461 * @param hlptim: LPTIM handle 01462 * @retval Compare value. 01463 */ 01464 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim) 01465 { 01466 /* Check the parameters */ 01467 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance)); 01468 01469 return (hlptim->Instance->CMP); 01470 } 01471 01472 /** 01473 * @} 01474 */ 01475 01476 01477 01478 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks 01479 * @brief LPTIM IRQ handler. 01480 * 01481 @verbatim 01482 ============================================================================== 01483 ##### LPTIM IRQ handler and callbacks ##### 01484 ============================================================================== 01485 [..] This section provides LPTIM IRQ handler and callback functions called within 01486 the IRQ handler. 01487 01488 @endverbatim 01489 * @{ 01490 */ 01491 01492 /** 01493 * @brief Handle LPTIM interrupt request. 01494 * @param hlptim: LPTIM handle 01495 * @retval None 01496 */ 01497 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim) 01498 { 01499 /* Compare match interrupt */ 01500 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET) 01501 { 01502 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET) 01503 { 01504 /* Clear Compare match flag */ 01505 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM); 01506 01507 /* Compare match Callback */ 01508 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01509 hlptim->CompareMatchCallback(hlptim); 01510 #else 01511 HAL_LPTIM_CompareMatchCallback(hlptim); 01512 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01513 } 01514 } 01515 01516 /* Autoreload match interrupt */ 01517 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET) 01518 { 01519 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET) 01520 { 01521 /* Clear Autoreload match flag */ 01522 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM); 01523 01524 /* Autoreload match Callback */ 01525 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01526 hlptim->AutoReloadMatchCallback(hlptim); 01527 #else 01528 HAL_LPTIM_AutoReloadMatchCallback(hlptim); 01529 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01530 } 01531 } 01532 01533 /* Trigger detected interrupt */ 01534 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET) 01535 { 01536 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET) 01537 { 01538 /* Clear Trigger detected flag */ 01539 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG); 01540 01541 /* Trigger detected callback */ 01542 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01543 hlptim->TriggerCallback(hlptim); 01544 #else 01545 HAL_LPTIM_TriggerCallback(hlptim); 01546 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01547 } 01548 } 01549 01550 /* Compare write interrupt */ 01551 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET) 01552 { 01553 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET) 01554 { 01555 /* Clear Compare write flag */ 01556 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK); 01557 01558 /* Compare write Callback */ 01559 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01560 hlptim->CompareWriteCallback(hlptim); 01561 #else 01562 HAL_LPTIM_CompareWriteCallback(hlptim); 01563 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01564 } 01565 } 01566 01567 /* Autoreload write interrupt */ 01568 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET) 01569 { 01570 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET) 01571 { 01572 /* Clear Autoreload write flag */ 01573 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK); 01574 01575 /* Autoreload write Callback */ 01576 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01577 hlptim->AutoReloadWriteCallback(hlptim); 01578 #else 01579 HAL_LPTIM_AutoReloadWriteCallback(hlptim); 01580 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01581 } 01582 } 01583 01584 /* Direction counter changed from Down to Up interrupt */ 01585 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET) 01586 { 01587 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET) 01588 { 01589 /* Clear Direction counter changed from Down to Up flag */ 01590 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP); 01591 01592 /* Direction counter changed from Down to Up Callback */ 01593 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01594 hlptim->DirectionUpCallback(hlptim); 01595 #else 01596 HAL_LPTIM_DirectionUpCallback(hlptim); 01597 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01598 } 01599 } 01600 01601 /* Direction counter changed from Up to Down interrupt */ 01602 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET) 01603 { 01604 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET) 01605 { 01606 /* Clear Direction counter changed from Up to Down flag */ 01607 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN); 01608 01609 /* Direction counter changed from Up to Down Callback */ 01610 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01611 hlptim->DirectionDownCallback(hlptim); 01612 #else 01613 HAL_LPTIM_DirectionDownCallback(hlptim); 01614 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01615 } 01616 } 01617 } 01618 01619 /** 01620 * @brief Compare match callback in non-blocking mode. 01621 * @param hlptim : LPTIM handle 01622 * @retval None 01623 */ 01624 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) 01625 { 01626 /* Prevent unused argument(s) compilation warning */ 01627 UNUSED(hlptim); 01628 01629 /* NOTE : This function should not be modified, when the callback is needed, 01630 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file 01631 */ 01632 } 01633 01634 /** 01635 * @brief Autoreload match callback in non-blocking mode. 01636 * @param hlptim : LPTIM handle 01637 * @retval None 01638 */ 01639 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim) 01640 { 01641 /* Prevent unused argument(s) compilation warning */ 01642 UNUSED(hlptim); 01643 01644 /* NOTE : This function should not be modified, when the callback is needed, 01645 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file 01646 */ 01647 } 01648 01649 /** 01650 * @brief Trigger detected callback in non-blocking mode. 01651 * @param hlptim : LPTIM handle 01652 * @retval None 01653 */ 01654 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim) 01655 { 01656 /* Prevent unused argument(s) compilation warning */ 01657 UNUSED(hlptim); 01658 01659 /* NOTE : This function should not be modified, when the callback is needed, 01660 the HAL_LPTIM_TriggerCallback could be implemented in the user file 01661 */ 01662 } 01663 01664 /** 01665 * @brief Compare write callback in non-blocking mode. 01666 * @param hlptim : LPTIM handle 01667 * @retval None 01668 */ 01669 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim) 01670 { 01671 /* Prevent unused argument(s) compilation warning */ 01672 UNUSED(hlptim); 01673 01674 /* NOTE : This function should not be modified, when the callback is needed, 01675 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file 01676 */ 01677 } 01678 01679 /** 01680 * @brief Autoreload write callback in non-blocking mode. 01681 * @param hlptim : LPTIM handle 01682 * @retval None 01683 */ 01684 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim) 01685 { 01686 /* Prevent unused argument(s) compilation warning */ 01687 UNUSED(hlptim); 01688 01689 /* NOTE : This function should not be modified, when the callback is needed, 01690 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file 01691 */ 01692 } 01693 01694 /** 01695 * @brief Direction counter changed from Down to Up callback in non-blocking mode. 01696 * @param hlptim : LPTIM handle 01697 * @retval None 01698 */ 01699 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim) 01700 { 01701 /* Prevent unused argument(s) compilation warning */ 01702 UNUSED(hlptim); 01703 01704 /* NOTE : This function should not be modified, when the callback is needed, 01705 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file 01706 */ 01707 } 01708 01709 /** 01710 * @brief Direction counter changed from Up to Down callback in non-blocking mode. 01711 * @param hlptim : LPTIM handle 01712 * @retval None 01713 */ 01714 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim) 01715 { 01716 /* Prevent unused argument(s) compilation warning */ 01717 UNUSED(hlptim); 01718 01719 /* NOTE : This function should not be modified, when the callback is needed, 01720 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file 01721 */ 01722 } 01723 01724 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01725 /** 01726 * @brief Register a User LPTIM callback to be used instead of the weak predefined callback 01727 * @param hlptim LPTIM handle 01728 * @param CallbackID ID of the callback to be registered 01729 * This parameter can be one of the following values: 01730 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID 01731 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID 01732 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID 01733 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID 01734 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID 01735 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID 01736 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID 01737 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID 01738 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID 01739 * @param pCallback pointer to the callback function 01740 * @retval status 01741 */ 01742 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *hlptim, 01743 HAL_LPTIM_CallbackIDTypeDef CallbackID, 01744 pLPTIM_CallbackTypeDef pCallback) 01745 { 01746 HAL_StatusTypeDef status = HAL_OK; 01747 01748 if (pCallback == NULL) 01749 { 01750 return HAL_ERROR; 01751 } 01752 01753 /* Process locked */ 01754 __HAL_LOCK(hlptim); 01755 01756 if (hlptim->State == HAL_LPTIM_STATE_READY) 01757 { 01758 switch (CallbackID) 01759 { 01760 case HAL_LPTIM_MSPINIT_CB_ID : 01761 hlptim->MspInitCallback = pCallback; 01762 break; 01763 01764 case HAL_LPTIM_MSPDEINIT_CB_ID : 01765 hlptim->MspDeInitCallback = pCallback; 01766 break; 01767 01768 case HAL_LPTIM_COMPARE_MATCH_CB_ID : 01769 hlptim->CompareMatchCallback = pCallback; 01770 break; 01771 01772 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID : 01773 hlptim->AutoReloadMatchCallback = pCallback; 01774 break; 01775 01776 case HAL_LPTIM_TRIGGER_CB_ID : 01777 hlptim->TriggerCallback = pCallback; 01778 break; 01779 01780 case HAL_LPTIM_COMPARE_WRITE_CB_ID : 01781 hlptim->CompareWriteCallback = pCallback; 01782 break; 01783 01784 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID : 01785 hlptim->AutoReloadWriteCallback = pCallback; 01786 break; 01787 01788 case HAL_LPTIM_DIRECTION_UP_CB_ID : 01789 hlptim->DirectionUpCallback = pCallback; 01790 break; 01791 01792 case HAL_LPTIM_DIRECTION_DOWN_CB_ID : 01793 hlptim->DirectionDownCallback = pCallback; 01794 break; 01795 01796 default : 01797 /* Return error status */ 01798 status = HAL_ERROR; 01799 break; 01800 } 01801 } 01802 else if (hlptim->State == HAL_LPTIM_STATE_RESET) 01803 { 01804 switch (CallbackID) 01805 { 01806 case HAL_LPTIM_MSPINIT_CB_ID : 01807 hlptim->MspInitCallback = pCallback; 01808 break; 01809 01810 case HAL_LPTIM_MSPDEINIT_CB_ID : 01811 hlptim->MspDeInitCallback = pCallback; 01812 break; 01813 01814 default : 01815 /* Return error status */ 01816 status = HAL_ERROR; 01817 break; 01818 } 01819 } 01820 else 01821 { 01822 /* Return error status */ 01823 status = HAL_ERROR; 01824 } 01825 01826 /* Release Lock */ 01827 __HAL_UNLOCK(hlptim); 01828 01829 return status; 01830 } 01831 01832 /** 01833 * @brief Unregister a LPTIM callback 01834 * LLPTIM callback is redirected to the weak predefined callback 01835 * @param hlptim LPTIM handle 01836 * @param CallbackID ID of the callback to be unregistered 01837 * This parameter can be one of the following values: 01838 * @arg @ref HAL_LPTIM_MSPINIT_CB_ID LPTIM Base Msp Init Callback ID 01839 * @arg @ref HAL_LPTIM_MSPDEINIT_CB_ID LPTIM Base Msp DeInit Callback ID 01840 * @arg @ref HAL_LPTIM_COMPARE_MATCH_CB_ID Compare match Callback ID 01841 * @arg @ref HAL_LPTIM_AUTORELOAD_MATCH_CB_ID Auto-reload match Callback ID 01842 * @arg @ref HAL_LPTIM_TRIGGER_CB_ID External trigger event detection Callback ID 01843 * @arg @ref HAL_LPTIM_COMPARE_WRITE_CB_ID Compare register write complete Callback ID 01844 * @arg @ref HAL_LPTIM_AUTORELOAD_WRITE_CB_ID Auto-reload register write complete Callback ID 01845 * @arg @ref HAL_LPTIM_DIRECTION_UP_CB_ID Up-counting direction change Callback ID 01846 * @arg @ref HAL_LPTIM_DIRECTION_DOWN_CB_ID Down-counting direction change Callback ID 01847 * @retval status 01848 */ 01849 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *hlptim, 01850 HAL_LPTIM_CallbackIDTypeDef CallbackID) 01851 { 01852 HAL_StatusTypeDef status = HAL_OK; 01853 01854 /* Process locked */ 01855 __HAL_LOCK(hlptim); 01856 01857 if (hlptim->State == HAL_LPTIM_STATE_READY) 01858 { 01859 switch (CallbackID) 01860 { 01861 case HAL_LPTIM_MSPINIT_CB_ID : 01862 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */ 01863 break; 01864 01865 case HAL_LPTIM_MSPDEINIT_CB_ID : 01866 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */ 01867 break; 01868 01869 case HAL_LPTIM_COMPARE_MATCH_CB_ID : 01870 hlptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Legacy weak IC Msp Init Callback */ 01871 break; 01872 01873 case HAL_LPTIM_AUTORELOAD_MATCH_CB_ID : 01874 hlptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Legacy weak IC Msp DeInit Callback */ 01875 break; 01876 01877 case HAL_LPTIM_TRIGGER_CB_ID : 01878 hlptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* Legacy weak OC Msp Init Callback */ 01879 break; 01880 01881 case HAL_LPTIM_COMPARE_WRITE_CB_ID : 01882 hlptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Legacy weak OC Msp DeInit Callback */ 01883 break; 01884 01885 case HAL_LPTIM_AUTORELOAD_WRITE_CB_ID : 01886 hlptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Legacy weak PWM Msp Init Callback */ 01887 break; 01888 01889 case HAL_LPTIM_DIRECTION_UP_CB_ID : 01890 hlptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Legacy weak PWM Msp DeInit Callback */ 01891 break; 01892 01893 case HAL_LPTIM_DIRECTION_DOWN_CB_ID : 01894 hlptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Legacy weak One Pulse Msp Init Callback */ 01895 break; 01896 01897 default : 01898 /* Return error status */ 01899 status = HAL_ERROR; 01900 break; 01901 } 01902 } 01903 else if (hlptim->State == HAL_LPTIM_STATE_RESET) 01904 { 01905 switch (CallbackID) 01906 { 01907 case HAL_LPTIM_MSPINIT_CB_ID : 01908 hlptim->MspInitCallback = HAL_LPTIM_MspInit; /* Legacy weak MspInit Callback */ 01909 break; 01910 01911 case HAL_LPTIM_MSPDEINIT_CB_ID : 01912 hlptim->MspDeInitCallback = HAL_LPTIM_MspDeInit; /* Legacy weak Msp DeInit Callback */ 01913 break; 01914 01915 default : 01916 /* Return error status */ 01917 status = HAL_ERROR; 01918 break; 01919 } 01920 } 01921 else 01922 { 01923 /* Return error status */ 01924 status = HAL_ERROR; 01925 } 01926 01927 /* Release Lock */ 01928 __HAL_UNLOCK(hlptim); 01929 01930 return status; 01931 } 01932 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01933 01934 /** 01935 * @} 01936 */ 01937 01938 /** @defgroup LPTIM_Exported_Functions_Group5 Peripheral State functions 01939 * @brief Peripheral State functions. 01940 * 01941 @verbatim 01942 ============================================================================== 01943 ##### Peripheral State functions ##### 01944 ============================================================================== 01945 [..] 01946 This subsection permits to get in run-time the status of the peripheral. 01947 01948 @endverbatim 01949 * @{ 01950 */ 01951 01952 /** 01953 * @brief Return the LPTIM handle state. 01954 * @param hlptim: LPTIM handle 01955 * @retval HAL state 01956 */ 01957 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim) 01958 { 01959 /* Return LPTIM handle state */ 01960 return hlptim->State; 01961 } 01962 01963 /** 01964 * @} 01965 */ 01966 01967 01968 /** 01969 * @} 01970 */ 01971 01972 /* Private functions ---------------------------------------------------------*/ 01973 01974 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions 01975 * @{ 01976 */ 01977 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 01978 /** 01979 * @brief Reset interrupt callbacks to the legacy weak callbacks. 01980 * @param lptim pointer to a LPTIM_HandleTypeDef structure that contains 01981 * the configuration information for LPTIM module. 01982 * @retval None 01983 */ 01984 static void LPTIM_ResetCallback(LPTIM_HandleTypeDef *lptim) 01985 { 01986 /* Reset the LPTIM callback to the legacy weak callbacks */ 01987 lptim->CompareMatchCallback = HAL_LPTIM_CompareMatchCallback; /* Compare match Callback */ 01988 lptim->AutoReloadMatchCallback = HAL_LPTIM_AutoReloadMatchCallback; /* Auto-reload match Callback */ 01989 lptim->TriggerCallback = HAL_LPTIM_TriggerCallback; /* External trigger event detection Callback */ 01990 lptim->CompareWriteCallback = HAL_LPTIM_CompareWriteCallback; /* Compare register write complete Callback */ 01991 lptim->AutoReloadWriteCallback = HAL_LPTIM_AutoReloadWriteCallback; /* Auto-reload register write complete Callback */ 01992 lptim->DirectionUpCallback = HAL_LPTIM_DirectionUpCallback; /* Up-counting direction change Callback */ 01993 lptim->DirectionDownCallback = HAL_LPTIM_DirectionDownCallback; /* Down-counting direction change Callback */ 01994 } 01995 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 01996 01997 /** 01998 * @} 01999 */ 02000 02001 #endif /* HAL_LPTIM_MODULE_ENABLED */ 02002 /** 02003 * @} 02004 */ 02005 02006 /** 02007 * @} 02008 */ 02009 02010 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/