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.
 
 
 

740 lines
32 KiB

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