You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

811 lines
35 KiB

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