py32f002b_hal_lptim.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal_lptim.h
  4. * @author MCU Application Team
  5. * @brief Header file of LPTIM HAL 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 __PY32F002B_HAL_LPTIM_H
  32. #define __PY32F002B_HAL_LPTIM_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f002b_hal_def.h"
  38. /** @addtogroup PY32F002B_HAL_Driver
  39. * @{
  40. */
  41. #if (defined (LPTIM)|| defined(LPTIM1))
  42. /** @addtogroup LPTIM
  43. * @{
  44. */
  45. /* Exported types ------------------------------------------------------------*/
  46. /** @defgroup LPTIM_Exported_Types LPTIM Exported Types
  47. * @{
  48. */
  49. /**
  50. * @brief LPTIM Initialization Structure definition
  51. */
  52. typedef struct
  53. {
  54. uint32_t Prescaler; /*!< Specifies the counter clock Prescaler.
  55. This parameter can be a value of @ref LPTIM_Clock_Prescaler */
  56. uint32_t UpdateMode; /*!< Specifies whether to update immediately or after the end
  57. of current period.
  58. This parameter can be a value of @ref LPTIM_Updating_Mode */
  59. } LPTIM_InitTypeDef;
  60. /**
  61. * @brief HAL LPTIM State structure definition
  62. */
  63. typedef enum
  64. {
  65. HAL_LPTIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */
  66. HAL_LPTIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  67. HAL_LPTIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */
  68. HAL_LPTIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
  69. HAL_LPTIM_STATE_ERROR = 0x04U /*!< Internal Process is ongoing */
  70. } HAL_LPTIM_StateTypeDef;
  71. /**
  72. * @brief LPTIM handle Structure definition
  73. */
  74. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  75. typedef struct __LPTIM_HandleTypeDef
  76. #else
  77. typedef struct
  78. #endif
  79. {
  80. LPTIM_TypeDef *Instance; /*!< Register base address */
  81. LPTIM_InitTypeDef Init; /*!< LPTIM required parameters */
  82. HAL_LockTypeDef Lock; /*!< LPTIM locking object */
  83. __IO HAL_LPTIM_StateTypeDef State; /*!< LPTIM peripheral state */
  84. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  85. void (* MspInitCallback) (struct __LPTIM_HandleTypeDef *hlptim); /*!< LPTIM Base Msp Init Callback */
  86. void (* MspDeInitCallback) (struct __LPTIM_HandleTypeDef *hlptim); /*!< LPTIM Base Msp DeInit Callback */
  87. void (* AutoReloadMatchCallback) (struct __LPTIM_HandleTypeDef *hlptim); /*!< Auto-reload match Callback */
  88. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  89. } LPTIM_HandleTypeDef;
  90. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  91. /**
  92. * @brief HAL LPTIM Callback ID enumeration definition
  93. */
  94. typedef enum
  95. {
  96. HAL_LPTIM_MSPINIT_CB_ID = 0x00U, /*!< LPTIM Base Msp Init Callback ID */
  97. HAL_LPTIM_MSPDEINIT_CB_ID = 0x01U, /*!< LPTIM Base Msp DeInit Callback ID */
  98. HAL_LPTIM_AUTORELOAD_MATCH_CB_ID = 0x03U, /*!< Auto-reload match Callback ID */
  99. } HAL_LPTIM_CallbackIDTypeDef;
  100. /**
  101. * @brief HAL TIM Callback pointer definition
  102. */
  103. typedef void (*pLPTIM_CallbackTypeDef)(LPTIM_HandleTypeDef * hlptim); /*!< pointer to the LPTIM callback function */
  104. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  105. /**
  106. * @}
  107. */
  108. /* Exported constants --------------------------------------------------------*/
  109. /** @defgroup LPTIM_Exported_Constants LPTIM Exported Constants
  110. * @{
  111. */
  112. /** @defgroup LPTIM_Clock_Prescaler LPTIM Clock Prescaler
  113. * @{
  114. */
  115. #define LPTIM_PRESCALER_DIV1 0x00000000U
  116. #define LPTIM_PRESCALER_DIV2 LPTIM_CFGR_PRESC_0
  117. #define LPTIM_PRESCALER_DIV4 LPTIM_CFGR_PRESC_1
  118. #define LPTIM_PRESCALER_DIV8 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_1)
  119. #define LPTIM_PRESCALER_DIV16 LPTIM_CFGR_PRESC_2
  120. #define LPTIM_PRESCALER_DIV32 (LPTIM_CFGR_PRESC_0 | LPTIM_CFGR_PRESC_2)
  121. #define LPTIM_PRESCALER_DIV64 (LPTIM_CFGR_PRESC_1 | LPTIM_CFGR_PRESC_2)
  122. #define LPTIM_PRESCALER_DIV128 LPTIM_CFGR_PRESC
  123. /**
  124. * @}
  125. */
  126. /** @defgroup LPTIM_Updating_Mode LPTIM Updating Mode
  127. * @{
  128. */
  129. #define LPTIM_UPDATE_IMMEDIATE 0x00000000U
  130. #define LPTIM_UPDATE_ENDOFPERIOD LPTIM_CFGR_PRELOAD
  131. /**
  132. * @}
  133. */
  134. /** @defgroup LPTIM_Flag_Definition LPTIM Flags Definition
  135. * @{
  136. */
  137. #define LPTIM_FLAG_ARRM LPTIM_ISR_ARRM
  138. #define LPTIM_FLAG_ARROK LPTIM_ISR_ARROK
  139. /**
  140. * @}
  141. */
  142. /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition
  143. * @{
  144. */
  145. #define LPTIM_IT_ARRM LPTIM_IER_ARRMIE
  146. #define LPTIM_IT_ARROK LPTIM_IER_ARROKIE
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @}
  152. */
  153. /* Exported macros -----------------------------------------------------------*/
  154. /** @defgroup LPTIM_Exported_Macros LPTIM Exported Macros
  155. * @{
  156. */
  157. /** @brief Reset LPTIM handle state.
  158. * @param __HANDLE__ LPTIM handle
  159. * @retval None
  160. */
  161. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  162. #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do { \
  163. (__HANDLE__)->State = HAL_LPTIM_STATE_RESET; \
  164. (__HANDLE__)->MspInitCallback = NULL; \
  165. (__HANDLE__)->MspDeInitCallback = NULL; \
  166. } while(0)
  167. #else
  168. #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET)
  169. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  170. /**
  171. * @brief Enable the LPTIM peripheral.
  172. * @param __HANDLE__ LPTIM handle
  173. * @retval None
  174. */
  175. #define __HAL_LPTIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (LPTIM_CR_ENABLE))
  176. /**
  177. * @brief Disable the LPTIM peripheral.
  178. * @param __HANDLE__ LPTIM handle
  179. * @retval None
  180. */
  181. #define __HAL_LPTIM_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(LPTIM_CR_ENABLE))
  182. /**
  183. * @brief Start the LPTIM peripheral in single mode.
  184. * @param __HANDLE__ LPTIM handle
  185. * @retval None
  186. */
  187. #define __HAL_LPTIM_START_SINGLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_SNGSTRT)
  188. #if defined(LPTIM_CR_CNTSTRT)
  189. /**
  190. * @brief Start the LPTIM peripheral in continue mode.
  191. * @param __HANDLE__ LPTIM handle
  192. * @retval None
  193. */
  194. #define __HAL_LPTIM_START_CONTINUE(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_CNTSTRT)
  195. #endif
  196. /**
  197. * @brief Reset after read of the LPTIM Counter register in asynchronous mode.
  198. * @param __HANDLE__ LPTIM handle
  199. * @retval None
  200. */
  201. #define __HAL_LPTIM_RESET_COUNTER_AFTERREAD(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_RSTARE)
  202. /**
  203. * @brief Write the passed parameter in the Autoreload register.
  204. * @param __HANDLE__ LPTIM handle
  205. * @param __VALUE__ Autoreload value
  206. * @retval None
  207. */
  208. #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->ARR = (__VALUE__))
  209. /**
  210. * @brief Check whether the specified LPTIM flag is set or not.
  211. * @param __HANDLE__ LPTIM handle
  212. * @param __FLAG__ LPTIM flag to check
  213. * This parameter can be a value of:
  214. * @arg LPTIM_FLAG_ARRM : Autoreload match Flag.
  215. * @arg LPTIM_FLAG_ARROK : Autoreload Update completed Flag.
  216. * @retval The state of the specified flag (SET or RESET).
  217. */
  218. #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__))
  219. /**
  220. * @brief Clear the specified LPTIM flag.
  221. * @param __HANDLE__ LPTIM handle.
  222. * @param __FLAG__ LPTIM flag to clear.
  223. * This parameter can be a value of:
  224. * @arg LPTIM_FLAG_ARRM : Autoreload match Flag.
  225. * @arg LPTIM_FLAG_ARROK : Autoreload Update completed Flag.
  226. * @retval None.
  227. */
  228. #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  229. /**
  230. * @brief Enable the specified LPTIM interrupt.
  231. * @param __HANDLE__ LPTIM handle.
  232. * @param __INTERRUPT__ LPTIM interrupt to set.
  233. * This parameter can be a value of:
  234. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  235. * @arg LPTIM_IT_ARROK : Autoreload Update completed Interrupt.
  236. * @retval None.
  237. */
  238. #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
  239. /**
  240. * @brief Disable the specified LPTIM interrupt.
  241. * @param __HANDLE__ LPTIM handle.
  242. * @param __INTERRUPT__ LPTIM interrupt to set.
  243. * This parameter can be a value of:
  244. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  245. * @arg LPTIM_IT_ARROK : Autoreload Update completed Interrupt.
  246. * @retval None.
  247. */
  248. #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
  249. /**
  250. * @brief Check whether the specified LPTIM interrupt source is enabled or not.
  251. * @param __HANDLE__ LPTIM handle.
  252. * @param __INTERRUPT__ LPTIM interrupt to check.
  253. * This parameter can be a value of:
  254. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  255. * @arg LPTIM_IT_ARROK : Autoreload Update completed Interrupt.
  256. * @retval Interrupt status.
  257. */
  258. #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  259. /**
  260. * @}
  261. */
  262. /* Exported functions --------------------------------------------------------*/
  263. /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
  264. * @{
  265. */
  266. /** @addtogroup LPTIM_Exported_Functions_Group1
  267. * @brief Initialization and Configuration functions.
  268. * @{
  269. */
  270. /* Initialization/de-initialization functions ********************************/
  271. HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim);
  272. HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim);
  273. /* MSP functions *************************************************************/
  274. void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim);
  275. void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim);
  276. /**
  277. * @}
  278. */
  279. /** @addtogroup LPTIM_Exported_Functions_Group2
  280. * @brief Start-Stop operation functions.
  281. * @{
  282. */
  283. /* ############################## Set once Mode ##############################*/
  284. /* Blocking mode: Polling */
  285. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  286. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim);
  287. /* Non-Blocking mode: Interrupt */
  288. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  289. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim);
  290. /* ############################## Set Continue Mode ########################*/
  291. /* Blocking mode: Polling */
  292. HAL_StatusTypeDef HAL_LPTIM_SetContinue_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  293. HAL_StatusTypeDef HAL_LPTIM_SetContinue_Stop(LPTIM_HandleTypeDef *hlptim);
  294. /* Non-Blocking mode: Interrupt */
  295. HAL_StatusTypeDef HAL_LPTIM_SetContinue_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  296. HAL_StatusTypeDef HAL_LPTIM_SetContinue_Stop_IT(LPTIM_HandleTypeDef *hlptim);
  297. /**
  298. * @}
  299. */
  300. /** @addtogroup LPTIM_Exported_Functions_Group3
  301. * @brief Read operation functions.
  302. * @{
  303. */
  304. /* Reading operation functions ************************************************/
  305. uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim);
  306. uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim);
  307. /* Reset counter functions ****************************************************/
  308. uint32_t HAL_LPTIM_ResetCounter(LPTIM_HandleTypeDef *hlptim);
  309. /**
  310. * @}
  311. */
  312. /** @addtogroup LPTIM_Exported_Functions_Group4
  313. * @brief LPTIM IRQ handler and callback functions.
  314. * @{
  315. */
  316. /* LPTIM IRQ functions *******************************************************/
  317. void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim);
  318. /* CallBack functions ********************************************************/
  319. void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim);
  320. void HAL_LPTIM_AutoReloadUpdateCompletedCallback(LPTIM_HandleTypeDef *hlptim);
  321. /* Callbacks Register/UnRegister functions ***********************************/
  322. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  323. HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID, pLPTIM_CallbackTypeDef pCallback);
  324. HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID);
  325. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  326. /**
  327. * @}
  328. */
  329. /** @addtogroup LPTIM_Group5
  330. * @brief Peripheral State functions.
  331. * @{
  332. */
  333. /* Peripheral State functions ************************************************/
  334. HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim);
  335. /**
  336. * @}
  337. */
  338. /**
  339. * @}
  340. */
  341. /* Private types -------------------------------------------------------------*/
  342. /** @defgroup LPTIM_Private_Types LPTIM Private Types
  343. * @{
  344. */
  345. /**
  346. * @}
  347. */
  348. /* Private variables ---------------------------------------------------------*/
  349. /** @defgroup LPTIM_Private_Variables LPTIM Private Variables
  350. * @{
  351. */
  352. /**
  353. * @}
  354. */
  355. /* Private constants ---------------------------------------------------------*/
  356. /** @defgroup LPTIM_Private_Constants LPTIM Private Constants
  357. * @{
  358. */
  359. /**
  360. * @}
  361. */
  362. /* Private macros ------------------------------------------------------------*/
  363. /** @defgroup LPTIM_Private_Macros LPTIM Private Macros
  364. * @{
  365. */
  366. #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) == LPTIM_PRESCALER_DIV1 ) || \
  367. ((__PRESCALER__) == LPTIM_PRESCALER_DIV2 ) || \
  368. ((__PRESCALER__) == LPTIM_PRESCALER_DIV4 ) || \
  369. ((__PRESCALER__) == LPTIM_PRESCALER_DIV8 ) || \
  370. ((__PRESCALER__) == LPTIM_PRESCALER_DIV16 ) || \
  371. ((__PRESCALER__) == LPTIM_PRESCALER_DIV32 ) || \
  372. ((__PRESCALER__) == LPTIM_PRESCALER_DIV64 ) || \
  373. ((__PRESCALER__) == LPTIM_PRESCALER_DIV128))
  374. #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) == LPTIM_PRESCALER_DIV1)
  375. #define IS_LPTIM_UPDATE_MODE(__MODE__) (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \
  376. ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD))
  377. #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__) ((__AUTORELOAD__) <= 0x0000FFFFUL)
  378. #define IS_LPTIM_PERIOD(__PERIOD__) ((__PERIOD__) <= 0x0000FFFFUL)
  379. /**
  380. * @}
  381. */
  382. /* Private functions ---------------------------------------------------------*/
  383. /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
  384. * @{
  385. */
  386. /**
  387. * @}
  388. */
  389. /**
  390. * @}
  391. */
  392. #endif /* LPTIM1 || LPTIM2 */
  393. /**
  394. * @}
  395. */
  396. #ifdef __cplusplus
  397. }
  398. #endif
  399. #endif /* __PY32F002B_HAL_LPTIM_H */
  400. /************************ (C) COPYRIGHT Puya *****END OF FILE****/