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.
 
 
 

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