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.
 
 
 

728 lines
32 KiB

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