stm32h7xx_hal_comp.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_hal_comp.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 21-April-2017
  7. * @brief Header file of COMP HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32H7xx_HAL_COMP_H
  39. #define __STM32H7xx_HAL_COMP_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32h7xx_hal_def.h"
  45. /** @addtogroup STM32H7xx_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 ((uint32_t)0x10)
  85. typedef enum
  86. {
  87. HAL_COMP_STATE_RESET = 0x00, /*!< 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 = 0x01, /*!< 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 = 0x02, /*!< 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 ((uint32_t)0x00000000) /*!< Window mode disable: Comparators instances pair COMP1 and COMP2 are independent */
  115. #define COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CFGRx_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 ((uint32_t)0x00000000) /*!< High Speed */
  126. #define COMP_POWERMODE_MEDIUMSPEED (COMP_CFGRx_PWRMODE_0) /*!< Medium Speed */
  127. #define COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGRx_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 ((uint32_t)0x00000000) /*!< Comparator input plus connected to IO1 (pin PB0 for COMP1, pin PE9 for COMP2) */
  135. #define COMP_INPUT_PLUS_IO2 (COMP_CFGRx_INPSEL) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PE11 for COMP2) */
  136. /**
  137. * @}
  138. */
  139. /** @defgroup COMP_InputMinus COMP input minus (inverting input)
  140. * @{
  141. */
  142. #define COMP_INPUT_MINUS_1_4VREFINT ( COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
  143. #define COMP_INPUT_MINUS_1_2VREFINT ( COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
  144. #define COMP_INPUT_MINUS_3_4VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
  145. #define COMP_INPUT_MINUS_VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN ) /*!< Comparator input minus connected to VrefInt */
  146. #define COMP_INPUT_MINUS_DAC1_CH1 (COMP_CFGRx_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  147. #define COMP_INPUT_MINUS_DAC1_CH2 (COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  148. #define COMP_INPUT_MINUS_IO1 (COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PB1 for COMP1, pin PE10 for COMP2) */
  149. #define COMP_INPUT_MINUS_IO2 (COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PE7 for COMP2) */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup COMP_Hysteresis COMP hysteresis
  154. * @{
  155. */
  156. #define COMP_HYSTERESIS_NONE ((uint32_t)0x00000000) /*!< No hysteresis */
  157. #define COMP_HYSTERESIS_LOW (COMP_CFGRx_HYST_0) /*!< Hysteresis level low */
  158. #define COMP_HYSTERESIS_MEDIUM (COMP_CFGRx_HYST_1) /*!< Hysteresis level medium */
  159. #define COMP_HYSTERESIS_HIGH (COMP_CFGRx_HYST) /*!< Hysteresis level high */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup COMP_OutputPolarity COMP Output Polarity
  164. * @{
  165. */
  166. #define COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000) /*!< COMP output level is not inverted (comparator output is high when the input plus is at a higher voltage than the input minus) */
  167. #define COMP_OUTPUTPOL_INVERTED (COMP_CFGRx_POLARITY) /*!< COMP output level is inverted (comparator output is low when the input plus is at a higher voltage than the input minus) */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup COMP_BlankingSrce COMP Blanking Source
  172. * @{
  173. */
  174. /* Any blanking source can be selected for all comparators */
  175. #define COMP_BLANKINGSRC_NONE ((uint32_t)0x00000000) /*!< No blanking source */
  176. #define COMP_BLANKINGSRC_TIM1_OC5 (COMP_CFGRx_BLANKING_0) /*!< TIM1 OC5 selected as blanking source for comparator */
  177. #define COMP_BLANKINGSRC_TIM2_OC3 (COMP_CFGRx_BLANKING_1) /*!< TIM2 OC3 selected as blanking source for comparator */
  178. #define COMP_BLANKINGSRC_TIM3_OC3 (COMP_CFGRx_BLANKING_0 |COMP_CFGRx_BLANKING_1) /*!< TIM3 OC3 selected as blanking source for compartor */
  179. #define COMP_BLANKINGSRC_TIM3_OC4 (COMP_CFGRx_BLANKING_2) /*!< TIM3 OC4 selected as blanking source for comparator */
  180. #define COMP_BLANKINGSRC_TIM8_OC5 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_0) /*!< TIM8 OC5 selected as blanking source for comparator */
  181. #define COMP_BLANKINGSRC_TIM15_OC1 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_1) /*!< TIM15 OC1 selected as blanking source for comparator */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup COMP_OutputLevel COMP Output Level
  186. * @{
  187. */
  188. /* Note: Comparator output level values are fixed to "0" and "1", */
  189. /* corresponding COMP register bit is managed by HAL function to match */
  190. /* with these values (independently of bit position in register). */
  191. /* When output polarity is not inverted, comparator output is low when
  192. the input plus is at a lower voltage than the input minus */
  193. #define COMP_OUTPUT_LEVEL_LOW ((uint32_t)0x00000000)
  194. /* When output polarity is not inverted, comparator output is high when
  195. the input plus is at a higher voltage than the input minus */
  196. #define COMP_OUTPUT_LEVEL_HIGH ((uint32_t)0x00000001)
  197. /**
  198. * @}
  199. */
  200. /** @defgroup COMP_EXTI_TriggerMode COMP output to EXTI
  201. * @{
  202. */
  203. #define COMP_TRIGGERMODE_NONE ((uint32_t)0x00000000) /*!< Comparator output triggering no External Interrupt Line */
  204. #define COMP_TRIGGERMODE_IT_RISING (COMP_EXTI_IT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event with interruption, on rising edge */
  205. #define COMP_TRIGGERMODE_IT_FALLING (COMP_EXTI_IT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event with interruption, on falling edge */
  206. #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 */
  207. #define COMP_TRIGGERMODE_EVENT_RISING (COMP_EXTI_EVENT | COMP_EXTI_RISING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on rising edge */
  208. #define COMP_TRIGGERMODE_EVENT_FALLING (COMP_EXTI_EVENT | COMP_EXTI_FALLING) /*!< Comparator output triggering External Interrupt Line event only (without interruption), on falling edge */
  209. #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 */
  210. /**
  211. * @}
  212. */
  213. /** @defgroup COMP_Flag COMP Flag
  214. * @{
  215. */
  216. #define COMP_FLAG_C1I COMP_SR_C1IF /*!< Comparator 1 Interrupt Flag */
  217. #define COMP_FLAG_C2I COMP_SR_C2IF /*!< Comparator 2 Interrupt Flag */
  218. #define COMP_FLAG_LOCK COMP_CFGRx_LOCK /*!< Lock flag */
  219. /**
  220. * @}
  221. */
  222. /** @defgroup COMP_IT_CLEAR_Flags COMP Interruption Clear Flags
  223. * @{
  224. */
  225. #define COMP_CLEAR_C1IF COMP_ICFR_C1IF /*!< Clear Comparator 1 Interrupt Flag */
  226. #define COMP_CLEAR_C2IF COMP_ICFR_C2IF /*!< Clear Comparator 2 Interrupt Flag */
  227. /**
  228. * @}
  229. */
  230. /** @defgroup COMP_Interrupts_Definitions COMP Interrupts Definitions
  231. * @{
  232. */
  233. #define COMP_IT_EN COMP_CFGRx_ITEN
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /* Exported macros -----------------------------------------------------------*/
  241. /** @defgroup COMP_Exported_Macros COMP Exported Macros
  242. * @{
  243. */
  244. /** @defgroup COMP_Handle_Management COMP Handle Management
  245. * @{
  246. */
  247. /** @brief Reset COMP handle state.
  248. * @param __HANDLE__ COMP handle
  249. * @retval None
  250. */
  251. #define __HAL_COMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_COMP_STATE_RESET)
  252. /**
  253. * @brief Enable the specified comparator.
  254. * @param __HANDLE__ COMP handle
  255. * @retval None
  256. */
  257. #define __HAL_COMP_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_EN)
  258. /**
  259. * @brief Disable the specified comparator.
  260. * @param __HANDLE__ COMP handle
  261. * @retval None
  262. */
  263. #define __HAL_COMP_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_EN)
  264. /**
  265. * @brief Lock the specified comparator configuration.
  266. * @note Using this macro induce HAL COMP handle state machine being no
  267. * more in line with COMP instance state.
  268. * To keep HAL COMP handle state machine updated, it is recommended
  269. * to use function "HAL_COMP_Lock')".
  270. * @param __HANDLE__ COMP handle
  271. * @retval None
  272. */
  273. #define __HAL_COMP_LOCK(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_LOCK)
  274. /**
  275. * @brief Check whether the specified comparator is locked.
  276. * @param __HANDLE__ COMP handle
  277. * @retval Value 0 if COMP instance is not locked, value 1 if COMP instance is locked
  278. */
  279. #define __HAL_COMP_IS_LOCKED(__HANDLE__) (READ_BIT((__HANDLE__)->Instance->CFGR, COMP_CFGRx_LOCK) == COMP_CFGRx_LOCK)
  280. /**
  281. * @}
  282. */
  283. /** @defgroup COMP_Exti_Management COMP external interrupt line management
  284. * @{
  285. */
  286. /**
  287. * @brief Enable the COMP1 EXTI line rising edge trigger.
  288. * @retval None
  289. */
  290. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP1)
  291. /**
  292. * @brief Disable the COMP1 EXTI line rising edge trigger.
  293. * @retval None
  294. */
  295. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP1)
  296. /**
  297. * @brief Enable the COMP1 EXTI line falling edge trigger.
  298. * @retval None
  299. */
  300. #define __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP1)
  301. /**
  302. * @brief Disable the COMP1 EXTI line falling edge trigger.
  303. * @retval None
  304. */
  305. #define __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP1)
  306. /**
  307. * @brief Enable the COMP1 EXTI line rising & falling edge trigger.
  308. * @retval None
  309. */
  310. #define __HAL_COMP_COMP1_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  311. __HAL_COMP_COMP1_EXTI_ENABLE_RISING_EDGE(); \
  312. __HAL_COMP_COMP1_EXTI_ENABLE_FALLING_EDGE(); \
  313. } while(0)
  314. /**
  315. * @brief Disable the COMP1 EXTI line rising & falling edge trigger.
  316. * @retval None
  317. */
  318. #define __HAL_COMP_COMP1_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  319. __HAL_COMP_COMP1_EXTI_DISABLE_RISING_EDGE(); \
  320. __HAL_COMP_COMP1_EXTI_DISABLE_FALLING_EDGE(); \
  321. } while(0)
  322. /**
  323. * @brief Enable the COMP1 EXTI line in interrupt mode.
  324. * @retval None
  325. */
  326. #define __HAL_COMP_COMP1_EXTI_ENABLE_IT() SET_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP1)
  327. /**
  328. * @brief Disable the COMP1 EXTI line in interrupt mode.
  329. * @retval None
  330. */
  331. #define __HAL_COMP_COMP1_EXTI_DISABLE_IT() CLEAR_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP1)
  332. /**
  333. * @brief Enable the COMP1 EXTI Line in event mode.
  334. * @retval None
  335. */
  336. #define __HAL_COMP_COMP1_EXTI_ENABLE_EVENT() SET_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP1)
  337. /**
  338. * @brief Disable the COMP1 EXTI Line in event mode.
  339. * @retval None
  340. */
  341. #define __HAL_COMP_COMP1_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP1)
  342. /**
  343. * @brief Check whether the COMP1 EXTI line flag is set or not.
  344. * @retval RESET or SET
  345. */
  346. #define __HAL_COMP_COMP1_EXTI_GET_FLAG() READ_BIT(EXTI_D1->PR1, COMP_EXTI_LINE_COMP1)
  347. /**
  348. * @brief Clear the COMP1 EXTI flag.
  349. * @retval None
  350. */
  351. #define __HAL_COMP_COMP1_EXTI_CLEAR_FLAG() WRITE_REG(EXTI_D1->PR1, COMP_EXTI_LINE_COMP1)
  352. /**
  353. * @brief Generate a software interrupt on the COMP1 EXTI line.
  354. * @retval None
  355. */
  356. #define __HAL_COMP_COMP1_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, COMP_EXTI_LINE_COMP1)
  357. /**
  358. * @brief Enable the COMP1 D3 EXTI Line in event mode.
  359. * @retval None
  360. */
  361. #define __HAL_COMP_COMP1_EXTID3_ENABLE_EVENT() SET_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP1)
  362. /**
  363. * @brief Disable the COMP1 D3 EXTI Line in event mode.
  364. * @retval None
  365. */
  366. #define __HAL_COMP_COMP1_EXTID3_DISABLE_EVENT() CLEAR_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP1)
  367. /**
  368. * @brief Enable the COMP2 EXTI line rising edge trigger.
  369. * @retval None
  370. */
  371. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE() SET_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP2)
  372. /**
  373. * @brief Disable the COMP2 EXTI line rising edge trigger.
  374. * @retval None
  375. */
  376. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE() CLEAR_BIT(EXTI->RTSR1, COMP_EXTI_LINE_COMP2)
  377. /**
  378. * @brief Enable the COMP2 EXTI line falling edge trigger.
  379. * @retval None
  380. */
  381. #define __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE() SET_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP2)
  382. /**
  383. * @brief Disable the COMP2 EXTI line falling edge trigger.
  384. * @retval None
  385. */
  386. #define __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE() CLEAR_BIT(EXTI->FTSR1, COMP_EXTI_LINE_COMP2)
  387. /**
  388. * @brief Enable the COMP2 EXTI line rising & falling edge trigger.
  389. * @retval None
  390. */
  391. #define __HAL_COMP_COMP2_EXTI_ENABLE_RISING_FALLING_EDGE() do { \
  392. __HAL_COMP_COMP2_EXTI_ENABLE_RISING_EDGE(); \
  393. __HAL_COMP_COMP2_EXTI_ENABLE_FALLING_EDGE(); \
  394. } while(0)
  395. /**
  396. * @brief Disable the COMP2 EXTI line rising & falling edge trigger.
  397. * @retval None
  398. */
  399. #define __HAL_COMP_COMP2_EXTI_DISABLE_RISING_FALLING_EDGE() do { \
  400. __HAL_COMP_COMP2_EXTI_DISABLE_RISING_EDGE(); \
  401. __HAL_COMP_COMP2_EXTI_DISABLE_FALLING_EDGE(); \
  402. } while(0)
  403. /**
  404. * @brief Enable the COMP2 EXTI line.
  405. * @retval None
  406. */
  407. #define __HAL_COMP_COMP2_EXTI_ENABLE_IT() SET_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP2)
  408. /**
  409. * @brief Disable the COMP2 EXTI line.
  410. * @retval None
  411. */
  412. #define __HAL_COMP_COMP2_EXTI_DISABLE_IT() CLEAR_BIT(EXTI_D1->IMR1, COMP_EXTI_LINE_COMP2)
  413. /**
  414. * @brief Enable the COMP2 EXTI Line in event mode.
  415. * @retval None
  416. */
  417. #define __HAL_COMP_COMP2_EXTI_ENABLE_EVENT() SET_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP2)
  418. /**
  419. * @brief Disable the COMP2 EXTI Line in event mode.
  420. * @retval None
  421. */
  422. #define __HAL_COMP_COMP2_EXTI_DISABLE_EVENT() CLEAR_BIT(EXTI_D1->EMR1, COMP_EXTI_LINE_COMP2)
  423. /**
  424. * @brief Check whether the COMP2 EXTI line flag is set or not.
  425. * @retval RESET or SET
  426. */
  427. #define __HAL_COMP_COMP2_EXTI_GET_FLAG() READ_BIT(EXTI_D1->PR1, COMP_EXTI_LINE_COMP2)
  428. /**
  429. * @brief Clear the the COMP2 EXTI flag.
  430. * @retval None
  431. */
  432. #define __HAL_COMP_COMP2_EXTI_CLEAR_FLAG() WRITE_REG(EXTI_D1->PR1, COMP_EXTI_LINE_COMP2)
  433. /**
  434. * @brief Enable the COMP2 D3 EXTI Line in event mode.
  435. * @retval None
  436. */
  437. #define __HAL_COMP_COMP2_EXTID3_ENABLE_EVENT() SET_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP2)
  438. /**
  439. * @brief Disable the COMP2 D3 EXTI Line in event mode.
  440. * @retval None
  441. */
  442. #define __HAL_COMP_COMP2_EXTID3_DISABLE_EVENT() CLEAR_BIT(EXTI->D3PMR1, COMP_EXTI_LINE_COMP2)
  443. /**
  444. * @brief Generate a software interrupt on the COMP2 EXTI line.
  445. * @retval None
  446. */
  447. #define __HAL_COMP_COMP2_EXTI_GENERATE_SWIT() SET_BIT(EXTI->SWIER1, COMP_EXTI_LINE_COMP2)
  448. /** @brief Checks if the specified COMP interrupt source is enabled or disabled.
  449. * @param __HANDLE__: specifies the COMP Handle.
  450. * This parameter can be COMP1 where x: 1 or 2 to select the COMP peripheral.
  451. * @param __INTERRUPT__: specifies the COMP interrupt source to check.
  452. * This parameter can be one of the following values:
  453. * @arg COMP_IT_EN: Comparator interrupt enable
  454. *
  455. * @retval The new state of __IT__ (TRUE or FALSE)
  456. */
  457. #define __HAL_COMP_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CFGR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  458. /** @brief Checks whether the specified COMP flag is set or not.
  459. * @param __FLAG__: specifies the flag to check.
  460. * This parameter can be one of the following values:
  461. * @arg COMP_FLAG_C1I: Comparator 1 Interrupt Flag
  462. * @arg COMP_FLAG_C2I: Comparator 2 Interrupt Flag
  463. * @retval The new state of __FLAG__ (TRUE or FALSE)
  464. */
  465. #define __HAL_COMP_GET_FLAG(__FLAG__) ((COMP12->SR & (__FLAG__)) == (__FLAG__))
  466. /** @brief Clears the specified COMP pending flag.
  467. * @param __FLAG__: specifies the flag to check.
  468. * This parameter can be any combination of the following values:
  469. * @arg COMP_CLEAR_C1IF : Clear Comparator 1 Interrupt Flag
  470. * @arg COMP_CLEAR_C2IF : Clear Comparator 2 Interrupt Flag
  471. * @retval None
  472. */
  473. #define __HAL_COMP_CLEAR_FLAG(__FLAG__) (COMP12->ICFR = (__FLAG__))
  474. /** @brief Clear the COMP C1I flag.
  475. * @retval None
  476. */
  477. #define __HAL_COMP_CLEAR_C1IFLAG() __HAL_COMP_CLEAR_FLAG( COMP_CLEAR_C1IF)
  478. /** @brief Clear the COMP C2I flag.
  479. * @retval None
  480. */
  481. #define __HAL_COMP_CLEAR_C2IFLAG() __HAL_COMP_CLEAR_FLAG( COMP_CLEAR_C2IF)
  482. /** @brief Enable the specified COMP interrupt.
  483. * @param __HANDLE__: specifies the COMP Handle.
  484. * @param __INTERRUPT__: specifies the COMP interrupt source to enable.
  485. * This parameter can be one of the following values:
  486. * @arg COMP_CFGRx_ITEN : Comparator interrupt
  487. * @retval None
  488. */
  489. #define __HAL_COMP_ENABLE_IT(__HANDLE__, __INTERRUPT__) ( ((__HANDLE__)->Instance->CFGR) |= (__INTERRUPT__) )
  490. /** @brief Disable the specified COMP interrupt.
  491. * @param __HANDLE__: specifies the COMP Handle.
  492. * @param __INTERRUPT__: specifies the COMP interrupt source to enable.
  493. * This parameter can be one of the following values:
  494. * @arg COMP_CFGRx_ITEN : Comparator interrupt
  495. * @retval None
  496. */
  497. #define __HAL_COMP_DISABLE_IT(__HANDLE__,__INTERRUPT__) (((__HANDLE__)->Instance->CFGR) &= ~(__INTERRUPT__))
  498. /**
  499. * @}
  500. */
  501. /** @brief Enable the specified bit in the Option register.
  502. * @param __AF__: specifies the Alternate Function source selection .
  503. * This parameter can be one of the following values:
  504. * @arg COMP_OR_AFOPA6 : Alternate Function PA6 source selection
  505. * @arg COMP_OR_AFOPA8 : Alternate Function PA8 source selection
  506. * @arg COMP_OR_AFOPB12 : Alternate Function PB12 source selection
  507. * @arg COMP_OR_AFOPE6 : Alternate Function PE6 source selection
  508. * @arg COMP_OR_AFOPE15 : Alternate Function PE15 source selection
  509. * @arg COMP_OR_AFOPG2 : Alternate Function PG2 source selection
  510. * @arg COMP_OR_AFOPG3 : Alternate Function PG3 source selection
  511. * @arg COMP_OR_AFOPG4 : Alternate Function PG4 source selection
  512. * @arg COMP_OR_AFOPI1 : Alternate Function PI1 source selection
  513. * @arg COMP_OR_AFOPI4 : Alternate Function PI4 source selection
  514. * @arg COMP_OR_AFOPK2 : Alternate Function PK2 source selection
  515. * @retval None
  516. */
  517. #define __HAL_COMP_ENABLE_OR(__AF__) SET_BIT(COMP12->OR, (__AF__))
  518. /** @brief Disable the specified bit in the Option register.
  519. * @param __AF__: specifies the Alternate Function source selection .
  520. * This parameter can be one of the following values:
  521. * @arg COMP_OR_AFOPA6 : Alternate Function PA6 source selection
  522. * @arg COMP_OR_AFOPA8 : Alternate Function PA8 source selection
  523. * @arg COMP_OR_AFOPB12 : Alternate Function PB12 source selection
  524. * @arg COMP_OR_AFOPE6 : Alternate Function PE6 source selection
  525. * @arg COMP_OR_AFOPE15 : Alternate Function PE15 source selection
  526. * @arg COMP_OR_AFOPG2 : Alternate Function PG2 source selection
  527. * @arg COMP_OR_AFOPG3 : Alternate Function PG3 source selection
  528. * @arg COMP_OR_AFOPG4 : Alternate Function PG4 source selection
  529. * @arg COMP_OR_AFOPI1 : Alternate Function PI1 source selection
  530. * @arg COMP_OR_AFOPI4 : Alternate Function PI4 source selection
  531. * @arg COMP_OR_AFOPK2 : Alternate Function PK2 source selection
  532. * @retval None
  533. */
  534. #define __HAL_COMP_DISABLE_OR(__AF__) CLEAR_BIT(COMP12->OR, (__AF__))
  535. /**
  536. * @}
  537. */
  538. /* Private types -------------------------------------------------------------*/
  539. /* Private constants ---------------------------------------------------------*/
  540. /** @defgroup COMP_Private_Constants COMP Private Constants
  541. * @{
  542. */
  543. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  544. * @{
  545. */
  546. #define COMP_EXTI_LINE_COMP1 (EXTI_IMR1_IM20) /*!< EXTI line 20 connected to COMP1 output */
  547. #define COMP_EXTI_LINE_COMP2 (EXTI_IMR1_IM21) /*!< EXTI line 21 connected to COMP2 output */
  548. /**
  549. * @}
  550. */
  551. /** @defgroup COMP_ExtiLine COMP EXTI Lines
  552. * @{
  553. */
  554. #define COMP_EXTI_IT ((uint32_t) 0x01) /*!< EXTI line event with interruption */
  555. #define COMP_EXTI_EVENT ((uint32_t) 0x02) /*!< EXTI line event only (without interruption) */
  556. #define COMP_EXTI_RISING ((uint32_t) 0x10) /*!< EXTI line event on rising edge */
  557. #define COMP_EXTI_FALLING ((uint32_t) 0x20) /*!< EXTI line event on falling edge */
  558. /**
  559. * @}
  560. */
  561. /**
  562. * @}
  563. */
  564. /* Private macros ------------------------------------------------------------*/
  565. /** @defgroup COMP_Private_Macros COMP Private Macros
  566. * @{
  567. */
  568. /** @defgroup COMP_GET_EXTI_LINE COMP Private macros to get EXTI line associated with Comparators
  569. * @{
  570. */
  571. /**
  572. * @brief Get the specified EXTI line for a comparator instance.
  573. * @param __INSTANCE__: specifies the COMP instance.
  574. * @retval value of @ref COMP_ExtiLine
  575. */
  576. #define COMP_GET_EXTI_LINE(__INSTANCE__) (((__INSTANCE__) == COMP1) ? COMP_EXTI_LINE_COMP1 : \
  577. COMP_EXTI_LINE_COMP2)
  578. /**
  579. * @}
  580. */
  581. /** @defgroup COMP_IS_COMP_Definitions COMP private macros to check input parameters
  582. * @{
  583. */
  584. #define IS_COMP_WINDOWMODE(__WINDOWMODE__) (((__WINDOWMODE__) == COMP_WINDOWMODE_DISABLE) || \
  585. ((__WINDOWMODE__) == COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON) )
  586. #define IS_COMP_POWERMODE(__POWERMODE__) (((__POWERMODE__) == COMP_POWERMODE_HIGHSPEED) || \
  587. ((__POWERMODE__) == COMP_POWERMODE_MEDIUMSPEED) || \
  588. ((__POWERMODE__) == COMP_POWERMODE_ULTRALOWPOWER) )
  589. #define IS_COMP_INPUT_PLUS(__COMP_INSTANCE__, __INPUT_PLUS__) (((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO1) || \
  590. ((__INPUT_PLUS__) == COMP_INPUT_PLUS_IO2))
  591. #define IS_COMP_INPUT_MINUS(__COMP_INSTANCE__, __INPUT_MINUS__) (((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_4VREFINT) || \
  592. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_1_2VREFINT) || \
  593. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_3_4VREFINT) || \
  594. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_VREFINT) || \
  595. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH1) || \
  596. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_DAC1_CH2) || \
  597. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO1) || \
  598. ((__INPUT_MINUS__) == COMP_INPUT_MINUS_IO2))
  599. #define IS_COMP_HYSTERESIS(__HYSTERESIS__) (((__HYSTERESIS__) == COMP_HYSTERESIS_NONE) || \
  600. ((__HYSTERESIS__) == COMP_HYSTERESIS_LOW) || \
  601. ((__HYSTERESIS__) == COMP_HYSTERESIS_MEDIUM) || \
  602. ((__HYSTERESIS__) == COMP_HYSTERESIS_HIGH))
  603. #define IS_COMP_OUTPUTPOL(__POL__) (((__POL__) == COMP_OUTPUTPOL_NONINVERTED) || \
  604. ((__POL__) == COMP_OUTPUTPOL_INVERTED))
  605. #define IS_COMP_BLANKINGSRCE(__SOURCE__) (((__SOURCE__) == COMP_BLANKINGSRC_NONE) || \
  606. ((__SOURCE__) == COMP_BLANKINGSRC_TIM1_OC5) || \
  607. ((__SOURCE__) == COMP_BLANKINGSRC_TIM2_OC3) || \
  608. ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC3) || \
  609. ((__SOURCE__) == COMP_BLANKINGSRC_TIM3_OC4) || \
  610. ((__SOURCE__) == COMP_BLANKINGSRC_TIM8_OC5) || \
  611. ((__SOURCE__) == COMP_BLANKINGSRC_TIM15_OC1))
  612. #define IS_COMP_TRIGGERMODE(__MODE__) (((__MODE__) == COMP_TRIGGERMODE_NONE) || \
  613. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING) || \
  614. ((__MODE__) == COMP_TRIGGERMODE_IT_FALLING) || \
  615. ((__MODE__) == COMP_TRIGGERMODE_IT_RISING_FALLING) || \
  616. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING) || \
  617. ((__MODE__) == COMP_TRIGGERMODE_EVENT_FALLING) || \
  618. ((__MODE__) == COMP_TRIGGERMODE_EVENT_RISING_FALLING))
  619. #define IS_COMP_OUTPUT_LEVEL(__OUTPUT_LEVEL__) (((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_LOW) || \
  620. ((__OUTPUT_LEVEL__) == COMP_OUTPUT_LEVEL_HIGH))
  621. /**
  622. * @}
  623. */
  624. /**
  625. * @}
  626. */
  627. /* Exported functions --------------------------------------------------------*/
  628. /** @addtogroup COMP_Exported_Functions
  629. * @{
  630. */
  631. /** @addtogroup COMP_Exported_Functions_Group1
  632. * @{
  633. */
  634. /* Initialization and de-initialization functions **********************************/
  635. HAL_StatusTypeDef HAL_COMP_Init(COMP_HandleTypeDef *hcomp);
  636. HAL_StatusTypeDef HAL_COMP_DeInit (COMP_HandleTypeDef *hcomp);
  637. void HAL_COMP_MspInit(COMP_HandleTypeDef *hcomp);
  638. void HAL_COMP_MspDeInit(COMP_HandleTypeDef *hcomp);
  639. /**
  640. * @}
  641. */
  642. /* IO operation functions *****************************************************/
  643. /** @addtogroup COMP_Exported_Functions_Group2
  644. * @{
  645. */
  646. HAL_StatusTypeDef HAL_COMP_Start(COMP_HandleTypeDef *hcomp);
  647. HAL_StatusTypeDef HAL_COMP_Stop(COMP_HandleTypeDef *hcomp);
  648. HAL_StatusTypeDef HAL_COMP_Start_IT(COMP_HandleTypeDef *hcomp);
  649. HAL_StatusTypeDef HAL_COMP_Stop_IT(COMP_HandleTypeDef *hcomp);
  650. void HAL_COMP_IRQHandler(COMP_HandleTypeDef *hcomp);
  651. /**
  652. * @}
  653. */
  654. /* Peripheral Control functions ************************************************/
  655. /** @addtogroup COMP_Exported_Functions_Group3
  656. * @{
  657. */
  658. HAL_StatusTypeDef HAL_COMP_Lock(COMP_HandleTypeDef *hcomp);
  659. uint32_t HAL_COMP_GetOutputLevel(COMP_HandleTypeDef *hcomp);
  660. /* Callback in Interrupt mode */
  661. void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp);
  662. /**
  663. * @}
  664. */
  665. /* Peripheral State functions **************************************************/
  666. /** @addtogroup COMP_Exported_Functions_Group4
  667. * @{
  668. */
  669. HAL_COMP_StateTypeDef HAL_COMP_GetState(COMP_HandleTypeDef *hcomp);
  670. /**
  671. * @}
  672. */
  673. /**
  674. * @}
  675. */
  676. /**
  677. * @}
  678. */
  679. /**
  680. * @}
  681. */
  682. #ifdef __cplusplus
  683. }
  684. #endif
  685. #endif /* __STM32H7xx_HAL_COMP_H */
  686. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/