You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

663 lines
27 KiB

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