stm32f0xx_hal_comp.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP HAL 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 STM32F0xx_HAL_COMP_H
  20. #define STM32F0xx_HAL_COMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if defined (COMP1) || defined (COMP2)
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f0xx_hal_def.h"
  27. /** @addtogroup STM32F0xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup COMP COMP
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup COMP_Exported_Types COMP Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief COMP Init structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t InvertingInput; /*!< Selects the inverting input of the comparator.
  43. This parameter can be a value of @ref COMP_InvertingInput */
  44. uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator.
  45. This parameter can be a value of @ref COMP_NonInvertingInput */
  46. uint32_t Output; /*!< Selects the output redirection of the comparator.
  47. This parameter can be a value of @ref COMP_Output */
  48. uint32_t OutputPol; /*!< Selects the output polarity of the comparator.
  49. This parameter can be a value of @ref COMP_OutputPolarity */
  50. uint32_t Hysteresis; /*!< Selects the hysteresis voltage of the comparator.
  51. This parameter can be a value of @ref COMP_Hysteresis */
  52. uint32_t Mode; /*!< Selects the operating consumption mode of the comparator
  53. to adjust the speed/consumption.
  54. This parameter can be a value of @ref COMP_Mode */
  55. uint32_t WindowMode; /*!< Selects the window mode of the comparator 1 & 2.
  56. This parameter can be a value of @ref COMP_WindowMode */
  57. uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator (interrupt mode).
  58. This parameter can be a value of @ref COMP_TriggerMode */
  59. }COMP_InitTypeDef;
  60. /**
  61. * @brief COMP Handle Structure definition
  62. */
  63. typedef struct __COMP_HandleTypeDef
  64. {
  65. COMP_TypeDef *Instance; /*!< Register base address */
  66. COMP_InitTypeDef Init; /*!< COMP required parameters */
  67. HAL_LockTypeDef Lock; /*!< Locking object */
  68. __IO uint32_t State; /*!< COMP communication state
  69. This parameter can be a value of @ref COMP_State */
  70. __IO uint32_t ErrorCode; /*!< COMP Error code */
  71. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  72. void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */
  73. void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */
  74. void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
  75. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  76. }COMP_HandleTypeDef;
  77. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  78. /**
  79. * @brief HAL COMP Callback ID enumeration definition
  80. */
  81. typedef enum
  82. {
  83. HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */
  84. HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */
  85. HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */
  86. } HAL_COMP_CallbackIDTypeDef;
  87. /**
  88. * @brief HAL COMP Callback pointer definition
  89. */
  90. typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
  91. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  92. /**
  93. * @}
  94. */
  95. /* Exported constants --------------------------------------------------------*/
  96. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  97. * @{
  98. */
  99. /** @defgroup COMP_Error_Code COMP Error Code
  100. * @{
  101. */
  102. #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */
  103. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  104. #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */
  105. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  106. /**
  107. * @}
  108. */
  109. /** @defgroup COMP_State COMP State
  110. * @{
  111. */
  112. #define HAL_COMP_STATE_RESET (0x00000000U) /*!< COMP not yet initialized or disabled */
  113. #define HAL_COMP_STATE_READY (0x00000001U) /*!< COMP initialized and ready for use */
  114. #define HAL_COMP_STATE_READY_LOCKED (0x00000011U) /*!< COMP initialized but the configuration is locked */
  115. #define HAL_COMP_STATE_BUSY (0x00000002U) /*!< COMP is running */
  116. #define HAL_COMP_STATE_BUSY_LOCKED (0x00000012U) /*!< COMP is running and the configuration is locked */
  117. /**
  118. * @}
  119. */
  120. /** @defgroup COMP_OutputPolarity COMP OutputPolarity
  121. * @{
  122. */
  123. #define COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output on GPIO isn't inverted */
  124. #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMP1POL /*!< COMP output on GPIO is inverted */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup COMP_Hysteresis COMP Hysteresis
  129. * @{
  130. */
  131. #define COMP_HYSTERESIS_NONE (0x00000000U) /*!< No hysteresis */
  132. #define COMP_HYSTERESIS_LOW COMP_CSR_COMP1HYST_0 /*!< Hysteresis level low */
  133. #define COMP_HYSTERESIS_MEDIUM COMP_CSR_COMP1HYST_1 /*!< Hysteresis level medium */
  134. #define COMP_HYSTERESIS_HIGH COMP_CSR_COMP1HYST /*!< Hysteresis level high */
  135. /**
  136. * @}
  137. */
  138. /** @defgroup COMP_Mode COMP Mode
  139. * @{
  140. */
  141. /* Please refer to the electrical characteristics in the device datasheet for
  142. the power consumption values */
  143. #define COMP_MODE_HIGHSPEED (0x00000000U) /*!< High Speed */
  144. #define COMP_MODE_MEDIUMSPEED COMP_CSR_COMP1MODE_0 /*!< Medium Speed */
  145. #define COMP_MODE_LOWPOWER COMP_CSR_COMP1MODE_1 /*!< Low power mode */
  146. #define COMP_MODE_ULTRALOWPOWER COMP_CSR_COMP1MODE /*!< Ultra-low power mode */
  147. /**
  148. * @}
  149. */
  150. /** @defgroup COMP_InvertingInput COMP InvertingInput
  151. * @{
  152. */
  153. #define COMP_INVERTINGINPUT_1_4VREFINT (0x00000000U) /*!< 1/4 VREFINT connected to comparator inverting input */
  154. #define COMP_INVERTINGINPUT_1_2VREFINT COMP_CSR_COMP1INSEL_0 /*!< 1/2 VREFINT connected to comparator inverting input */
  155. #define COMP_INVERTINGINPUT_3_4VREFINT COMP_CSR_COMP1INSEL_1 /*!< 3/4 VREFINT connected to comparator inverting input */
  156. #define COMP_INVERTINGINPUT_VREFINT (COMP_CSR_COMP1INSEL_1|COMP_CSR_COMP1INSEL_0) /*!< VREFINT connected to comparator inverting input */
  157. #define COMP_INVERTINGINPUT_DAC1 COMP_CSR_COMP1INSEL_2 /*!< DAC_OUT1 (PA4) connected to comparator inverting input */
  158. #define COMP_INVERTINGINPUT_DAC1SWITCHCLOSED (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1SW1) /*!< DAC_OUT1 (PA4) connected to comparator inverting input
  159. and close switch (PA0 for COMP1 only) */
  160. #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_0) /*!< DAC_OUT2 (PA5) connected to comparator inverting input */
  161. #define COMP_INVERTINGINPUT_IO1 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_1) /*!< IO (PA0 for COMP1 and PA2 for COMP2) connected to comparator inverting input */
  162. /**
  163. * @}
  164. */
  165. /** @defgroup COMP_NonInvertingInput COMP NonInvertingInput
  166. * @{
  167. */
  168. #define COMP_NONINVERTINGINPUT_IO1 (0x00000000U) /*!< I/O1 (PA1 for COMP1, PA3 for COMP2)
  169. connected to comparator non inverting input */
  170. #define COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED COMP_CSR_COMP1SW1 /*!< DAC output connected to comparator COMP1 non inverting input */
  171. /**
  172. * @}
  173. */
  174. /** @defgroup COMP_Output COMP Output
  175. * @{
  176. */
  177. /* Output Redirection common for COMP1 and COMP2 */
  178. #define COMP_OUTPUT_NONE (0x00000000U) /*!< COMP output isn't connected to other peripherals */
  179. #define COMP_OUTPUT_TIM1BKIN COMP_CSR_COMP1OUTSEL_0 /*!< COMP output connected to TIM1 Break Input (BKIN) */
  180. #define COMP_OUTPUT_TIM1IC1 COMP_CSR_COMP1OUTSEL_1 /*!< COMP output connected to TIM1 Input Capture 1 */
  181. #define COMP_OUTPUT_TIM1OCREFCLR (COMP_CSR_COMP1OUTSEL_1|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF Clear */
  182. #define COMP_OUTPUT_TIM2IC4 COMP_CSR_COMP1OUTSEL_2 /*!< COMP output connected to TIM2 Input Capture 4 */
  183. #define COMP_OUTPUT_TIM2OCREFCLR (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF Clear */
  184. #define COMP_OUTPUT_TIM3IC1 (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 Input Capture 1 */
  185. #define COMP_OUTPUT_TIM3OCREFCLR COMP_CSR_COMP1OUTSEL /*!< COMP output connected to TIM3 OCREF Clear */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup COMP_OutputLevel COMP OutputLevel
  190. * @{
  191. */
  192. /* When output polarity is not inverted, comparator output is low when
  193. the non-inverting input is at a lower voltage than the inverting input*/
  194. #define COMP_OUTPUTLEVEL_LOW (0x00000000U)
  195. /* When output polarity is not inverted, comparator output is high when
  196. the non-inverting input is at a higher voltage than the inverting input */
  197. #define COMP_OUTPUTLEVEL_HIGH COMP_CSR_COMP1OUT
  198. /**
  199. * @}
  200. */
  201. /** @defgroup COMP_TriggerMode COMP TriggerMode
  202. * @{
  203. */
  204. #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< No External Interrupt trigger detection */
  205. #define COMP_TRIGGERMODE_IT_RISING (0x00000001U) /*!< External Interrupt Mode with Rising edge trigger detection */
  206. #define COMP_TRIGGERMODE_IT_FALLING (0x00000002U) /*!< External Interrupt Mode with Falling edge trigger detection */
  207. #define COMP_TRIGGERMODE_IT_RISING_FALLING (0x00000003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  208. #define COMP_TRIGGERMODE_EVENT_RISING (0x00000010U) /*!< Event Mode with Rising edge trigger detection */
  209. #define COMP_TRIGGERMODE_EVENT_FALLING (0x00000020U) /*!< Event Mode with Falling edge trigger detection */
  210. #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (0x00000030U) /*!< Event Mode with Rising/Falling edge trigger detection */
  211. /**
  212. * @}
  213. */
  214. /** @defgroup COMP_WindowMode COMP WindowMode
  215. * @{
  216. */
  217. #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disabled */
  218. #define COMP_WINDOWMODE_ENABLE COMP_CSR_WNDWEN /*!< Window mode enabled: non inverting input of comparator 2
  219. is connected to the non inverting input of comparator 1 (PA1) */
  220. /**
  221. * @}
  222. */
  223. /** @defgroup COMP_Flag COMP Flag
  224. * @{
  225. */
  226. #define COMP_FLAG_LOCK ((uint32_t)COMP_CSR_COMPxLOCK) /*!< Lock flag */
  227. /**
  228. * @}
  229. */
  230. /**
  231. * @}
  232. */
  233. /* Exported macros -----------------------------------------------------------*/
  234. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  235. * @{
  236. */
  237. /** @brief Reset COMP handle state
  238. * @param __HANDLE__ COMP handle.
  239. * @retval None
  240. */
  241. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  242. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
  243. (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
  244. (__HANDLE__)->MspInitCallback = NULL; \
  245. (__HANDLE__)->MspDeInitCallback = NULL; \
  246. } while(0)
  247. #else
  248. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  249. #endif
  250. /**
  251. * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
  252. * @param __HANDLE__ COMP handle
  253. * @retval None
  254. */
  255. #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
  256. /**
  257. * @brief Enable the specified comparator.
  258. * @param __HANDLE__ COMP handle.
  259. * @retval None
  260. */
  261. #define __HAL_COMP_ENABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  262. SET_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
  263. SET_BIT(COMP->CSR, COMP_CSR_COMP2EN))
  264. /**
  265. * @brief Disable the specified comparator.
  266. * @param __HANDLE__ COMP handle.
  267. * @retval None
  268. */
  269. #define __HAL_COMP_DISABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  270. CLEAR_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
  271. CLEAR_BIT(COMP->CSR, COMP_CSR_COMP2EN))
  272. /**
  273. * @brief Lock the specified comparator configuration.
  274. * @param __HANDLE__ COMP handle.
  275. * @retval None
  276. */
  277. #define __HAL_COMP_LOCK(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  278. SET_BIT(COMP->CSR, COMP_CSR_COMP1LOCK) : \
  279. SET_BIT(COMP->CSR, COMP_CSR_COMP2LOCK))
  280. /**
  281. * @brief Enable the COMP1 EXTI line rising edge trigger.
  282. * @retval None
  283. */
  284. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  285. /**
  286. * @brief Disable the COMP1 EXTI line rising edge trigger.
  287. * @retval None
  288. */
  289. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  290. /**
  291. * @brief Enable the COMP1 EXTI line falling edge trigger.
  292. * @retval None
  293. */
  294. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  295. /**
  296. * @brief Disable the COMP1 EXTI line falling edge trigger.
  297. * @retval None
  298. */
  299. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  300. /**
  301. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  302. * @retval None
  303. */
  304. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  305. __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
  306. __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
  307. } while(0)
  308. /**
  309. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  310. * @retval None
  311. */
  312. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  313. __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
  314. __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
  315. } while(0)
  316. /**
  317. * @brief Enable the COMP1 EXTI line in interrupt mode.
  318. * @retval None
  319. */
  320. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  321. /**
  322. * @brief Disable the COMP1 EXTI line in interrupt mode.
  323. * @retval None
  324. */
  325. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  326. /**
  327. * @brief Generate a software interrupt on the COMP1 EXTI line.
  328. * @retval None
  329. */
  330. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
  331. /**
  332. * @brief Enable the COMP1 EXTI Line in event mode.
  333. * @retval None
  334. */
  335. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  336. /**
  337. * @brief Disable the COMP1 EXTI Line in event mode.
  338. * @retval None
  339. */
  340. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  341. /**
  342. * @brief Check whether the COMP1 EXTI line flag is set or not.
  343. * @retval RESET or SET
  344. */
  345. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
  346. /**
  347. * @brief Clear the COMP1 EXTI flag.
  348. * @retval None
  349. */
  350. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
  351. /**
  352. * @brief Enable the COMP2 EXTI line rising edge trigger.
  353. * @retval None
  354. */
  355. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  356. /**
  357. * @brief Disable the COMP2 EXTI line rising edge trigger.
  358. * @retval None
  359. */
  360. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  361. /**
  362. * @brief Enable the COMP2 EXTI line falling edge trigger.
  363. * @retval None
  364. */
  365. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  366. /**
  367. * @brief Disable the COMP2 EXTI line falling edge trigger.
  368. * @retval None
  369. */
  370. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  371. /**
  372. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  373. * @retval None
  374. */
  375. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  376. __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
  377. __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
  378. } while(0)
  379. /**
  380. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  381. * @retval None
  382. */
  383. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  384. __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
  385. __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
  386. } while(0)
  387. /**
  388. * @brief Enable the COMP2 EXTI line in interrupt mode.
  389. * @retval None
  390. */
  391. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  392. /**
  393. * @brief Disable the COMP2 EXTI line in interrupt mode.
  394. * @retval None
  395. */
  396. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  397. /**
  398. * @brief Generate a software interrupt on the COMP2 EXTI line.
  399. * @retval None
  400. */
  401. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
  402. /**
  403. * @brief Enable the COMP2 EXTI Line in event mode.
  404. * @retval None
  405. */
  406. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  407. /**
  408. * @brief Disable the COMP2 EXTI Line in event mode.
  409. * @retval None
  410. */
  411. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  412. /**
  413. * @brief Check whether the COMP2 EXTI line flag is set or not.
  414. * @retval RESET or SET
  415. */
  416. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
  417. /**
  418. * @brief Clear the COMP2 EXTI flag.
  419. * @retval None
  420. */
  421. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
  422. /** @brief Check whether the specified COMP flag is set or not.
  423. * @param __HANDLE__ specifies the COMP Handle.
  424. * @param __FLAG__ specifies the flag to check.
  425. * This parameter can be one of the following values:
  426. * @arg COMP_FLAG_LOCK: lock flag
  427. * @retval The new state of __FLAG__ (TRUE or FALSE).
  428. */
  429. #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->CSR & (__FLAG__)) == (__FLAG__))
  430. /**
  431. * @}
  432. */
  433. /* Exported functions --------------------------------------------------------*/
  434. /** @addtogroup COMP_Exported_Functions COMP Exported Functions
  435. * @{
  436. */
  437. /** @addtogroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions
  438. * @brief Initialization and Configuration functions
  439. * @{
  440. */
  441. /* Initialization and de-initialization functions ****************************/
  442. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  443. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  444. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  445. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  446. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  447. /* Callbacks Register/UnRegister functions ***********************************/
  448. HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
  449. HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
  450. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  451. /**
  452. * @}
  453. */
  454. /** @addtogroup COMP_Exported_Functions_Group2 I/O operation functions
  455. * @brief Data transfers functions
  456. * @{
  457. */
  458. /* IO operation functions *****************************************************/
  459. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  460. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  461. HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
  462. HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
  463. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  464. /**
  465. * @}
  466. */
  467. /** @addtogroup COMP_Exported_Functions_Group3 Peripheral Control functions
  468. * @brief management functions
  469. * @{
  470. */
  471. /* Peripheral Control functions ***********************************************/
  472. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  473. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  474. /* Callback in Interrupt mode */
  475. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  476. /**
  477. * @}
  478. */
  479. /** @addtogroup COMP_Exported_Functions_Group4 Peripheral State functions
  480. * @brief Peripheral State functions
  481. * @{
  482. */
  483. /* Peripheral State and Error functions ***************************************/
  484. uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  485. uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
  486. /**
  487. * @}
  488. */
  489. /**
  490. * @}
  491. */
  492. /* Private types -------------------------------------------------------------*/
  493. /* Private constants ---------------------------------------------------------*/
  494. /** @defgroup COMP_Private_Constants COMP Private Constants
  495. * @{
  496. */
  497. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  498. * Elements values convention: XXXX0000
  499. * - XXXX : Interrupt mask in the EMR/IMR/RTSR/FTSR register
  500. * @{
  501. */
  502. #define COMP_EXTI_LINE_COMP1 ((uint32_t)EXTI_IMR_MR21) /*!< EXTI line 21 connected to COMP1 output */
  503. #define COMP_EXTI_LINE_COMP2 ((uint32_t)EXTI_IMR_MR22) /*!< EXTI line 22 connected to COMP2 output */
  504. /**
  505. * @}
  506. */
  507. /**
  508. * @}
  509. */
  510. /* Private macros ------------------------------------------------------------*/
  511. /** @defgroup COMP_Private_Macros COMP Private Macros
  512. * @{
  513. */
  514. /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators
  515. * @{
  516. */
  517. /**
  518. * @brief Get the specified EXTI line for a comparator instance.
  519. * @param __INSTANCE__ specifies the COMP instance.
  520. * @retval value of @ref COMP_ExtiLine
  521. */
  522. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \
  523. COMP_EXTI_LINE_COMP2)
  524. /**
  525. * @}
  526. */
  527. /** @defgroup COMP_IS_COMP_Definitions COMP Private macros to check input parameters
  528. * @{
  529. */
  530. #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \
  531. ((POL) == COMP_OUTPUTPOL_INVERTED))
  532. #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_HYSTERESIS_NONE) || \
  533. ((HYSTERESIS) == COMP_HYSTERESIS_LOW) || \
  534. ((HYSTERESIS) == COMP_HYSTERESIS_MEDIUM) || \
  535. ((HYSTERESIS) == COMP_HYSTERESIS_HIGH))
  536. #define IS_COMP_MODE(MODE) (((MODE) == COMP_MODE_HIGHSPEED) || \
  537. ((MODE) == COMP_MODE_MEDIUMSPEED) || \
  538. ((MODE) == COMP_MODE_LOWPOWER) || \
  539. ((MODE) == COMP_MODE_ULTRALOWPOWER))
  540. #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \
  541. ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \
  542. ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \
  543. ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \
  544. ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \
  545. ((INPUT) == COMP_INVERTINGINPUT_DAC1SWITCHCLOSED) || \
  546. ((INPUT) == COMP_INVERTINGINPUT_DAC2) || \
  547. ((INPUT) == COMP_INVERTINGINPUT_IO1))
  548. #define IS_COMP_NONINVERTINGINPUT(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_IO1) || \
  549. ((INPUT) == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED))
  550. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_NONE) || \
  551. ((OUTPUT) == COMP_OUTPUT_TIM1BKIN) || \
  552. ((OUTPUT) == COMP_OUTPUT_TIM1IC1) || \
  553. ((OUTPUT) == COMP_OUTPUT_TIM1OCREFCLR) || \
  554. ((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \
  555. ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \
  556. ((OUTPUT) == COMP_OUTPUT_TIM3IC1) || \
  557. ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR))
  558. #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \
  559. ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE))
  560. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  561. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  562. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  563. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  564. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  565. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  566. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  567. /**
  568. * @}
  569. */
  570. /** @defgroup COMP_Lock COMP Lock
  571. * @{
  572. */
  573. #define COMP_LOCK_DISABLE (0x00000000U)
  574. #define COMP_LOCK_ENABLE COMP_CSR_COMP1LOCK
  575. #define COMP_STATE_BIT_LOCK (0x10U)
  576. /**
  577. * @}
  578. */
  579. /**
  580. * @}
  581. */
  582. /* Private functions ---------------------------------------------------------*/
  583. /**
  584. * @}
  585. */
  586. /**
  587. * @}
  588. */
  589. #endif /* COMP1 || COMP2 */
  590. #ifdef __cplusplus
  591. }
  592. #endif
  593. #endif /* STM32F0xx_HAL_COMP_H */