py32f0xx_hal_lptim.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_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 __PY32F0xx_HAL_LPTIM_H
  32. #define __PY32F0xx_HAL_LPTIM_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal_def.h"
  38. /** @addtogroup PY32F0xx_HAL_Driver
  39. * @{
  40. */
  41. #if defined (LPTIM)
  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. /**
  139. * @}
  140. */
  141. /** @defgroup LPTIM_Interrupts_Definition LPTIM Interrupts Definition
  142. * @{
  143. */
  144. #define LPTIM_IT_ARRM LPTIM_IER_ARRMIE
  145. /**
  146. * @}
  147. */
  148. /**
  149. * @}
  150. */
  151. /* Exported macros -----------------------------------------------------------*/
  152. /** @defgroup LPTIM_Exported_Macros LPTIM Exported Macros
  153. * @{
  154. */
  155. /** @brief Reset LPTIM handle state.
  156. * @param __HANDLE__ LPTIM handle
  157. * @retval None
  158. */
  159. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  160. #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) do { \
  161. (__HANDLE__)->State = HAL_LPTIM_STATE_RESET; \
  162. (__HANDLE__)->MspInitCallback = NULL; \
  163. (__HANDLE__)->MspDeInitCallback = NULL; \
  164. } while(0)
  165. #else
  166. #define __HAL_LPTIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_LPTIM_STATE_RESET)
  167. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  168. /**
  169. * @brief Enable the LPTIM peripheral.
  170. * @param __HANDLE__ LPTIM handle
  171. * @retval None
  172. */
  173. #define __HAL_LPTIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= (LPTIM_CR_ENABLE))
  174. /**
  175. * @brief Disable the LPTIM peripheral.
  176. * @param __HANDLE__ LPTIM handle
  177. * @retval None
  178. */
  179. #define __HAL_LPTIM_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR &= ~(LPTIM_CR_ENABLE))
  180. /**
  181. * @brief Start the LPTIM peripheral in single mode.
  182. * @param __HANDLE__ LPTIM handle
  183. * @retval None
  184. */
  185. #define __HAL_LPTIM_START_SINGLE(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_SNGSTRT)
  186. /**
  187. * @brief Reset after read of the LPTIM Counter register in asynchronous mode.
  188. * @param __HANDLE__ LPTIM handle
  189. * @retval None
  190. */
  191. #define __HAL_LPTIM_RESET_COUNTER_AFTERREAD(__HANDLE__) ((__HANDLE__)->Instance->CR |= LPTIM_CR_RSTARE)
  192. /**
  193. * @brief Write the passed parameter in the Autoreload register.
  194. * @param __HANDLE__ LPTIM handle
  195. * @param __VALUE__ Autoreload value
  196. * @retval None
  197. */
  198. #define __HAL_LPTIM_AUTORELOAD_SET(__HANDLE__ , __VALUE__) ((__HANDLE__)->Instance->ARR = (__VALUE__))
  199. /**
  200. * @brief Check whether the specified LPTIM flag is set or not.
  201. * @param __HANDLE__ LPTIM handle
  202. * @param __FLAG__ LPTIM flag to check
  203. * This parameter can be a value of:
  204. * @arg LPTIM_FLAG_ARRM : Autoreload match Flag.
  205. * @retval The state of the specified flag (SET or RESET).
  206. */
  207. #define __HAL_LPTIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR &(__FLAG__)) == (__FLAG__))
  208. /**
  209. * @brief Clear the specified LPTIM flag.
  210. * @param __HANDLE__ LPTIM handle.
  211. * @param __FLAG__ LPTIM flag to clear.
  212. * This parameter can be a value of:
  213. * @arg LPTIM_FLAG_ARRM : Autoreload match Flag.
  214. * @retval None.
  215. */
  216. #define __HAL_LPTIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  217. /**
  218. * @brief Enable the specified LPTIM interrupt.
  219. * @param __HANDLE__ LPTIM handle.
  220. * @param __INTERRUPT__ LPTIM interrupt to set.
  221. * This parameter can be a value of:
  222. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  223. * @retval None.
  224. */
  225. #define __HAL_LPTIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER |= (__INTERRUPT__))
  226. /**
  227. * @brief Disable the specified LPTIM interrupt.
  228. * @param __HANDLE__ LPTIM handle.
  229. * @param __INTERRUPT__ LPTIM interrupt to set.
  230. * This parameter can be a value of:
  231. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  232. * @retval None.
  233. */
  234. #define __HAL_LPTIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IER &= (~(__INTERRUPT__)))
  235. /**
  236. * @brief Check whether the specified LPTIM interrupt source is enabled or not.
  237. * @param __HANDLE__ LPTIM handle.
  238. * @param __INTERRUPT__ LPTIM interrupt to check.
  239. * This parameter can be a value of:
  240. * @arg LPTIM_IT_ARRM : Autoreload match Interrupt.
  241. * @retval Interrupt status.
  242. */
  243. #define __HAL_LPTIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  244. /**
  245. * @}
  246. */
  247. /* Exported functions --------------------------------------------------------*/
  248. /** @defgroup LPTIM_Exported_Functions LPTIM Exported Functions
  249. * @{
  250. */
  251. /* Initialization/de-initialization functions ********************************/
  252. HAL_StatusTypeDef HAL_LPTIM_Init(LPTIM_HandleTypeDef *hlptim);
  253. HAL_StatusTypeDef HAL_LPTIM_DeInit(LPTIM_HandleTypeDef *hlptim);
  254. /* MSP functions *************************************************************/
  255. void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim);
  256. void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef *hlptim);
  257. /* ############################## Set once Mode ##############################*/
  258. /* Blocking mode: Polling */
  259. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  260. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop(LPTIM_HandleTypeDef *hlptim);
  261. /* Non-Blocking mode: Interrupt */
  262. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Start_IT(LPTIM_HandleTypeDef *hlptim, uint32_t Period);
  263. HAL_StatusTypeDef HAL_LPTIM_SetOnce_Stop_IT(LPTIM_HandleTypeDef *hlptim);
  264. /* Reading operation functions ************************************************/
  265. uint32_t HAL_LPTIM_ReadCounter(LPTIM_HandleTypeDef *hlptim);
  266. uint32_t HAL_LPTIM_ReadAutoReload(LPTIM_HandleTypeDef *hlptim);
  267. /* LPTIM IRQ functions *******************************************************/
  268. void HAL_LPTIM_IRQHandler(LPTIM_HandleTypeDef *hlptim);
  269. /* CallBack functions ********************************************************/
  270. void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim);
  271. /* Callbacks Register/UnRegister functions ***********************************/
  272. #if (USE_HAL_LPTIM_REGISTER_CALLBACKS == 1)
  273. HAL_StatusTypeDef HAL_LPTIM_RegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID, pLPTIM_CallbackTypeDef pCallback);
  274. HAL_StatusTypeDef HAL_LPTIM_UnRegisterCallback(LPTIM_HandleTypeDef *lphtim, HAL_LPTIM_CallbackIDTypeDef CallbackID);
  275. #endif /* USE_HAL_LPTIM_REGISTER_CALLBACKS */
  276. /* Peripheral State functions ************************************************/
  277. HAL_LPTIM_StateTypeDef HAL_LPTIM_GetState(LPTIM_HandleTypeDef *hlptim);
  278. /**
  279. * @}
  280. */
  281. /* Private types -------------------------------------------------------------*/
  282. /** @defgroup LPTIM_Private_Types LPTIM Private Types
  283. * @{
  284. */
  285. /**
  286. * @}
  287. */
  288. /* Private variables ---------------------------------------------------------*/
  289. /** @defgroup LPTIM_Private_Variables LPTIM Private Variables
  290. * @{
  291. */
  292. /**
  293. * @}
  294. */
  295. /* Private constants ---------------------------------------------------------*/
  296. /** @defgroup LPTIM_Private_Constants LPTIM Private Constants
  297. * @{
  298. */
  299. /**
  300. * @}
  301. */
  302. /* Private macros ------------------------------------------------------------*/
  303. /** @defgroup LPTIM_Private_Macros LPTIM Private Macros
  304. * @{
  305. */
  306. #define IS_LPTIM_CLOCK_PRESCALER(__PRESCALER__) (((__PRESCALER__) == LPTIM_PRESCALER_DIV1 ) || \
  307. ((__PRESCALER__) == LPTIM_PRESCALER_DIV2 ) || \
  308. ((__PRESCALER__) == LPTIM_PRESCALER_DIV4 ) || \
  309. ((__PRESCALER__) == LPTIM_PRESCALER_DIV8 ) || \
  310. ((__PRESCALER__) == LPTIM_PRESCALER_DIV16 ) || \
  311. ((__PRESCALER__) == LPTIM_PRESCALER_DIV32 ) || \
  312. ((__PRESCALER__) == LPTIM_PRESCALER_DIV64 ) || \
  313. ((__PRESCALER__) == LPTIM_PRESCALER_DIV128))
  314. #define IS_LPTIM_CLOCK_PRESCALERDIV1(__PRESCALER__) ((__PRESCALER__) == LPTIM_PRESCALER_DIV1)
  315. #define IS_LPTIM_UPDATE_MODE(__MODE__) (((__MODE__) == LPTIM_UPDATE_IMMEDIATE) || \
  316. ((__MODE__) == LPTIM_UPDATE_ENDOFPERIOD))
  317. #define IS_LPTIM_AUTORELOAD(__AUTORELOAD__) ((__AUTORELOAD__) <= 0x0000FFFFUL)
  318. #define IS_LPTIM_PERIOD(__PERIOD__) ((__PERIOD__) <= 0x0000FFFFUL)
  319. /**
  320. * @}
  321. */
  322. /* Private functions ---------------------------------------------------------*/
  323. /** @defgroup LPTIM_Private_Functions LPTIM Private Functions
  324. * @{
  325. */
  326. /**
  327. * @}
  328. */
  329. /**
  330. * @}
  331. */
  332. #endif /* LPTIM1 || LPTIM2 */
  333. /**
  334. * @}
  335. */
  336. #ifdef __cplusplus
  337. }
  338. #endif
  339. #endif /* __PY32F0xx_HAL_LPTIM_H */
  340. /************************ (C) COPYRIGHT Puya *****END OF FILE****/