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