stm32l5xx_hal_comp.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /**
  2. ******************************************************************************
  3. * @file stm32l5xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 STM32L5xx_HAL_COMP_H
  20. #define STM32L5xx_HAL_COMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l5xx_hal_def.h"
  26. #include "stm32l5xx_ll_exti.h"
  27. /** @addtogroup STM32L5xx_HAL_Driver
  28. * @{
  29. */
  30. #if defined (COMP1) || defined (COMP2)
  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
  46. instance of the pair of COMP instances composing window mode.
  47. This parameter can be a value of @ref COMP_WindowMode */
  48. uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed.
  49. Note: For the characteristics of comparator power modes
  50. (propagation delay and power consumption), refer to device datasheet.
  51. This parameter can be a value of @ref COMP_PowerMode */
  52. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  53. This parameter can be a value of @ref COMP_InputPlus */
  54. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  55. This parameter can be a value of @ref COMP_InputMinus */
  56. uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus.
  57. This parameter can be a value of @ref COMP_Hysteresis */
  58. uint32_t OutputPol; /*!< Set comparator output polarity.
  59. This parameter can be a value of @ref COMP_OutputPolarity */
  60. uint32_t BlankingSrce; /*!< Set comparator blanking source.
  61. This parameter can be a value of @ref COMP_BlankingSrce */
  62. uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI).
  63. This parameter can be a value of @ref COMP_EXTI_TriggerMode */
  64. } COMP_InitTypeDef;
  65. /**
  66. * @brief HAL COMP state machine: HAL COMP states definition
  67. */
  68. #define COMP_STATE_BITFIELD_LOCK (0x10U)
  69. typedef enum
  70. {
  71. HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */
  72. HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
  73. HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */
  74. HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */
  75. HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */
  76. HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */
  77. } HAL_COMP_StateTypeDef;
  78. /**
  79. * @brief COMP Handle Structure definition
  80. */
  81. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  82. typedef struct __COMP_HandleTypeDef
  83. #else
  84. typedef struct
  85. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  86. {
  87. COMP_TypeDef *Instance; /*!< Register base address */
  88. COMP_InitTypeDef Init; /*!< COMP required parameters */
  89. HAL_LockTypeDef Lock; /*!< Locking object */
  90. __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */
  91. __IO uint32_t ErrorCode; /*!< COMP error code */
  92. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  93. void (* TriggerCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP trigger callback */
  94. void (* MspInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp Init callback */
  95. void (* MspDeInitCallback)(struct __COMP_HandleTypeDef *hcomp); /*!< COMP Msp DeInit callback */
  96. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  97. } COMP_HandleTypeDef;
  98. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  99. /**
  100. * @brief HAL COMP Callback ID enumeration definition
  101. */
  102. typedef enum
  103. {
  104. HAL_COMP_TRIGGER_CB_ID = 0x00U, /*!< COMP trigger callback ID */
  105. HAL_COMP_MSPINIT_CB_ID = 0x01U, /*!< COMP Msp Init callback ID */
  106. HAL_COMP_MSPDEINIT_CB_ID = 0x02U /*!< COMP Msp DeInit callback ID */
  107. } HAL_COMP_CallbackIDTypeDef;
  108. /**
  109. * @brief HAL COMP Callback pointer definition
  110. */
  111. typedef void (*pCOMP_CallbackTypeDef)(COMP_HandleTypeDef *hcomp); /*!< pointer to a COMP callback function */
  112. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  113. /**
  114. * @}
  115. */
  116. /* Exported constants --------------------------------------------------------*/
  117. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  118. * @{
  119. */
  120. /** @defgroup COMP_Error_Code COMP Error Code
  121. * @{
  122. */
  123. #define HAL_COMP_ERROR_NONE (0x00UL) /*!< No error */
  124. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  125. #define HAL_COMP_ERROR_INVALID_CALLBACK (0x01UL) /*!< Invalid Callback error */
  126. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  127. /**
  128. * @}
  129. */
  130. /** @defgroup COMP_WindowMode COMP Window Mode
  131. * @{
  132. */
  133. #define COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators
  134. instances pair COMP1 and COMP2 are
  135. independent */
  136. #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< Window mode enable: Comparators instances
  137. pair COMP1 and COMP2 have their input
  138. plus connected together.
  139. The common input is COMP1 input plus
  140. (COMP2 input plus is no more accessible).
  141. */
  142. /**
  143. * @}
  144. */
  145. /** @defgroup COMP_PowerMode COMP power mode
  146. * @{
  147. */
  148. /* Note: For the characteristics of comparator power modes */
  149. /* (propagation delay and power consumption), */
  150. /* refer to device datasheet. */
  151. #define COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< High Speed */
  152. #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */
  153. #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE) /*!< Ultra-low power mode */
  154. /**
  155. * @}
  156. */
  157. /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
  158. * @{
  159. */
  160. #define COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
  161. #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
  162. #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA2 for COMP1, not available for COMP2) */
  163. /**
  164. * @}
  165. */
  166. /** @defgroup COMP_InputMinus COMP input minus (inverting input)
  167. * @{
  168. */
  169. #define COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
  170. #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
  171. #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
  172. #define COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */
  173. #define COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  174. #define COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  175. #define COMP_INPUT_MINUS_IO1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PB3 for COMP2) */
  176. #define COMP_INPUT_MINUS_IO2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2) */
  177. /**
  178. * @}
  179. */
  180. /** @defgroup COMP_Hysteresis COMP hysteresis
  181. * @{
  182. */
  183. #define COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
  184. #define COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
  185. #define COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
  186. #define COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
  187. /**
  188. * @}
  189. */
  190. /** @defgroup COMP_OutputPolarity COMP output Polarity
  191. * @{
  192. */
  193. #define COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
  194. #define COMP_OUTPUTPOL_INVERTED (COMP_CSR_POLARITY) /*!< COMP output level is inverted (comparator output is low when the input plus is at a higher voltage than the input minus) */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup COMP_BlankingSrce COMP blanking source
  199. * @{
  200. */
  201. #define COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
  202. #define COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
  203. #define COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
  204. #define COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
  205. #define COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
  206. #define COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
  207. #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
  208. /**
  209. * @}
  210. */
  211. /** @defgroup COMP_OutputLevel COMP Output Level
  212. * @{
  213. */
  214. /* Note: Comparator output level values are fixed to "0" and "1", */
  215. /* corresponding COMP register bit is managed by HAL function to match */
  216. /* with these values (independently of bit position in register). */
  217. /* When output polarity is not inverted, comparator output is low when
  218. the input plus is at a lower voltage than the input minus */
  219. #define COMP_OUTPUT_LEVEL_LOW (0x00000000UL)
  220. /* When output polarity is not inverted, comparator output is high when
  221. the input plus is at a higher voltage than the input minus */
  222. #define COMP_OUTPUT_LEVEL_HIGH (0x00000001UL)
  223. /**
  224. * @}
  225. */
  226. /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
  227. * @{
  228. */
  229. #define COMP_TRIGGERMODE_NONE (0x00000000UL) /*!< Comparator output triggering no External Interrupt Line */
  230. #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
  231. #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
  232. #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 */
  233. #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
  234. #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
  235. #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 */
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /* Exported macro ------------------------------------------------------------*/
  243. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  244. * @{
  245. */
  246. /** @defgroup COMP_Handle_Management COMP Handle Management
  247. * @{
  248. */
  249. /** @brief Reset COMP handle state.
  250. * @param __HANDLE__ COMP handle
  251. * @retval None
  252. */
  253. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  254. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) do{ \
  255. (__HANDLE__)->State = HAL_COMP_STATE_RESET; \
  256. (__HANDLE__)->MspInitCallback = NULL; \
  257. (__HANDLE__)->MspDeInitCallback = NULL; \
  258. } while(0)
  259. #else
  260. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  261. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  262. /**
  263. * @brief Clear COMP error code (set it to no error code "HAL_COMP_ERROR_NONE").
  264. * @param __HANDLE__ COMP handle
  265. * @retval None
  266. */
  267. #define COMP_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_COMP_ERROR_NONE)
  268. /**
  269. * @brief Enable the specified comparator.
  270. * @param __HANDLE__ COMP handle
  271. * @retval None
  272. */
  273. #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  274. /**
  275. * @brief Disable the specified comparator.
  276. * @param __HANDLE__ COMP handle
  277. * @retval None
  278. */
  279. #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  280. /**
  281. * @brief Lock the specified comparator configuration.
  282. * @note Using this macro induce HAL COMP handle state machine being no
  283. * more in line with COMP instance state.
  284. * To keep HAL COMP handle state machine updated, it is recommended
  285. * to use function "HAL_COMP_Lock')".
  286. * @param __HANDLE__ COMP handle
  287. * @retval None
  288. */
  289. #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
  290. /**
  291. * @brief Check whether the specified comparator is locked.
  292. * @param __HANDLE__ COMP handle
  293. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  294. */
  295. #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
  296. /**
  297. * @}
  298. */
  299. /** @defgroup COMP_Exti_Management COMP external interrupt line management
  300. * @{
  301. */
  302. /**
  303. * @brief Enable the COMP1 EXTI line rising edge trigger.
  304. * @retval None
  305. */
  306. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(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() LL_EXTI_DisableRisingTrig_0_31(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() LL_EXTI_EnableFallingTrig_0_31(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() LL_EXTI_DisableFallingTrig_0_31(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. LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  328. LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  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. LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  336. LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1);\
  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() LL_EXTI_EnableIT_0_31(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() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
  348. /**
  349. * @brief Generate a software interrupt on the COMP1 EXTI line.
  350. * @retval None
  351. */
  352. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
  353. /**
  354. * @brief Enable the COMP1 EXTI line in event mode.
  355. * @retval None
  356. */
  357. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
  358. /**
  359. * @brief Disable the COMP1 EXTI line in event mode.
  360. * @retval None
  361. */
  362. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
  363. /**
  364. * @brief Check whether the COMP1 EXTI line rising flag is set.
  365. * @retval RESET or SET
  366. */
  367. #define __HAL_COMP_COMP1_EXTI_GET_RISING_FLAG() LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
  368. /**
  369. * @brief Clear the COMP1 EXTI rising flag.
  370. * @retval None
  371. */
  372. #define __HAL_COMP_COMP1_EXTI_CLEAR_RISING_FLAG() LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP1)
  373. /**
  374. * @brief Check whether the COMP1 EXTI line falling flag is set.
  375. * @retval RESET or SET
  376. */
  377. #define __HAL_COMP_COMP1_EXTI_GET_FALLING_FLAG() LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
  378. /**
  379. * @brief Clear the COMP1 EXTI falling flag.
  380. * @retval None
  381. */
  382. #define __HAL_COMP_COMP1_EXTI_CLEAR_FALLING_FLAG() LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP1)
  383. /**
  384. * @brief Enable the COMP2 EXTI line rising edge trigger.
  385. * @retval None
  386. */
  387. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
  388. /**
  389. * @brief Disable the COMP2 EXTI line rising edge trigger.
  390. * @retval None
  391. */
  392. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
  393. /**
  394. * @brief Enable the COMP2 EXTI line falling edge trigger.
  395. * @retval None
  396. */
  397. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
  398. /**
  399. * @brief Disable the COMP2 EXTI line falling edge trigger.
  400. * @retval None
  401. */
  402. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
  403. /**
  404. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  405. * @retval None
  406. */
  407. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  408. LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  409. LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  410. } while(0)
  411. /**
  412. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  413. * @retval None
  414. */
  415. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  416. LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  417. LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2);\
  418. } while(0)
  419. /**
  420. * @brief Enable the COMP2 EXTI line in interrupt mode.
  421. * @retval None
  422. */
  423. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
  424. /**
  425. * @brief Disable the COMP2 EXTI line in interrupt mode.
  426. * @retval None
  427. */
  428. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
  429. /**
  430. * @brief Generate a software interrupt on the COMP2 EXTI line.
  431. * @retval None
  432. */
  433. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
  434. /**
  435. * @brief Enable the COMP2 EXTI line in event mode.
  436. * @retval None
  437. */
  438. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
  439. /**
  440. * @brief Disable the COMP2 EXTI line in event mode.
  441. * @retval None
  442. */
  443. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
  444. /**
  445. * @brief Check whether the COMP2 EXTI line rising flag is set.
  446. * @retval RESET or SET
  447. */
  448. #define __HAL_COMP_COMP2_EXTI_GET_RISING_FLAG() LL_EXTI_IsActiveRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
  449. /**
  450. * @brief Clear the COMP2 EXTI rising flag.
  451. * @retval None
  452. */
  453. #define __HAL_COMP_COMP2_EXTI_CLEAR_RISING_FLAG() LL_EXTI_ClearRisingFlag_0_31(COMP_EXTI_LINE_COMP2)
  454. /**
  455. * @brief Check whether the COMP2 EXTI line falling flag is set.
  456. * @retval RESET or SET
  457. */
  458. #define __HAL_COMP_COMP2_EXTI_GET_FALLING_FLAG() LL_EXTI_IsActiveFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
  459. /**
  460. * @brief Clear the COMP2 EXTI falling flag.
  461. * @retval None
  462. */
  463. #define __HAL_COMP_COMP2_EXTI_CLEAR_FALLING_FLAG() LL_EXTI_ClearFallingFlag_0_31(COMP_EXTI_LINE_COMP2)
  464. /**
  465. * @}
  466. */
  467. /**
  468. * @}
  469. */
  470. /* Private types -------------------------------------------------------------*/
  471. /* Private constants ---------------------------------------------------------*/
  472. /** @defgroup COMP_Private_Constants COMP Private Constants
  473. * @{
  474. */
  475. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  476. * @{
  477. */
  478. #define COMP_EXTI_LINE_COMP1 (LL_EXTI_LINE_21) /*!< EXTI line 21 connected to COMP1 output */
  479. #define COMP_EXTI_LINE_COMP2 (LL_EXTI_LINE_22) /*!< EXTI line 22 connected to COMP2 output */
  480. /**
  481. * @}
  482. */
  483. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  484. * @{
  485. */
  486. #define COMP_EXTI_IT (0x00000001UL) /*!< EXTI line event with interruption */
  487. #define COMP_EXTI_EVENT (0x00000002UL) /*!< EXTI line event only (without interruption) */
  488. #define COMP_EXTI_RISING (0x00000010UL) /*!< EXTI line event on rising edge */
  489. #define COMP_EXTI_FALLING (0x00000020UL) /*!< EXTI line event on falling edge */
  490. /**
  491. * @}
  492. */
  493. /**
  494. * @}
  495. */
  496. /* Private macros ------------------------------------------------------------*/
  497. /** @defgroup COMP_Private_Macros COMP Private Macros
  498. * @{
  499. */
  500. /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
  501. * @{
  502. */
  503. /**
  504. * @brief Get the specified EXTI line for a comparator instance.
  505. * @param __INSTANCE__ specifies the COMP instance.
  506. * @retval value of @ref COMP_ExtiLine
  507. */
  508. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \
  509. : COMP_EXTI_LINE_COMP2)
  510. /**
  511. * @}
  512. */
  513. /** @defgroup COMP_IS_COMP_Private_Definitions COMP private macros to check input parameters
  514. * @{
  515. */
  516. #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
  517. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) )
  518. #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \
  519. ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \
  520. ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) )
  521. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) ((__COMP_INSTANCE__ == COMP1) \
  522. ? (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  523. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
  524. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3) ) \
  525. : \
  526. (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  527. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) ) \
  528. )
  529. /* Note: On this STM32 series, comparator input minus parameters are */
  530. /* the same on all COMP instances. */
  531. /* However, comparator instance kept as macro parameter for */
  532. /* compatibility with other STM32 series. */
  533. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  534. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  535. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  536. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  537. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  538. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
  539. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  540. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
  541. #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \
  542. ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \
  543. ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
  544. ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
  545. #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
  546. ((__POL__) == COMP_OUTPUTPOL_INVERTED))
  547. #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \
  548. (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \
  549. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \
  550. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \
  551. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \
  552. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) \
  553. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) \
  554. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2) \
  555. )
  556. #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  557. ((((__INSTANCE__) == COMP1) && \
  558. (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \
  559. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  560. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  561. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) \
  562. || \
  563. (((__INSTANCE__) == COMP2) && \
  564. (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \
  565. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) || \
  566. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) || \
  567. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2))))
  568. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  569. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  570. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  571. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  572. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  573. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  574. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  575. #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
  576. ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
  577. /**
  578. * @}
  579. */
  580. /**
  581. * @}
  582. */
  583. /* Exported functions --------------------------------------------------------*/
  584. /** @addtogroup COMP_Exported_Functions
  585. * @{
  586. */
  587. /** @addtogroup COMP_Exported_Functions_Group1
  588. * @{
  589. */
  590. /* Initialization and de-initialization functions **********************************/
  591. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  592. HAL_StatusTypeDef HAL_COMP_DeInit(COMP_HandleTypeDef *hcomp);
  593. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  594. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  595. #if (USE_HAL_COMP_REGISTER_CALLBACKS == 1)
  596. /* Callbacks Register/UnRegister functions ***********************************/
  597. HAL_StatusTypeDef HAL_COMP_RegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID,
  598. pCOMP_CallbackTypeDef pCallback);
  599. HAL_StatusTypeDef HAL_COMP_UnRegisterCallback(COMP_HandleTypeDef *hcomp, HAL_COMP_CallbackIDTypeDef CallbackID);
  600. #endif /* USE_HAL_COMP_REGISTER_CALLBACKS */
  601. /**
  602. * @}
  603. */
  604. /* IO operation functions *****************************************************/
  605. /** @addtogroup COMP_Exported_Functions_Group2
  606. * @{
  607. */
  608. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  609. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  610. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  611. /**
  612. * @}
  613. */
  614. /* Peripheral Control functions ************************************************/
  615. /** @addtogroup COMP_Exported_Functions_Group3
  616. * @{
  617. */
  618. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  619. uint32_t HAL_COMP_GetOutputLevel(const COMP_HandleTypeDef *hcomp);
  620. /* Callback in interrupt mode */
  621. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  622. /**
  623. * @}
  624. */
  625. /* Peripheral State functions **************************************************/
  626. /** @addtogroup COMP_Exported_Functions_Group4
  627. * @{
  628. */
  629. HAL_COMP_StateTypeDef HAL_COMP_GetState(const COMP_HandleTypeDef *hcomp);
  630. uint32_t HAL_COMP_GetError(const COMP_HandleTypeDef *hcomp);
  631. /**
  632. * @}
  633. */
  634. /**
  635. * @}
  636. */
  637. /**
  638. * @}
  639. */
  640. #endif /* COMP1 || COMP2 */
  641. /**
  642. * @}
  643. */
  644. #ifdef __cplusplus
  645. }
  646. #endif
  647. #endif /* STM32L5xx_HAL_COMP_H */