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.

stm32l1xx_hal_comp.h 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_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) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST 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. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32L1xx_HAL_COMP_H
  21. #define __STM32L1xx_HAL_COMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx_hal_def.h"
  27. /** @addtogroup STM32L1xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup 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. Note: Inverting input can be changed on the fly, while comparator is running.
  45. Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded (On COMP1, inverting input is fixed to Vrefint). */
  46. uint32_t NonInvertingInput; /*!< Selects the non inverting input of the comparator.
  47. This parameter can be a value of @ref COMPEx_NonInvertingInput */
  48. uint32_t Output; /*!< Selects the output redirection of the comparator.
  49. This parameter can be a value of @ref COMP_Output
  50. Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */
  51. uint32_t Mode; /*!< Selects the operating consumption mode of the comparator
  52. to adjust the speed/consumption.
  53. This parameter can be a value of @ref COMP_Mode
  54. Note: This feature is available on COMP2 only. If COMP1 is selected, this parameter is discarded. */
  55. uint32_t WindowMode; /*!< Selects the window mode of the 2 comparators.
  56. If enabled, non-inverting inputs of the 2 comparators are connected together and are using inputs of COMP2 only (COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP).
  57. This parameter can be a value of @ref COMP_WindowMode
  58. Note: This feature must be enabled from COMP2 instance. If COMP1 is selected, this parameter is discarded. */
  59. uint32_t TriggerMode; /*!< Selects the trigger mode of the comparator when using interruption on EXTI line (interrupt mode).
  60. This parameter can be a value of @ref COMP_TriggerMode
  61. Note: This feature is used with function "HAL_COMP_Start_IT()". In all other functions, this parameter is discarded. */
  62. uint32_t NonInvertingInputPull; /*!< Selects the internal pulling resistor connected on non inverting input.
  63. This parameter can be a value of @ref COMP_NonInvertingInputPull
  64. Note: To avoid extra power consumption, only one resistor should be enabled at a time.
  65. Note: This feature is available on COMP1 only. If COMP2 is selected, this parameter is discarded. */
  66. }COMP_InitTypeDef;
  67. /**
  68. * @brief HAL State structures definition
  69. */
  70. typedef enum
  71. {
  72. HAL_COMP_STATE_RESET = 0x00, /*!< COMP not yet initialized or disabled */
  73. HAL_COMP_STATE_READY = 0x01, /*!< COMP initialized and ready for use */
  74. HAL_COMP_STATE_READY_LOCKED = 0x11, /*!< COMP initialized but the configuration is locked */
  75. HAL_COMP_STATE_BUSY = 0x02, /*!< COMP is running */
  76. HAL_COMP_STATE_BUSY_LOCKED = 0x12 /*!< COMP is running and the configuration is locked */
  77. }HAL_COMP_StateTypeDef;
  78. /**
  79. * @brief COMP Handle Structure definition
  80. */
  81. typedef struct __COMP_HandleTypeDef
  82. {
  83. COMP_TypeDef *Instance; /*!< Register base address */
  84. COMP_InitTypeDef Init; /*!< COMP required parameters */
  85. HAL_LockTypeDef Lock; /*!< Locking object */
  86. __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */
  87. __IO uint32_t ErrorCode; /*!< COMP Error code */
  88. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  89. void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */
  90. void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */
  91. void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
  92. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  93. } COMP_HandleTypeDef;
  94. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  95. /**
  96. * @brief HAL COMP Callback ID enumeration definition
  97. */
  98. typedef enum
  99. {
  100. HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */
  101. HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */
  102. HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */
  103. } HAL_COMP_CallbackIDTypeDef;
  104. /**
  105. * @brief HAL COMP Callback pointer definition
  106. */
  107. typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
  108. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  109. /**
  110. * @}
  111. */
  112. /* Exported constants --------------------------------------------------------*/
  113. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  114. * @{
  115. */
  116. /** @defgroup COMP_Error_Code COMP Error Code
  117. * @{
  118. */
  119. #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */
  120. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  121. #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */
  122. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup COMP_Output COMP Output
  127. * @{
  128. */
  129. #define COMP_OUTPUT_TIM2IC4 (0x00000000U) /*!< COMP2 output connected to TIM2 Input Capture 4 */
  130. #define COMP_OUTPUT_TIM2OCREFCLR ( COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM2 OCREF Clear */
  131. #define COMP_OUTPUT_TIM3IC4 ( COMP_CSR_OUTSEL_1 ) /*!< COMP2 output connected to TIM3 Input Capture 4 */
  132. #define COMP_OUTPUT_TIM3OCREFCLR ( COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM3 OCREF Clear */
  133. #define COMP_OUTPUT_TIM4IC4 (COMP_CSR_OUTSEL_2 ) /*!< COMP2 output connected to TIM4 Input Capture 4 */
  134. #define COMP_OUTPUT_TIM4OCREFCLR (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_0) /*!< COMP2 output connected to TIM4 OCREF Clear */
  135. #define COMP_OUTPUT_TIM10IC1 (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 ) /*!< COMP2 output connected to TIM10 Input Capture 1 */
  136. #define COMP_OUTPUT_NONE (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP2 output is not connected to other peripherals */
  137. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OUTPUT_TIM2IC4) || \
  138. ((OUTPUT) == COMP_OUTPUT_TIM2OCREFCLR) || \
  139. ((OUTPUT) == COMP_OUTPUT_TIM3IC4) || \
  140. ((OUTPUT) == COMP_OUTPUT_TIM3OCREFCLR) || \
  141. ((OUTPUT) == COMP_OUTPUT_TIM4IC4) || \
  142. ((OUTPUT) == COMP_OUTPUT_TIM4OCREFCLR) || \
  143. ((OUTPUT) == COMP_OUTPUT_TIM10IC1) || \
  144. ((OUTPUT) == COMP_OUTPUT_NONE) )
  145. /**
  146. * @}
  147. */
  148. /** @defgroup COMP_InvertingInput COMP InvertingInput
  149. * @{
  150. */
  151. /* Inverting Input specific to COMP2 */
  152. #define COMP_INVERTINGINPUT_IO ( COMP_CSR_INSEL_0) /*!< External I/O (COMP2_INM connected to pin PB3) connected to comparator 2 inverting input */
  153. #define COMP_INVERTINGINPUT_VREFINT ( COMP_CSR_INSEL_1 ) /*!< VREFINT connected to comparator 2 inverting input */
  154. #define COMP_INVERTINGINPUT_3_4VREFINT ( COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< 3/4 VREFINT connected to comparator 2 inverting input */
  155. #define COMP_INVERTINGINPUT_1_2VREFINT (COMP_CSR_INSEL_2 ) /*!< 1/2 VREFINT connected to comparator 2 inverting input */
  156. #define COMP_INVERTINGINPUT_1_4VREFINT (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_0) /*!< 1/4 VREFINT connected to comparator 2 inverting input */
  157. #define COMP_INVERTINGINPUT_DAC1 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 ) /*!< DAC_OUT1 (PA4) connected to comparator 2 inverting input */
  158. #define COMP_INVERTINGINPUT_DAC2 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< DAC2_OUT (PA5) connected to comparator 2 inverting input */
  159. #define IS_COMP_INVERTINGINPUT(INPUT) (((INPUT) == COMP_INVERTINGINPUT_IO) || \
  160. ((INPUT) == COMP_INVERTINGINPUT_VREFINT) || \
  161. ((INPUT) == COMP_INVERTINGINPUT_3_4VREFINT) || \
  162. ((INPUT) == COMP_INVERTINGINPUT_1_2VREFINT) || \
  163. ((INPUT) == COMP_INVERTINGINPUT_1_4VREFINT) || \
  164. ((INPUT) == COMP_INVERTINGINPUT_DAC1) || \
  165. ((INPUT) == COMP_INVERTINGINPUT_DAC2) )
  166. /**
  167. * @}
  168. */
  169. /** @defgroup COMP_Mode COMP Mode
  170. * @{
  171. */
  172. /* Please refer to the electrical characteristics in the device datasheet for
  173. the power consumption values */
  174. #define COMP_MODE_LOWSPEED (0x00000000U) /*!< Low Speed */
  175. #define COMP_MODE_HIGHSPEED COMP_CSR_SPEED /*!< High Speed */
  176. #define IS_COMP_MODE(SPEED) (((SPEED) == COMP_MODE_LOWSPEED) || \
  177. ((SPEED) == COMP_MODE_HIGHSPEED))
  178. /**
  179. * @}
  180. */
  181. /** @defgroup COMP_WindowMode COMP WindowMode
  182. * @{
  183. */
  184. #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disabled: COMP1 non-inverting input is independant */
  185. #define COMP_WINDOWMODE_ENABLE COMP_CSR_WNDWE /*!< Window mode enabled: COMP1 non-inverting input is no more accessible, even from ADC channel VCOMP) (connected to COMP2 non-inverting input) */
  186. #define IS_COMP_WINDOWMODE(WINDOWMODE) (((WINDOWMODE) == COMP_WINDOWMODE_DISABLE) || \
  187. ((WINDOWMODE) == COMP_WINDOWMODE_ENABLE))
  188. /**
  189. * @}
  190. */
  191. /** @defgroup COMP_OutputLevel COMP OutputLevel
  192. * @{
  193. */
  194. /* Comparator output is low when the non-inverting input is at a lower */
  195. /* voltage than the inverting input. */
  196. #define COMP_OUTPUTLEVEL_LOW (0x00000000U)
  197. /* Comparator output is high when the non-inverting input is at a higher */
  198. /* voltage than the inverting input. */
  199. #define COMP_OUTPUTLEVEL_HIGH (0x00000001U)
  200. /**
  201. * @}
  202. */
  203. /** @defgroup COMP_TriggerMode COMP TriggerMode
  204. * @{
  205. */
  206. #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< No External Interrupt trigger detection */
  207. #define COMP_TRIGGERMODE_IT_RISING (0x00000001U) /*!< External Interrupt Mode with Rising edge trigger detection */
  208. #define COMP_TRIGGERMODE_IT_FALLING (0x00000002U) /*!< External Interrupt Mode with Falling edge trigger detection */
  209. #define COMP_TRIGGERMODE_IT_RISING_FALLING (0x00000003U) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
  210. #define IS_COMP_TRIGGERMODE(MODE) (((MODE) == COMP_TRIGGERMODE_NONE) || \
  211. ((MODE) == COMP_TRIGGERMODE_IT_RISING) || \
  212. ((MODE) == COMP_TRIGGERMODE_IT_FALLING) || \
  213. ((MODE) == COMP_TRIGGERMODE_IT_RISING_FALLING) )
  214. /**
  215. * @}
  216. */
  217. /** @defgroup COMP_ExtiLineEvent COMP ExtiLineEvent
  218. * @{
  219. */
  220. #define COMP_EXTI_LINE_COMP1 EXTI_RTSR_TR21 /*!< External interrupt line 21 Connected to COMP1 */
  221. #define COMP_EXTI_LINE_COMP2 EXTI_RTSR_TR22 /*!< External interrupt line 22 Connected to COMP2 */
  222. /**
  223. * @}
  224. */
  225. /** @defgroup COMP_NonInvertingInputPull COMP NonInvertingInputPull
  226. * @{
  227. */
  228. #define COMP_NONINVERTINGINPUT_NOPULL (0x00000000U) /*!< No internal pull-up or pull-down resistor connected to comparator non inverting input */
  229. #define COMP_NONINVERTINGINPUT_10KPU COMP_CSR_10KPU /*!< Internal 10kOhm pull-up resistor connected to comparator non inverting input */
  230. #define COMP_NONINVERTINGINPUT_10KPD COMP_CSR_10KPD /*!< Internal 10kOhm pull-down resistor connected to comparator non inverting input */
  231. #define COMP_NONINVERTINGINPUT_400KPU COMP_CSR_400KPU /*!< Internal 400kOhm pull-up resistor connected to comparator non inverting input */
  232. #define COMP_NONINVERTINGINPUT_400KPD COMP_CSR_400KPD /*!< Internal 400kOhm pull-down resistor connected to comparator non inverting input */
  233. #define IS_COMP_NONINVERTINGINPUTPULL(INPUT) (((INPUT) == COMP_NONINVERTINGINPUT_NOPULL) || \
  234. ((INPUT) == COMP_NONINVERTINGINPUT_10KPU) || \
  235. ((INPUT) == COMP_NONINVERTINGINPUT_10KPD) || \
  236. ((INPUT) == COMP_NONINVERTINGINPUT_400KPU) || \
  237. ((INPUT) == COMP_NONINVERTINGINPUT_400KPD) )
  238. /**
  239. * @}
  240. */
  241. /**
  242. * @}
  243. */
  244. /* Exported macro ------------------------------------------------------------*/
  245. /** @defgroup COMP_Exported_Macro COMP Exported Macro
  246. * @{
  247. */
  248. /** @defgroup COMP_Handle_Management COMP Handle Management
  249. * @{
  250. */
  251. /** @brief Reset COMP handle state
  252. * @param __HANDLE__ COMP handle.
  253. * @retval None
  254. */
  255. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  256. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
  257. (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
  258. (__HANDLE__)->MspInitCallback = NULL; \
  259. (__HANDLE__)->MspDeInitCallback = NULL; \
  260. } while(0)
  261. #else
  262. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  263. #endif
  264. /**
  265. * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
  266. * @param __HANDLE__ COMP handle
  267. * @retval None
  268. */
  269. #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
  270. /**
  271. * @brief Enables the specified comparator
  272. * @param __HANDLE__ COMP handle.
  273. * @retval None.
  274. */
  275. #define __HAL_COMP_ENABLE(__HANDLE__) \
  276. ( ( ((__HANDLE__)->Instance == COMP1) \
  277. )? \
  278. SET_BIT(COMP->CSR, COMP_CSR_CMP1EN) \
  279. : \
  280. MODIFY_REG(COMP->CSR, COMP_CSR_INSEL, (__HANDLE__)->Init.InvertingInput ) \
  281. )
  282. /**
  283. * @brief Disables the specified comparator
  284. * @param __HANDLE__ COMP handle.
  285. * @retval None.
  286. */
  287. #define __HAL_COMP_DISABLE(__HANDLE__) \
  288. ( ( ((__HANDLE__)->Instance == COMP1) \
  289. )? \
  290. CLEAR_BIT(COMP->CSR, COMP_CSR_CMP1EN) \
  291. : \
  292. CLEAR_BIT(COMP->CSR, COMP_CSR_INSEL) \
  293. )
  294. /** @brief Checks whether the specified COMP flag is set or not.
  295. * @param __HANDLE__ specifies the COMP Handle.
  296. * @param __FLAG__ specifies the flag to check.
  297. * This parameter can be one of the following values:
  298. * @arg COMP_FLAG_LOCK: lock flag
  299. * @retval The new state of __FLAG__ (TRUE or FALSE).
  300. */
  301. #define __HAL_COMP_GET_FLAG(__HANDLE__, __FLAG__) (READ_BIT((__HANDLE__)->Instance->CSR, (__FLAG__)) == (__FLAG__))
  302. /**
  303. * @brief Enable the COMP1 EXTI line rising edge trigger.
  304. * @retval None
  305. */
  306. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  307. /**
  308. * @brief Disable the COMP1 EXTI line rising edge trigger.
  309. * @retval None
  310. */
  311. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  312. /**
  313. * @brief Enable the COMP1 EXTI line falling edge trigger.
  314. * @retval None
  315. */
  316. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  317. /**
  318. * @brief Disable the COMP1 EXTI line falling edge trigger.
  319. * @retval None
  320. */
  321. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  322. /**
  323. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  324. * @retval None
  325. */
  326. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  327. __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
  328. __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
  329. } while(0)
  330. /**
  331. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  332. * @retval None
  333. */
  334. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  335. __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
  336. __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
  337. } while(0)
  338. /**
  339. * @brief Enable the COMP1 EXTI line in interrupt mode.
  340. * @retval None
  341. */
  342. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  343. /**
  344. * @brief Disable the COMP1 EXTI line in interrupt mode.
  345. * @retval None
  346. */
  347. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  348. /**
  349. * @brief Enable the COMP1 EXTI Line in event mode.
  350. * @retval None
  351. */
  352. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  353. /**
  354. * @brief Disable the COMP1 EXTI Line in event mode.
  355. * @retval None
  356. */
  357. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  358. /**
  359. * @brief Check whether the COMP1 EXTI line flag is set or not.
  360. * @retval RESET or SET
  361. */
  362. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
  363. /**
  364. * @brief Clear the the COMP1 EXTI flag.
  365. * @retval None
  366. */
  367. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
  368. /**
  369. * @brief Generates a Software interrupt on COMP1 EXTI Line.
  370. * @retval None
  371. */
  372. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
  373. /**
  374. * @brief Enable the COMP2 EXTI line rising edge trigger.
  375. * @retval None
  376. */
  377. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  378. /**
  379. * @brief Disable the COMP2 EXTI line rising edge trigger.
  380. * @retval None
  381. */
  382. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  383. /**
  384. * @brief Enable the COMP2 EXTI line falling edge trigger.
  385. * @retval None
  386. */
  387. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  388. /**
  389. * @brief Disable the COMP2 EXTI line falling edge trigger.
  390. * @retval None
  391. */
  392. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  393. /**
  394. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  395. * @retval None
  396. */
  397. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  398. __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
  399. __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
  400. } while(0)
  401. /**
  402. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  403. * @retval None
  404. */
  405. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  406. __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
  407. __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
  408. } while(0)
  409. /**
  410. * @brief Enable the COMP2 EXTI line.
  411. * @retval None
  412. */
  413. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  414. /**
  415. * @brief Disable the COMP2 EXTI line.
  416. * @retval None
  417. */
  418. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  419. /**
  420. * @brief Enable the COMP2 EXTI Line in event mode.
  421. * @retval None
  422. */
  423. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  424. /**
  425. * @brief Disable the COMP2 EXTI Line in event mode.
  426. * @retval None
  427. */
  428. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  429. /**
  430. * @brief Check whether the COMP2 EXTI line flag is set or not.
  431. * @retval RESET or SET
  432. */
  433. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
  434. /**
  435. * @brief Clear the the COMP2 EXTI flag.
  436. * @retval None
  437. */
  438. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
  439. /**
  440. * @brief Generates a Software interrupt on COMP1 EXTI Line.
  441. * @retval None
  442. */
  443. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
  444. /**
  445. * @}
  446. */
  447. /* Private macro -------------------------------------------------------------*/
  448. /** @defgroup COMP_Private_Macro COMP Private Macro
  449. * @{
  450. */
  451. /**
  452. * @brief Get the specified EXTI line for a comparator instance
  453. * @param __INSTANCE__ specifies the COMP instance.
  454. * @retval value of @ref COMP_ExtiLineEvent
  455. */
  456. #define COMP_GET_EXTI_LINE(__INSTANCE__) \
  457. ( ( ((__INSTANCE__) == COMP1) \
  458. )? \
  459. (COMP_EXTI_LINE_COMP1) \
  460. : \
  461. (COMP_EXTI_LINE_COMP2) \
  462. )
  463. /**
  464. * @brief Select the COMP register CSR bit CMPxOUT corresponding to the
  465. * selected COMP instance.
  466. * @param __HANDLE__: COMP handle
  467. * @retval Comparator register CSR bit COMP_CSR_CMP1OUT or COMP_CSR_CMP2OUT
  468. */
  469. #define __COMP_CSR_CMPXOUT(__HANDLE__) \
  470. ( ( ((__HANDLE__)->Instance == COMP1) \
  471. )? \
  472. (COMP_CSR_CMP1OUT) \
  473. : \
  474. (COMP_CSR_CMP2OUT) \
  475. )
  476. /**
  477. * @brief Verification of COMP state: enabled or disabled
  478. * @param __HANDLE__: COMP handle
  479. * @retval SET (COMP enabled) or RESET (COMP disabled)
  480. */
  481. #define __COMP_IS_ENABLED(__HANDLE__) \
  482. ( ( ((__HANDLE__)->Instance == COMP1) \
  483. )? \
  484. (((READ_BIT(COMP->CSR , COMP_CSR_CMP1EN) == COMP_CSR_CMP1EN) \
  485. ) ? SET : RESET) \
  486. : \
  487. (((READ_BIT(COMP->CSR , COMP_CSR_INSEL) != RESET) \
  488. ) ? SET : RESET) \
  489. )
  490. /**
  491. * @}
  492. */
  493. /* Include COMP HAL Extension module */
  494. #include "stm32l1xx_hal_comp_ex.h"
  495. /* Exported functions --------------------------------------------------------*/
  496. /** @addtogroup COMP_Exported_Functions
  497. * @{
  498. */
  499. /* Initialization and de-initialization functions ******************************/
  500. /** @addtogroup COMP_Exported_Functions_Group1
  501. * @{
  502. */
  503. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  504. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  505. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  506. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  507. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  508. /* Callbacks Register/UnRegister functions ***********************************/
  509. HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
  510. HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
  511. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  512. /**
  513. * @}
  514. */
  515. /* I/O operation functions *****************************************************/
  516. /** @addtogroup COMP_Exported_Functions_Group2
  517. * @{
  518. */
  519. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  520. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  521. HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
  522. HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
  523. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  524. /**
  525. * @}
  526. */
  527. /* Peripheral Control functions ************************************************/
  528. /** @addtogroup COMP_Exported_Functions_Group3
  529. * @{
  530. */
  531. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  532. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  533. /* Callback in Interrupt mode */
  534. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  535. /**
  536. * @}
  537. */
  538. /* Peripheral State functions **************************************************/
  539. /** @addtogroup COMP_Exported_Functions_Group4
  540. * @{
  541. */
  542. HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  543. uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
  544. /**
  545. * @}
  546. */
  547. /**
  548. * @}
  549. */
  550. /**
  551. * @}
  552. */
  553. /**
  554. * @}
  555. */
  556. #ifdef __cplusplus
  557. }
  558. #endif
  559. #endif /* __STM32L1xx_HAL_COMP_H */
  560. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/