训练营PLSR题目
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

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