py32f0xx_ll_lptim.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_lptim.h
  4. * @author MCU Application Team
  5. * @brief Header file of LPTIM LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya 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. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef PY32F0XX_LL_LPTIM_H
  32. #define PY32F0XX_LL_LPTIM_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_LL_Driver
  39. * @{
  40. */
  41. #if defined (LPTIM)
  42. /** @defgroup LPTIM_LL LPTIM
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private constants ---------------------------------------------------------*/
  48. /* Private macros ------------------------------------------------------------*/
  49. #if defined(USE_FULL_LL_DRIVER)
  50. /** @defgroup LPTIM_LL_Private_Macros LPTIM Private Macros
  51. * @{
  52. */
  53. /**
  54. * @}
  55. */
  56. #endif /*USE_FULL_LL_DRIVER*/
  57. /* Exported types ------------------------------------------------------------*/
  58. #if defined(USE_FULL_LL_DRIVER)
  59. /** @defgroup LPTIM_LL_ES_INIT LPTIM Exported Init structure
  60. * @{
  61. */
  62. /**
  63. * @brief LPTIM Init structure definition
  64. */
  65. typedef struct
  66. {
  67. uint32_t Prescaler; /*!< Specifies the prescaler division ratio.
  68. This parameter can be a value of @ref LPTIM_LL_EC_PRESCALER.
  69. This feature can be modified afterwards using using unitary
  70. function @ref LL_LPTIM_SetPrescaler().*/
  71. uint32_t UpdateMode; /*!< Specifies whether to update immediately or after the end
  72. of current period.
  73. This parameter can be a value of @ref LPTIM_LL_EC_UPDATE_MODE
  74. This feature can be modified afterwards using using unitary
  75. function @ref LL_LPTIM_SetUpdateMode().*/
  76. } LL_LPTIM_InitTypeDef;
  77. /**
  78. * @}
  79. */
  80. #endif /* USE_FULL_LL_DRIVER */
  81. /* Exported constants --------------------------------------------------------*/
  82. /** @defgroup LPTIM_LL_Exported_Constants LPTIM Exported Constants
  83. * @{
  84. */
  85. /** @defgroup LPTIM_LL_EC_GET_FLAG Get Flags Defines
  86. * @brief Flags defines which can be used with LL_LPTIM_ReadReg function
  87. * @{
  88. */
  89. #define LL_LPTIM_ISR_ARRM LPTIM_ISR_ARRM /*!< Autoreload match */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup LPTIM_LL_EC_IT IT Defines
  94. * @brief IT defines which can be used with LL_LPTIM_ReadReg and LL_LPTIM_WriteReg functions
  95. * @{
  96. */
  97. #define LL_LPTIM_IER_ARRMIE LPTIM_IER_ARRMIE /*!< Autoreload match */
  98. /**
  99. * @}
  100. */
  101. /** @defgroup LPTIM_LL_EC_OPERATING_MODE Operating Mode
  102. * @{
  103. */
  104. #define LL_LPTIM_OPERATING_MODE_ONESHOT LPTIM_CR_SNGSTRT /*!<LP Tilmer starts in single mode*/
  105. /**
  106. * @}
  107. */
  108. /** @defgroup LPTIM_LL_EC_UPDATE_MODE Update Mode
  109. * @{
  110. */
  111. #define LL_LPTIM_UPDATE_MODE_IMMEDIATE 0x00000000U /*!<Preload is disabled: registers are updated after each APB bus write access*/
  112. #define LL_LPTIM_UPDATE_MODE_ENDOFPERIOD LPTIM_CFGR_PRELOAD /*!<preload is enabled: registers are updated at the end of the current LPTIM period*/
  113. /**
  114. * @}
  115. */
  116. /** @defgroup LPTIM_LL_EC_PRESCALER Prescaler Value
  117. * @{
  118. */
  119. #define LL_LPTIM_PRESCALER_DIV1 0x00000000U /*!<Prescaler division factor is set to 1*/
  120. #define LL_LPTIM_PRESCALER_DIV2 LPTIM_CFGR_PRESC_0 /*!<Prescaler division factor is set to 2*/
  121. #define LL_LPTIM_PRESCALER_DIV4 LPTIM_CFGR_PRESC_1 /*!<Prescaler division factor is set to 4*/
  122. #define LL_LPTIM_PRESCALER_DIV8 (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_0) /*!<Prescaler division factor is set to 8*/
  123. #define LL_LPTIM_PRESCALER_DIV16 LPTIM_CFGR_PRESC_2 /*!<Prescaler division factor is set to 16*/
  124. #define LL_LPTIM_PRESCALER_DIV32 (LPTIM_CFGR_PRESC_2 | LPTIM_CFGR_PRESC_0) /*!<Prescaler division factor is set to 32*/
  125. #define LL_LPTIM_PRESCALER_DIV64 (LPTIM_CFGR_PRESC_2 | LPTIM_CFGR_PRESC_1) /*!<Prescaler division factor is set to 64*/
  126. #define LL_LPTIM_PRESCALER_DIV128 LPTIM_CFGR_PRESC /*!<Prescaler division factor is set to 128*/
  127. /**
  128. * @}
  129. */
  130. /**
  131. * @}
  132. */
  133. /* Exported macro ------------------------------------------------------------*/
  134. /** @defgroup LPTIM_LL_Exported_Macros LPTIM Exported Macros
  135. * @{
  136. */
  137. /** @defgroup LPTIM_LL_EM_WRITE_READ Common Write and read registers Macros
  138. * @{
  139. */
  140. /**
  141. * @brief Write a value in LPTIM register
  142. * @param __INSTANCE__ LPTIM Instance
  143. * @param __REG__ Register to be written
  144. * @param __VALUE__ Value to be written in the register
  145. * @retval None
  146. */
  147. #define LL_LPTIM_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  148. /**
  149. * @brief Read a value in LPTIM register
  150. * @param __INSTANCE__ LPTIM Instance
  151. * @param __REG__ Register to be read
  152. * @retval Register value
  153. */
  154. #define LL_LPTIM_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @}
  160. */
  161. /* Exported functions --------------------------------------------------------*/
  162. /** @defgroup LPTIM_LL_Exported_Functions LPTIM Exported Functions
  163. * @{
  164. */
  165. #if defined(USE_FULL_LL_DRIVER)
  166. /** @defgroup LPTIM_LL_EF_Init Initialisation and deinitialisation functions
  167. * @{
  168. */
  169. ErrorStatus LL_LPTIM_DeInit(LPTIM_TypeDef *LPTIMx);
  170. void LL_LPTIM_StructInit(LL_LPTIM_InitTypeDef *LPTIM_InitStruct);
  171. ErrorStatus LL_LPTIM_Init(LPTIM_TypeDef *LPTIMx, LL_LPTIM_InitTypeDef *LPTIM_InitStruct);
  172. /**
  173. * @}
  174. */
  175. #endif /* USE_FULL_LL_DRIVER */
  176. /** @defgroup LPTIM_LL_EF_LPTIM_Configuration LPTIM Configuration
  177. * @{
  178. */
  179. /**
  180. * @brief Enable the LPTIM instance
  181. * @note After setting the ENABLE bit, a delay of two counter clock is needed
  182. * before the LPTIM instance is actually enabled.
  183. * @rmtoll CR ENABLE LL_LPTIM_Enable
  184. * @param LPTIMx Low-Power Timer instance
  185. * @retval None
  186. */
  187. __STATIC_INLINE void LL_LPTIM_Enable(LPTIM_TypeDef *LPTIMx)
  188. {
  189. SET_BIT(LPTIMx->CR, LPTIM_CR_ENABLE);
  190. }
  191. /**
  192. * @brief Disable the LPTIM instance
  193. * @rmtoll CR ENABLE LL_LPTIM_Disable
  194. * @param LPTIMx Low-Power Timer instance
  195. * @retval None
  196. */
  197. __STATIC_INLINE void LL_LPTIM_Disable(LPTIM_TypeDef *LPTIMx)
  198. {
  199. CLEAR_BIT(LPTIMx->CR, LPTIM_CR_ENABLE);
  200. }
  201. /**
  202. * @brief Indicates whether the LPTIM instance is enabled.
  203. * @rmtoll CR ENABLE LL_LPTIM_IsEnabled
  204. * @param LPTIMx Low-Power Timer instance
  205. * @retval State of bit (1 or 0).
  206. */
  207. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabled(LPTIM_TypeDef *LPTIMx)
  208. {
  209. return (((READ_BIT(LPTIMx->CR, LPTIM_CR_ENABLE) == LPTIM_CR_ENABLE) ? 1UL : 0UL));
  210. }
  211. /**
  212. * @brief Starts the LPTIM counter in the desired mode.
  213. * @note LPTIM instance must be enabled before starting the counter.
  214. * @rmtoll CR SNGSTRT LL_LPTIM_StartCounter
  215. * @param LPTIMx Low-Power Timer instance
  216. * @param OperatingMode This parameter can be one of the following values:
  217. * @arg @ref LL_LPTIM_OPERATING_MODE_ONESHOT
  218. * @retval None
  219. */
  220. __STATIC_INLINE void LL_LPTIM_StartCounter(LPTIM_TypeDef *LPTIMx, uint32_t OperatingMode)
  221. {
  222. MODIFY_REG(LPTIMx->CR, LPTIM_CR_SNGSTRT, OperatingMode);
  223. }
  224. /**
  225. * @brief Enable reset after read.
  226. * @note After calling this function any read access to LPTIM_CNT
  227. * register will asynchronously reset the LPTIM_CNT register content.
  228. * @rmtoll CR RSTARE LL_LPTIM_EnableResetAfterRead
  229. * @param LPTIMx Low-Power Timer instance
  230. * @retval None
  231. */
  232. __STATIC_INLINE void LL_LPTIM_EnableResetAfterRead(LPTIM_TypeDef *LPTIMx)
  233. {
  234. SET_BIT(LPTIMx->CR, LPTIM_CR_RSTARE);
  235. }
  236. /**
  237. * @brief Disable reset after read.
  238. * @rmtoll CR RSTARE LL_LPTIM_DisableResetAfterRead
  239. * @param LPTIMx Low-Power Timer instance
  240. * @retval None
  241. */
  242. __STATIC_INLINE void LL_LPTIM_DisableResetAfterRead(LPTIM_TypeDef *LPTIMx)
  243. {
  244. CLEAR_BIT(LPTIMx->CR, LPTIM_CR_RSTARE);
  245. }
  246. /**
  247. * @brief Indicate whether the reset after read feature is enabled.
  248. * @rmtoll CR RSTARE LL_LPTIM_IsEnabledResetAfterRead
  249. * @param LPTIMx Low-Power Timer instance
  250. * @retval State of bit (1 or 0).
  251. */
  252. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledResetAfterRead(LPTIM_TypeDef *LPTIMx)
  253. {
  254. return (((READ_BIT(LPTIMx->CR, LPTIM_CR_RSTARE) == LPTIM_CR_RSTARE) ? 1UL : 0UL));
  255. }
  256. /**
  257. * @brief Set the LPTIM registers update mode (enable/disable register preload)
  258. * @note This function must be called when the LPTIM instance is disabled.
  259. * @rmtoll CFGR PRELOAD LL_LPTIM_SetUpdateMode
  260. * @param LPTIMx Low-Power Timer instance
  261. * @param UpdateMode This parameter can be one of the following values:
  262. * @arg @ref LL_LPTIM_UPDATE_MODE_IMMEDIATE
  263. * @arg @ref LL_LPTIM_UPDATE_MODE_ENDOFPERIOD
  264. * @retval None
  265. */
  266. __STATIC_INLINE void LL_LPTIM_SetUpdateMode(LPTIM_TypeDef *LPTIMx, uint32_t UpdateMode)
  267. {
  268. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_PRELOAD, UpdateMode);
  269. }
  270. /**
  271. * @brief Get the LPTIM registers update mode
  272. * @rmtoll CFGR PRELOAD LL_LPTIM_GetUpdateMode
  273. * @param LPTIMx Low-Power Timer instance
  274. * @retval Returned value can be one of the following values:
  275. * @arg @ref LL_LPTIM_UPDATE_MODE_IMMEDIATE
  276. * @arg @ref LL_LPTIM_UPDATE_MODE_ENDOFPERIOD
  277. */
  278. __STATIC_INLINE uint32_t LL_LPTIM_GetUpdateMode(LPTIM_TypeDef *LPTIMx)
  279. {
  280. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_PRELOAD));
  281. }
  282. /**
  283. * @brief Set the auto reload value
  284. * @note The LPTIMx_ARR register content must only be modified when the LPTIM is enabled
  285. * @note After a write to the LPTIMx_ARR register a new write operation to the
  286. * same register can only be performed when the previous write operation
  287. * is completed. Any successive write before the ARROK flag is set, will
  288. * lead to unpredictable results.
  289. * @note autoreload value be strictly greater than the compare value.
  290. * @rmtoll ARR ARR LL_LPTIM_SetAutoReload
  291. * @param LPTIMx Low-Power Timer instance
  292. * @param AutoReload Value between Min_Data=0x00 and Max_Data=0xFFFF
  293. * @retval None
  294. */
  295. __STATIC_INLINE void LL_LPTIM_SetAutoReload(LPTIM_TypeDef *LPTIMx, uint32_t AutoReload)
  296. {
  297. MODIFY_REG(LPTIMx->ARR, LPTIM_ARR_ARR, AutoReload);
  298. }
  299. /**
  300. * @brief Get actual auto reload value
  301. * @rmtoll ARR ARR LL_LPTIM_GetAutoReload
  302. * @param LPTIMx Low-Power Timer instance
  303. * @retval AutoReload Value between Min_Data=0x00 and Max_Data=0xFFFF
  304. */
  305. __STATIC_INLINE uint32_t LL_LPTIM_GetAutoReload(LPTIM_TypeDef *LPTIMx)
  306. {
  307. return (uint32_t)(READ_BIT(LPTIMx->ARR, LPTIM_ARR_ARR));
  308. }
  309. /**
  310. * @brief Get actual counter value
  311. * @note When the LPTIM instance is running with an asynchronous clock, reading
  312. * the LPTIMx_CNT register may return unreliable values. So in this case
  313. * it is necessary to perform two consecutive read accesses and verify
  314. * that the two returned values are identical.
  315. * @rmtoll CNT CNT LL_LPTIM_GetCounter
  316. * @param LPTIMx Low-Power Timer instance
  317. * @retval Counter value
  318. */
  319. __STATIC_INLINE uint32_t LL_LPTIM_GetCounter(LPTIM_TypeDef *LPTIMx)
  320. {
  321. return (uint32_t)(READ_BIT(LPTIMx->CNT, LPTIM_CNT_CNT));
  322. }
  323. /**
  324. * @brief Set actual prescaler division ratio.
  325. * @note This function must be called when the LPTIM instance is disabled.
  326. * @note When the LPTIM is configured to be clocked by an internal clock source
  327. * and the LPTIM counter is configured to be updated by active edges
  328. * detected on the LPTIM external Input1, the internal clock provided to
  329. * the LPTIM must be not be prescaled.
  330. * @rmtoll CFGR PRESC LL_LPTIM_SetPrescaler
  331. * @param LPTIMx Low-Power Timer instance
  332. * @param Prescaler This parameter can be one of the following values:
  333. * @arg @ref LL_LPTIM_PRESCALER_DIV1
  334. * @arg @ref LL_LPTIM_PRESCALER_DIV2
  335. * @arg @ref LL_LPTIM_PRESCALER_DIV4
  336. * @arg @ref LL_LPTIM_PRESCALER_DIV8
  337. * @arg @ref LL_LPTIM_PRESCALER_DIV16
  338. * @arg @ref LL_LPTIM_PRESCALER_DIV32
  339. * @arg @ref LL_LPTIM_PRESCALER_DIV64
  340. * @arg @ref LL_LPTIM_PRESCALER_DIV128
  341. * @retval None
  342. */
  343. __STATIC_INLINE void LL_LPTIM_SetPrescaler(LPTIM_TypeDef *LPTIMx, uint32_t Prescaler)
  344. {
  345. MODIFY_REG(LPTIMx->CFGR, LPTIM_CFGR_PRESC, Prescaler);
  346. }
  347. /**
  348. * @brief Get actual prescaler division ratio.
  349. * @rmtoll CFGR PRESC LL_LPTIM_GetPrescaler
  350. * @param LPTIMx Low-Power Timer instance
  351. * @retval Returned value can be one of the following values:
  352. * @arg @ref LL_LPTIM_PRESCALER_DIV1
  353. * @arg @ref LL_LPTIM_PRESCALER_DIV2
  354. * @arg @ref LL_LPTIM_PRESCALER_DIV4
  355. * @arg @ref LL_LPTIM_PRESCALER_DIV8
  356. * @arg @ref LL_LPTIM_PRESCALER_DIV16
  357. * @arg @ref LL_LPTIM_PRESCALER_DIV32
  358. * @arg @ref LL_LPTIM_PRESCALER_DIV64
  359. * @arg @ref LL_LPTIM_PRESCALER_DIV128
  360. */
  361. __STATIC_INLINE uint32_t LL_LPTIM_GetPrescaler(LPTIM_TypeDef *LPTIMx)
  362. {
  363. return (uint32_t)(READ_BIT(LPTIMx->CFGR, LPTIM_CFGR_PRESC));
  364. }
  365. /**
  366. * @}
  367. */
  368. /** @defgroup LPTIM_LL_EF_FLAG_Management FLAG Management
  369. * @{
  370. */
  371. /**
  372. * @brief Clear the autoreload match flag (ARRMCF)
  373. * @rmtoll ICR ARRMCF LL_LPTIM_ClearFLAG_ARRM
  374. * @param LPTIMx Low-Power Timer instance
  375. * @retval None
  376. */
  377. __STATIC_INLINE void LL_LPTIM_ClearFLAG_ARRM(LPTIM_TypeDef *LPTIMx)
  378. {
  379. SET_BIT(LPTIMx->ICR, LPTIM_ICR_ARRMCF);
  380. }
  381. /**
  382. * @brief Inform application whether a autoreload match interrupt has occurred.
  383. * @rmtoll ISR ARRM LL_LPTIM_IsActiveFlag_ARRM
  384. * @param LPTIMx Low-Power Timer instance
  385. * @retval State of bit (1 or 0).
  386. */
  387. __STATIC_INLINE uint32_t LL_LPTIM_IsActiveFlag_ARRM(LPTIM_TypeDef *LPTIMx)
  388. {
  389. return (((READ_BIT(LPTIMx->ISR, LPTIM_ISR_ARRM) == LPTIM_ISR_ARRM) ? 1UL : 0UL));
  390. }
  391. /**
  392. * @}
  393. */
  394. /** @defgroup LPTIM_LL_EF_IT_Management Interrupt Management
  395. * @{
  396. */
  397. /**
  398. * @brief Enable autoreload match interrupt (ARRMIE).
  399. * @rmtoll IER ARRMIE LL_LPTIM_EnableIT_ARRM
  400. * @param LPTIMx Low-Power Timer instance
  401. * @retval None
  402. */
  403. __STATIC_INLINE void LL_LPTIM_EnableIT_ARRM(LPTIM_TypeDef *LPTIMx)
  404. {
  405. SET_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE);
  406. }
  407. /**
  408. * @brief Disable autoreload match interrupt (ARRMIE).
  409. * @rmtoll IER ARRMIE LL_LPTIM_DisableIT_ARRM
  410. * @param LPTIMx Low-Power Timer instance
  411. * @retval None
  412. */
  413. __STATIC_INLINE void LL_LPTIM_DisableIT_ARRM(LPTIM_TypeDef *LPTIMx)
  414. {
  415. CLEAR_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE);
  416. }
  417. /**
  418. * @brief Indicates whether the autoreload match interrupt (ARRMIE) is enabled.
  419. * @rmtoll IER ARRMIE LL_LPTIM_IsEnabledIT_ARRM
  420. * @param LPTIMx Low-Power Timer instance
  421. * @retval State of bit (1 or 0).
  422. */
  423. __STATIC_INLINE uint32_t LL_LPTIM_IsEnabledIT_ARRM(LPTIM_TypeDef *LPTIMx)
  424. {
  425. return (((READ_BIT(LPTIMx->IER, LPTIM_IER_ARRMIE) == LPTIM_IER_ARRMIE) ? 1UL : 0UL));
  426. }
  427. /**
  428. * @}
  429. */
  430. /**
  431. * @}
  432. */
  433. /**
  434. * @}
  435. */
  436. #endif /* LPTIM */
  437. /**
  438. * @}
  439. */
  440. #ifdef __cplusplus
  441. }
  442. #endif
  443. #endif /* PY32F0XX_LL_LPTIM_H */
  444. /************************ (C) COPYRIGHT Puya *****END OF FILE****/