stm32l4xx_hal_comp.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L4xx_HAL_COMP_H
  37. #define __STM32L4xx_HAL_COMP_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. #if defined (COMP1) || defined (COMP2)
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "stm32l4xx_hal_def.h"
  44. #include "stm32l4xx_ll_exti.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup COMP
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup COMP_Exported_Types COMP Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief COMP Init structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t WindowMode; /*!< Set window mode of a pair of comparators instances
  61. (2 consecutive instances odd and even COMP<x> and COMP<x+1>).
  62. Note: HAL COMP driver allows to set window mode from any COMP instance of the pair of COMP instances composing window mode.
  63. This parameter can be a value of @ref COMP_WindowMode */
  64. uint32_t Mode; /*!< Set comparator operating mode to adjust power and speed.
  65. Note: For the characteritics of comparator power modes
  66. (propagation delay and power consumption), refer to device datasheet.
  67. This parameter can be a value of @ref COMP_PowerMode */
  68. uint32_t NonInvertingInput; /*!< Set comparator input plus (non-inverting input).
  69. This parameter can be a value of @ref COMP_InputPlus */
  70. uint32_t InvertingInput; /*!< Set comparator input minus (inverting input).
  71. This parameter can be a value of @ref COMP_InputMinus */
  72. uint32_t Hysteresis; /*!< Set comparator hysteresis mode of the input minus.
  73. This parameter can be a value of @ref COMP_Hysteresis */
  74. uint32_t OutputPol; /*!< Set comparator output polarity.
  75. This parameter can be a value of @ref COMP_OutputPolarity */
  76. uint32_t BlankingSrce; /*!< Set comparator blanking source.
  77. This parameter can be a value of @ref COMP_BlankingSrce */
  78. uint32_t TriggerMode; /*!< Set the comparator output triggering External Interrupt Line (EXTI).
  79. This parameter can be a value of @ref COMP_EXTI_TriggerMode */
  80. }COMP_InitTypeDef;
  81. /**
  82. * @brief HAL COMP state machine: HAL COMP states definition
  83. */
  84. #define COMP_STATE_BITFIELD_LOCK (0x10U)
  85. typedef enum
  86. {
  87. HAL_COMP_STATE_RESET = 0x00U, /*!< COMP not yet initialized */
  88. HAL_COMP_STATE_RESET_LOCKED = (HAL_COMP_STATE_RESET | COMP_STATE_BITFIELD_LOCK), /*!< COMP not yet initialized and configuration is locked */
  89. HAL_COMP_STATE_READY = 0x01U, /*!< COMP initialized and ready for use */
  90. HAL_COMP_STATE_READY_LOCKED = (HAL_COMP_STATE_READY | COMP_STATE_BITFIELD_LOCK), /*!< COMP initialized but configuration is locked */
  91. HAL_COMP_STATE_BUSY = 0x02U, /*!< COMP is running */
  92. HAL_COMP_STATE_BUSY_LOCKED = (HAL_COMP_STATE_BUSY | COMP_STATE_BITFIELD_LOCK) /*!< COMP is running and configuration is locked */
  93. }HAL_COMP_StateTypeDef;
  94. /**
  95. * @brief COMP Handle Structure definition
  96. */
  97. typedef struct
  98. {
  99. COMP_TypeDef *Instance; /*!< Register base address */
  100. COMP_InitTypeDef Init; /*!< COMP required parameters */
  101. HAL_LockTypeDef Lock; /*!< Locking object */
  102. __IO HAL_COMP_StateTypeDef State; /*!< COMP communication state */
  103. } COMP_HandleTypeDef;
  104. /**
  105. * @}
  106. */
  107. /* Exported constants --------------------------------------------------------*/
  108. /** @defgroup COMP_Exported_Constants COMP Exported Constants
  109. * @{
  110. */
  111. /** @defgroup COMP_WindowMode COMP Window Mode
  112. * @{
  113. */
  114. #define COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
  115. #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE) /*!< 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). */
  116. /**
  117. * @}
  118. */
  119. /** @defgroup COMP_PowerMode COMP power mode
  120. * @{
  121. */
  122. /* Note: For the characteritics of comparator power modes */
  123. /* (propagation delay and power consumption), */
  124. /* refer to device datasheet. */
  125. #define COMP_POWERMODE_HIGHSPEED (0x00000000U) /*!< High Speed */
  126. #define COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< Medium Speed */
  127. #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_PWRMODE) /*!< Ultra-low power mode */
  128. /**
  129. * @}
  130. */
  131. /** @defgroup COMP_InputPlus COMP input plus (non-inverting input)
  132. * @{
  133. */
  134. #define COMP_INPUT_PLUS_IO1 (0x00000000U) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2) */
  135. #define COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2) */
  136. #if defined(COMP_CSR_INPSEL_1)
  137. #define COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2) */
  138. #endif
  139. /**
  140. * @}
  141. */
  142. /** @defgroup COMP_InputMinus COMP input minus (inverting input)
  143. * @{
  144. */
  145. #define COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
  146. #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
  147. #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
  148. #define COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */
  149. #define COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  150. #if defined(DAC_CHANNEL2_SUPPORT)
  151. #define COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  152. #endif
  153. #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) */
  154. #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) */
  155. #if defined(COMP_CSR_INMESEL_1)
  156. #define COMP_INPUT_MINUS_IO3 ( COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2) */
  157. #define COMP_INPUT_MINUS_IO4 (COMP_CSR_INMESEL_1 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO4 (pin PA4 for COMP1, pin PA4 for COMP2) */
  158. #define COMP_INPUT_MINUS_IO5 (COMP_CSR_INMESEL_1 | COMP_CSR_INMESEL_0 | COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO5 (pin PA5 for COMP1, pin PA5 for COMP2) */
  159. #endif
  160. /**
  161. * @}
  162. */
  163. /** @defgroup COMP_Hysteresis COMP hysteresis
  164. * @{
  165. */
  166. #define COMP_HYSTERESIS_NONE (0x00000000U) /*!< No hysteresis */
  167. #define COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
  168. #define COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
  169. #define COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup COMP_OutputPolarity COMP output Polarity
  174. * @{
  175. */
  176. #define COMP_OUTPUTPOL_NONINVERTED (0x00000000U) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
  177. #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) */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup COMP_BlankingSrce COMP blanking source
  182. * @{
  183. */
  184. #define COMP_BLANKINGSRC_NONE (0x00000000U) /*!<Comparator output without blanking */
  185. #define COMP_BLANKINGSRC_TIM1_OC5_COMP1 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1) */
  186. #define COMP_BLANKINGSRC_TIM2_OC3_COMP1 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1) */
  187. #define COMP_BLANKINGSRC_TIM3_OC3_COMP1 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1) */
  188. #define COMP_BLANKINGSRC_TIM3_OC4_COMP2 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP2) */
  189. #define COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2) */
  190. #define COMP_BLANKINGSRC_TIM15_OC1_COMP2 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP2) */
  191. /**
  192. * @}
  193. */
  194. /** @defgroup COMP_OutputLevel COMP Output Level
  195. * @{
  196. */
  197. /* Note: Comparator output level values are fixed to "0" and "1", */
  198. /* corresponding COMP register bit is managed by HAL function to match */
  199. /* with these values (independently of bit position in register). */
  200. /* When output polarity is not inverted, comparator output is low when
  201. the input plus is at a lower voltage than the input minus */
  202. #define COMP_OUTPUT_LEVEL_LOW (0x00000000U)
  203. /* When output polarity is not inverted, comparator output is high when
  204. the input plus is at a higher voltage than the input minus */
  205. #define COMP_OUTPUT_LEVEL_HIGH (0x00000001U)
  206. /**
  207. * @}
  208. */
  209. /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
  210. * @{
  211. */
  212. #define COMP_TRIGGERMODE_NONE (0x00000000U) /*!< Comparator output triggering no External Interrupt Line */
  213. #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
  214. #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
  215. #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 */
  216. #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
  217. #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
  218. #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 */
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. /* Exported macro ------------------------------------------------------------*/
  226. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  227. * @{
  228. */
  229. /** @defgroup COMP_Handle_Management COMP Handle Management
  230. * @{
  231. */
  232. /** @brief Reset COMP handle state.
  233. * @param __HANDLE__ COMP handle
  234. * @retval None
  235. */
  236. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  237. /**
  238. * @brief Enable the specified comparator.
  239. * @param __HANDLE__ COMP handle
  240. * @retval None
  241. */
  242. #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  243. /**
  244. * @brief Disable the specified comparator.
  245. * @param __HANDLE__ COMP handle
  246. * @retval None
  247. */
  248. #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_EN)
  249. /**
  250. * @brief Lock the specified comparator configuration.
  251. * @note Using this macro induce HAL COMP handle state machine being no
  252. * more in line with COMP instance state.
  253. * To keep HAL COMP handle state machine updated, it is recommended
  254. * to use function "HAL_COMP_Lock')".
  255. * @param __HANDLE__ COMP handle
  256. * @retval None
  257. */
  258. #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK)
  259. /**
  260. * @brief Check whether the specified comparator is locked.
  261. * @param __HANDLE__ COMP handle
  262. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  263. */
  264. #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CSR, COMP_CSR_LOCK) == COMP_CSR_LOCK)
  265. /**
  266. * @}
  267. */
  268. /** @defgroup COMP_Exti_Management COMP external interrupt line management
  269. * @{
  270. */
  271. /**
  272. * @brief Enable the COMP1 EXTI line rising edge trigger.
  273. * @retval None
  274. */
  275. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
  276. /**
  277. * @brief Disable the COMP1 EXTI line rising edge trigger.
  278. * @retval None
  279. */
  280. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1)
  281. /**
  282. * @brief Enable the COMP1 EXTI line falling edge trigger.
  283. * @retval None
  284. */
  285. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
  286. /**
  287. * @brief Disable the COMP1 EXTI line falling edge trigger.
  288. * @retval None
  289. */
  290. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1)
  291. /**
  292. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  293. * @retval None
  294. */
  295. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  296. LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  297. LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  298. } while(0)
  299. /**
  300. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  301. * @retval None
  302. */
  303. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  304. LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  305. LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP1); \
  306. } while(0)
  307. /**
  308. * @brief Enable the COMP1 EXTI line in interrupt mode.
  309. * @retval None
  310. */
  311. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP1)
  312. /**
  313. * @brief Disable the COMP1 EXTI line in interrupt mode.
  314. * @retval None
  315. */
  316. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP1)
  317. /**
  318. * @brief Generate a software interrupt on the COMP1 EXTI line.
  319. * @retval None
  320. */
  321. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP1)
  322. /**
  323. * @brief Enable the COMP1 EXTI line in event mode.
  324. * @retval None
  325. */
  326. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP1)
  327. /**
  328. * @brief Disable the COMP1 EXTI line in event mode.
  329. * @retval None
  330. */
  331. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP1)
  332. /**
  333. * @brief Check whether the COMP1 EXTI line flag is set.
  334. * @retval RESET or SET
  335. */
  336. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP1)
  337. /**
  338. * @brief Clear the COMP1 EXTI flag.
  339. * @retval None
  340. */
  341. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP1)
  342. /**
  343. * @brief Enable the COMP2 EXTI line rising edge trigger.
  344. * @retval None
  345. */
  346. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
  347. /**
  348. * @brief Disable the COMP2 EXTI line rising edge trigger.
  349. * @retval None
  350. */
  351. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2)
  352. /**
  353. * @brief Enable the COMP2 EXTI line falling edge trigger.
  354. * @retval None
  355. */
  356. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
  357. /**
  358. * @brief Disable the COMP2 EXTI line falling edge trigger.
  359. * @retval None
  360. */
  361. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2)
  362. /**
  363. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  364. * @retval None
  365. */
  366. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  367. LL_EXTI_EnableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  368. LL_EXTI_EnableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  369. } while(0)
  370. /**
  371. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  372. * @retval None
  373. */
  374. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  375. LL_EXTI_DisableRisingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  376. LL_EXTI_DisableFallingTrig_0_31(COMP_EXTI_LINE_COMP2); \
  377. } while(0)
  378. /**
  379. * @brief Enable the COMP2 EXTI line in interrupt mode.
  380. * @retval None
  381. */
  382. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() LL_EXTI_EnableIT_0_31(COMP_EXTI_LINE_COMP2)
  383. /**
  384. * @brief Disable the COMP2 EXTI line in interrupt mode.
  385. * @retval None
  386. */
  387. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() LL_EXTI_DisableIT_0_31(COMP_EXTI_LINE_COMP2)
  388. /**
  389. * @brief Generate a software interrupt on the COMP2 EXTI line.
  390. * @retval None
  391. */
  392. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() LL_EXTI_GenerateSWI_0_31(COMP_EXTI_LINE_COMP2)
  393. /**
  394. * @brief Enable the COMP2 EXTI line in event mode.
  395. * @retval None
  396. */
  397. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() LL_EXTI_EnableEvent_0_31(COMP_EXTI_LINE_COMP2)
  398. /**
  399. * @brief Disable the COMP2 EXTI line in event mode.
  400. * @retval None
  401. */
  402. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() LL_EXTI_DisableEvent_0_31(COMP_EXTI_LINE_COMP2)
  403. /**
  404. * @brief Check whether the COMP2 EXTI line flag is set.
  405. * @retval RESET or SET
  406. */
  407. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() LL_EXTI_IsActiveFlag_0_31(COMP_EXTI_LINE_COMP2)
  408. /**
  409. * @brief Clear the COMP2 EXTI flag.
  410. * @retval None
  411. */
  412. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() LL_EXTI_ClearFlag_0_31(COMP_EXTI_LINE_COMP2)
  413. /**
  414. * @}
  415. */
  416. /**
  417. * @}
  418. */
  419. /* Private types -------------------------------------------------------------*/
  420. /* Private constants ---------------------------------------------------------*/
  421. /** @defgroup COMP_Private_Constants COMP Private Constants
  422. * @{
  423. */
  424. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  425. * @{
  426. */
  427. #define COMP_EXTI_LINE_COMP1 (LL_EXTI_LINE_21) /*!< EXTI line 21 connected to COMP1 output */
  428. #define COMP_EXTI_LINE_COMP2 (LL_EXTI_LINE_22) /*!< EXTI line 22 connected to COMP2 output */
  429. /**
  430. * @}
  431. */
  432. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  433. * @{
  434. */
  435. #define COMP_EXTI_IT (0x01U) /*!< EXTI line event with interruption */
  436. #define COMP_EXTI_EVENT (0x02U) /*!< EXTI line event only (without interruption) */
  437. #define COMP_EXTI_RISING (0x10U) /*!< EXTI line event on rising edge */
  438. #define COMP_EXTI_FALLING (0x20U) /*!< EXTI line event on falling edge */
  439. /**
  440. * @}
  441. */
  442. /**
  443. * @}
  444. */
  445. /* Private macros ------------------------------------------------------------*/
  446. /** @defgroup COMP_Private_Macros COMP Private Macros
  447. * @{
  448. */
  449. /** @defgroup COMP_GET_EXTI_LINE COMP private macros to get EXTI line associated with comparators
  450. * @{
  451. */
  452. /**
  453. * @brief Get the specified EXTI line for a comparator instance.
  454. * @param __INSTANCE__ specifies the COMP instance.
  455. * @retval value of @ref COMP_ExtiLine
  456. */
  457. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 \
  458. : COMP_EXTI_LINE_COMP2)
  459. /**
  460. * @}
  461. */
  462. /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
  463. * @{
  464. */
  465. #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
  466. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) )
  467. #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \
  468. ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \
  469. ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) )
  470. #if defined(COMP_CSR_INPSEL_1)
  471. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  472. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2) || \
  473. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO3))
  474. #else
  475. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  476. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2))
  477. #endif
  478. /* Note: On this STM32 serie, comparator input minus parameters are */
  479. /* the same on all COMP instances. */
  480. /* However, comparator instance kept as macro parameter for */
  481. /* compatibility with other STM32 families. */
  482. #if defined(COMP_CSR_INMESEL_1) && defined(DAC_CHANNEL2_SUPPORT)
  483. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  484. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  485. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  486. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  487. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  488. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
  489. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  490. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \
  491. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \
  492. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \
  493. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5))
  494. #elif defined(COMP_CSR_INMESEL_1)
  495. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  496. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  497. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  498. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  499. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  500. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  501. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2) || \
  502. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO3) || \
  503. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO4) || \
  504. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO5))
  505. #elif defined(DAC_CHANNEL2_SUPPORT)
  506. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  507. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  508. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  509. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  510. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  511. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
  512. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  513. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
  514. #else
  515. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  516. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  517. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  518. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  519. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  520. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  521. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
  522. #endif
  523. #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \
  524. ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \
  525. ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
  526. ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
  527. #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
  528. ((__POL__) == COMP_OUTPUTPOL_INVERTED))
  529. #define IS_COMP_BLANKINGSRCE(__OUTPUT_BLANKING_SOURCE__) \
  530. ( ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) \
  531. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) \
  532. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) \
  533. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1) \
  534. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) \
  535. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) \
  536. || ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2) \
  537. )
  538. #define IS_COMP_BLANKINGSRC_INSTANCE(__INSTANCE__, __OUTPUT_BLANKING_SOURCE__) \
  539. ((((__INSTANCE__) == COMP1) && \
  540. (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \
  541. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5_COMP1) || \
  542. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3_COMP1) || \
  543. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3_COMP1))) \
  544. || \
  545. (((__INSTANCE__) == COMP2) && \
  546. (((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_NONE) || \
  547. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4_COMP2) || \
  548. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5_COMP2) || \
  549. ((__OUTPUT_BLANKING_SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1_COMP2))))
  550. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  551. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  552. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  553. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  554. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  555. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  556. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  557. #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
  558. ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
  559. /**
  560. * @}
  561. */
  562. /**
  563. * @}
  564. */
  565. /* Exported functions --------------------------------------------------------*/
  566. /** @addtogroup COMP_Exported_Functions
  567. * @{
  568. */
  569. /** @addtogroup COMP_Exported_Functions_Group1
  570. * @{
  571. */
  572. /* Initialization and de-initialization functions **********************************/
  573. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  574. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  575. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  576. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  577. /**
  578. * @}
  579. */
  580. /* IO operation functions *****************************************************/
  581. /** @addtogroup COMP_Exported_Functions_Group2
  582. * @{
  583. */
  584. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  585. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  586. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  587. /**
  588. * @}
  589. */
  590. /* Peripheral Control functions ************************************************/
  591. /** @addtogroup COMP_Exported_Functions_Group3
  592. * @{
  593. */
  594. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  595. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  596. /* Callback in interrupt mode */
  597. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  598. /**
  599. * @}
  600. */
  601. /* Peripheral State functions **************************************************/
  602. /** @addtogroup COMP_Exported_Functions_Group4
  603. * @{
  604. */
  605. HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  606. /**
  607. * @}
  608. */
  609. /**
  610. * @}
  611. */
  612. /**
  613. * @}
  614. */
  615. /**
  616. * @}
  617. */
  618. #ifdef __cplusplus
  619. }
  620. #endif
  621. #endif /* COMP1 || COMP2 */
  622. #endif /* __STM32L4xx_HAL_COMP_H */
  623. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/