stm32f0xx_hal_comp.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @version V1.3.1
  6. * @date 29-January-2016
  7. * @brief Header file of COMP HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F0xx_HAL_COMP_H
  39. #define __STM32F0xx_HAL_COMP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #if defined(STM32F051x8) || defined(STM32F058xx) || \
  44. defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \
  45. defined(STM32F091xC) || defined(STM32F098xx)
  46. /* Includes ------------------------------------------------------------------*/
  47. #include "stm32f0xx_hal_def.h"
  48. /** @addtogroup STM32F0xx_HAL_Driver
  49. * @{
  50. */
  51. /** @addtogroup COMP COMP
  52. * @{
  53. */
  54. /* Exported types ------------------------------------------------------------*/
  55. /** @defgroup COMP_Exported_Types COMP Exported Types
  56. * @{
  57. */
  58. /**
  59. * @brief COMP Init structure definition
  60. */
  61. typedef struct
  62. {
  63. uint32_t InvertingInput; /*!< Selects the inverting input of the comparator.
  64. This parameter can be a value of @ref COMP_InvertingInput */
  65. uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator.
  66. This parameter can be a value of @ref COMP_NonInvertingInput */
  67. uint32_t Output; /*!< Selects the output redirection of the comparator.
  68. This parameter can be a value of @ref COMP_Output */
  69. uint32_t OutputPol; /*!< Selects the output polarity of the comparator.
  70. This parameter can be a value of @ref COMP_OutputPolarity */
  71. uint32_t Hysteresis; /*!< Selects the hysteresis voltage of the comparator.
  72. This parameter can be a value of @ref COMP_Hysteresis */
  73. uint32_t Mode; /*!< Selects the operating comsumption mode of the comparator
  74. to adjust the speed/consumption.
  75. This parameter can be a value of @ref COMP_Mode */
  76. uint32_t WindowMode; /*!< Selects the window mode of the comparator 1 & 2.
  77. This parameter can be a value of @ref COMP_WindowMode */
  78. uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator (interrupt mode).
  79. This parameter can be a value of @ref COMP_TriggerMode */
  80. }COMP_InitTypeDef;
  81. /**
  82. * @brief COMP Handle Structure definition
  83. */
  84. typedef struct
  85. {
  86. COMP_TypeDef *Instance; /*!< Register base address */
  87. COMP_InitTypeDef Init; /*!< COMP required parameters */
  88. HAL_LockTypeDef Lock; /*!< Locking object */
  89. __IO uint32_t State; /*!< COMP communication state
  90. This parameter can be a value of @ref COMP_State */
  91. }COMP_HandleTypeDef;
  92. /**
  93. * @}
  94. */
  95. /* Exported constants --------------------------------------------------------*/
  96. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  97. * @{
  98. */
  99. /** @defgroup COMP_State COMP State
  100. * @{
  101. */
  102. #define HAL_COMP_STATE_RESET ((uint32_t)0x00000000) /*!< COMP not yet initialized or disabled */
  103. #define HAL_COMP_STATE_READY ((uint32_t)0x00000001) /*!< COMP initialized and ready for use */
  104. #define HAL_COMP_STATE_READY_LOCKED ((uint32_t)0x00000011) /*!< COMP initialized but the configuration is locked */
  105. #define HAL_COMP_STATE_BUSY ((uint32_t)0x00000002) /*!< COMP is running */
  106. #define HAL_COMP_STATE_BUSY_LOCKED ((uint32_t)0x00000012) /*!< COMP is running and the configuration is locked */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup COMP_OutputPolarity COMP OutputPolarity
  111. * @{
  112. */
  113. #define COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000) /*!< COMP output on GPIO isn't inverted */
  114. #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMP1POL /*!< COMP output on GPIO is inverted */
  115. /**
  116. * @}
  117. */
  118. /** @defgroup COMP_Hysteresis COMP Hysteresis
  119. * @{
  120. */
  121. #define COMP_HYSTERESIS_NONE ((uint32_t)0x00000000) /*!< No hysteresis */
  122. #define COMP_HYSTERESIS_LOW COMP_CSR_COMP1HYST_0 /*!< Hysteresis level low */
  123. #define COMP_HYSTERESIS_MEDIUM COMP_CSR_COMP1HYST_1 /*!< Hysteresis level medium */
  124. #define COMP_HYSTERESIS_HIGH COMP_CSR_COMP1HYST /*!< Hysteresis level high */
  125. /**
  126. * @}
  127. */
  128. /** @defgroup COMP_Mode COMP Mode
  129. * @{
  130. */
  131. /* Please refer to the electrical characteristics in the device datasheet for
  132. the power consumption values */
  133. #define COMP_MODE_HIGHSPEED ((uint32_t)0x00000000) /*!< High Speed */
  134. #define COMP_MODE_MEDIUMSPEED COMP_CSR_COMP1MODE_0 /*!< Medium Speed */
  135. #define COMP_MODE_LOWPOWER COMP_CSR_COMP1MODE_1 /*!< Low power mode */
  136. #define COMP_MODE_ULTRALOWPOWER COMP_CSR_COMP1MODE /*!< Ultra-low power mode */
  137. /**
  138. * @}
  139. */
  140. /** @defgroup COMP_InvertingInput COMP InvertingInput
  141. * @{
  142. */
  143. #define COMP_INVERTINGINPUT_1_4VREFINT ((uint32_t)0x00000000) /*!< 1/4 VREFINT connected to comparator inverting input */
  144. #define COMP_INVERTINGINPUT_1_2VREFINT COMP_CSR_COMP1INSEL_0 /*!< 1/2 VREFINT connected to comparator inverting input */
  145. #define COMP_INVERTINGINPUT_3_4VREFINT COMP_CSR_COMP1INSEL_1 /*!< 3/4 VREFINT connected to comparator inverting input */
  146. #define COMP_INVERTINGINPUT_VREFINT (COMP_CSR_COMP1INSEL_1|COMP_CSR_COMP1INSEL_0) /*!< VREFINT connected to comparator inverting input */
  147. #define COMP_INVERTINGINPUT_DAC1 COMP_CSR_COMP1INSEL_2 /*!< DAC_OUT1 (PA4) connected to comparator inverting input */
  148. #define COMP_INVERTINGINPUT_DAC1SWITCHCLOSED (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1SW1) /*!< DAC_OUT1 (PA4) connected to comparator inverting input
  149. and close switch (PA0 for COMP1 only) */
  150. #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_COMP1INSEL_2|COMP_CSR_COMP1INSEL_0) /*!< DAC_OUT2 (PA5) connected to comparator inverting input */
  151. #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 */
  152. /**
  153. * @}
  154. */
  155. /** @defgroup COMP_NonInvertingInput COMP NonInvertingInput
  156. * @{
  157. */
  158. #define COMP_NONINVERTINGINPUT_IO1 ((uint32_t)0x00000000) /*!< I/O1 (PA1 for COMP1, PA3 for COMP2)
  159. connected to comparator non inverting input */
  160. #define COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED COMP_CSR_COMP1SW1 /*!< DAC ouput connected to comparator COMP1 non inverting input */
  161. /**
  162. * @}
  163. */
  164. /** @defgroup COMP_Output COMP Output
  165. * @{
  166. */
  167. /* Output Redirection common for COMP1 and COMP2 */
  168. #define COMP_OUTPUT_NONE ((uint32_t)0x00000000) /*!< COMP output isn't connected to other peripherals */
  169. #define COMP_OUTPUT_TIM1BKIN COMP_CSR_COMP1OUTSEL_0 /*!< COMP output connected to TIM1 Break Input (BKIN) */
  170. #define COMP_OUTPUT_TIM1IC1 COMP_CSR_COMP1OUTSEL_1 /*!< COMP output connected to TIM1 Input Capture 1 */
  171. #define COMP_OUTPUT_TIM1OCREFCLR (COMP_CSR_COMP1OUTSEL_1|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF Clear */
  172. #define COMP_OUTPUT_TIM2IC4 COMP_CSR_COMP1OUTSEL_2 /*!< COMP output connected to TIM2 Input Capture 4 */
  173. #define COMP_OUTPUT_TIM2OCREFCLR (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF Clear */
  174. #define COMP_OUTPUT_TIM3IC1 (COMP_CSR_COMP1OUTSEL_2|COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 Input Capture 1 */
  175. #define COMP_OUTPUT_TIM3OCREFCLR COMP_CSR_COMP1OUTSEL /*!< COMP output connected to TIM3 OCREF Clear */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup COMP_OutputLevel COMP OutputLevel
  180. * @{
  181. */
  182. /* When output polarity is not inverted, comparator output is low when
  183. the non-inverting input is at a lower voltage than the inverting input*/
  184. #define COMP_OUTPUTLEVEL_LOW ((uint32_t)0x00000000)
  185. /* When output polarity is not inverted, comparator output is high when
  186. the non-inverting input is at a higher voltage than the inverting input */
  187. #define COMP_OUTPUTLEVEL_HIGH COMP_CSR_COMP1OUT
  188. /**
  189. * @}
  190. */
  191. /** @defgroup COMP_TriggerMode COMP TriggerMode
  192. * @{
  193. */
  194. #define COMP_TRIGGERMODE_NONE ((uint32_t)0x00000000) /*!< No External Interrupt trigger detection */
  195. #define COMP_TRIGGERMODE_IT_RISING ((uint32_t)0x00000001) /*!< External Interrupt Mode with Rising edge trigger detection */
  196. #define COMP_TRIGGERMODE_IT_FALLING ((uint32_t)0x00000002) /*!< External Interrupt Mode with Falling edge trigger detection */
  197. #define COMP_TRIGGERMODE_IT_RISING_FALLING ((uint32_t)0x00000003) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  198. #define COMP_TRIGGERMODE_EVENT_RISING ((uint32_t)0x00000010) /*!< Event Mode with Rising edge trigger detection */
  199. #define COMP_TRIGGERMODE_EVENT_FALLING ((uint32_t)0x00000020) /*!< Event Mode with Falling edge trigger detection */
  200. #define COMP_TRIGGERMODE_EVENT_RISING_FALLING ((uint32_t)0x00000030) /*!< Event Mode with Rising/Falling edge trigger detection */
  201. /**
  202. * @}
  203. */
  204. /** @defgroup COMP_WindowMode COMP WindowMode
  205. * @{
  206. */
  207. #define COMP_WINDOWMODE_DISABLE ((uint32_t)0x00000000) /*!< Window mode disabled */
  208. #define COMP_WINDOWMODE_ENABLE COMP_CSR_WNDWEN /*!< Window mode enabled: non inverting input of comparator 2
  209. is connected to the non inverting input of comparator 1 (PA1) */
  210. /**
  211. * @}
  212. */
  213. /** @defgroup COMP_Flag COMP Flag
  214. * @{
  215. */
  216. #define COMP_FLAG_LOCK ((uint32_t)COMP_CSR_COMPxLOCK) /*!< Lock flag */
  217. /**
  218. * @}
  219. */
  220. /**
  221. * @}
  222. */
  223. /* Exported macros -----------------------------------------------------------*/
  224. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  225. * @{
  226. */
  227. /** @brief Reset COMP handle state
  228. * @param __HANDLE__: COMP handle.
  229. * @retval None
  230. */
  231. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  232. /**
  233. * @brief Enable the specified comparator.
  234. * @param __HANDLE__: COMP handle.
  235. * @retval None
  236. */
  237. #define __HAL_COMP_ENABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  238. SET_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
  239. SET_BIT(COMP->CSR, COMP_CSR_COMP2EN))
  240. /**
  241. * @brief Disable the specified comparator.
  242. * @param __HANDLE__: COMP handle.
  243. * @retval None
  244. */
  245. #define __HAL_COMP_DISABLE(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  246. CLEAR_BIT(COMP->CSR, COMP_CSR_COMP1EN) : \
  247. CLEAR_BIT(COMP->CSR, COMP_CSR_COMP2EN))
  248. /**
  249. * @brief Lock the specified comparator configuration.
  250. * @param __HANDLE__: COMP handle.
  251. * @retval None
  252. */
  253. #define __HAL_COMP_LOCK(__HANDLE__) (((__HANDLE__)->Instance == COMP1) ? \
  254. SET_BIT(COMP->CSR, COMP_CSR_COMP1LOCK) : \
  255. SET_BIT(COMP->CSR, COMP_CSR_COMP2LOCK))
  256. /**
  257. * @brief Enable the COMP1 EXTI line rising edge trigger.
  258. * @retval None
  259. */
  260. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  261. /**
  262. * @brief Disable the COMP1 EXTI line rising edge trigger.
  263. * @retval None
  264. */
  265. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  266. /**
  267. * @brief Enable the COMP1 EXTI line falling edge trigger.
  268. * @retval None
  269. */
  270. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  271. /**
  272. * @brief Disable the COMP1 EXTI line falling edge trigger.
  273. * @retval None
  274. */
  275. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  276. /**
  277. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  278. * @retval None
  279. */
  280. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  281. __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
  282. __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
  283. } while(0)
  284. /**
  285. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  286. * @retval None
  287. */
  288. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  289. __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
  290. __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
  291. } while(0)
  292. /**
  293. * @brief Enable the COMP1 EXTI line in interrupt mode.
  294. * @retval None
  295. */
  296. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  297. /**
  298. * @brief Disable the COMP1 EXTI line in interrupt mode.
  299. * @retval None
  300. */
  301. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  302. /**
  303. * @brief Generate a software interrupt on the COMP1 EXTI line.
  304. * @retval None
  305. */
  306. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
  307. /**
  308. * @brief Enable the COMP1 EXTI Line in event mode.
  309. * @retval None
  310. */
  311. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  312. /**
  313. * @brief Disable the COMP1 EXTI Line in event mode.
  314. * @retval None
  315. */
  316. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  317. /**
  318. * @brief Check whether the COMP1 EXTI line flag is set or not.
  319. * @retval RESET or SET
  320. */
  321. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
  322. /**
  323. * @brief Clear the COMP1 EXTI flag.
  324. * @retval None
  325. */
  326. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
  327. /**
  328. * @brief Enable the COMP2 EXTI line rising edge trigger.
  329. * @retval None
  330. */
  331. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  332. /**
  333. * @brief Disable the COMP2 EXTI line rising edge trigger.
  334. * @retval None
  335. */
  336. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  337. /**
  338. * @brief Enable the COMP2 EXTI line falling edge trigger.
  339. * @retval None
  340. */
  341. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  342. /**
  343. * @brief Disable the COMP2 EXTI line falling edge trigger.
  344. * @retval None
  345. */
  346. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  347. /**
  348. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  349. * @retval None
  350. */
  351. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  352. __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
  353. __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
  354. } while(0)
  355. /**
  356. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  357. * @retval None
  358. */
  359. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  360. __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
  361. __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
  362. } while(0)
  363. /**
  364. * @brief Enable the COMP2 EXTI line in interrupt mode.
  365. * @retval None
  366. */
  367. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  368. /**
  369. * @brief Disable the COMP2 EXTI line in interrupt mode.
  370. * @retval None
  371. */
  372. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  373. /**
  374. * @brief Generate a software interrupt on the COMP2 EXTI line.
  375. * @retval None
  376. */
  377. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
  378. /**
  379. * @brief Enable the COMP2 EXTI Line in event mode.
  380. * @retval None
  381. */
  382. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  383. /**
  384. * @brief Disable the COMP2 EXTI Line in event mode.
  385. * @retval None
  386. */
  387. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  388. /**
  389. * @brief Check whether the COMP2 EXTI line flag is set or not.
  390. * @retval RESET or SET
  391. */
  392. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
  393. /**
  394. * @brief Clear the COMP2 EXTI flag.
  395. * @retval None
  396. */
  397. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
  398. /** @brief Check whether the specified COMP flag is set or not.
  399. * @param __HANDLE__: specifies the COMP Handle.
  400. * @param __FLAG__: specifies the flag to check.
  401. * This parameter can be one of the following values:
  402. * @arg COMP_FLAG_LOCK: lock flag
  403. * @retval The new state of __FLAG__ (TRUE or FALSE).
  404. */
  405. #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->CSR & (__FLAG__)) == (__FLAG__))
  406. /**
  407. * @}
  408. */
  409. /* Exported functions --------------------------------------------------------*/
  410. /** @addtogroup COMP_Exported_Functions COMP Exported Functions
  411. * @{
  412. */
  413. /** @addtogroup COMP_Exported_Functions_Group1 Initialization/de-initialization functions
  414. * @brief Initialization and Configuration functions
  415. * @{
  416. */
  417. /* Initialization and de-initialization functions ****************************/
  418. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  419. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  420. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  421. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  422. /**
  423. * @}
  424. */
  425. /** @addtogroup COMP_Exported_Functions_Group2 I/O operation functions
  426. * @brief Data transfers functions
  427. * @{
  428. */
  429. /* IO operation functions *****************************************************/
  430. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  431. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  432. HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
  433. HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
  434. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  435. /**
  436. * @}
  437. */
  438. /** @addtogroup COMP_Exported_Functions_Group3 Peripheral Control functions
  439. * @brief management functions
  440. * @{
  441. */
  442. /* Peripheral Control functions ***********************************************/
  443. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  444. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  445. /* Callback in Interrupt mode */
  446. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  447. /**
  448. * @}
  449. */
  450. /** @addtogroup COMP_Exported_Functions_Group4 Peripheral State functions
  451. * @brief Peripheral State functions
  452. * @{
  453. */
  454. /* Peripheral State and Error functions ***************************************/
  455. uint32_t HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  456. /**
  457. * @}
  458. */
  459. /**
  460. * @}
  461. */
  462. /* Private types -------------------------------------------------------------*/
  463. /* Private constants ---------------------------------------------------------*/
  464. /** @defgroup COMP_Private_Constants COMP Private Constants
  465. * @{
  466. */
  467. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  468. * Elements values convention: XXXX0000
  469. * - XXXX : Interrupt mask in the EMR/IMR/RTSR/FTSR register
  470. * @{
  471. */
  472. #define COMP_EXTI_LINE_COMP1 ((uint32_t)EXTI_IMR_MR21) /*!< EXTI line 21 connected to COMP1 output */
  473. #define COMP_EXTI_LINE_COMP2 ((uint32_t)EXTI_IMR_MR22) /*!< EXTI line 22 connected to COMP2 output */
  474. /**
  475. * @}
  476. */
  477. /**
  478. * @}
  479. */
  480. /* Private macros ------------------------------------------------------------*/
  481. /** @defgroup COMP_Private_Macros COMP Private Macros
  482. * @{
  483. */
  484. /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators
  485. * @{
  486. */
  487. /**
  488. * @brief Get the specified EXTI line for a comparator instance.
  489. * @param __INSTANCE__: specifies the COMP instance.
  490. * @retval value of @ref COMP_ExtiLine
  491. */
  492. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \
  493. COMP_EXTI_LINE_COMP2)
  494. /**
  495. * @}
  496. */
  497. /** @defgroup COMP_IS_COMP_Definitions COMP Private macros to check input parameters
  498. * @{
  499. */
  500. #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \
  501. ((POL) == COMP_OUTPUTPOL_INVERTED))
  502. #define IS_COMP_HYSTERESIS(HYSTERESIS) (((HYSTERESIS) == COMP_HYSTERESIS_NONE) || \
  503. ((HYSTERESIS) == COMP_HYSTERESIS_LOW) || \
  504. ((HYSTERESIS) == COMP_HYSTERESIS_MEDIUM) || \
  505. ((HYSTERESIS) == COMP_HYSTERESIS_HIGH))
  506. #define IS_COMP_MODE(MODE) (((MODE) == COMP_MODE_HIGHSPEED) || \
  507. ((MODE) == COMP_MODE_MEDIUMSPEED) || \
  508. ((MODE) == COMP_MODE_LOWPOWER) || \
  509. ((MODE) == COMP_MODE_ULTRALOWPOWER))
  510. #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \
  511. ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \
  512. ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \
  513. ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \
  514. ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \
  515. ((INPUT) == COMP_INVERTINGINPUT_DAC1SWITCHCLOSED) || \
  516. ((INPUT) == COMP_INVERTINGINPUT_DAC2) || \
  517. ((INPUT) == COMP_INVERTINGINPUT_IO1))
  518. #define IS_COMP_NONINVERTINGINPUT(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_IO1) || \
  519. ((INPUT) == COMP_NONINVERTINGINPUT_DAC1SWITCHCLOSED))
  520. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_NONE) || \
  521. ((OUTPUT) == COMP_OUTPUT_TIM1BKIN) || \
  522. ((OUTPUT) == COMP_OUTPUT_TIM1IC1) || \
  523. ((OUTPUT) == COMP_OUTPUT_TIM1OCREFCLR) || \
  524. ((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \
  525. ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \
  526. ((OUTPUT) == COMP_OUTPUT_TIM3IC1) || \
  527. ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR))
  528. #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \
  529. ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE))
  530. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  531. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  532. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  533. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  534. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  535. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  536. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  537. /**
  538. * @}
  539. */
  540. /** @defgroup COMP_Lock COMP Lock
  541. * @{
  542. */
  543. #define COMP_LOCK_DISABLE ((uint32_t)0x00000000)
  544. #define COMP_LOCK_ENABLE COMP_CSR_COMP1LOCK
  545. #define COMP_STATE_BIT_LOCK ((uint32_t)0x10)
  546. /**
  547. * @}
  548. */
  549. /**
  550. * @}
  551. */
  552. /* Private functions ---------------------------------------------------------*/
  553. /**
  554. * @}
  555. */
  556. /**
  557. * @}
  558. */
  559. #endif /* STM32F051x8 || STM32F058xx || */
  560. /* STM32F071xB || STM32F072xB || STM32F078xx || */
  561. /* STM32F091xC || STM32F098xx */
  562. #ifdef __cplusplus
  563. }
  564. #endif
  565. #endif /* __STM32F0xx_HAL_COMP_H */
  566. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/