Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

1382 linhas
50 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_lptim.h
  4. * @author MCD Application Team
  5. * @brief Header file of LPTIM LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 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 STM32F4xx_LL_LPTIM_H
  21. #define STM32F4xx_LL_LPTIM_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx.h"
  27. /** @addtogroup STM32F4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (LPTIM1)
  31. /** @defgroup LPTIM_LL LPTIM
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. #if defined(USE_FULL_LL_DRIVER)
  39. /** @defgroup LPTIM_LL_Private_Macros LPTIM Private Macros
  40. * @{
  41. */
  42. /**
  43. * @}
  44. */
  45. #endif /*USE_FULL_LL_DRIVER*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup LPTIM_LL_ES_INIT LPTIM Exported Init structure
  49. * @{
  50. */
  51. /**
  52. * @brief LPTIM Init structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t ClockSource; /*!< Specifies the source of the clock used by the LPTIM instance.
  57. This parameter can be a value of @ref LPTIM_LL_EC_CLK_SOURCE.
  58. This feature can be modified afterwards using unitary
  59. function @ref LL_LPTIM_SetClockSource().*/
  60. uint32_t Prescaler; /*!< Specifies the prescaler division ratio.
  61. This parameter can be a value of @ref LPTIM_LL_EC_PRESCALER.
  62. This feature can be modified afterwards using using unitary
  63. function @ref LL_LPTIM_SetPrescaler().*/
  64. uint32_t Waveform; /*!< Specifies the waveform shape.
  65. This parameter can be a value of @ref LPTIM_LL_EC_OUTPUT_WAVEFORM.
  66. This feature can be modified afterwards using unitary
  67. function @ref LL_LPTIM_ConfigOutput().*/
  68. uint32_t Polarity; /*!< Specifies waveform polarity.
  69. This parameter can be a value of @ref LPTIM_LL_EC_OUTPUT_POLARITY.
  70. This feature can be modified afterwards using unitary
  71. function @ref LL_LPTIM_ConfigOutput().*/
  72. } LL_LPTIM_InitTypeDef;
  73. /**
  74. * @}
  75. */
  76. #endif /* USE_FULL_LL_DRIVER */
  77. /* Exported constants --------------------------------------------------------*/
  78. /** @defgroup LPTIM_LL_Exported_Constants LPTIM Exported Constants
  79. * @{
  80. */
  81. /** @defgroup LPTIM_LL_EC_GET_FLAG Get Flags Defines
  82. * @brief Flags defines which can be used with LL_LPTIM_ReadReg function
  83. * @{
  84. */
  85. #define LL_LPTIM_ISR_CMPM LPTIM_ISR_CMPM /*!< Compare match */
  86. #define LL_LPTIM_ISR_CMPOK LPTIM_ISR_CMPOK /*!< Compare register update OK */
  87. #define LL_LPTIM_ISR_ARRM LPTIM_ISR_ARRM /*!< Autoreload match */
  88. #define LL_LPTIM_ISR_EXTTRIG LPTIM_ISR_EXTTRIG /*!< External trigger edge event */
  89. #define LL_LPTIM_ISR_ARROK LPTIM_ISR_ARROK /*!< Autoreload register update OK */
  90. #define LL_LPTIM_ISR_UP LPTIM_ISR_UP /*!< Counter direction change down to up */
  91. #define LL_LPTIM_ISR_DOWN LPTIM_ISR_DOWN /*!< Counter direction change up to down */
  92. /**
  93. * @}
  94. */
  95. /** @defgroup LPTIM_LL_EC_IT IT Defines
  96. * @brief IT defines which can be used with LL_LPTIM_ReadReg and LL_LPTIM_WriteReg functions
  97. * @{
  98. */
  99. #define LL_LPTIM_IER_CMPMIE LPTIM_IER_CMPMIE /*!< Compare match */
  100. #define LL_LPTIM_IER_CMPOKIE LPTIM_IER_CMPOKIE /*!< Compare register update OK */
  101. #define LL_LPTIM_IER_ARRMIE LPTIM_IER_ARRMIE /*!< Autoreload match */
  102. #define LL_LPTIM_IER_EXTTRIGIE LPTIM_IER_EXTTRIGIE /*!< External trigger edge event */
  103. #define LL_LPTIM_IER_ARROKIE LPTIM_IER_ARROKIE /*!< Autoreload register update OK */
  104. #define LL_LPTIM_IER_UPIE LPTIM_IER_UPIE /*!< Counter direction change down to up */
  105. #define LL_LPTIM_IER_DOWNIE LPTIM_IER_DOWNIE /*!< Counter direction change up to down */
  106. /**
  107. * @}
  108. */
  109. /** @defgroup LPTIM_LL_EC_OPERATING_MODE Operating Mode
  110. * @{
  111. */
  112. #define LL_LPTIM_OPERATING_MODE_CONTINUOUS LPTIM_CR_CNTSTRT /*!<LP Timer starts in continuous mode*/
  113. #define LL_LPTIM_OPERATING_MODE_ONESHOT LPTIM_CR_SNGSTRT /*!<LP Tilmer starts in single mode*/
  114. /**
  115. * @}
  116. */
  117. /** @defgroup LPTIM_LL_EC_UPDATE_MODE Update Mode
  118. * @{
  119. */
  120. #define LL_LPTIM_UPDATE_MODE_IMMEDIATE 0x00000000U /*!<Preload is disabled: registers are updated after each APB bus write access*/
  121. #define LL_LPTIM_UPDATE_MODE_ENDOFPERIOD LPTIM_CFGR_PRELOAD /*!<preload is enabled: registers are updated at the end of the current LPTIM period*/
  122. /**
  123. * @}
  124. */
  125. /** @defgroup LPTIM_LL_EC_COUNTER_MODE Counter Mode
  126. * @{
  127. */
  128. #define LL_LPTIM_COUNTER_MODE_INTERNAL 0x00000000U /*!<The counter is incremented following each internal clock pulse*/
  129. #define LL_LPTIM_COUNTER_MODE_EXTERNAL LPTIM_CFGR_COUNTMODE /*!<The counter is incremented following each valid clock pulse on the LPTIM external Input1*/
  130. /**
  131. * @}
  132. */
  133. /** @defgroup LPTIM_LL_EC_OUTPUT_WAVEFORM Output Waveform Type
  134. * @{
  135. */
  136. #define LL_LPTIM_OUTPUT_WAVEFORM_PWM 0x00000000U /*!<LPTIM generates either a PWM waveform or a One pulse waveform depending on chosen operating mode CONTINUOUS or SINGLE*/
  137. #define LL_LPTIM_OUTPUT_WAVEFORM_SETONCE LPTIM_CFGR_WAVE /*!<LPTIM generates a Set Once waveform*/
  138. /**
  139. * @}
  140. */
  141. /** @defgroup LPTIM_LL_EC_OUTPUT_POLARITY Output Polarity
  142. * @{
  143. */
  144. #define LL_LPTIM_OUTPUT_POLARITY_REGULAR 0x00000000U /*!<The LPTIM output reflects the compare results between LPTIMx_ARR and LPTIMx_CMP registers*/
  145. #define LL_LPTIM_OUTPUT_POLARITY_INVERSE LPTIM_CFGR_WAVPOL /*!<The LPTIM output reflects the inverse of the compare results between LPTIMx_ARR and LPTIMx_CMP registers*/
  146. /**
  147. * @}
  148. */
  149. /** @defgroup LPTIM_LL_EC_PRESCALER Prescaler Value
  150. * @{
  151. */
  152. #define LL_LPTIM_PRESCALER_DIV1 0x00000000U /*!<Prescaler division factor is set to 1*/
  153. #define LL_LPTIM_PRESCALER_DIV2 LPTIM_CFGR_PRESC_0 /*!<Prescaler division factor is set to 2*/
  154. #define LL_LPTIM_PRESCALER_DIV4 LPTIM_CFGR_PRESC_1 /*!<Prescaler division factor is set to 4*/
  155. #define LL_LPTIM_PRESCALER_DIV8 (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_0) /*!<Prescaler division factor is set to 8*/
  156. #define LL_LPTIM_PRESCALER_DIV16 LPTIM_CFGR_PRESC_2 /*!<Prescaler division factor is set to 16*/
  157. #define LL_LPTIM_PRESCALER_DIV32 (LPTIM_CFGR_PRESC_2 | LPTIM_CFGR_PRESC_0) /*!<Prescaler division factor is set to 32*/
  158. #define LL_LPTIM_PRESCALER_DIV64 (LPTIM_CFGR_PRESC_2 | LPTIM_CFGR_PRESC_1) /*!<Prescaler division factor is set to 64*/
  159. #define LL_LPTIM_PRESCALER_DIV128 LPTIM_CFGR_PRESC /*!<Prescaler division factor is set to 128*/
  160. /**
  161. * @}
  162. */
  163. /** @defgroup LPTIM_LL_EC_TRIG_SOURCE Trigger Source
  164. * @{
  165. */
  166. #define LL_LPTIM_TRIG_SOURCE_GPIO 0x00000000U /*!<External input trigger is connected to TIMx_ETR input*/
  167. #define LL_LPTIM_TRIG_SOURCE_RTCALARMA LPTIM_CFGR_TRIGSEL_0 /*!<External input trigger is connected to RTC Alarm A*/
  168. #define LL_LPTIM_TRIG_SOURCE_RTCALARMB LPTIM_CFGR_TRIGSEL_1 /*!<External input trigger is connected to RTC Alarm B*/
  169. #define LL_LPTIM_TRIG_SOURCE_RTCTAMP1 (LPTIM_CFGR_TRIGSEL_1 | LPTIM_CFGR_TRIGSEL_0) /*!<External input trigger is connected to RTC Tamper 1*/
  170. #define LL_LPTIM_TRIG_SOURCE_TIM1_TRGO LPTIM_CFGR_TRIGSEL_2 /*!<External input trigger is connected to TIM1*/
  171. #define LL_LPTIM_TRIG_SOURCE_TIM5_TRGO (LPTIM_CFGR_TRIGSEL_2 | LPTIM_CFGR_TRIGSEL_0) /*!<External input trigger is connected to TIM5*/
  172. /**
  173. * @}
  174. */
  175. /** @defgroup LPTIM_LL_EC_TRIG_FILTER Trigger Filter
  176. * @{
  177. */
  178. #define LL_LPTIM_TRIG_FILTER_NONE 0x00000000U /*!<Any trigger active level change is considered as a valid trigger*/
  179. #define LL_LPTIM_TRIG_FILTER_2 LPTIM_CFGR_TRGFLT_0 /*!<Trigger active level change must be stable for at least 2 clock periods before it is considered as valid trigger*/
  180. #define LL_LPTIM_TRIG_FILTER_4 LPTIM_CFGR_TRGFLT_1 /*!<Trigger active level change must be stable for at least 4 clock periods before it is considered as valid trigger*/
  181. #define LL_LPTIM_TRIG_FILTER_8 LPTIM_CFGR_TRGFLT /*!<Trigger active level change must be stable for at least 8 clock periods before it is considered as valid trigger*/
  182. /**
  183. * @}
  184. */
  185. /** @defgroup LPTIM_LL_EC_TRIG_POLARITY Trigger Polarity
  186. * @{
  187. */
  188. #define LL_LPTIM_TRIG_POLARITY_RISING LPTIM_CFGR_TRIGEN_0 /*!<LPTIM counter starts when a rising edge is detected*/
  189. #define LL_LPTIM_TRIG_POLARITY_FALLING LPTIM_CFGR_TRIGEN_1 /*!<LPTIM counter starts when a falling edge is detected*/
  190. #define LL_LPTIM_TRIG_POLARITY_RISING_FALLING LPTIM_CFGR_TRIGEN /*!<LPTIM counter starts when a rising or a falling edge is detected*/
  191. /**
  192. * @}
  193. */
  194. /** @defgroup LPTIM_LL_EC_CLK_SOURCE Clock Source
  195. * @{
  196. */
  197. #define LL_LPTIM_CLK_SOURCE_INTERNAL 0x00000000U /*!<LPTIM is clocked by internal clock source (APB clock or any of the embedded oscillators)*/
  198. #define LL_LPTIM_CLK_SOURCE_EXTERNAL LPTIM_CFGR_CKSEL /*!<LPTIM is clocked by an external clock source through the LPTIM external Input1*/
  199. /**
  200. * @}
  201. */
  202. /** @defgroup LPTIM_LL_EC_CLK_FILTER Clock Filter
  203. * @{
  204. */
  205. #define LL_LPTIM_CLK_FILTER_NONE 0x00000000U /*!<Any external clock signal level change is considered as a valid transition*/
  206. #define LL_LPTIM_CLK_FILTER_2 LPTIM_CFGR_CKFLT_0 /*!<External clock signal level change must be stable for at least 2 clock periods before it is considered as valid transition*/
  207. #define LL_LPTIM_CLK_FILTER_4 LPTIM_CFGR_CKFLT_1 /*!<External clock signal level change must be stable for at least 4 clock periods before it is considered as valid transition*/
  208. #define LL_LPTIM_CLK_FILTER_8 LPTIM_CFGR_CKFLT /*!<External clock signal level change must be stable for at least 8 clock periods before it is considered as valid transition*/
  209. /**
  210. * @}
  211. */
  212. /** @defgroup LPTIM_LL_EC_CLK_POLARITY Clock Polarity
  213. * @{
  214. */
  215. #define LL_LPTIM_CLK_POLARITY_RISING 0x00000000U /*!< The rising edge is the active edge used for counting*/
  216. #define LL_LPTIM_CLK_POLARITY_FALLING LPTIM_CFGR_CKPOL_0 /*!< The falling edge is the active edge used for counting*/
  217. #define LL_LPTIM_CLK_POLARITY_RISING_FALLING LPTIM_CFGR_CKPOL_1 /*!< Both edges are active edges*/
  218. /**
  219. * @}
  220. */
  221. /** @defgroup LPTIM_LL_EC_ENCODER_MODE Encoder Mode
  222. * @{
  223. */
  224. #define LL_LPTIM_ENCODER_MODE_RISING 0x00000000U /*!< The rising edge is the active edge used for counting*/
  225. #define LL_LPTIM_ENCODER_MODE_FALLING LPTIM_CFGR_CKPOL_0 /*!< The falling edge is the active edge used for counting*/
  226. #define LL_LPTIM_ENCODER_MODE_RISING_FALLING LPTIM_CFGR_CKPOL_1 /*!< Both edges are active edges*/
  227. /**
  228. * @}
  229. */
  230. /** @defgroup LPTIM_EC_INPUT1_SRC Input1 Source
  231. * @{
  232. */
  233. #define LL_LPTIM_INPUT1_SRC_PAD_AF 0x00000000U
  234. #define LL_LPTIM_INPUT1_SRC_PAD_PA4 LPTIM_OR_OR_0
  235. #define LL_LPTIM_INPUT1_SRC_PAD_PB9 LPTIM_OR_OR_1
  236. #define LL_LPTIM_INPUT1_SRC_TIM_DAC LPTIM_OR_OR
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /* Exported macro ------------------------------------------------------------*/
  244. /** @defgroup LPTIM_LL_Exported_Macros LPTIM Exported Macros
  245. * @{
  246. */
  247. /** @defgroup LPTIM_LL_EM_WRITE_READ Common Write and read registers Macros
  248. * @{
  249. */
  250. /**
  251. * @brief Write a value in LPTIM register
  252. * @param __INSTANCE__ LPTIM Instance
  253. * @param __REG__ Register to be written
  254. * @param __VALUE__ Value to be written in the register
  255. * @retval None
  256. */
  257. #define LL_LPTIM_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  258. /**
  259. * @brief Read a value in LPTIM register
  260. * @param __INSTANCE__ LPTIM Instance
  261. * @param __REG__ Register to be read
  262. * @retval Register value
  263. */
  264. #define LL_LPTIM_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  265. /**
  266. * @}
  267. */
  268. /**
  269. * @}
  270. */
  271. /* Exported functions --------------------------------------------------------*/
  272. /** @defgroup LPTIM_LL_Exported_Functions LPTIM Exported Functions
  273. * @{
  274. */
  275. #if defined(USE_FULL_LL_DRIVER)
  276. /** @defgroup LPTIM_LL_EF_Init Initialisation and deinitialisation functions
  277. * @{
  278. */
  279. ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx);
  280. void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct);
  281. ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct);
  282. void LL_LPTIM_Disable(LPTIM_TypeDef *LPTIMx);
  283. /**
  284. * @}
  285. */
  286. #endif /* USE_FULL_LL_DRIVER */
  287. /** @defgroup LPTIM_LL_EF_LPTIM_Configuration LPTIM Configuration
  288. * @{
  289. */
  290. /**
  291. * @brief Enable the LPTIM instance
  292. * @note After setting the ENABLE bit, a delay of two counter clock is needed
  293. * before the LPTIM instance is actually enabled.
  294. * @rmtoll CR ENABLE LL_LPTIM_Enable
  295. * @param LPTIMx Low-Power Timer instance
  296. * @retval None
  297. */
  298. __STATIC_INLINE void LL_LPTIM_Enable(LPTIM_TypeDef *LPTIMx)
  299. {
  300. SET_BIT(LPTIMx->CR, LPTIM_CR_ENABLE);
  301. }
  302. /**
  303. * @brief Indicates whether the LPTIM instance is enabled.
  304. * @rmtoll CR ENABLE LL_LPTIM_IsEnabled
  305. * @param LPTIMx Low-Power Timer instance
  306. * @retval State of bit (1 or 0).
  307. */
  308. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabled(LPTIM_TypeDef *LPTIMx)
  309. {
  310. return (((READ_BIT(LPTIMx->CR, LPTIM_CR_ENABLE) == LPTIM_CR_ENABLE) ? 1UL : 0UL));
  311. }
  312. /**
  313. * @brief Starts the LPTIM counter in the desired mode.
  314. * @note LPTIM instance must be enabled before starting the counter.
  315. * @note It is possible to change on the fly from One Shot mode to
  316. * Continuous mode.
  317. * @rmtoll CR CNTSTRT LL_LPTIM_StartCounter\n
  318. * CR SNGSTRT LL_LPTIM_StartCounter
  319. * @param LPTIMx Low-Power Timer instance
  320. * @param OperatingMode This parameter can be one of the following values:
  321. * @arg @ref LL_LPTIM_OPERATING_MODE_CONTINUOUS
  322. * @arg @ref LL_LPTIM_OPERATING_MODE_ONESHOT
  323. * @retval None
  324. */
  325. __STATIC_INLINE void LL_LPTIM_StartCounter(LPTIM_TypeDef *LPTIMx, uint32_t OperatingMode)
  326. {
  327. MODIFY_REG(LPTIMx->CR, LPTIM_CR_CNTSTRT | LPTIM_CR_SNGSTRT, OperatingMode);
  328. }
  329. /**
  330. * @brief Set the LPTIM registers update mode (enable/disable register preload)
  331. * @note This function must be called when the LPTIM instance is disabled.
  332. * @rmtoll CFGR PRELOAD LL_LPTIM_SetUpdateMode
  333. * @param LPTIMx Low-Power Timer instance
  334. * @param UpdateMode This parameter can be one of the following values:
  335. * @arg @ref LL_LPTIM_UPDATE_MODE_IMMEDIATE
  336. * @arg @ref LL_LPTIM_UPDATE_MODE_ENDOFPERIOD
  337. * @retval None
  338. */
  339. __STATIC_INLINE void LL_LPTIM_SetUpdateMode(LPTIM_TypeDef *LPTIMx, uint32_t UpdateMode)
  340. {
  341. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_PRELOAD, UpdateMode);
  342. }
  343. /**
  344. * @brief Get the LPTIM registers update mode
  345. * @rmtoll CFGR PRELOAD LL_LPTIM_GetUpdateMode
  346. * @param LPTIMx Low-Power Timer instance
  347. * @retval Returned value can be one of the following values:
  348. * @arg @ref LL_LPTIM_UPDATE_MODE_IMMEDIATE
  349. * @arg @ref LL_LPTIM_UPDATE_MODE_ENDOFPERIOD
  350. */
  351. __STATIC_INLINE uint32_t LL_LPTIM_GetUpdateMode(LPTIM_TypeDef *LPTIMx)
  352. {
  353. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_PRELOAD));
  354. }
  355. /**
  356. * @brief Set the auto reload value
  357. * @note The LPTIMx_ARR register content must only be modified when the LPTIM is enabled
  358. * @note After a write to the LPTIMx_ARR register a new write operation to the
  359. * same register can only be performed when the previous write operation
  360. * is completed. Any successive write before the ARROK flag is set, will
  361. * lead to unpredictable results.
  362. * @note autoreload value be strictly greater than the compare value.
  363. * @rmtoll ARR ARR LL_LPTIM_SetAutoReload
  364. * @param LPTIMx Low-Power Timer instance
  365. * @param AutoReload Value between Min_Data=0x00 and Max_Data=0xFFFF
  366. * @retval None
  367. */
  368. __STATIC_INLINE void LL_LPTIM_SetAutoReload(LPTIM_TypeDef *LPTIMx, uint32_t AutoReload)
  369. {
  370. MODIFY_REG(LPTIMx->ARR, LPTIM_ARR_ARR, AutoReload);
  371. }
  372. /**
  373. * @brief Get actual auto reload value
  374. * @rmtoll ARR ARR LL_LPTIM_GetAutoReload
  375. * @param LPTIMx Low-Power Timer instance
  376. * @retval AutoReload Value between Min_Data=0x00 and Max_Data=0xFFFF
  377. */
  378. __STATIC_INLINE uint32_t LL_LPTIM_GetAutoReload(LPTIM_TypeDef *LPTIMx)
  379. {
  380. return (uint32_t)(READ_BIT(LPTIMx->ARR, LPTIM_ARR_ARR));
  381. }
  382. /**
  383. * @brief Set the compare value
  384. * @note After a write to the LPTIMx_CMP register a new write operation to the
  385. * same register can only be performed when the previous write operation
  386. * is completed. Any successive write before the CMPOK flag is set, will
  387. * lead to unpredictable results.
  388. * @rmtoll CMP CMP LL_LPTIM_SetCompare
  389. * @param LPTIMx Low-Power Timer instance
  390. * @param CompareValue Value between Min_Data=0x00 and Max_Data=0xFFFF
  391. * @retval None
  392. */
  393. __STATIC_INLINE void LL_LPTIM_SetCompare(LPTIM_TypeDef *LPTIMx, uint32_t CompareValue)
  394. {
  395. MODIFY_REG(LPTIMx->CMP, LPTIM_CMP_CMP, CompareValue);
  396. }
  397. /**
  398. * @brief Get actual compare value
  399. * @rmtoll CMP CMP LL_LPTIM_GetCompare
  400. * @param LPTIMx Low-Power Timer instance
  401. * @retval CompareValue Value between Min_Data=0x00 and Max_Data=0xFFFF
  402. */
  403. __STATIC_INLINE uint32_t LL_LPTIM_GetCompare(LPTIM_TypeDef *LPTIMx)
  404. {
  405. return (uint32_t)(READ_BIT(LPTIMx->CMP, LPTIM_CMP_CMP));
  406. }
  407. /**
  408. * @brief Get actual counter value
  409. * @note When the LPTIM instance is running with an asynchronous clock, reading
  410. * the LPTIMx_CNT register may return unreliable values. So in this case
  411. * it is necessary to perform two consecutive read accesses and verify
  412. * that the two returned values are identical.
  413. * @rmtoll CNT CNT LL_LPTIM_GetCounter
  414. * @param LPTIMx Low-Power Timer instance
  415. * @retval Counter value
  416. */
  417. __STATIC_INLINE uint32_t LL_LPTIM_GetCounter(LPTIM_TypeDef *LPTIMx)
  418. {
  419. return (uint32_t)(READ_BIT(LPTIMx->CNT, LPTIM_CNT_CNT));
  420. }
  421. /**
  422. * @brief Set the counter mode (selection of the LPTIM counter clock source).
  423. * @note The counter mode can be set only when the LPTIM instance is disabled.
  424. * @rmtoll CFGR COUNTMODE LL_LPTIM_SetCounterMode
  425. * @param LPTIMx Low-Power Timer instance
  426. * @param CounterMode This parameter can be one of the following values:
  427. * @arg @ref LL_LPTIM_COUNTER_MODE_INTERNAL
  428. * @arg @ref LL_LPTIM_COUNTER_MODE_EXTERNAL
  429. * @retval None
  430. */
  431. __STATIC_INLINE void LL_LPTIM_SetCounterMode(LPTIM_TypeDef *LPTIMx, uint32_t CounterMode)
  432. {
  433. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_COUNTMODE, CounterMode);
  434. }
  435. /**
  436. * @brief Get the counter mode
  437. * @rmtoll CFGR COUNTMODE LL_LPTIM_GetCounterMode
  438. * @param LPTIMx Low-Power Timer instance
  439. * @retval Returned value can be one of the following values:
  440. * @arg @ref LL_LPTIM_COUNTER_MODE_INTERNAL
  441. * @arg @ref LL_LPTIM_COUNTER_MODE_EXTERNAL
  442. */
  443. __STATIC_INLINE uint32_t LL_LPTIM_GetCounterMode(LPTIM_TypeDef *LPTIMx)
  444. {
  445. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_COUNTMODE));
  446. }
  447. /**
  448. * @brief Configure the LPTIM instance output (LPTIMx_OUT)
  449. * @note This function must be called when the LPTIM instance is disabled.
  450. * @note Regarding the LPTIM output polarity the change takes effect
  451. * immediately, so the output default value will change immediately after
  452. * the polarity is re-configured, even before the timer is enabled.
  453. * @rmtoll CFGR WAVE LL_LPTIM_ConfigOutput\n
  454. * CFGR WAVPOL LL_LPTIM_ConfigOutput
  455. * @param LPTIMx Low-Power Timer instance
  456. * @param Waveform This parameter can be one of the following values:
  457. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_PWM
  458. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_SETONCE
  459. * @param Polarity This parameter can be one of the following values:
  460. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_REGULAR
  461. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_INVERSE
  462. * @retval None
  463. */
  464. __STATIC_INLINE void LL_LPTIM_ConfigOutput(LPTIM_TypeDef *LPTIMx, uint32_t Waveform, uint32_t Polarity)
  465. {
  466. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_WAVE | LPTIM_CFGR_WAVPOL, Waveform | Polarity);
  467. }
  468. /**
  469. * @brief Set waveform shape
  470. * @rmtoll CFGR WAVE LL_LPTIM_SetWaveform
  471. * @param LPTIMx Low-Power Timer instance
  472. * @param Waveform This parameter can be one of the following values:
  473. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_PWM
  474. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_SETONCE
  475. * @retval None
  476. */
  477. __STATIC_INLINE void LL_LPTIM_SetWaveform(LPTIM_TypeDef *LPTIMx, uint32_t Waveform)
  478. {
  479. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_WAVE, Waveform);
  480. }
  481. /**
  482. * @brief Get actual waveform shape
  483. * @rmtoll CFGR WAVE LL_LPTIM_GetWaveform
  484. * @param LPTIMx Low-Power Timer instance
  485. * @retval Returned value can be one of the following values:
  486. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_PWM
  487. * @arg @ref LL_LPTIM_OUTPUT_WAVEFORM_SETONCE
  488. */
  489. __STATIC_INLINE uint32_t LL_LPTIM_GetWaveform(LPTIM_TypeDef *LPTIMx)
  490. {
  491. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_WAVE));
  492. }
  493. /**
  494. * @brief Set output polarity
  495. * @rmtoll CFGR WAVPOL LL_LPTIM_SetPolarity
  496. * @param LPTIMx Low-Power Timer instance
  497. * @param Polarity This parameter can be one of the following values:
  498. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_REGULAR
  499. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_INVERSE
  500. * @retval None
  501. */
  502. __STATIC_INLINE void LL_LPTIM_SetPolarity(LPTIM_TypeDef *LPTIMx, uint32_t Polarity)
  503. {
  504. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_WAVPOL, Polarity);
  505. }
  506. /**
  507. * @brief Get actual output polarity
  508. * @rmtoll CFGR WAVPOL LL_LPTIM_GetPolarity
  509. * @param LPTIMx Low-Power Timer instance
  510. * @retval Returned value can be one of the following values:
  511. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_REGULAR
  512. * @arg @ref LL_LPTIM_OUTPUT_POLARITY_INVERSE
  513. */
  514. __STATIC_INLINE uint32_t LL_LPTIM_GetPolarity(LPTIM_TypeDef *LPTIMx)
  515. {
  516. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_WAVPOL));
  517. }
  518. /**
  519. * @brief Set actual prescaler division ratio.
  520. * @note This function must be called when the LPTIM instance is disabled.
  521. * @note When the LPTIM is configured to be clocked by an internal clock source
  522. * and the LPTIM counter is configured to be updated by active edges
  523. * detected on the LPTIM external Input1, the internal clock provided to
  524. * the LPTIM must be not be prescaled.
  525. * @rmtoll CFGR PRESC LL_LPTIM_SetPrescaler
  526. * @param LPTIMx Low-Power Timer instance
  527. * @param Prescaler This parameter can be one of the following values:
  528. * @arg @ref LL_LPTIM_PRESCALER_DIV1
  529. * @arg @ref LL_LPTIM_PRESCALER_DIV2
  530. * @arg @ref LL_LPTIM_PRESCALER_DIV4
  531. * @arg @ref LL_LPTIM_PRESCALER_DIV8
  532. * @arg @ref LL_LPTIM_PRESCALER_DIV16
  533. * @arg @ref LL_LPTIM_PRESCALER_DIV32
  534. * @arg @ref LL_LPTIM_PRESCALER_DIV64
  535. * @arg @ref LL_LPTIM_PRESCALER_DIV128
  536. * @retval None
  537. */
  538. __STATIC_INLINE void LL_LPTIM_SetPrescaler(LPTIM_TypeDef *LPTIMx, uint32_t Prescaler)
  539. {
  540. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_PRESC, Prescaler);
  541. }
  542. /**
  543. * @brief Get actual prescaler division ratio.
  544. * @rmtoll CFGR PRESC LL_LPTIM_GetPrescaler
  545. * @param LPTIMx Low-Power Timer instance
  546. * @retval Returned value can be one of the following values:
  547. * @arg @ref LL_LPTIM_PRESCALER_DIV1
  548. * @arg @ref LL_LPTIM_PRESCALER_DIV2
  549. * @arg @ref LL_LPTIM_PRESCALER_DIV4
  550. * @arg @ref LL_LPTIM_PRESCALER_DIV8
  551. * @arg @ref LL_LPTIM_PRESCALER_DIV16
  552. * @arg @ref LL_LPTIM_PRESCALER_DIV32
  553. * @arg @ref LL_LPTIM_PRESCALER_DIV64
  554. * @arg @ref LL_LPTIM_PRESCALER_DIV128
  555. */
  556. __STATIC_INLINE uint32_t LL_LPTIM_GetPrescaler(LPTIM_TypeDef *LPTIMx)
  557. {
  558. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_PRESC));
  559. }
  560. /**
  561. * @brief Set LPTIM input 1 source (default GPIO).
  562. * @rmtoll OR OR LL_LPTIM_SetInput1Src
  563. * @param LPTIMx Low-Power Timer instance
  564. * @param Src This parameter can be one of the following values:
  565. * @arg @ref LL_LPTIM_INPUT1_SRC_PAD_AF
  566. * @arg @ref LL_LPTIM_INPUT1_SRC_PAD_PA4
  567. * @arg @ref LL_LPTIM_INPUT1_SRC_PAD_PB9
  568. * @arg @ref LL_LPTIM_INPUT1_SRC_TIM_DAC
  569. * @retval None
  570. */
  571. __STATIC_INLINE void LL_LPTIM_SetInput1Src(LPTIM_TypeDef *LPTIMx, uint32_t Src)
  572. {
  573. MODIFY_REG(LPTIMx->OR, LPTIM_OR_OR, Src);
  574. }
  575. /**
  576. * @}
  577. */
  578. /** @defgroup LPTIM_LL_EF_Trigger_Configuration Trigger Configuration
  579. * @{
  580. */
  581. /**
  582. * @brief Enable the timeout function
  583. * @note This function must be called when the LPTIM instance is disabled.
  584. * @note The first trigger event will start the timer, any successive trigger
  585. * event will reset the counter and the timer will restart.
  586. * @note The timeout value corresponds to the compare value; if no trigger
  587. * occurs within the expected time frame, the MCU is waked-up by the
  588. * compare match event.
  589. * @rmtoll CFGR TIMOUT LL_LPTIM_EnableTimeout
  590. * @param LPTIMx Low-Power Timer instance
  591. * @retval None
  592. */
  593. __STATIC_INLINE void LL_LPTIM_EnableTimeout(LPTIM_TypeDef *LPTIMx)
  594. {
  595. SET_BIT(LPTIMx->CFGR, LPTIM_CFGR_TIMOUT);
  596. }
  597. /**
  598. * @brief Disable the timeout function
  599. * @note This function must be called when the LPTIM instance is disabled.
  600. * @note A trigger event arriving when the timer is already started will be
  601. * ignored.
  602. * @rmtoll CFGR TIMOUT LL_LPTIM_DisableTimeout
  603. * @param LPTIMx Low-Power Timer instance
  604. * @retval None
  605. */
  606. __STATIC_INLINE void LL_LPTIM_DisableTimeout(LPTIM_TypeDef *LPTIMx)
  607. {
  608. CLEAR_BIT(LPTIMx->CFGR, LPTIM_CFGR_TIMOUT);
  609. }
  610. /**
  611. * @brief Indicate whether the timeout function is enabled.
  612. * @rmtoll CFGR TIMOUT LL_LPTIM_IsEnabledTimeout
  613. * @param LPTIMx Low-Power Timer instance
  614. * @retval State of bit (1 or 0).
  615. */
  616. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledTimeout(LPTIM_TypeDef *LPTIMx)
  617. {
  618. return (((READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_TIMOUT) == LPTIM_CFGR_TIMOUT) ? 1UL : 0UL));
  619. }
  620. /**
  621. * @brief Start the LPTIM counter
  622. * @note This function must be called when the LPTIM instance is disabled.
  623. * @rmtoll CFGR TRIGEN LL_LPTIM_TrigSw
  624. * @param LPTIMx Low-Power Timer instance
  625. * @retval None
  626. */
  627. __STATIC_INLINE void LL_LPTIM_TrigSw(LPTIM_TypeDef *LPTIMx)
  628. {
  629. CLEAR_BIT(LPTIMx->CFGR, LPTIM_CFGR_TRIGEN);
  630. }
  631. /**
  632. * @brief Configure the external trigger used as a trigger event for the LPTIM.
  633. * @note This function must be called when the LPTIM instance is disabled.
  634. * @note An internal clock source must be present when a digital filter is
  635. * required for the trigger.
  636. * @rmtoll CFGR TRIGSEL LL_LPTIM_ConfigTrigger\n
  637. * CFGR TRGFLT LL_LPTIM_ConfigTrigger\n
  638. * CFGR TRIGEN LL_LPTIM_ConfigTrigger
  639. * @param LPTIMx Low-Power Timer instance
  640. * @param Source This parameter can be one of the following values:
  641. * @arg @ref LL_LPTIM_TRIG_SOURCE_GPIO
  642. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCALARMA
  643. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCALARMB
  644. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCTAMP1
  645. * @arg @ref LL_LPTIM_TRIG_SOURCE_TIM1_TRGO
  646. * @arg @ref LL_LPTIM_TRIG_SOURCE_TIM5_TRGO
  647. * @param Filter This parameter can be one of the following values:
  648. * @arg @ref LL_LPTIM_TRIG_FILTER_NONE
  649. * @arg @ref LL_LPTIM_TRIG_FILTER_2
  650. * @arg @ref LL_LPTIM_TRIG_FILTER_4
  651. * @arg @ref LL_LPTIM_TRIG_FILTER_8
  652. * @param Polarity This parameter can be one of the following values:
  653. * @arg @ref LL_LPTIM_TRIG_POLARITY_RISING
  654. * @arg @ref LL_LPTIM_TRIG_POLARITY_FALLING
  655. * @arg @ref LL_LPTIM_TRIG_POLARITY_RISING_FALLING
  656. * @retval None
  657. */
  658. __STATIC_INLINE void LL_LPTIM_ConfigTrigger(LPTIM_TypeDef *LPTIMx, uint32_t Source, uint32_t Filter, uint32_t Polarity)
  659. {
  660. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_TRIGSEL | LPTIM_CFGR_TRGFLT | LPTIM_CFGR_TRIGEN, Source | Filter | Polarity);
  661. }
  662. /**
  663. * @brief Get actual external trigger source.
  664. * @rmtoll CFGR TRIGSEL LL_LPTIM_GetTriggerSource
  665. * @param LPTIMx Low-Power Timer instance
  666. * @retval Returned value can be one of the following values:
  667. * @arg @ref LL_LPTIM_TRIG_SOURCE_GPIO
  668. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCALARMA
  669. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCALARMB
  670. * @arg @ref LL_LPTIM_TRIG_SOURCE_RTCTAMP1
  671. * @arg @ref LL_LPTIM_TRIG_SOURCE_TIM1_TRGO
  672. * @arg @ref LL_LPTIM_TRIG_SOURCE_TIM5_TRGO
  673. */
  674. __STATIC_INLINE uint32_t LL_LPTIM_GetTriggerSource(LPTIM_TypeDef *LPTIMx)
  675. {
  676. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_TRIGSEL));
  677. }
  678. /**
  679. * @brief Get actual external trigger filter.
  680. * @rmtoll CFGR TRGFLT LL_LPTIM_GetTriggerFilter
  681. * @param LPTIMx Low-Power Timer instance
  682. * @retval Returned value can be one of the following values:
  683. * @arg @ref LL_LPTIM_TRIG_FILTER_NONE
  684. * @arg @ref LL_LPTIM_TRIG_FILTER_2
  685. * @arg @ref LL_LPTIM_TRIG_FILTER_4
  686. * @arg @ref LL_LPTIM_TRIG_FILTER_8
  687. */
  688. __STATIC_INLINE uint32_t LL_LPTIM_GetTriggerFilter(LPTIM_TypeDef *LPTIMx)
  689. {
  690. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_TRGFLT));
  691. }
  692. /**
  693. * @brief Get actual external trigger polarity.
  694. * @rmtoll CFGR TRIGEN LL_LPTIM_GetTriggerPolarity
  695. * @param LPTIMx Low-Power Timer instance
  696. * @retval Returned value can be one of the following values:
  697. * @arg @ref LL_LPTIM_TRIG_POLARITY_RISING
  698. * @arg @ref LL_LPTIM_TRIG_POLARITY_FALLING
  699. * @arg @ref LL_LPTIM_TRIG_POLARITY_RISING_FALLING
  700. */
  701. __STATIC_INLINE uint32_t LL_LPTIM_GetTriggerPolarity(LPTIM_TypeDef *LPTIMx)
  702. {
  703. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_TRIGEN));
  704. }
  705. /**
  706. * @}
  707. */
  708. /** @defgroup LPTIM_LL_EF_Clock_Configuration Clock Configuration
  709. * @{
  710. */
  711. /**
  712. * @brief Set the source of the clock used by the LPTIM instance.
  713. * @note This function must be called when the LPTIM instance is disabled.
  714. * @rmtoll CFGR CKSEL LL_LPTIM_SetClockSource
  715. * @param LPTIMx Low-Power Timer instance
  716. * @param ClockSource This parameter can be one of the following values:
  717. * @arg @ref LL_LPTIM_CLK_SOURCE_INTERNAL
  718. * @arg @ref LL_LPTIM_CLK_SOURCE_EXTERNAL
  719. * @retval None
  720. */
  721. __STATIC_INLINE void LL_LPTIM_SetClockSource(LPTIM_TypeDef *LPTIMx, uint32_t ClockSource)
  722. {
  723. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_CKSEL, ClockSource);
  724. }
  725. /**
  726. * @brief Get actual LPTIM instance clock source.
  727. * @rmtoll CFGR CKSEL LL_LPTIM_GetClockSource
  728. * @param LPTIMx Low-Power Timer instance
  729. * @retval Returned value can be one of the following values:
  730. * @arg @ref LL_LPTIM_CLK_SOURCE_INTERNAL
  731. * @arg @ref LL_LPTIM_CLK_SOURCE_EXTERNAL
  732. */
  733. __STATIC_INLINE uint32_t LL_LPTIM_GetClockSource(LPTIM_TypeDef *LPTIMx)
  734. {
  735. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_CKSEL));
  736. }
  737. /**
  738. * @brief Configure the active edge or edges used by the counter when
  739. the LPTIM is clocked by an external clock source.
  740. * @note This function must be called when the LPTIM instance is disabled.
  741. * @note When both external clock signal edges are considered active ones,
  742. * the LPTIM must also be clocked by an internal clock source with a
  743. * frequency equal to at least four times the external clock frequency.
  744. * @note An internal clock source must be present when a digital filter is
  745. * required for external clock.
  746. * @rmtoll CFGR CKFLT LL_LPTIM_ConfigClock\n
  747. * CFGR CKPOL LL_LPTIM_ConfigClock
  748. * @param LPTIMx Low-Power Timer instance
  749. * @param ClockFilter This parameter can be one of the following values:
  750. * @arg @ref LL_LPTIM_CLK_FILTER_NONE
  751. * @arg @ref LL_LPTIM_CLK_FILTER_2
  752. * @arg @ref LL_LPTIM_CLK_FILTER_4
  753. * @arg @ref LL_LPTIM_CLK_FILTER_8
  754. * @param ClockPolarity This parameter can be one of the following values:
  755. * @arg @ref LL_LPTIM_CLK_POLARITY_RISING
  756. * @arg @ref LL_LPTIM_CLK_POLARITY_FALLING
  757. * @arg @ref LL_LPTIM_CLK_POLARITY_RISING_FALLING
  758. * @retval None
  759. */
  760. __STATIC_INLINE void LL_LPTIM_ConfigClock(LPTIM_TypeDef *LPTIMx, uint32_t ClockFilter, uint32_t ClockPolarity)
  761. {
  762. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_CKFLT | LPTIM_CFGR_CKPOL, ClockFilter | ClockPolarity);
  763. }
  764. /**
  765. * @brief Get actual clock polarity
  766. * @rmtoll CFGR CKPOL LL_LPTIM_GetClockPolarity
  767. * @param LPTIMx Low-Power Timer instance
  768. * @retval Returned value can be one of the following values:
  769. * @arg @ref LL_LPTIM_CLK_POLARITY_RISING
  770. * @arg @ref LL_LPTIM_CLK_POLARITY_FALLING
  771. * @arg @ref LL_LPTIM_CLK_POLARITY_RISING_FALLING
  772. */
  773. __STATIC_INLINE uint32_t LL_LPTIM_GetClockPolarity(LPTIM_TypeDef *LPTIMx)
  774. {
  775. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_CKPOL));
  776. }
  777. /**
  778. * @brief Get actual clock digital filter
  779. * @rmtoll CFGR CKFLT LL_LPTIM_GetClockFilter
  780. * @param LPTIMx Low-Power Timer instance
  781. * @retval Returned value can be one of the following values:
  782. * @arg @ref LL_LPTIM_CLK_FILTER_NONE
  783. * @arg @ref LL_LPTIM_CLK_FILTER_2
  784. * @arg @ref LL_LPTIM_CLK_FILTER_4
  785. * @arg @ref LL_LPTIM_CLK_FILTER_8
  786. */
  787. __STATIC_INLINE uint32_t LL_LPTIM_GetClockFilter(LPTIM_TypeDef *LPTIMx)
  788. {
  789. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_CKFLT));
  790. }
  791. /**
  792. * @}
  793. */
  794. /** @defgroup LPTIM_LL_EF_Encoder_Mode Encoder Mode
  795. * @{
  796. */
  797. /**
  798. * @brief Configure the encoder mode.
  799. * @note This function must be called when the LPTIM instance is disabled.
  800. * @rmtoll CFGR CKPOL LL_LPTIM_SetEncoderMode
  801. * @param LPTIMx Low-Power Timer instance
  802. * @param EncoderMode This parameter can be one of the following values:
  803. * @arg @ref LL_LPTIM_ENCODER_MODE_RISING
  804. * @arg @ref LL_LPTIM_ENCODER_MODE_FALLING
  805. * @arg @ref LL_LPTIM_ENCODER_MODE_RISING_FALLING
  806. * @retval None
  807. */
  808. __STATIC_INLINE void LL_LPTIM_SetEncoderMode(LPTIM_TypeDef *LPTIMx, uint32_t EncoderMode)
  809. {
  810. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_CKPOL, EncoderMode);
  811. }
  812. /**
  813. * @brief Get actual encoder mode.
  814. * @rmtoll CFGR CKPOL LL_LPTIM_GetEncoderMode
  815. * @param LPTIMx Low-Power Timer instance
  816. * @retval Returned value can be one of the following values:
  817. * @arg @ref LL_LPTIM_ENCODER_MODE_RISING
  818. * @arg @ref LL_LPTIM_ENCODER_MODE_FALLING
  819. * @arg @ref LL_LPTIM_ENCODER_MODE_RISING_FALLING
  820. */
  821. __STATIC_INLINE uint32_t LL_LPTIM_GetEncoderMode(LPTIM_TypeDef *LPTIMx)
  822. {
  823. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_CKPOL));
  824. }
  825. /**
  826. * @brief Enable the encoder mode
  827. * @note This function must be called when the LPTIM instance is disabled.
  828. * @note In this mode the LPTIM instance must be clocked by an internal clock
  829. * source. Also, the prescaler division ratio must be equal to 1.
  830. * @note LPTIM instance must be configured in continuous mode prior enabling
  831. * the encoder mode.
  832. * @rmtoll CFGR ENC LL_LPTIM_EnableEncoderMode
  833. * @param LPTIMx Low-Power Timer instance
  834. * @retval None
  835. */
  836. __STATIC_INLINE void LL_LPTIM_EnableEncoderMode(LPTIM_TypeDef *LPTIMx)
  837. {
  838. SET_BIT(LPTIMx->CFGR, LPTIM_CFGR_ENC);
  839. }
  840. /**
  841. * @brief Disable the encoder mode
  842. * @note This function must be called when the LPTIM instance is disabled.
  843. * @rmtoll CFGR ENC LL_LPTIM_DisableEncoderMode
  844. * @param LPTIMx Low-Power Timer instance
  845. * @retval None
  846. */
  847. __STATIC_INLINE void LL_LPTIM_DisableEncoderMode(LPTIM_TypeDef *LPTIMx)
  848. {
  849. CLEAR_BIT(LPTIMx->CFGR, LPTIM_CFGR_ENC);
  850. }
  851. /**
  852. * @brief Indicates whether the LPTIM operates in encoder mode.
  853. * @rmtoll CFGR ENC LL_LPTIM_IsEnabledEncoderMode
  854. * @param LPTIMx Low-Power Timer instance
  855. * @retval State of bit (1 or 0).
  856. */
  857. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledEncoderMode(LPTIM_TypeDef *LPTIMx)
  858. {
  859. return (((READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_ENC) == LPTIM_CFGR_ENC) ? 1UL : 0UL));
  860. }
  861. /**
  862. * @}
  863. */
  864. /** @defgroup LPTIM_LL_EF_FLAG_Management FLAG Management
  865. * @{
  866. */
  867. /**
  868. * @brief Clear the compare match flag (CMPMCF)
  869. * @rmtoll ICR CMPMCF LL_LPTIM_ClearFLAG_CMPM
  870. * @param LPTIMx Low-Power Timer instance
  871. * @retval None
  872. */
  873. __STATIC_INLINE void LL_LPTIM_ClearFLAG_CMPM(LPTIM_TypeDef *LPTIMx)
  874. {
  875. SET_BIT(LPTIMx->ICR, LPTIM_ICR_CMPMCF);
  876. }
  877. /**
  878. * @brief Inform application whether a compare match interrupt has occurred.
  879. * @rmtoll ISR CMPM LL_LPTIM_IsActiveFlag_CMPM
  880. * @param LPTIMx Low-Power Timer instance
  881. * @retval State of bit (1 or 0).
  882. */
  883. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_CMPM(LPTIM_TypeDef *LPTIMx)
  884. {
  885. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_CMPM) == LPTIM_ISR_CMPM) ? 1UL : 0UL));
  886. }
  887. /**
  888. * @brief Clear the autoreload match flag (ARRMCF)
  889. * @rmtoll ICR ARRMCF LL_LPTIM_ClearFLAG_ARRM
  890. * @param LPTIMx Low-Power Timer instance
  891. * @retval None
  892. */
  893. __STATIC_INLINE void LL_LPTIM_ClearFLAG_ARRM(LPTIM_TypeDef *LPTIMx)
  894. {
  895. SET_BIT(LPTIMx->ICR, LPTIM_ICR_ARRMCF);
  896. }
  897. /**
  898. * @brief Inform application whether a autoreload match interrupt has occurred.
  899. * @rmtoll ISR ARRM LL_LPTIM_IsActiveFlag_ARRM
  900. * @param LPTIMx Low-Power Timer instance
  901. * @retval State of bit (1 or 0).
  902. */
  903. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_ARRM(LPTIM_TypeDef *LPTIMx)
  904. {
  905. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_ARRM) == LPTIM_ISR_ARRM) ? 1UL : 0UL));
  906. }
  907. /**
  908. * @brief Clear the external trigger valid edge flag(EXTTRIGCF).
  909. * @rmtoll ICR EXTTRIGCF LL_LPTIM_ClearFlag_EXTTRIG
  910. * @param LPTIMx Low-Power Timer instance
  911. * @retval None
  912. */
  913. __STATIC_INLINE void LL_LPTIM_ClearFlag_EXTTRIG(LPTIM_TypeDef *LPTIMx)
  914. {
  915. SET_BIT(LPTIMx->ICR, LPTIM_ICR_EXTTRIGCF);
  916. }
  917. /**
  918. * @brief Inform application whether a valid edge on the selected external trigger input has occurred.
  919. * @rmtoll ISR EXTTRIG LL_LPTIM_IsActiveFlag_EXTTRIG
  920. * @param LPTIMx Low-Power Timer instance
  921. * @retval State of bit (1 or 0).
  922. */
  923. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_EXTTRIG(LPTIM_TypeDef *LPTIMx)
  924. {
  925. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_EXTTRIG) == LPTIM_ISR_EXTTRIG) ? 1UL : 0UL));
  926. }
  927. /**
  928. * @brief Clear the compare register update interrupt flag (CMPOKCF).
  929. * @rmtoll ICR CMPOKCF LL_LPTIM_ClearFlag_CMPOK
  930. * @param LPTIMx Low-Power Timer instance
  931. * @retval None
  932. */
  933. __STATIC_INLINE void LL_LPTIM_ClearFlag_CMPOK(LPTIM_TypeDef *LPTIMx)
  934. {
  935. SET_BIT(LPTIMx->ICR, LPTIM_ICR_CMPOKCF);
  936. }
  937. /**
  938. * @brief Informs application whether the APB bus write operation to the LPTIMx_CMP register has been successfully
  939. completed. If so, a new one can be initiated.
  940. * @rmtoll ISR CMPOK LL_LPTIM_IsActiveFlag_CMPOK
  941. * @param LPTIMx Low-Power Timer instance
  942. * @retval State of bit (1 or 0).
  943. */
  944. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_CMPOK(LPTIM_TypeDef *LPTIMx)
  945. {
  946. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_CMPOK) == LPTIM_ISR_CMPOK) ? 1UL : 0UL));
  947. }
  948. /**
  949. * @brief Clear the autoreload register update interrupt flag (ARROKCF).
  950. * @rmtoll ICR ARROKCF LL_LPTIM_ClearFlag_ARROK
  951. * @param LPTIMx Low-Power Timer instance
  952. * @retval None
  953. */
  954. __STATIC_INLINE void LL_LPTIM_ClearFlag_ARROK(LPTIM_TypeDef *LPTIMx)
  955. {
  956. SET_BIT(LPTIMx->ICR, LPTIM_ICR_ARROKCF);
  957. }
  958. /**
  959. * @brief Informs application whether the APB bus write operation to the LPTIMx_ARR register has been successfully
  960. completed. If so, a new one can be initiated.
  961. * @rmtoll ISR ARROK LL_LPTIM_IsActiveFlag_ARROK
  962. * @param LPTIMx Low-Power Timer instance
  963. * @retval State of bit (1 or 0).
  964. */
  965. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_ARROK(LPTIM_TypeDef *LPTIMx)
  966. {
  967. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_ARROK) == LPTIM_ISR_ARROK) ? 1UL : 0UL));
  968. }
  969. /**
  970. * @brief Clear the counter direction change to up interrupt flag (UPCF).
  971. * @rmtoll ICR UPCF LL_LPTIM_ClearFlag_UP
  972. * @param LPTIMx Low-Power Timer instance
  973. * @retval None
  974. */
  975. __STATIC_INLINE void LL_LPTIM_ClearFlag_UP(LPTIM_TypeDef *LPTIMx)
  976. {
  977. SET_BIT(LPTIMx->ICR, LPTIM_ICR_UPCF);
  978. }
  979. /**
  980. * @brief Informs the application whether the counter direction has changed from down to up (when the LPTIM instance
  981. operates in encoder mode).
  982. * @rmtoll ISR UP LL_LPTIM_IsActiveFlag_UP
  983. * @param LPTIMx Low-Power Timer instance
  984. * @retval State of bit (1 or 0).
  985. */
  986. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_UP(LPTIM_TypeDef *LPTIMx)
  987. {
  988. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_UP) == LPTIM_ISR_UP) ? 1UL : 0UL));
  989. }
  990. /**
  991. * @brief Clear the counter direction change to down interrupt flag (DOWNCF).
  992. * @rmtoll ICR DOWNCF LL_LPTIM_ClearFlag_DOWN
  993. * @param LPTIMx Low-Power Timer instance
  994. * @retval None
  995. */
  996. __STATIC_INLINE void LL_LPTIM_ClearFlag_DOWN(LPTIM_TypeDef *LPTIMx)
  997. {
  998. SET_BIT(LPTIMx->ICR, LPTIM_ICR_DOWNCF);
  999. }
  1000. /**
  1001. * @brief Informs the application whether the counter direction has changed from up to down (when the LPTIM instance
  1002. operates in encoder mode).
  1003. * @rmtoll ISR DOWN LL_LPTIM_IsActiveFlag_DOWN
  1004. * @param LPTIMx Low-Power Timer instance
  1005. * @retval State of bit (1 or 0).
  1006. */
  1007. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_DOWN(LPTIM_TypeDef *LPTIMx)
  1008. {
  1009. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_DOWN) == LPTIM_ISR_DOWN) ? 1UL : 0UL));
  1010. }
  1011. /**
  1012. * @}
  1013. */
  1014. /** @defgroup LPTIM_LL_EF_IT_Management Interrupt Management
  1015. * @{
  1016. */
  1017. /**
  1018. * @brief Enable compare match interrupt (CMPMIE).
  1019. * @rmtoll IER CMPMIE LL_LPTIM_EnableIT_CMPM
  1020. * @param LPTIMx Low-Power Timer instance
  1021. * @retval None
  1022. */
  1023. __STATIC_INLINE void LL_LPTIM_EnableIT_CMPM(LPTIM_TypeDef *LPTIMx)
  1024. {
  1025. SET_BIT(LPTIMx->IER, LPTIM_IER_CMPMIE);
  1026. }
  1027. /**
  1028. * @brief Disable compare match interrupt (CMPMIE).
  1029. * @rmtoll IER CMPMIE LL_LPTIM_DisableIT_CMPM
  1030. * @param LPTIMx Low-Power Timer instance
  1031. * @retval None
  1032. */
  1033. __STATIC_INLINE void LL_LPTIM_DisableIT_CMPM(LPTIM_TypeDef *LPTIMx)
  1034. {
  1035. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_CMPMIE);
  1036. }
  1037. /**
  1038. * @brief Indicates whether the compare match interrupt (CMPMIE) is enabled.
  1039. * @rmtoll IER CMPMIE LL_LPTIM_IsEnabledIT_CMPM
  1040. * @param LPTIMx Low-Power Timer instance
  1041. * @retval State of bit (1 or 0).
  1042. */
  1043. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_CMPM(LPTIM_TypeDef *LPTIMx)
  1044. {
  1045. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_CMPMIE) == LPTIM_IER_CMPMIE) ? 1UL : 0UL));
  1046. }
  1047. /**
  1048. * @brief Enable autoreload match interrupt (ARRMIE).
  1049. * @rmtoll IER ARRMIE LL_LPTIM_EnableIT_ARRM
  1050. * @param LPTIMx Low-Power Timer instance
  1051. * @retval None
  1052. */
  1053. __STATIC_INLINE void LL_LPTIM_EnableIT_ARRM(LPTIM_TypeDef *LPTIMx)
  1054. {
  1055. SET_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE);
  1056. }
  1057. /**
  1058. * @brief Disable autoreload match interrupt (ARRMIE).
  1059. * @rmtoll IER ARRMIE LL_LPTIM_DisableIT_ARRM
  1060. * @param LPTIMx Low-Power Timer instance
  1061. * @retval None
  1062. */
  1063. __STATIC_INLINE void LL_LPTIM_DisableIT_ARRM(LPTIM_TypeDef *LPTIMx)
  1064. {
  1065. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE);
  1066. }
  1067. /**
  1068. * @brief Indicates whether the autoreload match interrupt (ARRMIE) is enabled.
  1069. * @rmtoll IER ARRMIE LL_LPTIM_IsEnabledIT_ARRM
  1070. * @param LPTIMx Low-Power Timer instance
  1071. * @retval State of bit (1 or 0).
  1072. */
  1073. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_ARRM(LPTIM_TypeDef *LPTIMx)
  1074. {
  1075. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE) == LPTIM_IER_ARRMIE) ? 1UL : 0UL));
  1076. }
  1077. /**
  1078. * @brief Enable external trigger valid edge interrupt (EXTTRIGIE).
  1079. * @rmtoll IER EXTTRIGIE LL_LPTIM_EnableIT_EXTTRIG
  1080. * @param LPTIMx Low-Power Timer instance
  1081. * @retval None
  1082. */
  1083. __STATIC_INLINE void LL_LPTIM_EnableIT_EXTTRIG(LPTIM_TypeDef *LPTIMx)
  1084. {
  1085. SET_BIT(LPTIMx->IER, LPTIM_IER_EXTTRIGIE);
  1086. }
  1087. /**
  1088. * @brief Disable external trigger valid edge interrupt (EXTTRIGIE).
  1089. * @rmtoll IER EXTTRIGIE LL_LPTIM_DisableIT_EXTTRIG
  1090. * @param LPTIMx Low-Power Timer instance
  1091. * @retval None
  1092. */
  1093. __STATIC_INLINE void LL_LPTIM_DisableIT_EXTTRIG(LPTIM_TypeDef *LPTIMx)
  1094. {
  1095. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_EXTTRIGIE);
  1096. }
  1097. /**
  1098. * @brief Indicates external trigger valid edge interrupt (EXTTRIGIE) is enabled.
  1099. * @rmtoll IER EXTTRIGIE LL_LPTIM_IsEnabledIT_EXTTRIG
  1100. * @param LPTIMx Low-Power Timer instance
  1101. * @retval State of bit (1 or 0).
  1102. */
  1103. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_EXTTRIG(LPTIM_TypeDef *LPTIMx)
  1104. {
  1105. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_EXTTRIGIE) == LPTIM_IER_EXTTRIGIE) ? 1UL : 0UL));
  1106. }
  1107. /**
  1108. * @brief Enable compare register write completed interrupt (CMPOKIE).
  1109. * @rmtoll IER CMPOKIE LL_LPTIM_EnableIT_CMPOK
  1110. * @param LPTIMx Low-Power Timer instance
  1111. * @retval None
  1112. */
  1113. __STATIC_INLINE void LL_LPTIM_EnableIT_CMPOK(LPTIM_TypeDef *LPTIMx)
  1114. {
  1115. SET_BIT(LPTIMx->IER, LPTIM_IER_CMPOKIE);
  1116. }
  1117. /**
  1118. * @brief Disable compare register write completed interrupt (CMPOKIE).
  1119. * @rmtoll IER CMPOKIE LL_LPTIM_DisableIT_CMPOK
  1120. * @param LPTIMx Low-Power Timer instance
  1121. * @retval None
  1122. */
  1123. __STATIC_INLINE void LL_LPTIM_DisableIT_CMPOK(LPTIM_TypeDef *LPTIMx)
  1124. {
  1125. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_CMPOKIE);
  1126. }
  1127. /**
  1128. * @brief Indicates whether the compare register write completed interrupt (CMPOKIE) is enabled.
  1129. * @rmtoll IER CMPOKIE LL_LPTIM_IsEnabledIT_CMPOK
  1130. * @param LPTIMx Low-Power Timer instance
  1131. * @retval State of bit (1 or 0).
  1132. */
  1133. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_CMPOK(LPTIM_TypeDef *LPTIMx)
  1134. {
  1135. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_CMPOKIE) == LPTIM_IER_CMPOKIE) ? 1UL : 0UL));
  1136. }
  1137. /**
  1138. * @brief Enable autoreload register write completed interrupt (ARROKIE).
  1139. * @rmtoll IER ARROKIE LL_LPTIM_EnableIT_ARROK
  1140. * @param LPTIMx Low-Power Timer instance
  1141. * @retval None
  1142. */
  1143. __STATIC_INLINE void LL_LPTIM_EnableIT_ARROK(LPTIM_TypeDef *LPTIMx)
  1144. {
  1145. SET_BIT(LPTIMx->IER, LPTIM_IER_ARROKIE);
  1146. }
  1147. /**
  1148. * @brief Disable autoreload register write completed interrupt (ARROKIE).
  1149. * @rmtoll IER ARROKIE LL_LPTIM_DisableIT_ARROK
  1150. * @param LPTIMx Low-Power Timer instance
  1151. * @retval None
  1152. */
  1153. __STATIC_INLINE void LL_LPTIM_DisableIT_ARROK(LPTIM_TypeDef *LPTIMx)
  1154. {
  1155. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_ARROKIE);
  1156. }
  1157. /**
  1158. * @brief Indicates whether the autoreload register write completed interrupt (ARROKIE) is enabled.
  1159. * @rmtoll IER ARROKIE LL_LPTIM_IsEnabledIT_ARROK
  1160. * @param LPTIMx Low-Power Timer instance
  1161. * @retval State of bit(1 or 0).
  1162. */
  1163. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_ARROK(LPTIM_TypeDef *LPTIMx)
  1164. {
  1165. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_ARROKIE) == LPTIM_IER_ARROKIE) ? 1UL : 0UL));
  1166. }
  1167. /**
  1168. * @brief Enable direction change to up interrupt (UPIE).
  1169. * @rmtoll IER UPIE LL_LPTIM_EnableIT_UP
  1170. * @param LPTIMx Low-Power Timer instance
  1171. * @retval None
  1172. */
  1173. __STATIC_INLINE void LL_LPTIM_EnableIT_UP(LPTIM_TypeDef *LPTIMx)
  1174. {
  1175. SET_BIT(LPTIMx->IER, LPTIM_IER_UPIE);
  1176. }
  1177. /**
  1178. * @brief Disable direction change to up interrupt (UPIE).
  1179. * @rmtoll IER UPIE LL_LPTIM_DisableIT_UP
  1180. * @param LPTIMx Low-Power Timer instance
  1181. * @retval None
  1182. */
  1183. __STATIC_INLINE void LL_LPTIM_DisableIT_UP(LPTIM_TypeDef *LPTIMx)
  1184. {
  1185. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_UPIE);
  1186. }
  1187. /**
  1188. * @brief Indicates whether the direction change to up interrupt (UPIE) is enabled.
  1189. * @rmtoll IER UPIE LL_LPTIM_IsEnabledIT_UP
  1190. * @param LPTIMx Low-Power Timer instance
  1191. * @retval State of bit(1 or 0).
  1192. */
  1193. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_UP(LPTIM_TypeDef *LPTIMx)
  1194. {
  1195. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_UPIE) == LPTIM_IER_UPIE) ? 1UL : 0UL));
  1196. }
  1197. /**
  1198. * @brief Enable direction change to down interrupt (DOWNIE).
  1199. * @rmtoll IER DOWNIE LL_LPTIM_EnableIT_DOWN
  1200. * @param LPTIMx Low-Power Timer instance
  1201. * @retval None
  1202. */
  1203. __STATIC_INLINE void LL_LPTIM_EnableIT_DOWN(LPTIM_TypeDef *LPTIMx)
  1204. {
  1205. SET_BIT(LPTIMx->IER, LPTIM_IER_DOWNIE);
  1206. }
  1207. /**
  1208. * @brief Disable direction change to down interrupt (DOWNIE).
  1209. * @rmtoll IER DOWNIE LL_LPTIM_DisableIT_DOWN
  1210. * @param LPTIMx Low-Power Timer instance
  1211. * @retval None
  1212. */
  1213. __STATIC_INLINE void LL_LPTIM_DisableIT_DOWN(LPTIM_TypeDef *LPTIMx)
  1214. {
  1215. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_DOWNIE);
  1216. }
  1217. /**
  1218. * @brief Indicates whether the direction change to down interrupt (DOWNIE) is enabled.
  1219. * @rmtoll IER DOWNIE LL_LPTIM_IsEnabledIT_DOWN
  1220. * @param LPTIMx Low-Power Timer instance
  1221. * @retval State of bit(1 or 0).
  1222. */
  1223. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_DOWN(LPTIM_TypeDef *LPTIMx)
  1224. {
  1225. return ((READ_BIT(LPTIMx->IER, LPTIM_IER_DOWNIE) == LPTIM_IER_DOWNIE) ? 1UL : 0UL);
  1226. }
  1227. /**
  1228. * @}
  1229. */
  1230. /**
  1231. * @}
  1232. */
  1233. /**
  1234. * @}
  1235. */
  1236. #endif /* LPTIM1 */
  1237. /**
  1238. * @}
  1239. */
  1240. #ifdef __cplusplus
  1241. }
  1242. #endif
  1243. #endif /* STM32F4xx_LL_LPTIM_H */
  1244. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/