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.
 
 
 

1362 lines
50 KiB

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