inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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