TUKS MCU Introductory course / TUKS-COURSE-TIMER
Committer:
elmot
Date:
Fri Feb 24 21:13:56 2017 +0000
Revision:
1:d0dfbce63a89
Ready-to-copy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elmot 1:d0dfbce63a89 1 /**
elmot 1:d0dfbce63a89 2 ******************************************************************************
elmot 1:d0dfbce63a89 3 * @file stm32l4xx_hal_lptim.c
elmot 1:d0dfbce63a89 4 * @author MCD Application Team
elmot 1:d0dfbce63a89 5 * @version V1.5.1
elmot 1:d0dfbce63a89 6 * @date 31-May-2016
elmot 1:d0dfbce63a89 7 * @brief LPTIM HAL module driver.
elmot 1:d0dfbce63a89 8 * This file provides firmware functions to manage the following
elmot 1:d0dfbce63a89 9 * functionalities of the Low Power Timer (LPTIM) peripheral:
elmot 1:d0dfbce63a89 10 * + Initialization and de-initialization functions.
elmot 1:d0dfbce63a89 11 * + Start/Stop operation functions in polling mode.
elmot 1:d0dfbce63a89 12 * + Start/Stop operation functions in interrupt mode.
elmot 1:d0dfbce63a89 13 * + Reading operation functions.
elmot 1:d0dfbce63a89 14 * + Peripheral State functions.
elmot 1:d0dfbce63a89 15 *
elmot 1:d0dfbce63a89 16 @verbatim
elmot 1:d0dfbce63a89 17 ==============================================================================
elmot 1:d0dfbce63a89 18 ##### How to use this driver #####
elmot 1:d0dfbce63a89 19 ==============================================================================
elmot 1:d0dfbce63a89 20 [..]
elmot 1:d0dfbce63a89 21 The LPTIM HAL driver can be used as follows:
elmot 1:d0dfbce63a89 22
elmot 1:d0dfbce63a89 23 (#)Initialize the LPTIM low level resources by implementing the
elmot 1:d0dfbce63a89 24 HAL_LPTIM_MspInit():
elmot 1:d0dfbce63a89 25 (++) Enable the LPTIM interface clock using __HAL_RCC_LPTIMx_CLK_ENABLE().
elmot 1:d0dfbce63a89 26 (++) In case of using interrupts (e.g. HAL_LPTIM_PWM_Start_IT()):
elmot 1:d0dfbce63a89 27 (+++) Configure the LPTIM interrupt priority using HAL_NVIC_SetPriority().
elmot 1:d0dfbce63a89 28 (+++) Enable the LPTIM IRQ handler using HAL_NVIC_EnableIRQ().
elmot 1:d0dfbce63a89 29 (+++) In LPTIM IRQ handler, call HAL_LPTIM_IRQHandler().
elmot 1:d0dfbce63a89 30
elmot 1:d0dfbce63a89 31 (#)Initialize the LPTIM HAL using HAL_LPTIM_Init(). This function
elmot 1:d0dfbce63a89 32 configures mainly:
elmot 1:d0dfbce63a89 33 (++) The instance: LPTIM1 or LPTIM2.
elmot 1:d0dfbce63a89 34 (++) Clock: the counter clock.
elmot 1:d0dfbce63a89 35 (+++) Source : it can be either the ULPTIM input (IN1) or one of
elmot 1:d0dfbce63a89 36 the internal clock; (APB, LSE, LSI or MSI).
elmot 1:d0dfbce63a89 37 (+++) Prescaler: select the clock divider.
elmot 1:d0dfbce63a89 38 (++) UltraLowPowerClock : To be used only if the ULPTIM is selected
elmot 1:d0dfbce63a89 39 as counter clock source.
elmot 1:d0dfbce63a89 40 (+++) Polarity: polarity of the active edge for the counter unit
elmot 1:d0dfbce63a89 41 if the ULPTIM input is selected.
elmot 1:d0dfbce63a89 42 (+++) SampleTime: clock sampling time to configure the clock glitch
elmot 1:d0dfbce63a89 43 filter.
elmot 1:d0dfbce63a89 44 (++) Trigger: How the counter start.
elmot 1:d0dfbce63a89 45 (+++) Source: trigger can be software or one of the hardware triggers.
elmot 1:d0dfbce63a89 46 (+++) ActiveEdge : only for hardware trigger.
elmot 1:d0dfbce63a89 47 (+++) SampleTime : trigger sampling time to configure the trigger
elmot 1:d0dfbce63a89 48 glitch filter.
elmot 1:d0dfbce63a89 49 (++) OutputPolarity : 2 opposite polarities are possible.
elmot 1:d0dfbce63a89 50 (++) UpdateMode: specifies whether the update of the autoreload and
elmot 1:d0dfbce63a89 51 the compare values is done immediately or after the end of current
elmot 1:d0dfbce63a89 52 period.
elmot 1:d0dfbce63a89 53 (++) Input1Source: Source selected for input1 (GPIO or comparator output).
elmot 1:d0dfbce63a89 54 (++) Input2Source: Source selected for input2 (GPIO or comparator output).
elmot 1:d0dfbce63a89 55 Input2 is used only for encoder feature so is used only for LPTIM1 instance.
elmot 1:d0dfbce63a89 56
elmot 1:d0dfbce63a89 57 (#)Six modes are available:
elmot 1:d0dfbce63a89 58
elmot 1:d0dfbce63a89 59 (++) PWM Mode: To generate a PWM signal with specified period and pulse,
elmot 1:d0dfbce63a89 60 call HAL_LPTIM_PWM_Start() or HAL_LPTIM_PWM_Start_IT() for interruption
elmot 1:d0dfbce63a89 61 mode.
elmot 1:d0dfbce63a89 62
elmot 1:d0dfbce63a89 63 (++) One Pulse Mode: To generate pulse with specified width in response
elmot 1:d0dfbce63a89 64 to a stimulus, call HAL_LPTIM_OnePulse_Start() or
elmot 1:d0dfbce63a89 65 HAL_LPTIM_OnePulse_Start_IT() for interruption mode.
elmot 1:d0dfbce63a89 66
elmot 1:d0dfbce63a89 67 (++) Set once Mode: In this mode, the output changes the level (from
elmot 1:d0dfbce63a89 68 low level to high level if the output polarity is configured high, else
elmot 1:d0dfbce63a89 69 the opposite) when a compare match occurs. To start this mode, call
elmot 1:d0dfbce63a89 70 HAL_LPTIM_SetOnce_Start() or HAL_LPTIM_SetOnce_Start_IT() for
elmot 1:d0dfbce63a89 71 interruption mode.
elmot 1:d0dfbce63a89 72
elmot 1:d0dfbce63a89 73 (++) Encoder Mode: To use the encoder interface call
elmot 1:d0dfbce63a89 74 HAL_LPTIM_Encoder_Start() or HAL_LPTIM_Encoder_Start_IT() for
elmot 1:d0dfbce63a89 75 interruption mode. Only available for LPTIM1 instance.
elmot 1:d0dfbce63a89 76
elmot 1:d0dfbce63a89 77 (++) Time out Mode: an active edge on one selected trigger input rests
elmot 1:d0dfbce63a89 78 the counter. The first trigger event will start the timer, any
elmot 1:d0dfbce63a89 79 successive trigger event will reset the counter and the timer will
elmot 1:d0dfbce63a89 80 restart. To start this mode call HAL_LPTIM_TimeOut_Start_IT() or
elmot 1:d0dfbce63a89 81 HAL_LPTIM_TimeOut_Start_IT() for interruption mode.
elmot 1:d0dfbce63a89 82
elmot 1:d0dfbce63a89 83 (++) Counter Mode: counter can be used to count external events on
elmot 1:d0dfbce63a89 84 the LPTIM Input1 or it can be used to count internal clock cycles.
elmot 1:d0dfbce63a89 85 To start this mode, call HAL_LPTIM_Counter_Start() or
elmot 1:d0dfbce63a89 86 HAL_LPTIM_Counter_Start_IT() for interruption mode.
elmot 1:d0dfbce63a89 87
elmot 1:d0dfbce63a89 88
elmot 1:d0dfbce63a89 89 (#) User can stop any process by calling the corresponding API:
elmot 1:d0dfbce63a89 90 HAL_LPTIM_Xxx_Stop() or HAL_LPTIM_Xxx_Stop_IT() if the process is
elmot 1:d0dfbce63a89 91 already started in interruption mode.
elmot 1:d0dfbce63a89 92
elmot 1:d0dfbce63a89 93 (#) De-initialize the LPTIM peripheral using HAL_LPTIM_DeInit().
elmot 1:d0dfbce63a89 94
elmot 1:d0dfbce63a89 95 @endverbatim
elmot 1:d0dfbce63a89 96 ******************************************************************************
elmot 1:d0dfbce63a89 97 * @attention
elmot 1:d0dfbce63a89 98 *
elmot 1:d0dfbce63a89 99 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
elmot 1:d0dfbce63a89 100 *
elmot 1:d0dfbce63a89 101 * Redistribution and use in source and binary forms, with or without modification,
elmot 1:d0dfbce63a89 102 * are permitted provided that the following conditions are met:
elmot 1:d0dfbce63a89 103 * 1. Redistributions of source code must retain the above copyright notice,
elmot 1:d0dfbce63a89 104 * this list of conditions and the following disclaimer.
elmot 1:d0dfbce63a89 105 * 2. Redistributions in binary form must reproduce the above copyright notice,
elmot 1:d0dfbce63a89 106 * this list of conditions and the following disclaimer in the documentation
elmot 1:d0dfbce63a89 107 * and/or other materials provided with the distribution.
elmot 1:d0dfbce63a89 108 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elmot 1:d0dfbce63a89 109 * may be used to endorse or promote products derived from this software
elmot 1:d0dfbce63a89 110 * without specific prior written permission.
elmot 1:d0dfbce63a89 111 *
elmot 1:d0dfbce63a89 112 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elmot 1:d0dfbce63a89 113 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elmot 1:d0dfbce63a89 114 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elmot 1:d0dfbce63a89 115 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elmot 1:d0dfbce63a89 116 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elmot 1:d0dfbce63a89 117 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elmot 1:d0dfbce63a89 118 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elmot 1:d0dfbce63a89 119 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elmot 1:d0dfbce63a89 120 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elmot 1:d0dfbce63a89 121 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elmot 1:d0dfbce63a89 122 *
elmot 1:d0dfbce63a89 123 ******************************************************************************
elmot 1:d0dfbce63a89 124 */
elmot 1:d0dfbce63a89 125
elmot 1:d0dfbce63a89 126 /* Includes ------------------------------------------------------------------*/
elmot 1:d0dfbce63a89 127 #include "stm32l4xx_hal.h"
elmot 1:d0dfbce63a89 128
elmot 1:d0dfbce63a89 129 /** @addtogroup STM32L4xx_HAL_Driver
elmot 1:d0dfbce63a89 130 * @{
elmot 1:d0dfbce63a89 131 */
elmot 1:d0dfbce63a89 132
elmot 1:d0dfbce63a89 133 /** @defgroup LPTIM LPTIM
elmot 1:d0dfbce63a89 134 * @brief LPTIM HAL module driver.
elmot 1:d0dfbce63a89 135 * @{
elmot 1:d0dfbce63a89 136 */
elmot 1:d0dfbce63a89 137
elmot 1:d0dfbce63a89 138 #ifdef HAL_LPTIM_MODULE_ENABLED
elmot 1:d0dfbce63a89 139 /* Private typedef -----------------------------------------------------------*/
elmot 1:d0dfbce63a89 140 /* Private define ------------------------------------------------------------*/
elmot 1:d0dfbce63a89 141 /* Private macro -------------------------------------------------------------*/
elmot 1:d0dfbce63a89 142 /* Private variables ---------------------------------------------------------*/
elmot 1:d0dfbce63a89 143 /* Private function prototypes -----------------------------------------------*/
elmot 1:d0dfbce63a89 144 /* Exported functions --------------------------------------------------------*/
elmot 1:d0dfbce63a89 145
elmot 1:d0dfbce63a89 146 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
elmot 1:d0dfbce63a89 147 * @{
elmot 1:d0dfbce63a89 148 */
elmot 1:d0dfbce63a89 149
elmot 1:d0dfbce63a89 150 /** @defgroup LPTIM_Exported_Functions_Group1 Initialization/de-initialization functions
elmot 1:d0dfbce63a89 151 * @brief Initialization and Configuration functions.
elmot 1:d0dfbce63a89 152 *
elmot 1:d0dfbce63a89 153 @verbatim
elmot 1:d0dfbce63a89 154 ==============================================================================
elmot 1:d0dfbce63a89 155 ##### Initialization and de-initialization functions #####
elmot 1:d0dfbce63a89 156 ==============================================================================
elmot 1:d0dfbce63a89 157 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 158 (+) Initialize the LPTIM according to the specified parameters in the
elmot 1:d0dfbce63a89 159 LPTIM_InitTypeDef and initialize the associated handle.
elmot 1:d0dfbce63a89 160 (+) DeInitialize the LPTIM peripheral.
elmot 1:d0dfbce63a89 161 (+) Initialize the LPTIM MSP.
elmot 1:d0dfbce63a89 162 (+) DeInitialize the LPTIM MSP.
elmot 1:d0dfbce63a89 163
elmot 1:d0dfbce63a89 164 @endverbatim
elmot 1:d0dfbce63a89 165 * @{
elmot 1:d0dfbce63a89 166 */
elmot 1:d0dfbce63a89 167
elmot 1:d0dfbce63a89 168 /**
elmot 1:d0dfbce63a89 169 * @brief Initialize the LPTIM according to the specified parameters in the
elmot 1:d0dfbce63a89 170 * LPTIM_InitTypeDef and initialize the associated handle.
elmot 1:d0dfbce63a89 171 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 172 * @retval HAL status
elmot 1:d0dfbce63a89 173 */
elmot 1:d0dfbce63a89 174 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 175 {
elmot 1:d0dfbce63a89 176 uint32_t tmpcfgr = 0;
elmot 1:d0dfbce63a89 177
elmot 1:d0dfbce63a89 178 /* Check the LPTIM handle allocation */
elmot 1:d0dfbce63a89 179 if(hlptim == NULL)
elmot 1:d0dfbce63a89 180 {
elmot 1:d0dfbce63a89 181 return HAL_ERROR;
elmot 1:d0dfbce63a89 182 }
elmot 1:d0dfbce63a89 183
elmot 1:d0dfbce63a89 184 /* Check the parameters */
elmot 1:d0dfbce63a89 185 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 186
elmot 1:d0dfbce63a89 187 assert_param(IS_LPTIM_CLOCK_SOURCE(hlptim->Init.Clock.Source));
elmot 1:d0dfbce63a89 188 assert_param(IS_LPTIM_CLOCK_PRESCALER(hlptim->Init.Clock.Prescaler));
elmot 1:d0dfbce63a89 189 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
elmot 1:d0dfbce63a89 190 {
elmot 1:d0dfbce63a89 191 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
elmot 1:d0dfbce63a89 192 assert_param(IS_LPTIM_CLOCK_SAMPLE_TIME(hlptim->Init.UltraLowPowerClock.SampleTime));
elmot 1:d0dfbce63a89 193 }
elmot 1:d0dfbce63a89 194 assert_param(IS_LPTIM_TRG_SOURCE(hlptim->Init.Trigger.Source));
elmot 1:d0dfbce63a89 195 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 196 {
elmot 1:d0dfbce63a89 197 assert_param(IS_LPTIM_TRIG_SAMPLE_TIME(hlptim->Init.Trigger.SampleTime));
elmot 1:d0dfbce63a89 198 assert_param(IS_LPTIM_EXT_TRG_POLARITY(hlptim->Init.Trigger.ActiveEdge));
elmot 1:d0dfbce63a89 199 }
elmot 1:d0dfbce63a89 200 assert_param(IS_LPTIM_OUTPUT_POLARITY(hlptim->Init.OutputPolarity));
elmot 1:d0dfbce63a89 201 assert_param(IS_LPTIM_UPDATE_MODE(hlptim->Init.UpdateMode));
elmot 1:d0dfbce63a89 202 assert_param(IS_LPTIM_COUNTER_SOURCE(hlptim->Init.CounterSource));
elmot 1:d0dfbce63a89 203
elmot 1:d0dfbce63a89 204 if(hlptim->State == HAL_LPTIM_STATE_RESET)
elmot 1:d0dfbce63a89 205 {
elmot 1:d0dfbce63a89 206 /* Allocate lock resource and initialize it */
elmot 1:d0dfbce63a89 207 hlptim->Lock = HAL_UNLOCKED;
elmot 1:d0dfbce63a89 208
elmot 1:d0dfbce63a89 209 /* Init the low level hardware */
elmot 1:d0dfbce63a89 210 HAL_LPTIM_MspInit(hlptim);
elmot 1:d0dfbce63a89 211 }
elmot 1:d0dfbce63a89 212
elmot 1:d0dfbce63a89 213 /* Change the LPTIM state */
elmot 1:d0dfbce63a89 214 hlptim->State = HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 215
elmot 1:d0dfbce63a89 216 /* Get the LPTIMx CFGR value */
elmot 1:d0dfbce63a89 217 tmpcfgr = hlptim->Instance->CFGR;
elmot 1:d0dfbce63a89 218
elmot 1:d0dfbce63a89 219 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
elmot 1:d0dfbce63a89 220 {
elmot 1:d0dfbce63a89 221 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKPOL | LPTIM_CFGR_CKFLT));
elmot 1:d0dfbce63a89 222 }
elmot 1:d0dfbce63a89 223 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 224 {
elmot 1:d0dfbce63a89 225 tmpcfgr &= (uint32_t)(~ (LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGSEL));
elmot 1:d0dfbce63a89 226 }
elmot 1:d0dfbce63a89 227
elmot 1:d0dfbce63a89 228 /* Clear CKSEL, PRESC, TRIGEN, TRGFLT, WAVPOL, PRELOAD & COUNTMODE bits */
elmot 1:d0dfbce63a89 229 tmpcfgr &= (uint32_t)(~(LPTIM_CFGR_CKSEL | LPTIM_CFGR_TRIGEN | LPTIM_CFGR_PRELOAD |
elmot 1:d0dfbce63a89 230 LPTIM_CFGR_WAVPOL | LPTIM_CFGR_PRESC | LPTIM_CFGR_COUNTMODE ));
elmot 1:d0dfbce63a89 231
elmot 1:d0dfbce63a89 232 /* Set initialization parameters */
elmot 1:d0dfbce63a89 233 tmpcfgr |= (hlptim->Init.Clock.Source |
elmot 1:d0dfbce63a89 234 hlptim->Init.Clock.Prescaler |
elmot 1:d0dfbce63a89 235 hlptim->Init.OutputPolarity |
elmot 1:d0dfbce63a89 236 hlptim->Init.UpdateMode |
elmot 1:d0dfbce63a89 237 hlptim->Init.CounterSource);
elmot 1:d0dfbce63a89 238
elmot 1:d0dfbce63a89 239 if ((hlptim->Init.Clock.Source) == LPTIM_CLOCKSOURCE_ULPTIM)
elmot 1:d0dfbce63a89 240 {
elmot 1:d0dfbce63a89 241 tmpcfgr |= (hlptim->Init.UltraLowPowerClock.Polarity |
elmot 1:d0dfbce63a89 242 hlptim->Init.UltraLowPowerClock.SampleTime);
elmot 1:d0dfbce63a89 243 }
elmot 1:d0dfbce63a89 244
elmot 1:d0dfbce63a89 245 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 246 {
elmot 1:d0dfbce63a89 247 /* Enable External trigger and set the trigger source */
elmot 1:d0dfbce63a89 248 tmpcfgr |= (hlptim->Init.Trigger.Source |
elmot 1:d0dfbce63a89 249 hlptim->Init.Trigger.ActiveEdge |
elmot 1:d0dfbce63a89 250 hlptim->Init.Trigger.SampleTime);
elmot 1:d0dfbce63a89 251 }
elmot 1:d0dfbce63a89 252
elmot 1:d0dfbce63a89 253 /* Write to LPTIMx CFGR */
elmot 1:d0dfbce63a89 254 hlptim->Instance->CFGR = tmpcfgr;
elmot 1:d0dfbce63a89 255
elmot 1:d0dfbce63a89 256 /* Configure LPTIM input sources */
elmot 1:d0dfbce63a89 257 if(hlptim->Instance == LPTIM1)
elmot 1:d0dfbce63a89 258 {
elmot 1:d0dfbce63a89 259 /* Check LPTIM1 Input1 and Input2 sources */
elmot 1:d0dfbce63a89 260 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
elmot 1:d0dfbce63a89 261 assert_param(IS_LPTIM_INPUT2_SOURCE(hlptim->Instance,hlptim->Init.Input2Source));
elmot 1:d0dfbce63a89 262
elmot 1:d0dfbce63a89 263 /* Configure LPTIM1 Input1 and Input2 sources */
elmot 1:d0dfbce63a89 264 hlptim->Instance->OR = (hlptim->Init.Input1Source | hlptim->Init.Input2Source);
elmot 1:d0dfbce63a89 265 }
elmot 1:d0dfbce63a89 266 else
elmot 1:d0dfbce63a89 267 {
elmot 1:d0dfbce63a89 268 /* Check LPTIM2 Input1 source */
elmot 1:d0dfbce63a89 269 assert_param(IS_LPTIM_INPUT1_SOURCE(hlptim->Instance,hlptim->Init.Input1Source));
elmot 1:d0dfbce63a89 270
elmot 1:d0dfbce63a89 271 /* Configure LPTIM2 Input1 source */
elmot 1:d0dfbce63a89 272 hlptim->Instance->OR = hlptim->Init.Input1Source;
elmot 1:d0dfbce63a89 273 }
elmot 1:d0dfbce63a89 274
elmot 1:d0dfbce63a89 275 /* Change the LPTIM state */
elmot 1:d0dfbce63a89 276 hlptim->State = HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 277
elmot 1:d0dfbce63a89 278 /* Return function status */
elmot 1:d0dfbce63a89 279 return HAL_OK;
elmot 1:d0dfbce63a89 280 }
elmot 1:d0dfbce63a89 281
elmot 1:d0dfbce63a89 282 /**
elmot 1:d0dfbce63a89 283 * @brief DeInitialize the LPTIM peripheral.
elmot 1:d0dfbce63a89 284 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 285 * @retval HAL status
elmot 1:d0dfbce63a89 286 */
elmot 1:d0dfbce63a89 287 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 288 {
elmot 1:d0dfbce63a89 289 /* Check the LPTIM handle allocation */
elmot 1:d0dfbce63a89 290 if(hlptim == NULL)
elmot 1:d0dfbce63a89 291 {
elmot 1:d0dfbce63a89 292 return HAL_ERROR;
elmot 1:d0dfbce63a89 293 }
elmot 1:d0dfbce63a89 294
elmot 1:d0dfbce63a89 295 /* Change the LPTIM state */
elmot 1:d0dfbce63a89 296 hlptim->State = HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 297
elmot 1:d0dfbce63a89 298 /* Disable the LPTIM Peripheral Clock */
elmot 1:d0dfbce63a89 299 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 300
elmot 1:d0dfbce63a89 301 /* DeInit the low level hardware: CLOCK, NVIC.*/
elmot 1:d0dfbce63a89 302 HAL_LPTIM_MspDeInit(hlptim);
elmot 1:d0dfbce63a89 303
elmot 1:d0dfbce63a89 304 /* Change the LPTIM state */
elmot 1:d0dfbce63a89 305 hlptim->State = HAL_LPTIM_STATE_RESET;
elmot 1:d0dfbce63a89 306
elmot 1:d0dfbce63a89 307 /* Release Lock */
elmot 1:d0dfbce63a89 308 __HAL_UNLOCK(hlptim);
elmot 1:d0dfbce63a89 309
elmot 1:d0dfbce63a89 310 /* Return function status */
elmot 1:d0dfbce63a89 311 return HAL_OK;
elmot 1:d0dfbce63a89 312 }
elmot 1:d0dfbce63a89 313
elmot 1:d0dfbce63a89 314 /**
elmot 1:d0dfbce63a89 315 * @brief Initialize the LPTIM MSP.
elmot 1:d0dfbce63a89 316 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 317 * @retval None
elmot 1:d0dfbce63a89 318 */
elmot 1:d0dfbce63a89 319 __weak void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 320 {
elmot 1:d0dfbce63a89 321 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 322 UNUSED(hlptim);
elmot 1:d0dfbce63a89 323
elmot 1:d0dfbce63a89 324 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 325 the HAL_LPTIM_MspInit could be implemented in the user file
elmot 1:d0dfbce63a89 326 */
elmot 1:d0dfbce63a89 327 }
elmot 1:d0dfbce63a89 328
elmot 1:d0dfbce63a89 329 /**
elmot 1:d0dfbce63a89 330 * @brief DeInitialize LPTIM MSP.
elmot 1:d0dfbce63a89 331 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 332 * @retval None
elmot 1:d0dfbce63a89 333 */
elmot 1:d0dfbce63a89 334 __weak void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 335 {
elmot 1:d0dfbce63a89 336 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 337 UNUSED(hlptim);
elmot 1:d0dfbce63a89 338
elmot 1:d0dfbce63a89 339 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 340 the HAL_LPTIM_MspDeInit could be implemented in the user file
elmot 1:d0dfbce63a89 341 */
elmot 1:d0dfbce63a89 342 }
elmot 1:d0dfbce63a89 343
elmot 1:d0dfbce63a89 344 /**
elmot 1:d0dfbce63a89 345 * @}
elmot 1:d0dfbce63a89 346 */
elmot 1:d0dfbce63a89 347
elmot 1:d0dfbce63a89 348 /** @defgroup LPTIM_Exported_Functions_Group2 LPTIM Start-Stop operation functions
elmot 1:d0dfbce63a89 349 * @brief Start-Stop operation functions.
elmot 1:d0dfbce63a89 350 *
elmot 1:d0dfbce63a89 351 @verbatim
elmot 1:d0dfbce63a89 352 ==============================================================================
elmot 1:d0dfbce63a89 353 ##### LPTIM Start Stop operation functions #####
elmot 1:d0dfbce63a89 354 ==============================================================================
elmot 1:d0dfbce63a89 355 [..] This section provides functions allowing to:
elmot 1:d0dfbce63a89 356 (+) Start the PWM mode.
elmot 1:d0dfbce63a89 357 (+) Stop the PWM mode.
elmot 1:d0dfbce63a89 358 (+) Start the One pulse mode.
elmot 1:d0dfbce63a89 359 (+) Stop the One pulse mode.
elmot 1:d0dfbce63a89 360 (+) Start the Set once mode.
elmot 1:d0dfbce63a89 361 (+) Stop the Set once mode.
elmot 1:d0dfbce63a89 362 (+) Start the Encoder mode.
elmot 1:d0dfbce63a89 363 (+) Stop the Encoder mode.
elmot 1:d0dfbce63a89 364 (+) Start the Timeout mode.
elmot 1:d0dfbce63a89 365 (+) Stop the Timeout mode.
elmot 1:d0dfbce63a89 366 (+) Start the Counter mode.
elmot 1:d0dfbce63a89 367 (+) Stop the Counter mode.
elmot 1:d0dfbce63a89 368
elmot 1:d0dfbce63a89 369
elmot 1:d0dfbce63a89 370 @endverbatim
elmot 1:d0dfbce63a89 371 * @{
elmot 1:d0dfbce63a89 372 */
elmot 1:d0dfbce63a89 373
elmot 1:d0dfbce63a89 374 /**
elmot 1:d0dfbce63a89 375 * @brief Start the LPTIM PWM generation.
elmot 1:d0dfbce63a89 376 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 377 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 378 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 379 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 380 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 381 * @retval HAL status
elmot 1:d0dfbce63a89 382 */
elmot 1:d0dfbce63a89 383 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 384 {
elmot 1:d0dfbce63a89 385 /* Check the parameters */
elmot 1:d0dfbce63a89 386 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 387 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 388 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 389
elmot 1:d0dfbce63a89 390 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 391 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 392
elmot 1:d0dfbce63a89 393 /* Reset WAVE bit to set PWM mode */
elmot 1:d0dfbce63a89 394 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 395
elmot 1:d0dfbce63a89 396 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 397 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 398
elmot 1:d0dfbce63a89 399 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 400 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 401
elmot 1:d0dfbce63a89 402 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 403 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 404
elmot 1:d0dfbce63a89 405 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 406 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 407
elmot 1:d0dfbce63a89 408 /* Change the TIM state*/
elmot 1:d0dfbce63a89 409 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 410
elmot 1:d0dfbce63a89 411 /* Return function status */
elmot 1:d0dfbce63a89 412 return HAL_OK;
elmot 1:d0dfbce63a89 413 }
elmot 1:d0dfbce63a89 414
elmot 1:d0dfbce63a89 415 /**
elmot 1:d0dfbce63a89 416 * @brief Stop the LPTIM PWM generation.
elmot 1:d0dfbce63a89 417 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 418 * @retval HAL status
elmot 1:d0dfbce63a89 419 */
elmot 1:d0dfbce63a89 420 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 421 {
elmot 1:d0dfbce63a89 422 /* Check the parameters */
elmot 1:d0dfbce63a89 423 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 424
elmot 1:d0dfbce63a89 425 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 426 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 427
elmot 1:d0dfbce63a89 428 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 429 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 430
elmot 1:d0dfbce63a89 431 /* Change the TIM state*/
elmot 1:d0dfbce63a89 432 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 433
elmot 1:d0dfbce63a89 434 /* Return function status */
elmot 1:d0dfbce63a89 435 return HAL_OK;
elmot 1:d0dfbce63a89 436 }
elmot 1:d0dfbce63a89 437
elmot 1:d0dfbce63a89 438 /**
elmot 1:d0dfbce63a89 439 * @brief Start the LPTIM PWM generation in interrupt mode.
elmot 1:d0dfbce63a89 440 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 441 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 442 * This parameter must be a value between 0x0000 and 0xFFFF
elmot 1:d0dfbce63a89 443 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 444 * This parameter must be a value between 0x0000 and 0xFFFF
elmot 1:d0dfbce63a89 445 * @retval HAL status
elmot 1:d0dfbce63a89 446 */
elmot 1:d0dfbce63a89 447 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 448 {
elmot 1:d0dfbce63a89 449 /* Check the parameters */
elmot 1:d0dfbce63a89 450 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 451 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 452 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 453
elmot 1:d0dfbce63a89 454 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 455 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 456
elmot 1:d0dfbce63a89 457 /* Reset WAVE bit to set PWM mode */
elmot 1:d0dfbce63a89 458 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 459
elmot 1:d0dfbce63a89 460 /* Enable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 461 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 462
elmot 1:d0dfbce63a89 463 /* Enable Compare write complete interrupt */
elmot 1:d0dfbce63a89 464 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 465
elmot 1:d0dfbce63a89 466 /* Enable Autoreload match interrupt */
elmot 1:d0dfbce63a89 467 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 468
elmot 1:d0dfbce63a89 469 /* Enable Compare match interrupt */
elmot 1:d0dfbce63a89 470 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 471
elmot 1:d0dfbce63a89 472 /* If external trigger source is used, then enable external trigger interrupt */
elmot 1:d0dfbce63a89 473 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 474 {
elmot 1:d0dfbce63a89 475 /* Enable external trigger interrupt */
elmot 1:d0dfbce63a89 476 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 477 }
elmot 1:d0dfbce63a89 478
elmot 1:d0dfbce63a89 479 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 480 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 481
elmot 1:d0dfbce63a89 482 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 483 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 484
elmot 1:d0dfbce63a89 485 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 486 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 487
elmot 1:d0dfbce63a89 488 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 489 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 490
elmot 1:d0dfbce63a89 491 /* Change the TIM state*/
elmot 1:d0dfbce63a89 492 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 493
elmot 1:d0dfbce63a89 494 /* Return function status */
elmot 1:d0dfbce63a89 495 return HAL_OK;
elmot 1:d0dfbce63a89 496 }
elmot 1:d0dfbce63a89 497
elmot 1:d0dfbce63a89 498 /**
elmot 1:d0dfbce63a89 499 * @brief Stop the LPTIM PWM generation in interrupt mode.
elmot 1:d0dfbce63a89 500 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 501 * @retval HAL status
elmot 1:d0dfbce63a89 502 */
elmot 1:d0dfbce63a89 503 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 504 {
elmot 1:d0dfbce63a89 505 /* Check the parameters */
elmot 1:d0dfbce63a89 506 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 507
elmot 1:d0dfbce63a89 508 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 509 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 510
elmot 1:d0dfbce63a89 511 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 512 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 513
elmot 1:d0dfbce63a89 514 /* Disable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 515 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 516
elmot 1:d0dfbce63a89 517 /* Disable Compare write complete interrupt */
elmot 1:d0dfbce63a89 518 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 519
elmot 1:d0dfbce63a89 520 /* Disable Autoreload match interrupt */
elmot 1:d0dfbce63a89 521 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 522
elmot 1:d0dfbce63a89 523 /* Disable Compare match interrupt */
elmot 1:d0dfbce63a89 524 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 525
elmot 1:d0dfbce63a89 526 /* If external trigger source is used, then disable external trigger interrupt */
elmot 1:d0dfbce63a89 527 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 528 {
elmot 1:d0dfbce63a89 529 /* Disable external trigger interrupt */
elmot 1:d0dfbce63a89 530 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 531 }
elmot 1:d0dfbce63a89 532
elmot 1:d0dfbce63a89 533 /* Change the TIM state*/
elmot 1:d0dfbce63a89 534 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 535
elmot 1:d0dfbce63a89 536 /* Return function status */
elmot 1:d0dfbce63a89 537 return HAL_OK;
elmot 1:d0dfbce63a89 538 }
elmot 1:d0dfbce63a89 539
elmot 1:d0dfbce63a89 540 /**
elmot 1:d0dfbce63a89 541 * @brief Start the LPTIM One pulse generation.
elmot 1:d0dfbce63a89 542 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 543 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 544 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 545 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 546 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 547 * @retval HAL status
elmot 1:d0dfbce63a89 548 */
elmot 1:d0dfbce63a89 549 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 550 {
elmot 1:d0dfbce63a89 551 /* Check the parameters */
elmot 1:d0dfbce63a89 552 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 553 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 554 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 555
elmot 1:d0dfbce63a89 556 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 557 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 558
elmot 1:d0dfbce63a89 559 /* Reset WAVE bit to set one pulse mode */
elmot 1:d0dfbce63a89 560 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 561
elmot 1:d0dfbce63a89 562 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 563 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 564
elmot 1:d0dfbce63a89 565 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 566 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 567
elmot 1:d0dfbce63a89 568 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 569 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 570
elmot 1:d0dfbce63a89 571 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 572 __HAL_LPTIM_START_SINGLE(hlptim);
elmot 1:d0dfbce63a89 573
elmot 1:d0dfbce63a89 574 /* Change the TIM state*/
elmot 1:d0dfbce63a89 575 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 576
elmot 1:d0dfbce63a89 577 /* Return function status */
elmot 1:d0dfbce63a89 578 return HAL_OK;
elmot 1:d0dfbce63a89 579 }
elmot 1:d0dfbce63a89 580
elmot 1:d0dfbce63a89 581 /**
elmot 1:d0dfbce63a89 582 * @brief Stop the LPTIM One pulse generation.
elmot 1:d0dfbce63a89 583 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 584 * @retval HAL status
elmot 1:d0dfbce63a89 585 */
elmot 1:d0dfbce63a89 586 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 587 {
elmot 1:d0dfbce63a89 588 /* Check the parameters */
elmot 1:d0dfbce63a89 589 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 590
elmot 1:d0dfbce63a89 591 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 592 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 593
elmot 1:d0dfbce63a89 594 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 595 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 596
elmot 1:d0dfbce63a89 597 /* Change the TIM state*/
elmot 1:d0dfbce63a89 598 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 599
elmot 1:d0dfbce63a89 600 /* Return function status */
elmot 1:d0dfbce63a89 601 return HAL_OK;
elmot 1:d0dfbce63a89 602 }
elmot 1:d0dfbce63a89 603
elmot 1:d0dfbce63a89 604 /**
elmot 1:d0dfbce63a89 605 * @brief Start the LPTIM One pulse generation in interrupt mode.
elmot 1:d0dfbce63a89 606 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 607 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 608 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 609 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 610 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 611 * @retval HAL status
elmot 1:d0dfbce63a89 612 */
elmot 1:d0dfbce63a89 613 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 614 {
elmot 1:d0dfbce63a89 615 /* Check the parameters */
elmot 1:d0dfbce63a89 616 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 617 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 618 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 619
elmot 1:d0dfbce63a89 620 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 621 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 622
elmot 1:d0dfbce63a89 623 /* Reset WAVE bit to set one pulse mode */
elmot 1:d0dfbce63a89 624 hlptim->Instance->CFGR &= ~LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 625
elmot 1:d0dfbce63a89 626 /* Enable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 627 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 628
elmot 1:d0dfbce63a89 629 /* Enable Compare write complete interrupt */
elmot 1:d0dfbce63a89 630 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 631
elmot 1:d0dfbce63a89 632 /* Enable Autoreload match interrupt */
elmot 1:d0dfbce63a89 633 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 634
elmot 1:d0dfbce63a89 635 /* Enable Compare match interrupt */
elmot 1:d0dfbce63a89 636 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 637
elmot 1:d0dfbce63a89 638 /* If external trigger source is used, then enable external trigger interrupt */
elmot 1:d0dfbce63a89 639 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 640 {
elmot 1:d0dfbce63a89 641 /* Enable external trigger interrupt */
elmot 1:d0dfbce63a89 642 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 643 }
elmot 1:d0dfbce63a89 644
elmot 1:d0dfbce63a89 645 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 646 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 647
elmot 1:d0dfbce63a89 648 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 649 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 650
elmot 1:d0dfbce63a89 651 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 652 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 653
elmot 1:d0dfbce63a89 654 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 655 __HAL_LPTIM_START_SINGLE(hlptim);
elmot 1:d0dfbce63a89 656
elmot 1:d0dfbce63a89 657 /* Change the TIM state*/
elmot 1:d0dfbce63a89 658 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 659
elmot 1:d0dfbce63a89 660 /* Return function status */
elmot 1:d0dfbce63a89 661 return HAL_OK;
elmot 1:d0dfbce63a89 662 }
elmot 1:d0dfbce63a89 663
elmot 1:d0dfbce63a89 664 /**
elmot 1:d0dfbce63a89 665 * @brief Stop the LPTIM One pulse generation in interrupt mode.
elmot 1:d0dfbce63a89 666 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 667 * @retval HAL status
elmot 1:d0dfbce63a89 668 */
elmot 1:d0dfbce63a89 669 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 670 {
elmot 1:d0dfbce63a89 671 /* Check the parameters */
elmot 1:d0dfbce63a89 672 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 673
elmot 1:d0dfbce63a89 674 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 675 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 676
elmot 1:d0dfbce63a89 677 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 678 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 679
elmot 1:d0dfbce63a89 680 /* Disable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 681 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 682
elmot 1:d0dfbce63a89 683 /* Disable Compare write complete interrupt */
elmot 1:d0dfbce63a89 684 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 685
elmot 1:d0dfbce63a89 686 /* Disable Autoreload match interrupt */
elmot 1:d0dfbce63a89 687 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 688
elmot 1:d0dfbce63a89 689 /* Disable Compare match interrupt */
elmot 1:d0dfbce63a89 690 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 691
elmot 1:d0dfbce63a89 692 /* If external trigger source is used, then disable external trigger interrupt */
elmot 1:d0dfbce63a89 693 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 694 {
elmot 1:d0dfbce63a89 695 /* Disable external trigger interrupt */
elmot 1:d0dfbce63a89 696 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 697 }
elmot 1:d0dfbce63a89 698
elmot 1:d0dfbce63a89 699 /* Change the TIM state*/
elmot 1:d0dfbce63a89 700 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 701
elmot 1:d0dfbce63a89 702 /* Return function status */
elmot 1:d0dfbce63a89 703 return HAL_OK;
elmot 1:d0dfbce63a89 704 }
elmot 1:d0dfbce63a89 705
elmot 1:d0dfbce63a89 706 /**
elmot 1:d0dfbce63a89 707 * @brief Start the LPTIM in Set once mode.
elmot 1:d0dfbce63a89 708 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 709 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 710 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 711 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 712 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 713 * @retval HAL status
elmot 1:d0dfbce63a89 714 */
elmot 1:d0dfbce63a89 715 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 716 {
elmot 1:d0dfbce63a89 717 /* Check the parameters */
elmot 1:d0dfbce63a89 718 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 719 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 720 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 721
elmot 1:d0dfbce63a89 722 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 723 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 724
elmot 1:d0dfbce63a89 725 /* Set WAVE bit to enable the set once mode */
elmot 1:d0dfbce63a89 726 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 727
elmot 1:d0dfbce63a89 728 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 729 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 730
elmot 1:d0dfbce63a89 731 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 732 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 733
elmot 1:d0dfbce63a89 734 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 735 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 736
elmot 1:d0dfbce63a89 737 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 738 __HAL_LPTIM_START_SINGLE(hlptim);
elmot 1:d0dfbce63a89 739
elmot 1:d0dfbce63a89 740 /* Change the TIM state*/
elmot 1:d0dfbce63a89 741 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 742
elmot 1:d0dfbce63a89 743 /* Return function status */
elmot 1:d0dfbce63a89 744 return HAL_OK;
elmot 1:d0dfbce63a89 745 }
elmot 1:d0dfbce63a89 746
elmot 1:d0dfbce63a89 747 /**
elmot 1:d0dfbce63a89 748 * @brief Stop the LPTIM Set once mode.
elmot 1:d0dfbce63a89 749 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 750 * @retval HAL status
elmot 1:d0dfbce63a89 751 */
elmot 1:d0dfbce63a89 752 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 753 {
elmot 1:d0dfbce63a89 754 /* Check the parameters */
elmot 1:d0dfbce63a89 755 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 756
elmot 1:d0dfbce63a89 757 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 758 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 759
elmot 1:d0dfbce63a89 760 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 761 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 762
elmot 1:d0dfbce63a89 763 /* Change the TIM state*/
elmot 1:d0dfbce63a89 764 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 765
elmot 1:d0dfbce63a89 766 /* Return function status */
elmot 1:d0dfbce63a89 767 return HAL_OK;
elmot 1:d0dfbce63a89 768 }
elmot 1:d0dfbce63a89 769
elmot 1:d0dfbce63a89 770 /**
elmot 1:d0dfbce63a89 771 * @brief Start the LPTIM Set once mode in interrupt mode.
elmot 1:d0dfbce63a89 772 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 773 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 774 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 775 * @param Pulse : Specifies the compare value.
elmot 1:d0dfbce63a89 776 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 777 * @retval HAL status
elmot 1:d0dfbce63a89 778 */
elmot 1:d0dfbce63a89 779 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse)
elmot 1:d0dfbce63a89 780 {
elmot 1:d0dfbce63a89 781 /* Check the parameters */
elmot 1:d0dfbce63a89 782 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 783 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 784 assert_param(IS_LPTIM_PULSE(Pulse));
elmot 1:d0dfbce63a89 785
elmot 1:d0dfbce63a89 786 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 787 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 788
elmot 1:d0dfbce63a89 789 /* Set WAVE bit to enable the set once mode */
elmot 1:d0dfbce63a89 790 hlptim->Instance->CFGR |= LPTIM_CFGR_WAVE;
elmot 1:d0dfbce63a89 791
elmot 1:d0dfbce63a89 792 /* Enable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 793 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 794
elmot 1:d0dfbce63a89 795 /* Enable Compare write complete interrupt */
elmot 1:d0dfbce63a89 796 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 797
elmot 1:d0dfbce63a89 798 /* Enable Autoreload match interrupt */
elmot 1:d0dfbce63a89 799 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 800
elmot 1:d0dfbce63a89 801 /* Enable Compare match interrupt */
elmot 1:d0dfbce63a89 802 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 803
elmot 1:d0dfbce63a89 804 /* If external trigger source is used, then enable external trigger interrupt */
elmot 1:d0dfbce63a89 805 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 806 {
elmot 1:d0dfbce63a89 807 /* Enable external trigger interrupt */
elmot 1:d0dfbce63a89 808 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 809 }
elmot 1:d0dfbce63a89 810
elmot 1:d0dfbce63a89 811 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 812 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 813
elmot 1:d0dfbce63a89 814 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 815 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 816
elmot 1:d0dfbce63a89 817 /* Load the pulse value in the compare register */
elmot 1:d0dfbce63a89 818 __HAL_LPTIM_COMPARE_SET(hlptim, Pulse);
elmot 1:d0dfbce63a89 819
elmot 1:d0dfbce63a89 820 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 821 __HAL_LPTIM_START_SINGLE(hlptim);
elmot 1:d0dfbce63a89 822
elmot 1:d0dfbce63a89 823 /* Change the TIM state*/
elmot 1:d0dfbce63a89 824 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 825
elmot 1:d0dfbce63a89 826 /* Return function status */
elmot 1:d0dfbce63a89 827 return HAL_OK;
elmot 1:d0dfbce63a89 828 }
elmot 1:d0dfbce63a89 829
elmot 1:d0dfbce63a89 830 /**
elmot 1:d0dfbce63a89 831 * @brief Stop the LPTIM Set once mode in interrupt mode.
elmot 1:d0dfbce63a89 832 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 833 * @retval HAL status
elmot 1:d0dfbce63a89 834 */
elmot 1:d0dfbce63a89 835 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 836 {
elmot 1:d0dfbce63a89 837 /* Check the parameters */
elmot 1:d0dfbce63a89 838 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 839
elmot 1:d0dfbce63a89 840 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 841 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 842
elmot 1:d0dfbce63a89 843 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 844 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 845
elmot 1:d0dfbce63a89 846 /* Disable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 847 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 848
elmot 1:d0dfbce63a89 849 /* Disable Compare write complete interrupt */
elmot 1:d0dfbce63a89 850 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPOK);
elmot 1:d0dfbce63a89 851
elmot 1:d0dfbce63a89 852 /* Disable Autoreload match interrupt */
elmot 1:d0dfbce63a89 853 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 854
elmot 1:d0dfbce63a89 855 /* Disable Compare match interrupt */
elmot 1:d0dfbce63a89 856 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 857
elmot 1:d0dfbce63a89 858 /* If external trigger source is used, then disable external trigger interrupt */
elmot 1:d0dfbce63a89 859 if ((hlptim->Init.Trigger.Source) != LPTIM_TRIGSOURCE_SOFTWARE)
elmot 1:d0dfbce63a89 860 {
elmot 1:d0dfbce63a89 861 /* Disable external trigger interrupt */
elmot 1:d0dfbce63a89 862 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_EXTTRIG);
elmot 1:d0dfbce63a89 863 }
elmot 1:d0dfbce63a89 864
elmot 1:d0dfbce63a89 865 /* Change the TIM state*/
elmot 1:d0dfbce63a89 866 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 867
elmot 1:d0dfbce63a89 868 /* Return function status */
elmot 1:d0dfbce63a89 869 return HAL_OK;
elmot 1:d0dfbce63a89 870 }
elmot 1:d0dfbce63a89 871
elmot 1:d0dfbce63a89 872 /**
elmot 1:d0dfbce63a89 873 * @brief Start the Encoder interface.
elmot 1:d0dfbce63a89 874 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 875 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 876 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 877 * @retval HAL status
elmot 1:d0dfbce63a89 878 */
elmot 1:d0dfbce63a89 879 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
elmot 1:d0dfbce63a89 880 {
elmot 1:d0dfbce63a89 881 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 882 uint32_t tmpcfgr;
elmot 1:d0dfbce63a89 883
elmot 1:d0dfbce63a89 884 /* Check the parameters */
elmot 1:d0dfbce63a89 885 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 886 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 887 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
elmot 1:d0dfbce63a89 888 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
elmot 1:d0dfbce63a89 889 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
elmot 1:d0dfbce63a89 890
elmot 1:d0dfbce63a89 891 /* Encoder feature is only available for LPTIM1 instance */
elmot 1:d0dfbce63a89 892 if (hlptim->Instance == LPTIM1)
elmot 1:d0dfbce63a89 893 {
elmot 1:d0dfbce63a89 894 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 895 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 896
elmot 1:d0dfbce63a89 897 /* Get the LPTIMx CFGR value */
elmot 1:d0dfbce63a89 898 tmpcfgr = hlptim->Instance->CFGR;
elmot 1:d0dfbce63a89 899
elmot 1:d0dfbce63a89 900 /* Clear CKPOL bits */
elmot 1:d0dfbce63a89 901 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
elmot 1:d0dfbce63a89 902
elmot 1:d0dfbce63a89 903 /* Set Input polarity */
elmot 1:d0dfbce63a89 904 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
elmot 1:d0dfbce63a89 905
elmot 1:d0dfbce63a89 906 /* Write to LPTIMx CFGR */
elmot 1:d0dfbce63a89 907 hlptim->Instance->CFGR = tmpcfgr;
elmot 1:d0dfbce63a89 908
elmot 1:d0dfbce63a89 909 /* Set ENC bit to enable the encoder interface */
elmot 1:d0dfbce63a89 910 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
elmot 1:d0dfbce63a89 911
elmot 1:d0dfbce63a89 912 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 913 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 914
elmot 1:d0dfbce63a89 915 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 916 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 917
elmot 1:d0dfbce63a89 918 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 919 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 920
elmot 1:d0dfbce63a89 921 /* Change the TIM state*/
elmot 1:d0dfbce63a89 922 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 923 }
elmot 1:d0dfbce63a89 924 else
elmot 1:d0dfbce63a89 925 {
elmot 1:d0dfbce63a89 926 status = HAL_ERROR;
elmot 1:d0dfbce63a89 927 }
elmot 1:d0dfbce63a89 928
elmot 1:d0dfbce63a89 929 /* Return function status */
elmot 1:d0dfbce63a89 930 return status;
elmot 1:d0dfbce63a89 931 }
elmot 1:d0dfbce63a89 932
elmot 1:d0dfbce63a89 933 /**
elmot 1:d0dfbce63a89 934 * @brief Stop the Encoder interface.
elmot 1:d0dfbce63a89 935 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 936 * @retval HAL status
elmot 1:d0dfbce63a89 937 */
elmot 1:d0dfbce63a89 938 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 939 {
elmot 1:d0dfbce63a89 940 /* Check the parameters */
elmot 1:d0dfbce63a89 941 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 942
elmot 1:d0dfbce63a89 943 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 944 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 945
elmot 1:d0dfbce63a89 946 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 947 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 948
elmot 1:d0dfbce63a89 949 /* Reset ENC bit to disable the encoder interface */
elmot 1:d0dfbce63a89 950 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
elmot 1:d0dfbce63a89 951
elmot 1:d0dfbce63a89 952 /* Change the TIM state*/
elmot 1:d0dfbce63a89 953 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 954
elmot 1:d0dfbce63a89 955 /* Return function status */
elmot 1:d0dfbce63a89 956 return HAL_OK;
elmot 1:d0dfbce63a89 957 }
elmot 1:d0dfbce63a89 958
elmot 1:d0dfbce63a89 959 /**
elmot 1:d0dfbce63a89 960 * @brief Start the Encoder interface in interrupt mode.
elmot 1:d0dfbce63a89 961 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 962 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 963 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 964 * @retval HAL status
elmot 1:d0dfbce63a89 965 */
elmot 1:d0dfbce63a89 966 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
elmot 1:d0dfbce63a89 967 {
elmot 1:d0dfbce63a89 968 HAL_StatusTypeDef status = HAL_OK;
elmot 1:d0dfbce63a89 969 uint32_t tmpcfgr;
elmot 1:d0dfbce63a89 970
elmot 1:d0dfbce63a89 971 /* Check the parameters */
elmot 1:d0dfbce63a89 972 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 973 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 974 assert_param(hlptim->Init.Clock.Source == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC);
elmot 1:d0dfbce63a89 975 assert_param(hlptim->Init.Clock.Prescaler == LPTIM_PRESCALER_DIV1);
elmot 1:d0dfbce63a89 976 assert_param(IS_LPTIM_CLOCK_POLARITY(hlptim->Init.UltraLowPowerClock.Polarity));
elmot 1:d0dfbce63a89 977
elmot 1:d0dfbce63a89 978 /* Encoder feature is only available for LPTIM1 instance */
elmot 1:d0dfbce63a89 979 if (hlptim->Instance == LPTIM1)
elmot 1:d0dfbce63a89 980 {
elmot 1:d0dfbce63a89 981 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 982 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 983
elmot 1:d0dfbce63a89 984 /* Configure edge sensitivity for encoder mode */
elmot 1:d0dfbce63a89 985 /* Get the LPTIMx CFGR value */
elmot 1:d0dfbce63a89 986 tmpcfgr = hlptim->Instance->CFGR;
elmot 1:d0dfbce63a89 987
elmot 1:d0dfbce63a89 988 /* Clear CKPOL bits */
elmot 1:d0dfbce63a89 989 tmpcfgr &= (uint32_t)(~LPTIM_CFGR_CKPOL);
elmot 1:d0dfbce63a89 990
elmot 1:d0dfbce63a89 991 /* Set Input polarity */
elmot 1:d0dfbce63a89 992 tmpcfgr |= hlptim->Init.UltraLowPowerClock.Polarity;
elmot 1:d0dfbce63a89 993
elmot 1:d0dfbce63a89 994 /* Write to LPTIMx CFGR */
elmot 1:d0dfbce63a89 995 hlptim->Instance->CFGR = tmpcfgr;
elmot 1:d0dfbce63a89 996
elmot 1:d0dfbce63a89 997 /* Set ENC bit to enable the encoder interface */
elmot 1:d0dfbce63a89 998 hlptim->Instance->CFGR |= LPTIM_CFGR_ENC;
elmot 1:d0dfbce63a89 999
elmot 1:d0dfbce63a89 1000 /* Enable "switch to down direction" interrupt */
elmot 1:d0dfbce63a89 1001 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_DOWN);
elmot 1:d0dfbce63a89 1002
elmot 1:d0dfbce63a89 1003 /* Enable "switch to up direction" interrupt */
elmot 1:d0dfbce63a89 1004 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_UP);
elmot 1:d0dfbce63a89 1005
elmot 1:d0dfbce63a89 1006 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 1007 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 1008
elmot 1:d0dfbce63a89 1009 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 1010 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 1011
elmot 1:d0dfbce63a89 1012 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 1013 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 1014
elmot 1:d0dfbce63a89 1015 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1016 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1017 }
elmot 1:d0dfbce63a89 1018 else
elmot 1:d0dfbce63a89 1019 {
elmot 1:d0dfbce63a89 1020 status = HAL_ERROR;
elmot 1:d0dfbce63a89 1021 }
elmot 1:d0dfbce63a89 1022
elmot 1:d0dfbce63a89 1023 /* Return function status */
elmot 1:d0dfbce63a89 1024 return status;
elmot 1:d0dfbce63a89 1025 }
elmot 1:d0dfbce63a89 1026
elmot 1:d0dfbce63a89 1027 /**
elmot 1:d0dfbce63a89 1028 * @brief Stop the Encoder interface in interrupt mode.
elmot 1:d0dfbce63a89 1029 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1030 * @retval HAL status
elmot 1:d0dfbce63a89 1031 */
elmot 1:d0dfbce63a89 1032 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1033 {
elmot 1:d0dfbce63a89 1034 /* Check the parameters */
elmot 1:d0dfbce63a89 1035 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1036
elmot 1:d0dfbce63a89 1037 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1038 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1039
elmot 1:d0dfbce63a89 1040 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 1041 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 1042
elmot 1:d0dfbce63a89 1043 /* Reset ENC bit to disable the encoder interface */
elmot 1:d0dfbce63a89 1044 hlptim->Instance->CFGR &= ~LPTIM_CFGR_ENC;
elmot 1:d0dfbce63a89 1045
elmot 1:d0dfbce63a89 1046 /* Disable "switch to down direction" interrupt */
elmot 1:d0dfbce63a89 1047 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_DOWN);
elmot 1:d0dfbce63a89 1048
elmot 1:d0dfbce63a89 1049 /* Disable "switch to up direction" interrupt */
elmot 1:d0dfbce63a89 1050 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_UP);
elmot 1:d0dfbce63a89 1051
elmot 1:d0dfbce63a89 1052 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1053 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1054
elmot 1:d0dfbce63a89 1055 /* Return function status */
elmot 1:d0dfbce63a89 1056 return HAL_OK;
elmot 1:d0dfbce63a89 1057 }
elmot 1:d0dfbce63a89 1058
elmot 1:d0dfbce63a89 1059 /**
elmot 1:d0dfbce63a89 1060 * @brief Start the Timeout function.
elmot 1:d0dfbce63a89 1061 * @note The first trigger event will start the timer, any successive
elmot 1:d0dfbce63a89 1062 * trigger event will reset the counter and the timer restarts.
elmot 1:d0dfbce63a89 1063 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1064 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 1065 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1066 * @param Timeout : Specifies the TimeOut value to rest the counter.
elmot 1:d0dfbce63a89 1067 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1068 * @retval HAL status
elmot 1:d0dfbce63a89 1069 */
elmot 1:d0dfbce63a89 1070 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
elmot 1:d0dfbce63a89 1071 {
elmot 1:d0dfbce63a89 1072 /* Check the parameters */
elmot 1:d0dfbce63a89 1073 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1074 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 1075 assert_param(IS_LPTIM_PULSE(Timeout));
elmot 1:d0dfbce63a89 1076
elmot 1:d0dfbce63a89 1077 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1078 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1079
elmot 1:d0dfbce63a89 1080 /* Set TIMOUT bit to enable the timeout function */
elmot 1:d0dfbce63a89 1081 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
elmot 1:d0dfbce63a89 1082
elmot 1:d0dfbce63a89 1083 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 1084 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 1085
elmot 1:d0dfbce63a89 1086 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 1087 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 1088
elmot 1:d0dfbce63a89 1089 /* Load the Timeout value in the compare register */
elmot 1:d0dfbce63a89 1090 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
elmot 1:d0dfbce63a89 1091
elmot 1:d0dfbce63a89 1092 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 1093 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 1094
elmot 1:d0dfbce63a89 1095 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1096 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1097
elmot 1:d0dfbce63a89 1098 /* Return function status */
elmot 1:d0dfbce63a89 1099 return HAL_OK;
elmot 1:d0dfbce63a89 1100 }
elmot 1:d0dfbce63a89 1101
elmot 1:d0dfbce63a89 1102 /**
elmot 1:d0dfbce63a89 1103 * @brief Stop the Timeout function.
elmot 1:d0dfbce63a89 1104 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1105 * @retval HAL status
elmot 1:d0dfbce63a89 1106 */
elmot 1:d0dfbce63a89 1107 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1108 {
elmot 1:d0dfbce63a89 1109 /* Check the parameters */
elmot 1:d0dfbce63a89 1110 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1111
elmot 1:d0dfbce63a89 1112 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1113 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1114
elmot 1:d0dfbce63a89 1115 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 1116 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 1117
elmot 1:d0dfbce63a89 1118 /* Reset TIMOUT bit to enable the timeout function */
elmot 1:d0dfbce63a89 1119 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
elmot 1:d0dfbce63a89 1120
elmot 1:d0dfbce63a89 1121 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1122 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1123
elmot 1:d0dfbce63a89 1124 /* Return function status */
elmot 1:d0dfbce63a89 1125 return HAL_OK;
elmot 1:d0dfbce63a89 1126 }
elmot 1:d0dfbce63a89 1127
elmot 1:d0dfbce63a89 1128 /**
elmot 1:d0dfbce63a89 1129 * @brief Start the Timeout function in interrupt mode.
elmot 1:d0dfbce63a89 1130 * @note The first trigger event will start the timer, any successive
elmot 1:d0dfbce63a89 1131 * trigger event will reset the counter and the timer restarts.
elmot 1:d0dfbce63a89 1132 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1133 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 1134 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1135 * @param Timeout : Specifies the TimeOut value to rest the counter.
elmot 1:d0dfbce63a89 1136 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1137 * @retval HAL status
elmot 1:d0dfbce63a89 1138 */
elmot 1:d0dfbce63a89 1139 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout)
elmot 1:d0dfbce63a89 1140 {
elmot 1:d0dfbce63a89 1141 /* Check the parameters */
elmot 1:d0dfbce63a89 1142 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1143 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 1144 assert_param(IS_LPTIM_PULSE(Timeout));
elmot 1:d0dfbce63a89 1145
elmot 1:d0dfbce63a89 1146 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1147 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1148
elmot 1:d0dfbce63a89 1149 /* Set TIMOUT bit to enable the timeout function */
elmot 1:d0dfbce63a89 1150 hlptim->Instance->CFGR |= LPTIM_CFGR_TIMOUT;
elmot 1:d0dfbce63a89 1151
elmot 1:d0dfbce63a89 1152 /* Enable Compare match interrupt */
elmot 1:d0dfbce63a89 1153 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 1154
elmot 1:d0dfbce63a89 1155 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 1156 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 1157
elmot 1:d0dfbce63a89 1158 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 1159 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 1160
elmot 1:d0dfbce63a89 1161 /* Load the Timeout value in the compare register */
elmot 1:d0dfbce63a89 1162 __HAL_LPTIM_COMPARE_SET(hlptim, Timeout);
elmot 1:d0dfbce63a89 1163
elmot 1:d0dfbce63a89 1164 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 1165 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 1166
elmot 1:d0dfbce63a89 1167 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1168 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1169
elmot 1:d0dfbce63a89 1170 /* Return function status */
elmot 1:d0dfbce63a89 1171 return HAL_OK;
elmot 1:d0dfbce63a89 1172 }
elmot 1:d0dfbce63a89 1173
elmot 1:d0dfbce63a89 1174 /**
elmot 1:d0dfbce63a89 1175 * @brief Stop the Timeout function in interrupt mode.
elmot 1:d0dfbce63a89 1176 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1177 * @retval HAL status
elmot 1:d0dfbce63a89 1178 */
elmot 1:d0dfbce63a89 1179 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1180 {
elmot 1:d0dfbce63a89 1181 /* Check the parameters */
elmot 1:d0dfbce63a89 1182 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1183
elmot 1:d0dfbce63a89 1184 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1185 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1186
elmot 1:d0dfbce63a89 1187 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 1188 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 1189
elmot 1:d0dfbce63a89 1190 /* Reset TIMOUT bit to enable the timeout function */
elmot 1:d0dfbce63a89 1191 hlptim->Instance->CFGR &= ~LPTIM_CFGR_TIMOUT;
elmot 1:d0dfbce63a89 1192
elmot 1:d0dfbce63a89 1193 /* Disable Compare match interrupt */
elmot 1:d0dfbce63a89 1194 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_CMPM);
elmot 1:d0dfbce63a89 1195
elmot 1:d0dfbce63a89 1196 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1197 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1198
elmot 1:d0dfbce63a89 1199 /* Return function status */
elmot 1:d0dfbce63a89 1200 return HAL_OK;
elmot 1:d0dfbce63a89 1201 }
elmot 1:d0dfbce63a89 1202
elmot 1:d0dfbce63a89 1203 /**
elmot 1:d0dfbce63a89 1204 * @brief Start the Counter mode.
elmot 1:d0dfbce63a89 1205 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1206 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 1207 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1208 * @retval HAL status
elmot 1:d0dfbce63a89 1209 */
elmot 1:d0dfbce63a89 1210 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
elmot 1:d0dfbce63a89 1211 {
elmot 1:d0dfbce63a89 1212 /* Check the parameters */
elmot 1:d0dfbce63a89 1213 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1214 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 1215
elmot 1:d0dfbce63a89 1216 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1217 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1218
elmot 1:d0dfbce63a89 1219 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
elmot 1:d0dfbce63a89 1220 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
elmot 1:d0dfbce63a89 1221 {
elmot 1:d0dfbce63a89 1222 /* Check if clock is prescaled */
elmot 1:d0dfbce63a89 1223 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
elmot 1:d0dfbce63a89 1224 /* Set clock prescaler to 0 */
elmot 1:d0dfbce63a89 1225 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
elmot 1:d0dfbce63a89 1226 }
elmot 1:d0dfbce63a89 1227
elmot 1:d0dfbce63a89 1228 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 1229 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 1230
elmot 1:d0dfbce63a89 1231 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 1232 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 1233
elmot 1:d0dfbce63a89 1234 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 1235 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 1236
elmot 1:d0dfbce63a89 1237 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1238 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1239
elmot 1:d0dfbce63a89 1240 /* Return function status */
elmot 1:d0dfbce63a89 1241 return HAL_OK;
elmot 1:d0dfbce63a89 1242 }
elmot 1:d0dfbce63a89 1243
elmot 1:d0dfbce63a89 1244 /**
elmot 1:d0dfbce63a89 1245 * @brief Stop the Counter mode.
elmot 1:d0dfbce63a89 1246 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1247 * @retval HAL status
elmot 1:d0dfbce63a89 1248 */
elmot 1:d0dfbce63a89 1249 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1250 {
elmot 1:d0dfbce63a89 1251 /* Check the parameters */
elmot 1:d0dfbce63a89 1252 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1253
elmot 1:d0dfbce63a89 1254 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1255 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1256
elmot 1:d0dfbce63a89 1257 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 1258 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 1259
elmot 1:d0dfbce63a89 1260 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1261 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1262
elmot 1:d0dfbce63a89 1263 /* Return function status */
elmot 1:d0dfbce63a89 1264 return HAL_OK;
elmot 1:d0dfbce63a89 1265 }
elmot 1:d0dfbce63a89 1266
elmot 1:d0dfbce63a89 1267 /**
elmot 1:d0dfbce63a89 1268 * @brief Start the Counter mode in interrupt mode.
elmot 1:d0dfbce63a89 1269 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1270 * @param Period : Specifies the Autoreload value.
elmot 1:d0dfbce63a89 1271 * This parameter must be a value between 0x0000 and 0xFFFF.
elmot 1:d0dfbce63a89 1272 * @retval HAL status
elmot 1:d0dfbce63a89 1273 */
elmot 1:d0dfbce63a89 1274 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period)
elmot 1:d0dfbce63a89 1275 {
elmot 1:d0dfbce63a89 1276 /* Check the parameters */
elmot 1:d0dfbce63a89 1277 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1278 assert_param(IS_LPTIM_PERIOD(Period));
elmot 1:d0dfbce63a89 1279
elmot 1:d0dfbce63a89 1280 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1281 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1282
elmot 1:d0dfbce63a89 1283 /* If clock source is not ULPTIM clock and counter source is external, then it must not be prescaled */
elmot 1:d0dfbce63a89 1284 if((hlptim->Init.Clock.Source != LPTIM_CLOCKSOURCE_ULPTIM) && (hlptim->Init.CounterSource == LPTIM_COUNTERSOURCE_EXTERNAL))
elmot 1:d0dfbce63a89 1285 {
elmot 1:d0dfbce63a89 1286 /* Check if clock is prescaled */
elmot 1:d0dfbce63a89 1287 assert_param(IS_LPTIM_CLOCK_PRESCALERDIV1(hlptim->Init.Clock.Prescaler));
elmot 1:d0dfbce63a89 1288 /* Set clock prescaler to 0 */
elmot 1:d0dfbce63a89 1289 hlptim->Instance->CFGR &= ~LPTIM_CFGR_PRESC;
elmot 1:d0dfbce63a89 1290 }
elmot 1:d0dfbce63a89 1291
elmot 1:d0dfbce63a89 1292 /* Enable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 1293 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 1294
elmot 1:d0dfbce63a89 1295 /* Enable Autoreload match interrupt */
elmot 1:d0dfbce63a89 1296 __HAL_LPTIM_ENABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 1297
elmot 1:d0dfbce63a89 1298 /* Enable the Peripheral */
elmot 1:d0dfbce63a89 1299 __HAL_LPTIM_ENABLE(hlptim);
elmot 1:d0dfbce63a89 1300
elmot 1:d0dfbce63a89 1301 /* Load the period value in the autoreload register */
elmot 1:d0dfbce63a89 1302 __HAL_LPTIM_AUTORELOAD_SET(hlptim, Period);
elmot 1:d0dfbce63a89 1303
elmot 1:d0dfbce63a89 1304 /* Start timer in continuous mode */
elmot 1:d0dfbce63a89 1305 __HAL_LPTIM_START_CONTINUOUS(hlptim);
elmot 1:d0dfbce63a89 1306
elmot 1:d0dfbce63a89 1307 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1308 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1309
elmot 1:d0dfbce63a89 1310 /* Return function status */
elmot 1:d0dfbce63a89 1311 return HAL_OK;
elmot 1:d0dfbce63a89 1312 }
elmot 1:d0dfbce63a89 1313
elmot 1:d0dfbce63a89 1314 /**
elmot 1:d0dfbce63a89 1315 * @brief Stop the Counter mode in interrupt mode.
elmot 1:d0dfbce63a89 1316 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1317 * @retval HAL status
elmot 1:d0dfbce63a89 1318 */
elmot 1:d0dfbce63a89 1319 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1320 {
elmot 1:d0dfbce63a89 1321 /* Check the parameters */
elmot 1:d0dfbce63a89 1322 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1323
elmot 1:d0dfbce63a89 1324 /* Set the LPTIM state */
elmot 1:d0dfbce63a89 1325 hlptim->State= HAL_LPTIM_STATE_BUSY;
elmot 1:d0dfbce63a89 1326
elmot 1:d0dfbce63a89 1327 /* Disable the Peripheral */
elmot 1:d0dfbce63a89 1328 __HAL_LPTIM_DISABLE(hlptim);
elmot 1:d0dfbce63a89 1329
elmot 1:d0dfbce63a89 1330 /* Disable Autoreload write complete interrupt */
elmot 1:d0dfbce63a89 1331 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARROK);
elmot 1:d0dfbce63a89 1332
elmot 1:d0dfbce63a89 1333 /* Disable Autoreload match interrupt */
elmot 1:d0dfbce63a89 1334 __HAL_LPTIM_DISABLE_IT(hlptim, LPTIM_IT_ARRM);
elmot 1:d0dfbce63a89 1335
elmot 1:d0dfbce63a89 1336 /* Change the TIM state*/
elmot 1:d0dfbce63a89 1337 hlptim->State= HAL_LPTIM_STATE_READY;
elmot 1:d0dfbce63a89 1338
elmot 1:d0dfbce63a89 1339 /* Return function status */
elmot 1:d0dfbce63a89 1340 return HAL_OK;
elmot 1:d0dfbce63a89 1341 }
elmot 1:d0dfbce63a89 1342
elmot 1:d0dfbce63a89 1343 /**
elmot 1:d0dfbce63a89 1344 * @}
elmot 1:d0dfbce63a89 1345 */
elmot 1:d0dfbce63a89 1346
elmot 1:d0dfbce63a89 1347 /** @defgroup LPTIM_Exported_Functions_Group3 LPTIM Read operation functions
elmot 1:d0dfbce63a89 1348 * @brief Read operation functions.
elmot 1:d0dfbce63a89 1349 *
elmot 1:d0dfbce63a89 1350 @verbatim
elmot 1:d0dfbce63a89 1351 ==============================================================================
elmot 1:d0dfbce63a89 1352 ##### LPTIM Read operation functions #####
elmot 1:d0dfbce63a89 1353 ==============================================================================
elmot 1:d0dfbce63a89 1354 [..] This section provides LPTIM Reading functions.
elmot 1:d0dfbce63a89 1355 (+) Read the counter value.
elmot 1:d0dfbce63a89 1356 (+) Read the period (Auto-reload) value.
elmot 1:d0dfbce63a89 1357 (+) Read the pulse (Compare)value.
elmot 1:d0dfbce63a89 1358 @endverbatim
elmot 1:d0dfbce63a89 1359 * @{
elmot 1:d0dfbce63a89 1360 */
elmot 1:d0dfbce63a89 1361
elmot 1:d0dfbce63a89 1362 /**
elmot 1:d0dfbce63a89 1363 * @brief Return the current counter value.
elmot 1:d0dfbce63a89 1364 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 1365 * @retval Counter value.
elmot 1:d0dfbce63a89 1366 */
elmot 1:d0dfbce63a89 1367 uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1368 {
elmot 1:d0dfbce63a89 1369 /* Check the parameters */
elmot 1:d0dfbce63a89 1370 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1371
elmot 1:d0dfbce63a89 1372 return (hlptim->Instance->CNT);
elmot 1:d0dfbce63a89 1373 }
elmot 1:d0dfbce63a89 1374
elmot 1:d0dfbce63a89 1375 /**
elmot 1:d0dfbce63a89 1376 * @brief Return the current Autoreload (Period) value.
elmot 1:d0dfbce63a89 1377 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 1378 * @retval Autoreload value.
elmot 1:d0dfbce63a89 1379 */
elmot 1:d0dfbce63a89 1380 uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1381 {
elmot 1:d0dfbce63a89 1382 /* Check the parameters */
elmot 1:d0dfbce63a89 1383 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1384
elmot 1:d0dfbce63a89 1385 return (hlptim->Instance->ARR);
elmot 1:d0dfbce63a89 1386 }
elmot 1:d0dfbce63a89 1387
elmot 1:d0dfbce63a89 1388 /**
elmot 1:d0dfbce63a89 1389 * @brief Return the current Compare (Pulse) value.
elmot 1:d0dfbce63a89 1390 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 1391 * @retval Compare value.
elmot 1:d0dfbce63a89 1392 */
elmot 1:d0dfbce63a89 1393 uint32_t HAL_LPTIM_ReadCompare(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1394 {
elmot 1:d0dfbce63a89 1395 /* Check the parameters */
elmot 1:d0dfbce63a89 1396 assert_param(IS_LPTIM_INSTANCE(hlptim->Instance));
elmot 1:d0dfbce63a89 1397
elmot 1:d0dfbce63a89 1398 return (hlptim->Instance->CMP);
elmot 1:d0dfbce63a89 1399 }
elmot 1:d0dfbce63a89 1400
elmot 1:d0dfbce63a89 1401 /**
elmot 1:d0dfbce63a89 1402 * @}
elmot 1:d0dfbce63a89 1403 */
elmot 1:d0dfbce63a89 1404
elmot 1:d0dfbce63a89 1405
elmot 1:d0dfbce63a89 1406
elmot 1:d0dfbce63a89 1407 /** @defgroup LPTIM_Exported_Functions_Group4 LPTIM IRQ handler and callbacks
elmot 1:d0dfbce63a89 1408 * @brief LPTIM IRQ handler.
elmot 1:d0dfbce63a89 1409 *
elmot 1:d0dfbce63a89 1410 @verbatim
elmot 1:d0dfbce63a89 1411 ==============================================================================
elmot 1:d0dfbce63a89 1412 ##### LPTIM IRQ handler and callbacks #####
elmot 1:d0dfbce63a89 1413 ==============================================================================
elmot 1:d0dfbce63a89 1414 [..] This section provides LPTIM IRQ handler and callback functions called within
elmot 1:d0dfbce63a89 1415 the IRQ handler.
elmot 1:d0dfbce63a89 1416
elmot 1:d0dfbce63a89 1417 @endverbatim
elmot 1:d0dfbce63a89 1418 * @{
elmot 1:d0dfbce63a89 1419 */
elmot 1:d0dfbce63a89 1420
elmot 1:d0dfbce63a89 1421 /**
elmot 1:d0dfbce63a89 1422 * @brief Handle LPTIM interrupt request.
elmot 1:d0dfbce63a89 1423 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 1424 * @retval None
elmot 1:d0dfbce63a89 1425 */
elmot 1:d0dfbce63a89 1426 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1427 {
elmot 1:d0dfbce63a89 1428 /* Compare match interrupt */
elmot 1:d0dfbce63a89 1429 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPM) != RESET)
elmot 1:d0dfbce63a89 1430 {
elmot 1:d0dfbce63a89 1431 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPM) != RESET)
elmot 1:d0dfbce63a89 1432 {
elmot 1:d0dfbce63a89 1433 /* Clear Compare match flag */
elmot 1:d0dfbce63a89 1434 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPM);
elmot 1:d0dfbce63a89 1435
elmot 1:d0dfbce63a89 1436 /* Compare match Callback */
elmot 1:d0dfbce63a89 1437 HAL_LPTIM_CompareMatchCallback(hlptim);
elmot 1:d0dfbce63a89 1438 }
elmot 1:d0dfbce63a89 1439 }
elmot 1:d0dfbce63a89 1440
elmot 1:d0dfbce63a89 1441 /* Autoreload match interrupt */
elmot 1:d0dfbce63a89 1442 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARRM) != RESET)
elmot 1:d0dfbce63a89 1443 {
elmot 1:d0dfbce63a89 1444 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARRM) != RESET)
elmot 1:d0dfbce63a89 1445 {
elmot 1:d0dfbce63a89 1446 /* Clear Autoreload match flag */
elmot 1:d0dfbce63a89 1447 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARRM);
elmot 1:d0dfbce63a89 1448
elmot 1:d0dfbce63a89 1449 /* Autoreload match Callback */
elmot 1:d0dfbce63a89 1450 HAL_LPTIM_AutoReloadMatchCallback(hlptim);
elmot 1:d0dfbce63a89 1451 }
elmot 1:d0dfbce63a89 1452 }
elmot 1:d0dfbce63a89 1453
elmot 1:d0dfbce63a89 1454 /* Trigger detected interrupt */
elmot 1:d0dfbce63a89 1455 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_EXTTRIG) != RESET)
elmot 1:d0dfbce63a89 1456 {
elmot 1:d0dfbce63a89 1457 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_EXTTRIG) != RESET)
elmot 1:d0dfbce63a89 1458 {
elmot 1:d0dfbce63a89 1459 /* Clear Trigger detected flag */
elmot 1:d0dfbce63a89 1460 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_EXTTRIG);
elmot 1:d0dfbce63a89 1461
elmot 1:d0dfbce63a89 1462 /* Trigger detected callback */
elmot 1:d0dfbce63a89 1463 HAL_LPTIM_TriggerCallback(hlptim);
elmot 1:d0dfbce63a89 1464 }
elmot 1:d0dfbce63a89 1465 }
elmot 1:d0dfbce63a89 1466
elmot 1:d0dfbce63a89 1467 /* Compare write interrupt */
elmot 1:d0dfbce63a89 1468 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_CMPOK) != RESET)
elmot 1:d0dfbce63a89 1469 {
elmot 1:d0dfbce63a89 1470 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_CMPOK) != RESET)
elmot 1:d0dfbce63a89 1471 {
elmot 1:d0dfbce63a89 1472 /* Clear Compare write flag */
elmot 1:d0dfbce63a89 1473 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_CMPOK);
elmot 1:d0dfbce63a89 1474
elmot 1:d0dfbce63a89 1475 /* Compare write Callback */
elmot 1:d0dfbce63a89 1476 HAL_LPTIM_CompareWriteCallback(hlptim);
elmot 1:d0dfbce63a89 1477 }
elmot 1:d0dfbce63a89 1478 }
elmot 1:d0dfbce63a89 1479
elmot 1:d0dfbce63a89 1480 /* Autoreload write interrupt */
elmot 1:d0dfbce63a89 1481 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_ARROK) != RESET)
elmot 1:d0dfbce63a89 1482 {
elmot 1:d0dfbce63a89 1483 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_ARROK) != RESET)
elmot 1:d0dfbce63a89 1484 {
elmot 1:d0dfbce63a89 1485 /* Clear Autoreload write flag */
elmot 1:d0dfbce63a89 1486 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_ARROK);
elmot 1:d0dfbce63a89 1487
elmot 1:d0dfbce63a89 1488 /* Autoreload write Callback */
elmot 1:d0dfbce63a89 1489 HAL_LPTIM_AutoReloadWriteCallback(hlptim);
elmot 1:d0dfbce63a89 1490 }
elmot 1:d0dfbce63a89 1491 }
elmot 1:d0dfbce63a89 1492
elmot 1:d0dfbce63a89 1493 /* Direction counter changed from Down to Up interrupt */
elmot 1:d0dfbce63a89 1494 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_UP) != RESET)
elmot 1:d0dfbce63a89 1495 {
elmot 1:d0dfbce63a89 1496 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_UP) != RESET)
elmot 1:d0dfbce63a89 1497 {
elmot 1:d0dfbce63a89 1498 /* Clear Direction counter changed from Down to Up flag */
elmot 1:d0dfbce63a89 1499 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_UP);
elmot 1:d0dfbce63a89 1500
elmot 1:d0dfbce63a89 1501 /* Direction counter changed from Down to Up Callback */
elmot 1:d0dfbce63a89 1502 HAL_LPTIM_DirectionUpCallback(hlptim);
elmot 1:d0dfbce63a89 1503 }
elmot 1:d0dfbce63a89 1504 }
elmot 1:d0dfbce63a89 1505
elmot 1:d0dfbce63a89 1506 /* Direction counter changed from Up to Down interrupt */
elmot 1:d0dfbce63a89 1507 if(__HAL_LPTIM_GET_FLAG(hlptim, LPTIM_FLAG_DOWN) != RESET)
elmot 1:d0dfbce63a89 1508 {
elmot 1:d0dfbce63a89 1509 if(__HAL_LPTIM_GET_IT_SOURCE(hlptim, LPTIM_IT_DOWN) != RESET)
elmot 1:d0dfbce63a89 1510 {
elmot 1:d0dfbce63a89 1511 /* Clear Direction counter changed from Up to Down flag */
elmot 1:d0dfbce63a89 1512 __HAL_LPTIM_CLEAR_FLAG(hlptim, LPTIM_FLAG_DOWN);
elmot 1:d0dfbce63a89 1513
elmot 1:d0dfbce63a89 1514 /* Direction counter changed from Up to Down Callback */
elmot 1:d0dfbce63a89 1515 HAL_LPTIM_DirectionDownCallback(hlptim);
elmot 1:d0dfbce63a89 1516 }
elmot 1:d0dfbce63a89 1517 }
elmot 1:d0dfbce63a89 1518 }
elmot 1:d0dfbce63a89 1519
elmot 1:d0dfbce63a89 1520 /**
elmot 1:d0dfbce63a89 1521 * @brief Compare match callback in non-blocking mode.
elmot 1:d0dfbce63a89 1522 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1523 * @retval None
elmot 1:d0dfbce63a89 1524 */
elmot 1:d0dfbce63a89 1525 __weak void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1526 {
elmot 1:d0dfbce63a89 1527 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1528 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1529
elmot 1:d0dfbce63a89 1530 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1531 the HAL_LPTIM_CompareMatchCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1532 */
elmot 1:d0dfbce63a89 1533 }
elmot 1:d0dfbce63a89 1534
elmot 1:d0dfbce63a89 1535 /**
elmot 1:d0dfbce63a89 1536 * @brief Autoreload match callback in non-blocking mode.
elmot 1:d0dfbce63a89 1537 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1538 * @retval None
elmot 1:d0dfbce63a89 1539 */
elmot 1:d0dfbce63a89 1540 __weak void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1541 {
elmot 1:d0dfbce63a89 1542 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1543 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1544
elmot 1:d0dfbce63a89 1545 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1546 the HAL_LPTIM_AutoReloadMatchCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1547 */
elmot 1:d0dfbce63a89 1548 }
elmot 1:d0dfbce63a89 1549
elmot 1:d0dfbce63a89 1550 /**
elmot 1:d0dfbce63a89 1551 * @brief Trigger detected callback in non-blocking mode.
elmot 1:d0dfbce63a89 1552 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1553 * @retval None
elmot 1:d0dfbce63a89 1554 */
elmot 1:d0dfbce63a89 1555 __weak void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1556 {
elmot 1:d0dfbce63a89 1557 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1558 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1559
elmot 1:d0dfbce63a89 1560 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1561 the HAL_LPTIM_TriggerCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1562 */
elmot 1:d0dfbce63a89 1563 }
elmot 1:d0dfbce63a89 1564
elmot 1:d0dfbce63a89 1565 /**
elmot 1:d0dfbce63a89 1566 * @brief Compare write callback in non-blocking mode.
elmot 1:d0dfbce63a89 1567 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1568 * @retval None
elmot 1:d0dfbce63a89 1569 */
elmot 1:d0dfbce63a89 1570 __weak void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1571 {
elmot 1:d0dfbce63a89 1572 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1573 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1574
elmot 1:d0dfbce63a89 1575 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1576 the HAL_LPTIM_CompareWriteCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1577 */
elmot 1:d0dfbce63a89 1578 }
elmot 1:d0dfbce63a89 1579
elmot 1:d0dfbce63a89 1580 /**
elmot 1:d0dfbce63a89 1581 * @brief Autoreload write callback in non-blocking mode.
elmot 1:d0dfbce63a89 1582 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1583 * @retval None
elmot 1:d0dfbce63a89 1584 */
elmot 1:d0dfbce63a89 1585 __weak void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1586 {
elmot 1:d0dfbce63a89 1587 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1588 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1589
elmot 1:d0dfbce63a89 1590 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1591 the HAL_LPTIM_AutoReloadWriteCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1592 */
elmot 1:d0dfbce63a89 1593 }
elmot 1:d0dfbce63a89 1594
elmot 1:d0dfbce63a89 1595 /**
elmot 1:d0dfbce63a89 1596 * @brief Direction counter changed from Down to Up callback in non-blocking mode.
elmot 1:d0dfbce63a89 1597 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1598 * @retval None
elmot 1:d0dfbce63a89 1599 */
elmot 1:d0dfbce63a89 1600 __weak void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1601 {
elmot 1:d0dfbce63a89 1602 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1603 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1604
elmot 1:d0dfbce63a89 1605 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1606 the HAL_LPTIM_DirectionUpCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1607 */
elmot 1:d0dfbce63a89 1608 }
elmot 1:d0dfbce63a89 1609
elmot 1:d0dfbce63a89 1610 /**
elmot 1:d0dfbce63a89 1611 * @brief Direction counter changed from Up to Down callback in non-blocking mode.
elmot 1:d0dfbce63a89 1612 * @param hlptim : LPTIM handle
elmot 1:d0dfbce63a89 1613 * @retval None
elmot 1:d0dfbce63a89 1614 */
elmot 1:d0dfbce63a89 1615 __weak void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1616 {
elmot 1:d0dfbce63a89 1617 /* Prevent unused argument(s) compilation warning */
elmot 1:d0dfbce63a89 1618 UNUSED(hlptim);
elmot 1:d0dfbce63a89 1619
elmot 1:d0dfbce63a89 1620 /* NOTE : This function should not be modified, when the callback is needed,
elmot 1:d0dfbce63a89 1621 the HAL_LPTIM_DirectionDownCallback could be implemented in the user file
elmot 1:d0dfbce63a89 1622 */
elmot 1:d0dfbce63a89 1623 }
elmot 1:d0dfbce63a89 1624
elmot 1:d0dfbce63a89 1625 /**
elmot 1:d0dfbce63a89 1626 * @}
elmot 1:d0dfbce63a89 1627 */
elmot 1:d0dfbce63a89 1628
elmot 1:d0dfbce63a89 1629 /** @defgroup LPTIM_Exported_Functions_Group5 Peripheral State functions
elmot 1:d0dfbce63a89 1630 * @brief Peripheral State functions.
elmot 1:d0dfbce63a89 1631 *
elmot 1:d0dfbce63a89 1632 @verbatim
elmot 1:d0dfbce63a89 1633 ==============================================================================
elmot 1:d0dfbce63a89 1634 ##### Peripheral State functions #####
elmot 1:d0dfbce63a89 1635 ==============================================================================
elmot 1:d0dfbce63a89 1636 [..]
elmot 1:d0dfbce63a89 1637 This subsection permits to get in run-time the status of the peripheral.
elmot 1:d0dfbce63a89 1638
elmot 1:d0dfbce63a89 1639 @endverbatim
elmot 1:d0dfbce63a89 1640 * @{
elmot 1:d0dfbce63a89 1641 */
elmot 1:d0dfbce63a89 1642
elmot 1:d0dfbce63a89 1643 /**
elmot 1:d0dfbce63a89 1644 * @brief Return the LPTIM handle state.
elmot 1:d0dfbce63a89 1645 * @param hlptim: LPTIM handle
elmot 1:d0dfbce63a89 1646 * @retval HAL state
elmot 1:d0dfbce63a89 1647 */
elmot 1:d0dfbce63a89 1648 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim)
elmot 1:d0dfbce63a89 1649 {
elmot 1:d0dfbce63a89 1650 /* Return LPTIM handle state */
elmot 1:d0dfbce63a89 1651 return hlptim->State;
elmot 1:d0dfbce63a89 1652 }
elmot 1:d0dfbce63a89 1653
elmot 1:d0dfbce63a89 1654 /**
elmot 1:d0dfbce63a89 1655 * @}
elmot 1:d0dfbce63a89 1656 */
elmot 1:d0dfbce63a89 1657
elmot 1:d0dfbce63a89 1658
elmot 1:d0dfbce63a89 1659 /**
elmot 1:d0dfbce63a89 1660 * @}
elmot 1:d0dfbce63a89 1661 */
elmot 1:d0dfbce63a89 1662
elmot 1:d0dfbce63a89 1663 #endif /* HAL_LPTIM_MODULE_ENABLED */
elmot 1:d0dfbce63a89 1664 /**
elmot 1:d0dfbce63a89 1665 * @}
elmot 1:d0dfbce63a89 1666 */
elmot 1:d0dfbce63a89 1667
elmot 1:d0dfbce63a89 1668 /**
elmot 1:d0dfbce63a89 1669 * @}
elmot 1:d0dfbce63a89 1670 */
elmot 1:d0dfbce63a89 1671
elmot 1:d0dfbce63a89 1672 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/