stm32l0xx_hal_comp.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef __STM32L0xx_HAL_COMP_H
  20. #define __STM32L0xx_HAL_COMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4)
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx_hal_def.h"
  27. /** @addtogroup STM32L0xx_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 WindowMode; /*!< Set window mode of a pair of comparators instances
  43. (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
  44. Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode.
  45. This parameter can be a value of @ref COMP_WindowMode */
  46. uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed.
  47. Note: For the characteristics of comparator power modes
  48. (propagation delay and power consumption), refer to device datasheet.
  49. This parameter can be a value of @ref COMP_PowerMode */
  50. uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input).
  51. This parameter can be a value of @ref COMP_InputPlus */
  52. uint32_t InvertingInput; /*!< Set comparator input minus (inverting input).
  53. This parameter can be a value of @ref COMP_InputMinus */
  54. uint32_t OutputPol; /*!< Set comparator output polarity.
  55. This parameter can be a value of @ref COMP_OutputPolarity */
  56. uint32_t LPTIMConnection; /*!< Set comparator output connection to LPTIM peripheral.
  57. This parameter can be a value of @ref COMP_LPTIMConnection */
  58. uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI).
  59. This parameter can be a value of @ref COMP_EXTI_TriggerMode */
  60. }COMP_InitTypeDef;
  61. /**
  62. * @brief HAL COMP state machine: HAL COMP states definition
  63. */
  64. #define COMP_STATE_BITFIELD_LOCK (0x10U)
  65. typedef enum
  66. {
  67. HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */
  68. HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
  69. HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */
  70. HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */
  71. HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */
  72. HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */
  73. }HAL_COMP_StateTypeDef;
  74. /**
  75. * @brief COMP Handle Structure definition
  76. */
  77. typedef struct __COMP_HandleTypeDef
  78. {
  79. COMP_TypeDef *Instance; /*!< Register base address */
  80. COMP_InitTypeDef Init; /*!< COMP required parameters */
  81. HAL_LockTypeDef Lock; /*!< Locking object */
  82. __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */
  83. __IO uint32_t ErrorCode; /*!< COMP Error code */
  84. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  85. void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */
  86. void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */
  87. void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
  88. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  89. } COMP_HandleTypeDef;
  90. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  91. /**
  92. * @brief HAL COMP Callback ID enumeration definition
  93. */
  94. typedef enum
  95. {
  96. HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */
  97. HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */
  98. HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */
  99. } HAL_COMP_CallbackIDTypeDef;
  100. /**
  101. * @brief HAL COMP Callback pointer definition
  102. */
  103. typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
  104. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  105. /**
  106. * @}
  107. */
  108. /* Exported constants --------------------------------------------------------*/
  109. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  110. * @{
  111. */
  112. /** @defgroup COMP_Error_Code COMP Error Code
  113. * @{
  114. */
  115. #define HAL_COMP_ERROR_NONE (0x00U) /*!< No error */
  116. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  117. #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01U) /*!< Invalid Callback error */
  118. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  119. /**
  120. * @}
  121. */
  122. /** @defgroup COMP_WindowMode COMP Window Mode
  123. * @{
  124. */
  125. #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
  126. #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_COMP1WM) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
  127. /**
  128. * @}
  129. */
  130. /** @defgroup COMP_PowerMode COMP power mode
  131. * @{
  132. */
  133. /* Note: For the characteristics of comparator power modes */
  134. /* (propagation delay and power consumption), */
  135. /* refer to device datasheet. */
  136. #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_COMP2SPEED) /*!< COMP power mode to low power (indicated as "high speed" in reference manual) (only for COMP instance: COMP2) */
  137. #define COMP_POWERMODE_ULTRALOWPOWER (0x00000000U) /*!< COMP power mode to ultra low power (indicated as "low speed" in reference manual) (only for COMP instance: COMP2) */
  138. /**
  139. * @}
  140. */
  141. /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
  142. * @{
  143. */
  144. #define COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */
  145. #define COMP_INPUT_PLUS_IO2 (COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB4 for COMP2) (only for COMP instance: COMP2) */
  146. #define COMP_INPUT_PLUS_IO3 (COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA5 for COMP2) (only for COMP instance: COMP2) */
  147. #define COMP_INPUT_PLUS_IO4 (COMP_CSR_COMP2INPSEL_0 | COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO4 (pin PB6 for COMP2) (only for COMP instance: COMP2) */
  148. #define COMP_INPUT_PLUS_IO5 (COMP_CSR_COMP2INPSEL_2) /*!< Comparator input plus connected to IO5 (pin PB7 for COMP2) (only for COMP instance: COMP2) */
  149. #if defined (STM32L011xx) || defined (STM32L021xx)
  150. #define COMP_INPUT_PLUS_IO6 (COMP_CSR_COMP2INPSEL_2 | COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO6 (pin PA7 for COMP2) (only for COMP instance: COMP2) (Available only on devices STM32L0 category 1) */
  151. #endif
  152. /**
  153. * @}
  154. */
  155. /** @defgroup COMP_InputMinus COMP input minus (inverting input)
  156. * @{
  157. */
  158. #define COMP_INPUT_MINUS_1_4VREFINT (COMP_CSR_COMP2INNSEL_2 ) /*!< Comparator input minus connected to 1/4 VREFINT (only for COMP instance: COMP2) */
  159. #define COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to 1/2 VREFINT (only for COMP instance: COMP2) */
  160. #define COMP_INPUT_MINUS_3_4VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to 3/4 VREFINT (only for COMP instance: COMP2) */
  161. #define COMP_INPUT_MINUS_VREFINT (0x00000000U) /*!< Comparator input minus connected to VrefInt */
  162. #define COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  163. #define COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  164. #define COMP_INPUT_MINUS_IO1 ( COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */
  165. #define COMP_INPUT_MINUS_IO2 (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO2 (pin PB3 for COMP2) (only for COMP instance: COMP2) */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup COMP_LPTIMConnection COMP Low power timer connection definition
  170. * @{
  171. */
  172. #define COMP_LPTIMCONNECTION_DISABLED (0x00000000U) /*!< COMPx signal is gated */
  173. #define COMP_LPTIMCONNECTION_IN1_ENABLED (0x00000001U) /*!< COMPx signal is connected to LPTIM input 1 */
  174. #define COMP_LPTIMCONNECTION_IN2_ENABLED (0x00000002U) /*!< COMPx signal is connected to LPTIM input 2 */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup COMP_OutputPolarity COMP output Polarity
  179. * @{
  180. */
  181. #define COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output on GPIO isn't inverted */
  182. #define COMP_OUTPUTPOL_INVERTED COMP_CSR_COMPxPOLARITY /*!< COMP output on GPIO is inverted */
  183. /**
  184. * @}
  185. */
  186. /** @defgroup COMP_OutputLevel COMP Output Level
  187. * @{
  188. */
  189. /* Note: Comparator output level values are fixed to "0" and "1", */
  190. /* corresponding COMP register bit is managed by HAL function to match */
  191. /* with these values (independently of bit position in register). */
  192. /* When output polarity is not inverted, comparator output is low when
  193. the input plus is at a lower voltage than the input minus */
  194. #define COMP_OUTPUT_LEVEL_LOW (0x00000000U)
  195. /* When output polarity is not inverted, comparator output is high when
  196. the input plus is at a higher voltage than the input minus */
  197. #define COMP_OUTPUT_LEVEL_HIGH (0x00000001U)
  198. /**
  199. * @}
  200. */
  201. /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
  202. * @{
  203. */
  204. #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< Comparator output triggering no External Interrupt Line */
  205. #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
  206. #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
  207. #define COMP_TRIGGERMODE_IT_RISING_FALLING (COMP_EXTI_IT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on both rising and falling edges */
  208. #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
  209. #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
  210. #define COMP_TRIGGERMODE_EVENT_RISING_FALLING (COMP_EXTI_EVENT | COMP_EXTI_RISING | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on both rising and falling edges */
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. /* Exported macro ------------------------------------------------------------*/
  218. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  219. * @{
  220. */
  221. /** @defgroup COMP_Handle_Management COMP Handle Management
  222. * @{
  223. */
  224. /** @brief Reset COMP handle state.
  225. * @param __HANDLE__ COMP handle
  226. * @retval None
  227. */
  228. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  229. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
  230. (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
  231. (__HANDLE__)->MspInitCallback = NULL; \
  232. (__HANDLE__)->MspDeInitCallback = NULL; \
  233. } while(0)
  234. #else
  235. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  236. #endif
  237. /**
  238. * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
  239. * @param __HANDLE__ COMP handle
  240. * @retval None
  241. */
  242. #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
  243. /**
  244. * @brief Enable the specified comparator.
  245. * @param __HANDLE__ COMP handle
  246. * @retval None
  247. */
  248. #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN)
  249. /**
  250. * @brief Disable the specified comparator.
  251. * @param __HANDLE__ COMP handle
  252. * @retval None
  253. */
  254. #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxEN)
  255. /**
  256. * @brief Lock the specified comparator configuration.
  257. * @note Using this macro induce HAL COMP handle state machine being no
  258. * more in line with COMP instance state.
  259. * To keep HAL COMP handle state machine updated, it is recommended
  260. * to use function "HAL_COMP_Lock')".
  261. * @param __HANDLE__ COMP handle
  262. * @retval None
  263. */
  264. #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK)
  265. /**
  266. * @brief Check whether the specified comparator is locked.
  267. * @param __HANDLE__ COMP handle
  268. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  269. */
  270. #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_COMPxLOCK) == COMP_CSR_COMPxLOCK)
  271. /**
  272. * @}
  273. */
  274. /** @defgroup COMP_Exti_Management COMP external interrupt line management
  275. * @{
  276. */
  277. /**
  278. * @brief Enable the COMP1 EXTI line rising edge trigger.
  279. * @retval None
  280. */
  281. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  282. /**
  283. * @brief Disable the COMP1 EXTI line rising edge trigger.
  284. * @retval None
  285. */
  286. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP1)
  287. /**
  288. * @brief Enable the COMP1 EXTI line falling edge trigger.
  289. * @retval None
  290. */
  291. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  292. /**
  293. * @brief Disable the COMP1 EXTI line falling edge trigger.
  294. * @retval None
  295. */
  296. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP1)
  297. /**
  298. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  299. * @retval None
  300. */
  301. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  302. __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
  303. __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
  304. } while(0)
  305. /**
  306. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  307. * @retval None
  308. */
  309. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  310. __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
  311. __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
  312. } while(0)
  313. /**
  314. * @brief Enable the COMP1 EXTI line in interrupt mode.
  315. * @retval None
  316. */
  317. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  318. /**
  319. * @brief Disable the COMP1 EXTI line in interrupt mode.
  320. * @retval None
  321. */
  322. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP1)
  323. /**
  324. * @brief Generate a software interrupt on the COMP1 EXTI line.
  325. * @retval None
  326. */
  327. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP1)
  328. /**
  329. * @brief Enable the COMP1 EXTI line in event mode.
  330. * @retval None
  331. */
  332. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  333. /**
  334. * @brief Disable the COMP1 EXTI line in event mode.
  335. * @retval None
  336. */
  337. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP1)
  338. /**
  339. * @brief Check whether the COMP1 EXTI line flag is set.
  340. * @retval RESET or SET
  341. */
  342. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP1)
  343. /**
  344. * @brief Clear the COMP1 EXTI flag.
  345. * @retval None
  346. */
  347. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP1)
  348. /**
  349. * @brief Enable the COMP2 EXTI line rising edge trigger.
  350. * @retval None
  351. */
  352. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  353. /**
  354. * @brief Disable the COMP2 EXTI line rising edge trigger.
  355. * @retval None
  356. */
  357. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR, COMP_EXTI_LINE_COMP2)
  358. /**
  359. * @brief Enable the COMP2 EXTI line falling edge trigger.
  360. * @retval None
  361. */
  362. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  363. /**
  364. * @brief Disable the COMP2 EXTI line falling edge trigger.
  365. * @retval None
  366. */
  367. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR, COMP_EXTI_LINE_COMP2)
  368. /**
  369. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  370. * @retval None
  371. */
  372. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  373. __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
  374. __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
  375. } while(0)
  376. /**
  377. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  378. * @retval None
  379. */
  380. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  381. __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
  382. __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
  383. } while(0)
  384. /**
  385. * @brief Enable the COMP2 EXTI line in interrupt mode.
  386. * @retval None
  387. */
  388. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  389. /**
  390. * @brief Disable the COMP2 EXTI line in interrupt mode.
  391. * @retval None
  392. */
  393. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI->IMR, COMP_EXTI_LINE_COMP2)
  394. /**
  395. * @brief Generate a software interrupt on the COMP2 EXTI line.
  396. * @retval None
  397. */
  398. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER, COMP_EXTI_LINE_COMP2)
  399. /**
  400. * @brief Enable the COMP2 EXTI line in event mode.
  401. * @retval None
  402. */
  403. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  404. /**
  405. * @brief Disable the COMP2 EXTI line in event mode.
  406. * @retval None
  407. */
  408. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI->EMR, COMP_EXTI_LINE_COMP2)
  409. /**
  410. * @brief Check whether the COMP2 EXTI line flag is set.
  411. * @retval RESET or SET
  412. */
  413. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI->PR, COMP_EXTI_LINE_COMP2)
  414. /**
  415. * @brief Clear the COMP2 EXTI flag.
  416. * @retval None
  417. */
  418. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI->PR, COMP_EXTI_LINE_COMP2)
  419. /**
  420. * @}
  421. */
  422. /**
  423. * @}
  424. */
  425. /* Private types -------------------------------------------------------------*/
  426. /* Private constants ---------------------------------------------------------*/
  427. /** @defgroup COMP_Private_Constants COMP Private Constants
  428. * @{
  429. */
  430. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  431. * @{
  432. */
  433. #define COMP_EXTI_LINE_COMP1 (EXTI_IMR_IM21) /*!< EXTI line 21 connected to COMP1 output */
  434. #define COMP_EXTI_LINE_COMP2 (EXTI_IMR_IM22) /*!< EXTI line 22 connected to COMP2 output */
  435. /**
  436. * @}
  437. */
  438. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  439. * @{
  440. */
  441. #define COMP_EXTI_IT (0x01U) /*!< EXTI line event with interruption */
  442. #define COMP_EXTI_EVENT (0x02U) /*!< EXTI line event only (without interruption) */
  443. #define COMP_EXTI_RISING (0x10U) /*!< EXTI line event on rising edge */
  444. #define COMP_EXTI_FALLING (0x20U) /*!< EXTI line event on falling edge */
  445. /**
  446. * @}
  447. */
  448. /**
  449. * @}
  450. */
  451. /* Private macros ------------------------------------------------------------*/
  452. /** @defgroup COMP_Private_Macros COMP Private Macros
  453. * @{
  454. */
  455. /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
  456. * @{
  457. */
  458. /**
  459. * @brief Get the specified EXTI line for a comparator instance.
  460. * @param __INSTANCE__ specifies the COMP instance.
  461. * @retval value of @ref COMP_ExtiLine
  462. */
  463. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? \
  464. COMP_EXTI_LINE_COMP1 : COMP_EXTI_LINE_COMP2)
  465. /**
  466. * @}
  467. */
  468. /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
  469. * @{
  470. */
  471. #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
  472. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) )
  473. #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \
  474. ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) )
  475. #define IS_COMP_WINDOWMODE_INSTANCE(INSTANCE) ((INSTANCE) == COMP1)
  476. #if defined (STM32L011xx) || defined (STM32L021xx)
  477. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  478. (((__COMP_INSTANCE__) == COMP1) \
  479. ? ( \
  480. (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1 \
  481. ) \
  482. : \
  483. ( \
  484. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) \
  485. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) \
  486. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) \
  487. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) \
  488. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5) \
  489. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO6) \
  490. ) \
  491. )
  492. #else
  493. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) \
  494. (((__COMP_INSTANCE__) == COMP1) \
  495. ? ( \
  496. (__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1 \
  497. ) \
  498. : \
  499. ( \
  500. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) \
  501. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) \
  502. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) \
  503. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO4) \
  504. || ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO5) \
  505. ) \
  506. )
  507. #endif
  508. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) \
  509. (((__COMP_INSTANCE__) == COMP1) \
  510. ? ( \
  511. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) \
  512. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) \
  513. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) \
  514. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) \
  515. ) \
  516. : \
  517. ( \
  518. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) \
  519. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) \
  520. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) \
  521. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) \
  522. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) \
  523. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) \
  524. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) \
  525. || ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) \
  526. ) \
  527. )
  528. #define IS_COMP1_LPTIMCONNECTION(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
  529. ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED))
  530. #define IS_COMP2_LPTIMCONNECTION(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
  531. ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED) || \
  532. ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN2_ENABLED))
  533. #define IS_COMP2_LPTIMCONNECTION_RESTRICTED(LPTIMCONNECTION) (((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_DISABLED) || \
  534. ((LPTIMCONNECTION) == COMP_LPTIMCONNECTION_IN1_ENABLED))
  535. #define IS_COMP_OUTPUTPOL(POL) (((POL) == COMP_OUTPUTPOL_NONINVERTED) || \
  536. ((POL) == COMP_OUTPUTPOL_INVERTED))
  537. #define IS_COMP_TRIGGERMODE(__TRIGGERMODE__) (((__TRIGGERMODE__) == COMP_TRIGGERMODE_NONE) || \
  538. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  539. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  540. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  541. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  542. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  543. ((__TRIGGERMODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING) )
  544. #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
  545. ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
  546. /**
  547. * @}
  548. */
  549. /**
  550. * @}
  551. */
  552. /* Include COMP HAL Extended module */
  553. #include "stm32l0xx_hal_comp_ex.h"
  554. /* Exported functions --------------------------------------------------------*/
  555. /** @addtogroup COMP_Exported_Functions
  556. * @{
  557. */
  558. /** @addtogroup COMP_Exported_Functions_Group1
  559. * @{
  560. */
  561. /* Initialization and de-initialization functions **********************************/
  562. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  563. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  564. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  565. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  566. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  567. /* Callbacks Register/UnRegister functions ***********************************/
  568. HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID, pCOMP_CallbackTypeDef pCallback);
  569. HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
  570. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  571. /**
  572. * @}
  573. */
  574. /* IO operation functions *****************************************************/
  575. /** @addtogroup COMP_Exported_Functions_Group2
  576. * @{
  577. */
  578. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  579. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  580. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  581. /**
  582. * @}
  583. */
  584. /* Peripheral Control functions ************************************************/
  585. /** @addtogroup COMP_Exported_Functions_Group3
  586. * @{
  587. */
  588. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  589. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  590. /* Callback in interrupt mode */
  591. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  592. /**
  593. * @}
  594. */
  595. /* Peripheral State functions **************************************************/
  596. /** @addtogroup COMP_Exported_Functions_Group4
  597. * @{
  598. */
  599. HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  600. uint32_t HAL_COMP_GetError(COMP_HandleTypeDef *hcomp);
  601. /**
  602. * @}
  603. */
  604. /**
  605. * @}
  606. */
  607. /**
  608. * @}
  609. */
  610. /**
  611. * @}
  612. */
  613. #endif /* !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) */
  614. #ifdef __cplusplus
  615. }
  616. #endif
  617. #endif /* __STM32L0xx_HAL_COMP_H */