py32f0xx_hal_comp.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_hal_comp.h
  4. * @author MCU Application Team
  5. * @brief Header file of COMP 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_COMP_H
  32. #define __PY32F0xx_HAL_COMP_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx_hal_def.h"
  38. #include "py32f0xx_ll_exti.h"
  39. /** @addtogroup PY32F0xx_HAL_Driver
  40. * @{
  41. */
  42. /** @addtogroup COMP
  43. * @{
  44. */
  45. /* Exported types ------------------------------------------------------------*/
  46. /** @defgroup COMP_Exported_Types COMP Exported Types
  47. * @{
  48. */
  49. /**
  50. * @brief COMP Init structure definition
  51. */
  52. typedef struct
  53. {
  54. uint32_t WindowMode; /*!< Set window mode of a pair of comparators instances
  55. (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
  56. Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode.
  57. This parameter can be a value of @ref COMP_WindowMode */
  58. uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed.
  59. Note: For the characteristics of comparator power modes
  60. (propagation delay and power consumption), refer to device datasheet.
  61. This parameter can be a value of @ref COMP_PowerMode */
  62. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  63. This parameter can be a value of @ref COMP_InputPlus */
  64. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  65. This parameter can be a value of @ref COMP_InputMinus */
  66. uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus.
  67. This parameter can be a value of @ref COMP_Hysteresis */
  68. uint32_t OutputPol; /*!< Set comparator output polarity.
  69. This parameter can be a value of @ref COMP_OutputPolarity */
  70. uint32_t DigitalFilter; /*!< Specifies the digital filter. the filter is prohibited
  71. when the value is zero.
  72. This parameter must be a number between 0 and 0xFFFF */
  73. uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI).
  74. This parameter can be a value of @ref COMP_EXTI_TriggerMode */
  75. } COMP_InitTypeDef;
  76. /**
  77. * @brief HAL COMP state machine: HAL COMP states definition
  78. */
  79. #define COMP_STATE_BITFIELD_LOCK (0x10U)
  80. typedef enum
  81. {
  82. HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */
  83. HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
  84. HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */
  85. HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */
  86. HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */
  87. HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */
  88. } HAL_COMP_StateTypeDef;
  89. /**
  90. * @brief COMP Handle Structure definition
  91. */
  92. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  93. typedef struct __COMP_HandleTypeDef
  94. #else
  95. typedef struct
  96. #endif
  97. {
  98. COMP_TypeDef *Instance; /*!< Register base address */
  99. COMP_InitTypeDef Init; /*!< COMP required parameters */
  100. HAL_LockTypeDef Lock; /*!< Locking object */
  101. __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */
  102. __IO uint32_t ErrorCode; /*!< COMP error code */
  103. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  104. void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */
  105. void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */
  106. void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
  107. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  108. } COMP_HandleTypeDef;
  109. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  110. /**
  111. * @brief HAL COMP Callback ID enumeration definition
  112. */
  113. typedef enum
  114. {
  115. HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */
  116. HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */
  117. HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */
  118. } HAL_COMP_CallbackIDTypeDef;
  119. /**
  120. * @brief HAL COMP Callback pointer definition
  121. */
  122. typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
  123. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  124. /**
  125. * @}
  126. */
  127. /* Exported constants --------------------------------------------------------*/
  128. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  129. * @{
  130. */
  131. /** @defgroup COMP_Error_Code COMP Error Code
  132. * @{
  133. */
  134. #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */
  135. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  136. #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */
  137. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  138. /**
  139. * @}
  140. */
  141. /** @defgroup COMP_WindowMode COMP Window Mode
  142. * @{
  143. */
  144. #define COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
  145. #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
  146. #define COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | COMP_WINDOWMODE_COMP2) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP2 input plus (COMP1 input plus is no more accessible). */
  147. /**
  148. * @}
  149. */
  150. /** @defgroup COMP_PowerMode COMP power mode
  151. * @{
  152. */
  153. /* Note: For the characteristics of comparator power modes */
  154. /* (propagation delay and power consumption), */
  155. /* refer to device datasheet. */
  156. #define COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< High Speed */
  157. #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
  162. * @{
  163. */
  164. #define COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PB8 for COMP1, pin PB4 for COMP2) */
  165. #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
  166. #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
  167. #define COMP_INPUT_PLUS_IO4 (COMP_CSR_INPSEL_1 | COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO4 (Reserved for COMP1, pin PF3 for COMP2) */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup COMP_InputMinus COMP input minus (inverting input)
  172. * @{
  173. */
  174. #define COMP_INPUT_MINUS_1_4VREFINT (0x00000000UL) /*!< Comparator input minus connected to 1/4 VrefInt */
  175. #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
  176. #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
  177. #define COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
  178. #define COMP_INPUT_MINUS_VCC ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to VCC */
  179. #define COMP_INPUT_MINUS_TS ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to temperature sensor */
  180. #define COMP_INPUT_MINUS_IO1 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
  181. #define COMP_INPUT_MINUS_IO2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (Reserved for COMP1, pin PB7 for COMP2) */
  182. #define COMP_INPUT_MINUS_IO3 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
  183. /**
  184. * @}
  185. */
  186. /** @defgroup COMP_Hysteresis COMP hysteresis
  187. * @{
  188. */
  189. #define COMP_HYSTERESIS_DISABLE (0x00000000UL) /*!< No hysteresis */
  190. #define COMP_HYSTERESIS_ENABLE (COMP_CSR_HYST) /*!< Hysteresis enable */
  191. /**
  192. * @}
  193. */
  194. /** @defgroup COMP_OutputPolarity COMP output Polarity
  195. * @{
  196. */
  197. #define COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
  198. #define COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output level is inverted (comparator output is low when the input plus is at a higher voltage than the input minus) */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup COMP_OutputLevel COMP Output Level
  203. * @{
  204. */
  205. /* Note: Comparator output level values are fixed to "0" and "1", */
  206. /* corresponding COMP register bit is managed by HAL function to match */
  207. /* with these values (independently of bit position in register). */
  208. /* When output polarity is not inverted, comparator output is low when
  209. the input plus is at a lower voltage than the input minus */
  210. #define COMP_OUTPUT_LEVEL_LOW (0x00000000UL)
  211. /* When output polarity is not inverted, comparator output is high when
  212. the input plus is at a higher voltage than the input minus */
  213. #define COMP_OUTPUT_LEVEL_HIGH (0x00000001UL)
  214. /**
  215. * @}
  216. */
  217. /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
  218. * @{
  219. */
  220. #define COMP_TRIGGERMODE_NONE (0x00000000UL) /*!< Comparator output triggering no External Interrupt Line */
  221. #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
  222. #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
  223. #define COMP_TRIGGERMODE_IT_RISING_FALLING (COMP_EXTI_IT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */
  224. #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
  225. #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
  226. #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */
  227. /**
  228. * @}
  229. */
  230. /**
  231. * @}
  232. */
  233. /* Exported macro ------------------------------------------------------------*/
  234. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  235. * @{
  236. */
  237. /** @defgroup COMP_Handle_Management COMP Handle Management
  238. * @{
  239. */
  240. /** @brief Reset COMP handle state.
  241. * @param __HANDLE__ COMP handle
  242. * @retval None
  243. */
  244. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  245. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
  246. (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
  247. (__HANDLE__)->MspInitCallback = NULL; \
  248. (__HANDLE__)->MspDeInitCallback = NULL; \
  249. } while(0)
  250. #else
  251. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  252. #endif
  253. /**
  254. * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
  255. * @param __HANDLE__ COMP handle
  256. * @retval None
  257. */
  258. #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
  259. /**
  260. * @brief Enable the specified comparator.
  261. * @param __HANDLE__ COMP handle
  262. * @retval None
  263. */
  264. #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  265. /**
  266. * @brief Disable the specified comparator.
  267. * @param __HANDLE__ COMP handle
  268. * @retval None
  269. */
  270. #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  271. /**
  272. * @brief Lock the specified comparator configuration.
  273. * @note Using this macro induce HAL COMP handle state machine being no
  274. * more in line with COMP instance state.
  275. * To keep HAL COMP handle state machine updated, it is recommended
  276. * to use function "HAL_COMP_Lock')".
  277. * @param __HANDLE__ COMP handle
  278. * @retval None
  279. */
  280. #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
  281. /**
  282. * @brief Check whether the specified comparator is locked.
  283. * @param __HANDLE__ COMP handle
  284. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  285. */
  286. #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
  287. /**
  288. * @brief Disable vrefint input.
  289. * @param __HANDLE__ COMP handle
  290. * @retval None
  291. */
  292. #define __HAL_COMP_DISABLE_SCALER(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_SCALER_EN)
  293. /**
  294. * @brief Check whether the vrefint input is enabled.
  295. * @param __HANDLE__ COMP handle
  296. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  297. */
  298. #define __HAL_COMP_IS_ENABLED_SCALER(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_SCALER_EN) == COMP_CSR_SCALER_EN)
  299. /**
  300. * @}
  301. */
  302. /** @defgroup COMP_Exti_Management COMP external interrupt line management
  303. * @{
  304. */
  305. /**
  306. * @brief Enable the COMP1 EXTI line rising edge trigger.
  307. * @retval None
  308. */
  309. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig(COMP_EXTI_LINE_COMP1)
  310. /**
  311. * @brief Disable the COMP1 EXTI line rising edge trigger.
  312. * @retval None
  313. */
  314. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig(COMP_EXTI_LINE_COMP1)
  315. /**
  316. * @brief Enable the COMP1 EXTI line falling edge trigger.
  317. * @retval None
  318. */
  319. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig(COMP_EXTI_LINE_COMP1)
  320. /**
  321. * @brief Disable the COMP1 EXTI line falling edge trigger.
  322. * @retval None
  323. */
  324. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig(COMP_EXTI_LINE_COMP1)
  325. /**
  326. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  327. * @retval None
  328. */
  329. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  330. LL_EXTI_EnableRisingTrig(COMP_EXTI_LINE_COMP1); \
  331. LL_EXTI_EnableFallingTrig(COMP_EXTI_LINE_COMP1); \
  332. } while(0)
  333. /**
  334. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  335. * @retval None
  336. */
  337. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  338. LL_EXTI_DisableRisingTrig(COMP_EXTI_LINE_COMP1); \
  339. LL_EXTI_DisableFallingTrig(COMP_EXTI_LINE_COMP1); \
  340. } while(0)
  341. /**
  342. * @brief Enable the COMP1 EXTI line in interrupt mode.
  343. * @retval None
  344. */
  345. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() LL_EXTI_EnableIT(COMP_EXTI_LINE_COMP1)
  346. /**
  347. * @brief Disable the COMP1 EXTI line in interrupt mode.
  348. * @retval None
  349. */
  350. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() LL_EXTI_DisableIT(COMP_EXTI_LINE_COMP1)
  351. /**
  352. * @brief Generate a software interrupt on the COMP1 EXTI line.
  353. * @retval None
  354. */
  355. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI(COMP_EXTI_LINE_COMP1)
  356. /**
  357. * @brief Enable the COMP1 EXTI line in event mode.
  358. * @retval None
  359. */
  360. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent(COMP_EXTI_LINE_COMP1)
  361. /**
  362. * @brief Disable the COMP1 EXTI line in event mode.
  363. * @retval None
  364. */
  365. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent(COMP_EXTI_LINE_COMP1)
  366. /**
  367. * @brief Enable the COMP2 EXTI line rising edge trigger.
  368. * @retval None
  369. */
  370. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig(COMP_EXTI_LINE_COMP2)
  371. /**
  372. * @brief Disable the COMP2 EXTI line rising edge trigger.
  373. * @retval None
  374. */
  375. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig(COMP_EXTI_LINE_COMP2)
  376. /**
  377. * @brief Enable the COMP2 EXTI line falling edge trigger.
  378. * @retval None
  379. */
  380. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig(COMP_EXTI_LINE_COMP2)
  381. /**
  382. * @brief Disable the COMP2 EXTI line falling edge trigger.
  383. * @retval None
  384. */
  385. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig(COMP_EXTI_LINE_COMP2)
  386. /**
  387. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  388. * @retval None
  389. */
  390. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  391. LL_EXTI_EnableRisingTrig(COMP_EXTI_LINE_COMP2); \
  392. LL_EXTI_EnableFallingTrig(COMP_EXTI_LINE_COMP2); \
  393. } while(0)
  394. /**
  395. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  396. * @retval None
  397. */
  398. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  399. LL_EXTI_DisableRisingTrig(COMP_EXTI_LINE_COMP2); \
  400. LL_EXTI_DisableFallingTrig(COMP_EXTI_LINE_COMP2); \
  401. } while(0)
  402. /**
  403. * @brief Enable the COMP2 EXTI line in interrupt mode.
  404. * @retval None
  405. */
  406. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT(COMP_EXTI_LINE_COMP2)
  407. /**
  408. * @brief Disable the COMP2 EXTI line in interrupt mode.
  409. * @retval None
  410. */
  411. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT(COMP_EXTI_LINE_COMP2)
  412. /**
  413. * @brief Generate a software interrupt on the COMP2 EXTI line.
  414. * @retval None
  415. */
  416. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI(COMP_EXTI_LINE_COMP2)
  417. /**
  418. * @brief Enable the COMP2 EXTI line in event mode.
  419. * @retval None
  420. */
  421. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent(COMP_EXTI_LINE_COMP2)
  422. /**
  423. * @brief Disable the COMP2 EXTI line in event mode.
  424. * @retval None
  425. */
  426. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent(COMP_EXTI_LINE_COMP2)
  427. /**
  428. * @}
  429. */
  430. /**
  431. * @}
  432. */
  433. /* Private types -------------------------------------------------------------*/
  434. /* Private constants ---------------------------------------------------------*/
  435. /** @defgroup COMP_Private_Constants COMP Private Constants
  436. * @{
  437. */
  438. /** @defgroup COMP_WindowMode_Instance_Differentiator COMP window mode instance differentiator
  439. * @{
  440. */
  441. #define COMP_WINDOWMODE_COMP2 0x00001000U /*!< COMP window mode using common input of COMP instance: COMP2 */
  442. /**
  443. * @}
  444. */
  445. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  446. * @{
  447. */
  448. #define COMP_EXTI_LINE_COMP1 (EXTI_IMR_IM17) /*!< EXTI line 17 connected to COMP1 output */
  449. #define COMP_EXTI_LINE_COMP2 (EXTI_IMR_IM18) /*!< EXTI line 18 connected to COMP2 output */
  450. /**
  451. * @}
  452. */
  453. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  454. * @{
  455. */
  456. #define COMP_EXTI_IT (0x00000001UL) /*!< EXTI line event with interruption */
  457. #define COMP_EXTI_EVENT (0x00000002UL) /*!< EXTI line event only (without interruption) */
  458. #define COMP_EXTI_RISING (0x00000010UL) /*!< EXTI line event on rising edge */
  459. #define COMP_EXTI_FALLING (0x00000020UL) /*!< EXTI line event on falling edge */
  460. /**
  461. * @}
  462. */
  463. /**
  464. * @}
  465. */
  466. /* Private macros ------------------------------------------------------------*/
  467. /** @defgroup COMP_Private_Macros COMP Private Macros
  468. * @{
  469. */
  470. /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
  471. * @{
  472. */
  473. /**
  474. * @brief Get the specified EXTI line for a comparator instance.
  475. * @param __INSTANCE__ specifies the COMP instance.
  476. * @retval value of @ref COMP_ExtiLine
  477. */
  478. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \
  479. : COMP_EXTI_LINE_COMP2)
  480. /**
  481. * @}
  482. */
  483. /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
  484. * @{
  485. */
  486. #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
  487. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON)|| \
  488. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON) )
  489. #define IS_COMP_WINDOWOUTPUT(__WINDOWOUTPUT__) (((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_EACH_COMP) || \
  490. ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP1) || \
  491. ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_COMP2) || \
  492. ((__WINDOWOUTPUT__) == COMP_WINDOWOUTPUT_BOTH) )
  493. #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \
  494. ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) )
  495. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  496. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
  497. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) || \
  498. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4))
  499. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  500. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  501. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  502. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  503. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VCC) || \
  504. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_TS) || \
  505. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  506. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \
  507. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3))
  508. #define IS_COMP_INPUT_MINUS_VREFINT(__INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  509. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  510. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  511. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT))
  512. #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_DISABLE) || \
  513. ((__HYSTERESIS__) == COMP_HYSTERESIS_ENABLE))
  514. #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
  515. ((__POL__) == COMP_OUTPUTPOL_INVERTED))
  516. #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \
  517. ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \
  518. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC4) \
  519. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5) \
  520. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3) \
  521. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3) \
  522. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC2) \
  523. )
  524. /* Note: Output blanking source common to all COMP instances */
  525. /* Macro kept for compatibility with other PY32 series */
  526. #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  527. (IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__))
  528. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  529. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  530. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  531. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  532. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  533. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  534. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  535. #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
  536. ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
  537. /**
  538. * @}
  539. */
  540. /**
  541. * @}
  542. */
  543. /* Exported functions --------------------------------------------------------*/
  544. /** @addtogroup COMP_Exported_Functions
  545. * @{
  546. */
  547. /** @addtogroup COMP_Exported_Functions_Group1
  548. * @{
  549. */
  550. /* Initialization and de-initialization functions **********************************/
  551. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  552. HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
  553. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  554. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  555. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  556. /* Callbacks Register/UnRegister functions ***********************************/
  557. HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
  558. pCOMP_CallbackTypeDef pCallback);
  559. HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
  560. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  561. /**
  562. * @}
  563. */
  564. /* IO operation functions *****************************************************/
  565. /** @addtogroup COMP_Exported_Functions_Group2
  566. * @{
  567. */
  568. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  569. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  570. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  571. /**
  572. * @}
  573. */
  574. /* Peripheral Control functions ************************************************/
  575. /** @addtogroup COMP_Exported_Functions_Group3
  576. * @{
  577. */
  578. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  579. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  580. /* Callback in interrupt mode */
  581. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  582. /**
  583. * @}
  584. */
  585. /* Peripheral State functions **************************************************/
  586. /** @addtogroup COMP_Exported_Functions_Group4
  587. * @{
  588. */
  589. HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  590. uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
  591. /**
  592. * @}
  593. */
  594. /**
  595. * @}
  596. */
  597. /**
  598. * @}
  599. */
  600. /**
  601. * @}
  602. */
  603. #ifdef __cplusplus
  604. }
  605. #endif
  606. #endif /* PY32F0xx_HAL_COMP_H */
  607. /************************ (C) COPYRIGHT Puya *****END OF FILE****/