stm32l1xx_hal_comp.h 27 KB

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