1 /** 2 ****************************************************************************** 3 * @file stm32wbxx_hal_lptim.h 4 * @author MCD Application Team 5 * @brief Header file of LPTIM HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32WBxx_HAL_LPTIM_H 21 #define STM32WBxx_HAL_LPTIM_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32wbxx_hal_def.h" 29 30 /** @addtogroup STM32WBxx_HAL_Driver 31 * @{ 32 */ 33 34 #if defined (LPTIM1) || defined (LPTIM2) 35 36 /** @addtogroup LPTIM 37 * @{ 38 */ 39 40 /* Exported types ------------------------------------------------------------*/ 41 /** @defgroup LPTIM_Exported_Types LPTIM Exported Types 42 * @{ 43 */ 44 #define LPTIM_EXTI_LINE_LPTIM1 EXTI_IMR1_IM29 /*!< External interrupt line 29 Connected to the LPTIM1 EXTI Line */ 45 #define LPTIM_EXTI_LINE_LPTIM2 EXTI_IMR1_IM30 /*!< External interrupt line 30 Connected to the LPTIM2 EXTI Line */ 46 47 /** 48 * @brief LPTIM Clock configuration definition 49 */ 50 typedef struct 51 { 52 uint32_t Source; /*!< Selects the clock source. 53 This parameter can be a value of @ref LPTIM_Clock_Source */ 54 55 uint32_t Prescaler; /*!< Specifies the counter clock Prescaler. 56 This parameter can be a value of @ref LPTIM_Clock_Prescaler */ 57 58 } LPTIM_ClockConfigTypeDef; 59 60 /** 61 * @brief LPTIM Clock configuration definition 62 */ 63 typedef struct 64 { 65 uint32_t Polarity; /*!< Selects the polarity of the active edge for the counter unit 66 if the ULPTIM input is selected. 67 Note: This parameter is used only when Ultra low power clock source is used. 68 Note: If the polarity is configured on 'both edges', an auxiliary clock 69 (one of the Low power oscillator) must be active. 70 This parameter can be a value of @ref LPTIM_Clock_Polarity */ 71 72 uint32_t SampleTime; /*!< Selects the clock sampling time to configure the clock glitch filter. 73 Note: This parameter is used only when Ultra low power clock source is used. 74 This parameter can be a value of @ref LPTIM_Clock_Sample_Time */ 75 76 } LPTIM_ULPClockConfigTypeDef; 77 78 /** 79 * @brief LPTIM Trigger configuration definition 80 */ 81 typedef struct 82 { 83 uint32_t Source; /*!< Selects the Trigger source. 84 This parameter can be a value of @ref LPTIM_Trigger_Source */ 85 86 uint32_t ActiveEdge; /*!< Selects the Trigger active edge. 87 Note: This parameter is used only when an external trigger is used. 88 This parameter can be a value of @ref LPTIM_External_Trigger_Polarity */ 89 90 uint32_t SampleTime; /*!< Selects the trigger sampling time to configure the clock glitch filter. 91 Note: This parameter is used only when an external trigger is used. 92 This parameter can be a value of @ref LPTIM_Trigger_Sample_Time */ 93 } LPTIM_TriggerConfigTypeDef; 94 95 /** 96 * @brief LPTIM Initialization Structure definition 97 */ 98 typedef struct 99 { 100 LPTIM_ClockConfigTypeDef Clock; /*!< Specifies the clock parameters */ 101 102 LPTIM_ULPClockConfigTypeDef UltraLowPowerClock;/*!< Specifies the Ultra Low Power clock parameters */ 103 104 LPTIM_TriggerConfigTypeDef Trigger; /*!< Specifies the Trigger parameters */ 105 106 uint32_t OutputPolarity; /*!< Specifies the Output polarity. 107 This parameter can be a value of @ref LPTIM_Output_Polarity */ 108 109 uint32_t UpdateMode; /*!< Specifies whether the update of the autoreload and the compare 110 values is done immediately or after the end of current period. 111 This parameter can be a value of @ref LPTIM_Updating_Mode */ 112 113 uint32_t CounterSource; /*!< Specifies whether the counter is incremented each internal event 114 or each external event. 115 This parameter can be a value of @ref LPTIM_Counter_Source */ 116 117 uint32_t Input1Source; /*!< Specifies source selected for input1 (GPIO or comparator output). 118 This parameter can be a value of @ref LPTIM_Input1_Source */ 119 120 uint32_t Input2Source; /*!< Specifies source selected for input2 (GPIO or comparator output). 121 Note: This parameter is used only for encoder feature so is used only 122 for LPTIM1 instance. 123 This parameter can be a value of @ref LPTIM_Input2_Source */ 124 } LPTIM_InitTypeDef; 125 126 /** 127 * @brief HAL LPTIM State structure definition 128 */ 129 typedef enum 130 { 131 HAL_LPTIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */ 132 HAL_LPTIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ 133 HAL_LPTIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */ 134 HAL_LPTIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */ 135 HAL_LPTIM_STATE_ERROR = 0x04U /*!< Internal Process is ongoing */ 136 } HAL_LPTIM_StateTypeDef; 137 138 /** 139 * @brief LPTIM handle Structure definition 140 */ 141 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 142 typedef struct __LPTIM_HandleTypeDef 143 #else 144 typedef struct 145 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 146 { 147 LPTIM_TypeDef *Instance; /*!< Register base address */ 148 149 LPTIM_InitTypeDef Init; /*!< LPTIM required parameters */ 150 151 HAL_StatusTypeDef Status; /*!< LPTIM peripheral status */ 152 153 HAL_LockTypeDef Lock; /*!< LPTIM locking object */ 154 155 __IO HAL_LPTIM_StateTypeDef State; /*!< LPTIM peripheral state */ 156 157 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 158 void (* MspInitCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< LPTIM Base Msp Init Callback */ 159 void (* MspDeInitCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< LPTIM Base Msp DeInit Callback */ 160 void (* CompareMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Compare match Callback */ 161 void (* AutoReloadMatchCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Auto-reload match Callback */ 162 void (* TriggerCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< External trigger event detection Callback */ 163 void (* CompareWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Compare register write complete Callback */ 164 void (* AutoReloadWriteCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Auto-reload register write complete Callback */ 165 void (* DirectionUpCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Up-counting direction change Callback */ 166 void (* DirectionDownCallback)(struct __LPTIM_HandleTypeDef *hlptim); /*!< Down-counting direction change Callback */ 167 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 168 } LPTIM_HandleTypeDef; 169 170 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 171 /** 172 * @brief HAL LPTIM Callback ID enumeration definition 173 */ 174 typedef enum 175 { 176 HAL_LPTIM_MSPINIT_CB_ID = 0x00U, /*!< LPTIM Base Msp Init Callback ID */ 177 HAL_LPTIM_MSPDEINIT_CB_ID = 0x01U, /*!< LPTIM Base Msp DeInit Callback ID */ 178 HAL_LPTIM_COMPARE_MATCH_CB_ID = 0x02U, /*!< Compare match Callback ID */ 179 HAL_LPTIM_AUTORELOAD_MATCH_CB_ID = 0x03U, /*!< Auto-reload match Callback ID */ 180 HAL_LPTIM_TRIGGER_CB_ID = 0x04U, /*!< External trigger event detection Callback ID */ 181 HAL_LPTIM_COMPARE_WRITE_CB_ID = 0x05U, /*!< Compare register write complete Callback ID */ 182 HAL_LPTIM_AUTORELOAD_WRITE_CB_ID = 0x06U, /*!< Auto-reload register write complete Callback ID */ 183 HAL_LPTIM_DIRECTION_UP_CB_ID = 0x07U, /*!< Up-counting direction change Callback ID */ 184 HAL_LPTIM_DIRECTION_DOWN_CB_ID = 0x08U, /*!< Down-counting direction change Callback ID */ 185 } HAL_LPTIM_CallbackIDTypeDef; 186 187 /** 188 * @brief HAL TIM Callback pointer definition 189 */ 190 typedef void (*pLPTIM_CallbackTypeDef)(LPTIM_HandleTypeDef *hlptim); /*!< pointer to the LPTIM callback function */ 191 192 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 193 /** 194 * @} 195 */ 196 197 /* Exported constants --------------------------------------------------------*/ 198 /** @defgroup LPTIM_Exported_Constants LPTIM Exported Constants 199 * @{ 200 */ 201 202 /** @defgroup LPTIM_Clock_Source LPTIM Clock Source 203 * @{ 204 */ 205 #define LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC 0x00000000U 206 #define LPTIM_CLOCKSOURCE_ULPTIM LPTIM_CFGR_CKSEL 207 /** 208 * @} 209 */ 210 211 /** @defgroup LPTIM_Clock_Prescaler LPTIM Clock Prescaler 212 * @{ 213 */ 214 #define LPTIM_PRESCALER_DIV1 0x00000000U 215 #define LPTIM_PRESCALER_DIV2 LPTIM_CFGR_PRESC_0 216 #define LPTIM_PRESCALER_DIV4 LPTIM_CFGR_PRESC_1 217 #define LPTIM_PRESCALER_DIV8 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_1) 218 #define LPTIM_PRESCALER_DIV16 LPTIM_CFGR_PRESC_2 219 #define LPTIM_PRESCALER_DIV32 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_2) 220 #define LPTIM_PRESCALER_DIV64 (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_2) 221 #define LPTIM_PRESCALER_DIV128 LPTIM_CFGR_PRESC 222 /** 223 * @} 224 */ 225 226 /** @defgroup LPTIM_Output_Polarity LPTIM Output Polarity 227 * @{ 228 */ 229 230 #define LPTIM_OUTPUTPOLARITY_HIGH 0x00000000U 231 #define LPTIM_OUTPUTPOLARITY_LOW LPTIM_CFGR_WAVPOL 232 /** 233 * @} 234 */ 235 236 /** @defgroup LPTIM_Clock_Sample_Time LPTIM Clock Sample Time 237 * @{ 238 */ 239 #define LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION 0x00000000U 240 #define LPTIM_CLOCKSAMPLETIME_2TRANSITIONS LPTIM_CFGR_CKFLT_0 241 #define LPTIM_CLOCKSAMPLETIME_4TRANSITIONS LPTIM_CFGR_CKFLT_1 242 #define LPTIM_CLOCKSAMPLETIME_8TRANSITIONS LPTIM_CFGR_CKFLT 243 /** 244 * @} 245 */ 246 247 /** @defgroup LPTIM_Clock_Polarity LPTIM Clock Polarity 248 * @{ 249 */ 250 #define LPTIM_CLOCKPOLARITY_RISING 0x00000000U 251 #define LPTIM_CLOCKPOLARITY_FALLING LPTIM_CFGR_CKPOL_0 252 #define LPTIM_CLOCKPOLARITY_RISING_FALLING LPTIM_CFGR_CKPOL_1 253 /** 254 * @} 255 */ 256 257 /** @defgroup LPTIM_Trigger_Source LPTIM Trigger Source 258 * @{ 259 */ 260 #define LPTIM_TRIGSOURCE_SOFTWARE 0x0000FFFFU 261 #define LPTIM_TRIGSOURCE_0 0x00000000U 262 #define LPTIM_TRIGSOURCE_1 LPTIM_CFGR_TRIGSEL_0 263 #define LPTIM_TRIGSOURCE_2 LPTIM_CFGR_TRIGSEL_1 264 #define LPTIM_TRIGSOURCE_3 (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_1) 265 #define LPTIM_TRIGSOURCE_4 LPTIM_CFGR_TRIGSEL_2 266 #define LPTIM_TRIGSOURCE_5 (LPTIM_CFGR_TRIGSEL_0 | LPTIM_CFGR_TRIGSEL_2) 267 #define LPTIM_TRIGSOURCE_6 (LPTIM_CFGR_TRIGSEL_1 | LPTIM_CFGR_TRIGSEL_2) 268 #define LPTIM_TRIGSOURCE_7 LPTIM_CFGR_TRIGSEL 269 /** 270 * @} 271 */ 272 273 /** @defgroup LPTIM_External_Trigger_Polarity LPTIM External Trigger Polarity 274 * @{ 275 */ 276 #define LPTIM_ACTIVEEDGE_RISING LPTIM_CFGR_TRIGEN_0 277 #define LPTIM_ACTIVEEDGE_FALLING LPTIM_CFGR_TRIGEN_1 278 #define LPTIM_ACTIVEEDGE_RISING_FALLING LPTIM_CFGR_TRIGEN 279 /** 280 * @} 281 */ 282 283 /** @defgroup LPTIM_Trigger_Sample_Time LPTIM Trigger Sample Time 284 * @{ 285 */ 286 #define LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION 0x00000000U 287 #define LPTIM_TRIGSAMPLETIME_2TRANSITIONS LPTIM_CFGR_TRGFLT_0 288 #define LPTIM_TRIGSAMPLETIME_4TRANSITIONS LPTIM_CFGR_TRGFLT_1 289 #define LPTIM_TRIGSAMPLETIME_8TRANSITIONS LPTIM_CFGR_TRGFLT 290 /** 291 * @} 292 */ 293 294 /** @defgroup LPTIM_Updating_Mode LPTIM Updating Mode 295 * @{ 296 */ 297 298 #define LPTIM_UPDATE_IMMEDIATE 0x00000000U 299 #define LPTIM_UPDATE_ENDOFPERIOD LPTIM_CFGR_PRELOAD 300 /** 301 * @} 302 */ 303 304 /** @defgroup LPTIM_Counter_Source LPTIM Counter Source 305 * @{ 306 */ 307 308 #define LPTIM_COUNTERSOURCE_INTERNAL 0x00000000U 309 #define LPTIM_COUNTERSOURCE_EXTERNAL LPTIM_CFGR_COUNTMODE 310 /** 311 * @} 312 */ 313 314 /** @defgroup LPTIM_Input1_Source LPTIM Input1 Source 315 * @{ 316 */ 317 318 #define LPTIM_INPUT1SOURCE_GPIO 0x00000000U /*!< For LPTIM1 and LPTIM2 */ 319 #if defined(COMP1) 320 #define LPTIM_INPUT1SOURCE_COMP1 LPTIM_OR_OR_0 /*!< For LPTIM1 and LPTIM2 */ 321 #endif 322 #if defined(COMP2) 323 #define LPTIM_INPUT1SOURCE_COMP2 LPTIM_OR_OR_1 /*!< For LPTIM2 */ 324 #define LPTIM_INPUT1SOURCE_COMP1_COMP2 LPTIM_OR_OR /*!< For LPTIM2 */ 325 #endif 326 /** 327 * @} 328 */ 329 330 /** @defgroup LPTIM_Input2_Source LPTIM Input2 Source 331 * @{ 332 */ 333 334 #define LPTIM_INPUT2SOURCE_GPIO 0x00000000U /*!< For LPTIM1 */ 335 #if defined(COMP2) 336 #define LPTIM_INPUT2SOURCE_COMP2 LPTIM_OR_OR_1 /*!< For LPTIM1 */ 337 #endif 338 /** 339 * @} 340 */ 341 342 /** @defgroup LPTIM_Flag_Definition LPTIM Flags Definition 343 * @{ 344 */ 345 346 #define LPTIM_FLAG_DOWN LPTIM_ISR_DOWN 347 #define LPTIM_FLAG_UP LPTIM_ISR_UP 348 #define LPTIM_FLAG_ARROK LPTIM_ISR_ARROK 349 #define LPTIM_FLAG_CMPOK LPTIM_ISR_CMPOK 350 #define LPTIM_FLAG_EXTTRIG LPTIM_ISR_EXTTRIG 351 #define LPTIM_FLAG_ARRM LPTIM_ISR_ARRM 352 #define LPTIM_FLAG_CMPM LPTIM_ISR_CMPM 353 /** 354 * @} 355 */ 356 357 /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition 358 * @{ 359 */ 360 #define LPTIM_IT_DOWN LPTIM_IER_DOWNIE 361 #define LPTIM_IT_UP LPTIM_IER_UPIE 362 #define LPTIM_IT_ARROK LPTIM_IER_ARROKIE 363 #define LPTIM_IT_CMPOK LPTIM_IER_CMPOKIE 364 #define LPTIM_IT_EXTTRIG LPTIM_IER_EXTTRIGIE 365 #define LPTIM_IT_ARRM LPTIM_IER_ARRMIE 366 #define LPTIM_IT_CMPM LPTIM_IER_CMPMIE 367 /** 368 * @} 369 */ 370 371 /** 372 * @} 373 */ 374 375 /* Exported macros -----------------------------------------------------------*/ 376 /** @defgroup LPTIM_Exported_Macros LPTIM Exported Macros 377 * @{ 378 */ 379 380 /** @brief Reset LPTIM handle state. 381 * @param __HANDLE__ LPTIM handle 382 * @retval None 383 */ 384 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 385 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do { \ 386 (__HANDLE__)->State = HAL_LPTIM_STATE_RESET; \ 387 (__HANDLE__)->MspInitCallback = NULL; \ 388 (__HANDLE__)->MspDeInitCallback = NULL; \ 389 } while(0) 390 #else 391 #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET) 392 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 393 394 /** 395 * @brief Enable the LPTIM peripheral. 396 * @param __HANDLE__ LPTIM handle 397 * @retval None 398 */ 399 #define __HAL_LPTIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (LPTIM_CR_ENABLE)) 400 401 /** 402 * @brief Disable the LPTIM peripheral. 403 * @param __HANDLE__ LPTIM handle 404 * @note The following sequence is required to solve LPTIM disable HW limitation. 405 * Please check Errata Sheet ES0335 for more details under "MCU may remain 406 * stuck in LPTIM interrupt when entering Stop mode" section. 407 * @note Please call @ref HAL_LPTIM_GetState() after a call to __HAL_LPTIM_DISABLE to 408 * check for TIMEOUT. 409 * @retval None 410 */ 411 #define __HAL_LPTIM_DISABLE(__HANDLE__) LPTIM_Disable(__HANDLE__) 412 413 /** 414 * @brief Start the LPTIM peripheral in Continuous mode. 415 * @param __HANDLE__ LPTIM handle 416 * @retval None 417 */ 418 #define __HAL_LPTIM_START_CONTINUOUS(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_CNTSTRT) 419 /** 420 * @brief Start the LPTIM peripheral in single mode. 421 * @param __HANDLE__ LPTIM handle 422 * @retval None 423 */ 424 #define __HAL_LPTIM_START_SINGLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_SNGSTRT) 425 426 /** 427 * @brief Reset the LPTIM Counter register in synchronous mode. 428 * @param __HANDLE__ LPTIM handle 429 * @retval None 430 */ 431 #define __HAL_LPTIM_RESET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_COUNTRST) 432 433 /** 434 * @brief Reset after read of the LPTIM Counter register in asynchronous mode. 435 * @param __HANDLE__ LPTIM handle 436 * @retval None 437 */ 438 #define __HAL_LPTIM_RESET_COUNTER_AFTERREAD(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_RSTARE) 439 440 /** 441 * @brief Write the passed parameter in the Autoreload register. 442 * @param __HANDLE__ LPTIM handle 443 * @param __VALUE__ Autoreload value 444 * @retval None 445 * @note The ARR register can only be modified when the LPTIM instance is enabled. 446 */ 447 #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->ARR = (__VALUE__)) 448 449 /** 450 * @brief Write the passed parameter in the Compare register. 451 * @param __HANDLE__ LPTIM handle 452 * @param __VALUE__ Compare value 453 * @retval None 454 * @note The CMP register can only be modified when the LPTIM instance is enabled. 455 */ 456 #define __HAL_LPTIM_COMPARE_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->CMP = (__VALUE__)) 457 458 /** 459 * @brief Check whether the specified LPTIM flag is set or not. 460 * @param __HANDLE__ LPTIM handle 461 * @param __FLAG__ LPTIM flag to check 462 * This parameter can be a value of: 463 * @arg LPTIM_FLAG_DOWN : Counter direction change up Flag. 464 * @arg LPTIM_FLAG_UP : Counter direction change down to up Flag. 465 * @arg LPTIM_FLAG_ARROK : Autoreload register update OK Flag. 466 * @arg LPTIM_FLAG_CMPOK : Compare register update OK Flag. 467 * @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag. 468 * @arg LPTIM_FLAG_ARRM : Autoreload match Flag. 469 * @arg LPTIM_FLAG_CMPM : Compare match Flag. 470 * @retval The state of the specified flag (SET or RESET). 471 */ 472 #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__)) 473 474 /** 475 * @brief Clear the specified LPTIM flag. 476 * @param __HANDLE__ LPTIM handle. 477 * @param __FLAG__ LPTIM flag to clear. 478 * This parameter can be a value of: 479 * @arg LPTIM_FLAG_DOWN : Counter direction change up Flag. 480 * @arg LPTIM_FLAG_UP : Counter direction change down to up Flag. 481 * @arg LPTIM_FLAG_ARROK : Autoreload register update OK Flag. 482 * @arg LPTIM_FLAG_CMPOK : Compare register update OK Flag. 483 * @arg LPTIM_FLAG_EXTTRIG : External trigger edge event Flag. 484 * @arg LPTIM_FLAG_ARRM : Autoreload match Flag. 485 * @arg LPTIM_FLAG_CMPM : Compare match Flag. 486 * @retval None. 487 */ 488 #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__)) 489 490 /** 491 * @brief Enable the specified LPTIM interrupt. 492 * @param __HANDLE__ LPTIM handle. 493 * @param __INTERRUPT__ LPTIM interrupt to set. 494 * This parameter can be a value of: 495 * @arg LPTIM_IT_DOWN : Counter direction change up Interrupt. 496 * @arg LPTIM_IT_UP : Counter direction change down to up Interrupt. 497 * @arg LPTIM_IT_ARROK : Autoreload register update OK Interrupt. 498 * @arg LPTIM_IT_CMPOK : Compare register update OK Interrupt. 499 * @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt. 500 * @arg LPTIM_IT_ARRM : Autoreload match Interrupt. 501 * @arg LPTIM_IT_CMPM : Compare match Interrupt. 502 * @retval None. 503 * @note The LPTIM interrupts can only be enabled when the LPTIM instance is disabled. 504 */ 505 #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__)) 506 507 /** 508 * @brief Disable the specified LPTIM interrupt. 509 * @param __HANDLE__ LPTIM handle. 510 * @param __INTERRUPT__ LPTIM interrupt to set. 511 * This parameter can be a value of: 512 * @arg LPTIM_IT_DOWN : Counter direction change up Interrupt. 513 * @arg LPTIM_IT_UP : Counter direction change down to up Interrupt. 514 * @arg LPTIM_IT_ARROK : Autoreload register update OK Interrupt. 515 * @arg LPTIM_IT_CMPOK : Compare register update OK Interrupt. 516 * @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt. 517 * @arg LPTIM_IT_ARRM : Autoreload match Interrupt. 518 * @arg LPTIM_IT_CMPM : Compare match Interrupt. 519 * @retval None. 520 * @note The LPTIM interrupts can only be disabled when the LPTIM instance is disabled. 521 */ 522 #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__))) 523 524 /** 525 * @brief Check whether the specified LPTIM interrupt source is enabled or not. 526 * @param __HANDLE__ LPTIM handle. 527 * @param __INTERRUPT__ LPTIM interrupt to check. 528 * This parameter can be a value of: 529 * @arg LPTIM_IT_DOWN : Counter direction change up Interrupt. 530 * @arg LPTIM_IT_UP : Counter direction change down to up Interrupt. 531 * @arg LPTIM_IT_ARROK : Autoreload register update OK Interrupt. 532 * @arg LPTIM_IT_CMPOK : Compare register update OK Interrupt. 533 * @arg LPTIM_IT_EXTTRIG : External trigger edge event Interrupt. 534 * @arg LPTIM_IT_ARRM : Autoreload match Interrupt. 535 * @arg LPTIM_IT_CMPM : Compare match Interrupt. 536 * @retval Interrupt status. 537 */ 538 539 #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER\ 540 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) 541 542 #define __HAL_LPTIM_LPTIM1_EXTI_ENABLE_IT() (EXTI->IMR1 |= LPTIM_EXTI_LINE_LPTIM1) 543 #define __HAL_LPTIM_LPTIM1_EXTI_DISABLE_IT() (EXTI->IMR1\ 544 &= ~(LPTIM_EXTI_LINE_LPTIM1)) 545 546 #define __HAL_LPTIM_LPTIM2_EXTI_ENABLE_IT() (EXTI->IMR1 |= LPTIM_EXTI_LINE_LPTIM2) 547 #define __HAL_LPTIM_LPTIM2_EXTI_DISABLE_IT() (EXTI->IMR1\ 548 &= ~(LPTIM_EXTI_LINE_LPTIM2)) 549 550 /** 551 * @} 552 */ 553 554 /* Exported functions --------------------------------------------------------*/ 555 /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions 556 * @{ 557 */ 558 559 /** @addtogroup LPTIM_Exported_Functions_Group1 560 * @brief Initialization and Configuration functions. 561 * @{ 562 */ 563 /* Initialization/de-initialization functions ********************************/ 564 HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim); 565 HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim); 566 567 /* MSP functions *************************************************************/ 568 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim); 569 void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim); 570 /** 571 * @} 572 */ 573 574 /** @addtogroup LPTIM_Exported_Functions_Group2 575 * @brief Start-Stop operation functions. 576 * @{ 577 */ 578 /* Start/Stop operation functions *********************************************/ 579 /* ################################# PWM Mode ################################*/ 580 /* Blocking mode: Polling */ 581 HAL_StatusTypeDef HAL_LPTIM_PWM_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 582 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop(LPTIM_HandleTypeDef *hlptim); 583 /* Non-Blocking mode: Interrupt */ 584 HAL_StatusTypeDef HAL_LPTIM_PWM_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 585 HAL_StatusTypeDef HAL_LPTIM_PWM_Stop_IT(LPTIM_HandleTypeDef *hlptim); 586 587 /* ############################# One Pulse Mode ##############################*/ 588 /* Blocking mode: Polling */ 589 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 590 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop(LPTIM_HandleTypeDef *hlptim); 591 /* Non-Blocking mode: Interrupt */ 592 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 593 HAL_StatusTypeDef HAL_LPTIM_OnePulse_Stop_IT(LPTIM_HandleTypeDef *hlptim); 594 595 /* ############################## Set once Mode ##############################*/ 596 /* Blocking mode: Polling */ 597 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 598 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim); 599 /* Non-Blocking mode: Interrupt */ 600 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Pulse); 601 HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim); 602 603 /* ############################### Encoder Mode ##############################*/ 604 /* Blocking mode: Polling */ 605 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period); 606 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop(LPTIM_HandleTypeDef *hlptim); 607 /* Non-Blocking mode: Interrupt */ 608 HAL_StatusTypeDef HAL_LPTIM_Encoder_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period); 609 HAL_StatusTypeDef HAL_LPTIM_Encoder_Stop_IT(LPTIM_HandleTypeDef *hlptim); 610 611 /* ############################# Time out Mode ##############################*/ 612 /* Blocking mode: Polling */ 613 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout); 614 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop(LPTIM_HandleTypeDef *hlptim); 615 /* Non-Blocking mode: Interrupt */ 616 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period, uint32_t Timeout); 617 HAL_StatusTypeDef HAL_LPTIM_TimeOut_Stop_IT(LPTIM_HandleTypeDef *hlptim); 618 619 /* ############################## Counter Mode ###############################*/ 620 /* Blocking mode: Polling */ 621 HAL_StatusTypeDef HAL_LPTIM_Counter_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period); 622 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop(LPTIM_HandleTypeDef *hlptim); 623 /* Non-Blocking mode: Interrupt */ 624 HAL_StatusTypeDef HAL_LPTIM_Counter_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period); 625 HAL_StatusTypeDef HAL_LPTIM_Counter_Stop_IT(LPTIM_HandleTypeDef *hlptim); 626 /** 627 * @} 628 */ 629 630 /** @addtogroup LPTIM_Exported_Functions_Group3 631 * @brief Read operation functions. 632 * @{ 633 */ 634 /* Reading operation functions ************************************************/ 635 uint32_t HAL_LPTIM_ReadCounter(const LPTIM_HandleTypeDef *hlptim); 636 uint32_t HAL_LPTIM_ReadAutoReload(const LPTIM_HandleTypeDef *hlptim); 637 uint32_t HAL_LPTIM_ReadCompare(const LPTIM_HandleTypeDef *hlptim); 638 /** 639 * @} 640 */ 641 642 /** @addtogroup LPTIM_Exported_Functions_Group4 643 * @brief LPTIM IRQ handler and callback functions. 644 * @{ 645 */ 646 /* LPTIM IRQ functions *******************************************************/ 647 void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim); 648 649 /* CallBack functions ********************************************************/ 650 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim); 651 void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim); 652 void HAL_LPTIM_TriggerCallback(LPTIM_HandleTypeDef *hlptim); 653 void HAL_LPTIM_CompareWriteCallback(LPTIM_HandleTypeDef *hlptim); 654 void HAL_LPTIM_AutoReloadWriteCallback(LPTIM_HandleTypeDef *hlptim); 655 void HAL_LPTIM_DirectionUpCallback(LPTIM_HandleTypeDef *hlptim); 656 void HAL_LPTIM_DirectionDownCallback(LPTIM_HandleTypeDef *hlptim); 657 658 /* Callbacks Register/UnRegister functions ***********************************/ 659 #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1) 660 HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID, 661 pLPTIM_CallbackTypeDef pCallback); 662 HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID); 663 #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */ 664 /** 665 * @} 666 */ 667 668 /** @addtogroup LPTIM_Group5 669 * @brief Peripheral State functions. 670 * @{ 671 */ 672 /* Peripheral State functions ************************************************/ 673 HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(const LPTIM_HandleTypeDef *hlptim); 674 /** 675 * @} 676 */ 677 678 /** 679 * @} 680 */ 681 682 /* Private types -------------------------------------------------------------*/ 683 /** @defgroup LPTIM_Private_Types LPTIM Private Types 684 * @{ 685 */ 686 687 /** 688 * @} 689 */ 690 691 /* Private variables ---------------------------------------------------------*/ 692 /** @defgroup LPTIM_Private_Variables LPTIM Private Variables 693 * @{ 694 */ 695 696 /** 697 * @} 698 */ 699 700 /* Private constants ---------------------------------------------------------*/ 701 /** @defgroup LPTIM_Private_Constants LPTIM Private Constants 702 * @{ 703 */ 704 705 /** 706 * @} 707 */ 708 709 /* Private macros ------------------------------------------------------------*/ 710 /** @defgroup LPTIM_Private_Macros LPTIM Private Macros 711 * @{ 712 */ 713 714 #define IS_LPTIM_CLOCK_SOURCE(__SOURCE__) (((__SOURCE__) == LPTIM_CLOCKSOURCE_ULPTIM) || \ 715 ((__SOURCE__) == LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC)) 716 717 718 #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) == LPTIM_PRESCALER_DIV1 ) || \ 719 ((__PRESCALER__) == LPTIM_PRESCALER_DIV2 ) || \ 720 ((__PRESCALER__) == LPTIM_PRESCALER_DIV4 ) || \ 721 ((__PRESCALER__) == LPTIM_PRESCALER_DIV8 ) || \ 722 ((__PRESCALER__) == LPTIM_PRESCALER_DIV16 ) || \ 723 ((__PRESCALER__) == LPTIM_PRESCALER_DIV32 ) || \ 724 ((__PRESCALER__) == LPTIM_PRESCALER_DIV64 ) || \ 725 ((__PRESCALER__) == LPTIM_PRESCALER_DIV128)) 726 727 #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) == LPTIM_PRESCALER_DIV1) 728 729 #define IS_LPTIM_OUTPUT_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_OUTPUTPOLARITY_LOW ) || \ 730 ((__POLARITY__) == LPTIM_OUTPUTPOLARITY_HIGH)) 731 732 #define IS_LPTIM_CLOCK_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_DIRECTTRANSITION) || \ 733 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_2TRANSITIONS) || \ 734 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_4TRANSITIONS) || \ 735 ((__SAMPLETIME__) == LPTIM_CLOCKSAMPLETIME_8TRANSITIONS)) 736 737 #define IS_LPTIM_CLOCK_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING) || \ 738 ((__POLARITY__) == LPTIM_CLOCKPOLARITY_FALLING) || \ 739 ((__POLARITY__) == LPTIM_CLOCKPOLARITY_RISING_FALLING)) 740 741 #define IS_LPTIM_TRG_SOURCE(__TRIG__) (((__TRIG__) == LPTIM_TRIGSOURCE_SOFTWARE) || \ 742 ((__TRIG__) == LPTIM_TRIGSOURCE_0) || \ 743 ((__TRIG__) == LPTIM_TRIGSOURCE_1) || \ 744 ((__TRIG__) == LPTIM_TRIGSOURCE_2) || \ 745 ((__TRIG__) == LPTIM_TRIGSOURCE_3) || \ 746 ((__TRIG__) == LPTIM_TRIGSOURCE_4) || \ 747 ((__TRIG__) == LPTIM_TRIGSOURCE_5) || \ 748 ((__TRIG__) == LPTIM_TRIGSOURCE_6) || \ 749 ((__TRIG__) == LPTIM_TRIGSOURCE_7)) 750 751 #define IS_LPTIM_EXT_TRG_POLARITY(__POLARITY__) (((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING ) || \ 752 ((__POLARITY__) == LPTIM_ACTIVEEDGE_FALLING ) || \ 753 ((__POLARITY__) == LPTIM_ACTIVEEDGE_RISING_FALLING )) 754 755 #define IS_LPTIM_TRIG_SAMPLE_TIME(__SAMPLETIME__) (((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_DIRECTTRANSITION) || \ 756 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_2TRANSITIONS ) || \ 757 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_4TRANSITIONS ) || \ 758 ((__SAMPLETIME__) == LPTIM_TRIGSAMPLETIME_8TRANSITIONS )) 759 760 #define IS_LPTIM_UPDATE_MODE(__MODE__) (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \ 761 ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD)) 762 763 #define IS_LPTIM_COUNTER_SOURCE(__SOURCE__) (((__SOURCE__) == LPTIM_COUNTERSOURCE_INTERNAL) || \ 764 ((__SOURCE__) == LPTIM_COUNTERSOURCE_EXTERNAL)) 765 766 #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__) ((0x00000001UL <= (__AUTORELOAD__)) &&\ 767 ((__AUTORELOAD__) <= 0x0000FFFFUL)) 768 769 #define IS_LPTIM_COMPARE(__COMPARE__) ((__COMPARE__) <= 0x0000FFFFUL) 770 771 #define IS_LPTIM_PERIOD(__PERIOD__) ((0x00000001UL <= (__PERIOD__)) &&\ 772 ((__PERIOD__) <= 0x0000FFFFUL)) 773 774 #define IS_LPTIM_PULSE(__PULSE__) ((__PULSE__) <= 0x0000FFFFUL) 775 776 #if defined(COMP1) 777 #if defined(COMP2) 778 #define IS_LPTIM_INPUT1_SOURCE(__INSTANCE__, __SOURCE__) \ 779 ((((__INSTANCE__) == LPTIM1) && \ 780 (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) || \ 781 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1))) \ 782 || \ 783 (((__INSTANCE__) == LPTIM2) && \ 784 (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) || \ 785 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1) || \ 786 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP2) || \ 787 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1_COMP2)))) 788 #else 789 #define IS_LPTIM_INPUT1_SOURCE(__INSTANCE__, __SOURCE__) \ 790 ((((__INSTANCE__) == LPTIM1) && \ 791 (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) || \ 792 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1))) \ 793 || \ 794 (((__INSTANCE__) == LPTIM2) && \ 795 (((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) || \ 796 ((__SOURCE__) == LPTIM_INPUT1SOURCE_COMP1)))) 797 #endif /* COMP2 */ 798 #else 799 #define IS_LPTIM_INPUT1_SOURCE(__INSTANCE__, __SOURCE__) \ 800 ((((__INSTANCE__) == LPTIM1) && \ 801 ((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO) ) \ 802 || \ 803 (((__INSTANCE__) == LPTIM2) && \ 804 ((__SOURCE__) == LPTIM_INPUT1SOURCE_GPIO))) 805 #endif /* COMP1*/ 806 807 #if defined(COMP2) 808 #define IS_LPTIM_INPUT2_SOURCE(__INSTANCE__, __SOURCE__) \ 809 (((__INSTANCE__) == LPTIM1) && \ 810 (((__SOURCE__) == LPTIM_INPUT2SOURCE_GPIO) || \ 811 ((__SOURCE__) == LPTIM_INPUT2SOURCE_COMP2))) 812 #else 813 #define IS_LPTIM_INPUT2_SOURCE(__INSTANCE__, __SOURCE__) \ 814 (((__INSTANCE__) == LPTIM1) && \ 815 (((__SOURCE__) == LPTIM_INPUT2SOURCE_GPIO))) 816 #endif 817 818 /** 819 * @} 820 */ 821 822 /* Private functions ---------------------------------------------------------*/ 823 /** @defgroup LPTIM_Private_Functions LPTIM Private Functions 824 * @{ 825 */ 826 void LPTIM_Disable(LPTIM_HandleTypeDef *hlptim); 827 /** 828 * @} 829 */ 830 831 /** 832 * @} 833 */ 834 835 #endif /* LPTIM1 || LPTIM2 */ 836 /** 837 * @} 838 */ 839 840 #ifdef __cplusplus 841 } 842 #endif 843 844 #endif /* STM32WBxx_HAL_LPTIM_H */ 845