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.
 
 
 

842 lines
36 KiB

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