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.
 
 
 

864 lines
37 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 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 __STM32H7xx_LL_COMP_H
  21. #define __STM32H7xx_LL_COMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx.h"
  27. /** @addtogroup STM32H7xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (COMP1) || defined (COMP2)
  31. /** @defgroup COMP_LL COMP
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  38. * @{
  39. */
  40. /* COMP registers bits positions */
  41. #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30U) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
  42. /**
  43. * @}
  44. */
  45. /* Private macros ------------------------------------------------------------*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  49. * @{
  50. */
  51. /**
  52. * @brief Structure definition of some features of COMP instance.
  53. */
  54. typedef struct
  55. {
  56. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  57. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  58. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  59. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  60. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  61. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  62. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  63. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  64. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  65. uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
  66. This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
  67. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
  68. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  69. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  70. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
  71. uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
  72. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
  73. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputBlankingSource(). */
  74. } LL_COMP_InitTypeDef;
  75. /**
  76. * @}
  77. */
  78. #endif /* USE_FULL_LL_DRIVER */
  79. /* Exported constants --------------------------------------------------------*/
  80. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  81. * @{
  82. */
  83. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  84. * @{
  85. */
  86. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
  87. #define LL_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). */
  88. /**
  89. * @}
  90. */
  91. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  92. * @{
  93. */
  94. #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
  95. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CFGRx_PWRMODE_0) /*!< COMP power mode to medium speed */
  96. #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CFGRx_PWRMODE_1 | COMP_CFGRx_PWRMODE_0) /*!< COMP power mode to ultra-low power */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  101. * @{
  102. */
  103. #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PB0 for COMP1, pin PE9 for COMP2) */
  104. #define LL_COMP_INPUT_PLUS_IO2 (COMP_CFGRx_INPSEL) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PE11 for COMP2) */
  105. #if defined (COMP_CFGRx_INP2SEL)
  106. #define LL_COMP_INPUT_PLUS_DAC2_CH1 (COMP_CFGRx_INP2SEL) /*!< Comparator input plus 2 connected to (DAC2_CH1 for COMP1) */
  107. #endif
  108. /**
  109. * @}
  110. */
  111. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  112. * @{
  113. */
  114. #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
  115. #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
  116. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
  117. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CFGRx_INMSEL_1 | COMP_CFGRx_INMSEL_0 | COMP_CFGRx_SCALEN ) /*!< Comparator input minus connected to VrefInt */
  118. #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CFGRx_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  119. #define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CFGRx_INMSEL_2 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  120. #define LL_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) */
  121. #define LL_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) */
  122. #if defined (COMP_CFGRx_INMSEL_3)
  123. #define LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1 (COMP_CFGRx_INMSEL_3 ) /*!< Comparator input minus connected to (temp sensor which is exist in ADC for COMP1, DAC2_CH1 for COMP2) */
  124. #define LL_COMP_INPUT_MINUS_VBAT_VDDAP (COMP_CFGRx_INMSEL_3 | COMP_CFGRx_INMSEL_0 ) /*!< Comparator input minus connected to (VBAT/4 for COMP1, VDDAP for COMP2) */
  125. #endif
  126. /**
  127. * @}
  128. */
  129. /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
  130. * @{
  131. */
  132. #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
  133. #define LL_COMP_HYSTERESIS_LOW ( COMP_CFGRx_HYST_0) /*!< Hysteresis level low */
  134. #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CFGRx_HYST_1 ) /*!< Hysteresis level medium */
  135. #define LL_COMP_HYSTERESIS_HIGH (COMP_CFGRx_HYST_1 | COMP_CFGRx_HYST_0) /*!< Hysteresis level high */
  136. /**
  137. * @}
  138. */
  139. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  140. * @{
  141. */
  142. #define LL_COMP_OUTPUTPOL_NONINVERTED (0x00000000UL) /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
  143. #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CFGRx_POLARITY) /*!< COMP output polarity is inverted: comparator output is low when the plus (non-inverting) input is at a lower voltage than the minus (inverting) input */
  144. /**
  145. * @}
  146. */
  147. /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
  148. * @{
  149. */
  150. #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
  151. #define LL_COMP_BLANKINGSRC_TIM1_OC5 (COMP_CFGRx_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2) */
  152. #define LL_COMP_BLANKINGSRC_TIM2_OC3 (COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2) */
  153. #define LL_COMP_BLANKINGSRC_TIM3_OC3 (COMP_CFGRx_BLANKING_0 |COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2) */
  154. #define LL_COMP_BLANKINGSRC_TIM3_OC4 (COMP_CFGRx_BLANKING_2) /*!< Comparator output blanking source TIM3 OC4 (common to all COMP instances: COMP1, COMP2) */
  155. #define LL_COMP_BLANKINGSRC_TIM8_OC5 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_0) /*!< Comparator output blanking source TIM8 OC5 (common to all COMP instances: COMP1, COMP2) */
  156. #define LL_COMP_BLANKINGSRC_TIM15_OC1 (COMP_CFGRx_BLANKING_2|COMP_CFGRx_BLANKING_1) /*!< Comparator output blanking source TIM15 OC1 (common to all COMP instances: COMP1, COMP2) */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  161. * @{
  162. */
  163. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  164. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  165. /**
  166. * @}
  167. */
  168. /** @defgroup COMP_LL_EC_OUTPUT_BKIN_TIMER Comparator output - Output to BKIN timer
  169. * @{
  170. */
  171. #define LL_COMP_AF_PA6 COMP_OR_AFOPA6 /*!< Comparator Alternate Function PA6 source selected to timer BKIN input */
  172. #define LL_COMP_AF_PA8 COMP_OR_AFOPA8 /*!< Comparator Alternate Function PA8 source selected to timer BKIN input */
  173. #define LL_COMP_AF_PB12 COMP_OR_AFOPB12 /*!< Comparator Alternate Function PB12 source selected to timer BKIN input */
  174. #define LL_COMP_AF_PE6 COMP_OR_AFOPE6 /*!< Comparator Alternate Function PE6 source selected to timer BKIN input */
  175. #define LL_COMP_AF_PE15 COMP_OR_AFOPE15 /*!< Comparator Alternate Function PE15 source selected to timer BKIN input */
  176. #define LL_COMP_AF_PG2 COMP_OR_AFOPG2 /*!< Comparator Alternate Function PG2 source selected to timer BKIN input */
  177. #define LL_COMP_AF_PG3 COMP_OR_AFOPG3 /*!< Comparator Alternate Function PG3 source selected to timer BKIN input */
  178. #define LL_COMP_AF_PG4 COMP_OR_AFOPG4 /*!< Comparator Alternate Function PG4 source selected to timer BKIN input */
  179. #define LL_COMP_AF_PI1 COMP_OR_AFOPI1 /*!< Comparator Alternate Function PI1 source selected to timer BKIN input */
  180. #define LL_COMP_AF_PI4 COMP_OR_AFOPI4 /*!< Comparator Alternate Function PI4 source selected to timer BKIN input */
  181. #define LL_COMP_AF_PK2 COMP_OR_AFOPK2 /*!< Comparator Alternate Function PK2 source selected to timer BKIN input */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  186. * @note Only COMP IP HW delays are defined in COMP LL driver driver,
  187. * not timeout values.
  188. * For details on delays values, refer to descriptions in source code
  189. * above each literal definition.
  190. * @{
  191. */
  192. /* Delay for comparator startup time. */
  193. /* Note: Delay required to reach propagation delay specification. */
  194. /* Literal set to maximum value (refer to device datasheet, */
  195. /* parameter "tSTART"). */
  196. /* Unit: us */
  197. #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
  198. /* Delay for comparator voltage scaler stabilization time. */
  199. /* Note: Voltage scaler is used when selecting comparator input */
  200. /* based on VrefInt: VrefInt or subdivision of VrefInt. */
  201. /* Literal set to maximum value (refer to device datasheet, */
  202. /* parameter "tSTART_SCALER"). */
  203. /* Unit: us */
  204. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
  205. /**
  206. * @}
  207. */
  208. /**
  209. * @}
  210. */
  211. /* Exported macro ------------------------------------------------------------*/
  212. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  213. * @{
  214. */
  215. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  216. * @{
  217. */
  218. /**
  219. * @brief Write a value in COMP register
  220. * @param __INSTANCE__ comparator instance
  221. * @param __REG__ Register to be written
  222. * @param __VALUE__ Value to be written in the register
  223. * @retval None
  224. */
  225. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  226. /**
  227. * @brief Read a value in COMP register
  228. * @param __INSTANCE__ comparator instance
  229. * @param __REG__ Register to be read
  230. * @retval Register value
  231. */
  232. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  233. /**
  234. * @}
  235. */
  236. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  237. * @{
  238. */
  239. /**
  240. * @brief Helper macro to select the COMP common instance
  241. * to which is belonging the selected COMP instance.
  242. * @note COMP common register instance can be used to
  243. * set parameters common to several COMP instances.
  244. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  245. * @param __COMPx__ COMP instance
  246. * @retval COMP common instance or value "0" if there is no COMP common instance.
  247. */
  248. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  249. (COMP12_COMMON)
  250. /**
  251. * @}
  252. */
  253. /**
  254. * @}
  255. */
  256. /* Exported functions --------------------------------------------------------*/
  257. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  258. * @{
  259. */
  260. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  261. * @{
  262. */
  263. /**
  264. * @brief Set window mode of a pair of comparators instances
  265. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  266. * @rmtoll CFGRx WINMODE LL_COMP_SetCommonWindowMode
  267. * @param COMPxy_COMMON Comparator common instance
  268. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  269. * @param WindowMode This parameter can be one of the following values:
  270. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  271. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  272. * @retval None
  273. */
  274. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  275. {
  276. /* Note: On this STM32 serie, window mode can be set only */
  277. /* from COMP instance: COMP2. */
  278. MODIFY_REG(COMPxy_COMMON->CFGR, COMP_CFGRx_WINMODE, WindowMode);
  279. }
  280. /**
  281. * @brief Get window mode of a pair of comparators instances
  282. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  283. * @rmtoll CFGRx WINMODE LL_COMP_GetCommonWindowMode
  284. * @param COMPxy_COMMON Comparator common instance
  285. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  286. * @retval Returned value can be one of the following values:
  287. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  288. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  289. */
  290. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  291. {
  292. return (uint32_t)(READ_BIT(COMPxy_COMMON->CFGR, COMP_CFGRx_WINMODE));
  293. }
  294. /**
  295. * @}
  296. */
  297. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  298. * @{
  299. */
  300. /**
  301. * @brief Set comparator instance operating mode to adjust power and speed.
  302. * @rmtoll CFGRx PWRMODE LL_COMP_SetPowerMode
  303. * @param COMPx Comparator instance
  304. * @param PowerMode This parameter can be one of the following values:
  305. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  306. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  307. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
  308. * @retval None
  309. */
  310. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  311. {
  312. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_PWRMODE, PowerMode);
  313. }
  314. /**
  315. * @brief Get comparator instance operating mode to adjust power and speed.
  316. * @rmtoll CFGRx PWRMODE LL_COMP_GetPowerMode
  317. * @param COMPx Comparator instance
  318. * @retval Returned value can be one of the following values:
  319. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  320. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  321. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
  322. */
  323. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  324. {
  325. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_PWRMODE));
  326. }
  327. /**
  328. * @}
  329. */
  330. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  331. * @{
  332. */
  333. /**
  334. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  335. * @note In case of comparator input selected to be connected to IO:
  336. * GPIO pins are specific to each comparator instance.
  337. * Refer to description of parameters or to reference manual.
  338. * @note On this STM32 serie, scaler bridge is configurable:
  339. * to optimize power consumption, this function enables the
  340. * voltage scaler bridge only when required
  341. * (when selecting comparator input based on VrefInt: VrefInt or
  342. * subdivision of VrefInt).
  343. * - For scaler bridge power consumption values,
  344. * refer to device datasheet, parameter "IDDA(SCALER)".
  345. * - Voltage scaler requires a delay for voltage stabilization.
  346. * Refer to device datasheet, parameter "tSTART_SCALER".
  347. * - Scaler bridge is common for all comparator instances,
  348. * therefore if at least one of the comparator instance
  349. * is requiring the scaler bridge, it remains enabled.
  350. * @rmtoll CFGRx INMSEL LL_COMP_ConfigInputs\n
  351. * CFGRx INPSEL LL_COMP_ConfigInputs\n
  352. * CFGRx BRGEN LL_COMP_ConfigInputs\n
  353. * CFGRx SCALEN LL_COMP_ConfigInputs
  354. * @param COMPx Comparator instance
  355. * @param InputMinus This parameter can be one of the following values:
  356. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  357. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  358. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  359. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  360. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  361. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  362. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  363. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  364. #if defined (COMP_CFGRx_INMSEL_3)
  365. * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
  366. * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
  367. #endif
  368. * @param InputPlus This parameter can be one of the following values:
  369. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  370. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  371. #if defined (COMP_CFGRx_INP2SEL)
  372. * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
  373. #endif
  374. * @retval None
  375. */
  376. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  377. {
  378. #if defined (COMP_CFGRx_INP2SEL)
  379. MODIFY_REG(COMPx->CFGR,
  380. COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL |
  381. COMP_CFGRx_INP2SEL |
  382. COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
  383. InputMinus | InputPlus);
  384. #else
  385. MODIFY_REG(COMPx->CFGR,
  386. COMP_CFGRx_INMSEL | COMP_CFGRx_INPSEL |
  387. COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN,
  388. InputMinus | InputPlus);
  389. #endif
  390. }
  391. /**
  392. * @brief Set comparator input plus (non-inverting).
  393. * @note In case of comparator input selected to be connected to IO:
  394. * GPIO pins are specific to each comparator instance.
  395. * Refer to description of parameters or to reference manual.
  396. * @rmtoll CFGRx INPSEL LL_COMP_SetInputPlus
  397. * @param COMPx Comparator instance
  398. * @param InputPlus This parameter can be one of the following values:
  399. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  400. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  401. #if defined (COMP_CFGRx_INP2SEL)
  402. * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
  403. #endif
  404. * @retval None
  405. */
  406. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  407. {
  408. #if defined (COMP_CFGRx_INP2SEL)
  409. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL , InputPlus);
  410. #else
  411. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INPSEL , InputPlus);
  412. #endif
  413. }
  414. /**
  415. * @brief Get comparator input plus (non-inverting).
  416. * @note In case of comparator input selected to be connected to IO:
  417. * GPIO pins are specific to each comparator instance.
  418. * Refer to description of parameters or to reference manual.
  419. * @rmtoll CFGRx INPSEL LL_COMP_GetInputPlus
  420. * @param COMPx Comparator instance
  421. * @retval Returned value can be one of the following values:
  422. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  423. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  424. #if defined (COMP_CFGRx_INP2SEL)
  425. * @arg @ref LL_COMP_INPUT_PLUS_DAC2_CH1
  426. #endif
  427. */
  428. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  429. {
  430. #if defined (COMP_CFGRx_INP2SEL)
  431. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL | COMP_CFGRx_INP2SEL));
  432. #else
  433. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INPSEL));
  434. #endif
  435. }
  436. /**
  437. * @brief Set comparator input minus (inverting).
  438. * @note In case of comparator input selected to be connected to IO:
  439. * GPIO pins are specific to each comparator instance.
  440. * Refer to description of parameters or to reference manual.
  441. * @note On this STM32 serie, scaler bridge is configurable:
  442. * to optimize power consumption, this function enables the
  443. * voltage scaler bridge only when required
  444. * (when selecting comparator input based on VrefInt: VrefInt or
  445. * subdivision of VrefInt).
  446. * - For scaler bridge power consumption values,
  447. * refer to device datasheet, parameter "IDDA(SCALER)".
  448. * - Voltage scaler requires a delay for voltage stabilization.
  449. * Refer to device datasheet, parameter "tSTART_SCALER".
  450. * - Scaler bridge is common for all comparator instances,
  451. * therefore if at least one of the comparator instance
  452. * is requiring the scaler bridge, it remains enabled.
  453. * @rmtoll CFGRx INMSEL LL_COMP_SetInputMinus\n
  454. * CFGRx BRGEN LL_COMP_SetInputMinus\n
  455. * CFGRx SCALEN LL_COMP_SetInputMinus
  456. * @param COMPx Comparator instance
  457. * @param InputMinus This parameter can be one of the following values:
  458. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  459. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  460. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  461. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  462. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  463. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  464. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  465. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  466. #if defined (COMP_CFGRx_INMSEL_3)
  467. * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
  468. * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
  469. #endif
  470. * @retval None
  471. */
  472. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  473. {
  474. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN, InputMinus);
  475. }
  476. /**
  477. * @brief Get comparator input minus (inverting).
  478. * @note In case of comparator input selected to be connected to IO:
  479. * GPIO pins are specific to each comparator instance.
  480. * Refer to description of parameters or to reference manual.
  481. * @rmtoll CFGRx INMSEL LL_COMP_GetInputMinus\n
  482. * CFGRx BRGEN LL_COMP_GetInputMinus\n
  483. * CFGRx SCALEN LL_COMP_GetInputMinus
  484. * @param COMPx Comparator instance
  485. * @retval Returned value can be one of the following values:
  486. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  487. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  488. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  489. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  490. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  491. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  492. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  493. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  494. #if defined (COMP_CFGRx_INMSEL_3)
  495. * @arg @ref LL_COMP_INPUT_MINUS_TPSENS_DAC2CH1
  496. * @arg @ref LL_COMP_INPUT_MINUS_VBAT_VDDAP
  497. #endif
  498. */
  499. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  500. {
  501. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_INMSEL | COMP_CFGRx_SCALEN | COMP_CFGRx_BRGEN));
  502. }
  503. /**
  504. * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
  505. * @rmtoll CFGRx HYST LL_COMP_SetInputHysteresis
  506. * @param COMPx Comparator instance
  507. * @param InputHysteresis This parameter can be one of the following values:
  508. * @arg @ref LL_COMP_HYSTERESIS_NONE
  509. * @arg @ref LL_COMP_HYSTERESIS_LOW
  510. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  511. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  512. * @retval None
  513. */
  514. __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
  515. {
  516. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_HYST, InputHysteresis);
  517. }
  518. /**
  519. * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
  520. * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
  521. * @param COMPx Comparator instance
  522. * @retval Returned value can be one of the following values:
  523. * @arg @ref LL_COMP_HYSTERESIS_NONE
  524. * @arg @ref LL_COMP_HYSTERESIS_LOW
  525. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  526. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  527. */
  528. __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
  529. {
  530. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_HYST));
  531. }
  532. /**
  533. * @}
  534. */
  535. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  536. * @{
  537. */
  538. /**
  539. * @brief Set comparator instance output polarity.
  540. * @rmtoll CFGRx POLARITY LL_COMP_SetOutputPolarity
  541. * @param COMPx Comparator instance
  542. * @param OutputPolarity This parameter can be one of the following values:
  543. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  544. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  545. * @retval None
  546. */
  547. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  548. {
  549. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_POLARITY, OutputPolarity);
  550. }
  551. /**
  552. * @brief Get comparator instance output polarity.
  553. * @rmtoll CFGRx POLARITY LL_COMP_GetOutputPolarity
  554. * @param COMPx Comparator instance
  555. * @retval Returned value can be one of the following values:
  556. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  557. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  558. */
  559. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
  560. {
  561. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_POLARITY));
  562. }
  563. /**
  564. * @brief Set comparator instance blanking source.
  565. * @note Blanking source may be specific to each comparator instance.
  566. * Refer to description of parameters or to reference manual.
  567. * @note Availability of parameters of blanking source from timer
  568. * depends on timers availability on the selected device.
  569. * @rmtoll CFGR BLANKING LL_COMP_SetOutputBlankingSource
  570. * @param COMPx Comparator instance
  571. * @param BlankingSource This parameter can be one of the following values:
  572. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  573. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
  574. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
  575. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
  576. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
  577. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
  578. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
  579. * @retval None
  580. */
  581. __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
  582. {
  583. MODIFY_REG(COMPx->CFGR, COMP_CFGRx_BLANKING, BlankingSource);
  584. }
  585. /**
  586. * @brief Get comparator instance blanking source.
  587. * @note Availability of parameters of blanking source from timer
  588. * depends on timers availability on the selected device.
  589. * @note Blanking source may be specific to each comparator instance.
  590. * Refer to description of parameters or to reference manual.
  591. * @rmtoll CFGR BLANKING LL_COMP_GetOutputBlankingSource
  592. * @param COMPx Comparator instance
  593. * @retval Returned value can be one of the following values:
  594. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  595. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5
  596. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3
  597. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3
  598. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4
  599. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5
  600. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
  601. */
  602. __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(COMP_TypeDef *COMPx)
  603. {
  604. return (uint32_t)(READ_BIT(COMPx->CFGR, COMP_CFGRx_BLANKING));
  605. }
  606. /** @brief Set the output alternate function in the Option register
  607. * in order to be used with the alternate function
  608. * of the timer break input.
  609. * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
  610. * @param COMPx specifies the instance.
  611. * @param CompAFx specifies the Alternate Function source selection.
  612. * This parameter can be one of the following values:
  613. * @arg @ref LL_COMP_AF_PA6
  614. * @arg @ref LL_COMP_AF_PA8
  615. * @arg @ref LL_COMP_AF_PB12
  616. * @arg @ref LL_COMP_AF_PE6
  617. * @arg @ref LL_COMP_AF_PE15
  618. * @arg @ref LL_COMP_AF_PG2
  619. * @arg @ref LL_COMP_AF_PG3
  620. * @arg @ref LL_COMP_AF_PG4
  621. * @arg @ref LL_COMP_AF_PI1
  622. * @arg @ref LL_COMP_AF_PI4
  623. * @arg @ref LL_COMP_AF_PK2
  624. * @retval None
  625. */
  626. __STATIC_INLINE void LL_COMP_SetOutputAlternateFunction(COMP_TypeDef *COMPx, uint32_t CompAFx)
  627. {
  628. MODIFY_REG(COMP12->OR, 0x7FFUL, (COMPx == COMP1) ? ((~CompAFx) & 0x7FFUL) : CompAFx);
  629. }
  630. /** @brief Get the output alternate function from the Option register.
  631. * @rmtoll OR AFOP COMP_LL_EC_OUTPUT_BKIN_TIMER
  632. * @param COMPx specifies the Comparator instance.
  633. * @retval Returned value can be one of the following values:
  634. * @arg @ref LL_COMP_AF_PA6
  635. * @arg @ref LL_COMP_AF_PA8
  636. * @arg @ref LL_COMP_AF_PB12
  637. * @arg @ref LL_COMP_AF_PE6
  638. * @arg @ref LL_COMP_AF_PE15
  639. * @arg @ref LL_COMP_AF_PG2
  640. * @arg @ref LL_COMP_AF_PG3
  641. * @arg @ref LL_COMP_AF_PG4
  642. * @arg @ref LL_COMP_AF_PI1
  643. * @arg @ref LL_COMP_AF_PI4
  644. * @arg @ref LL_COMP_AF_PK2
  645. */
  646. __STATIC_INLINE uint32_t LL_COMP_GetOutputAlternateFunction(COMP_TypeDef *COMPx )
  647. {
  648. return (uint32_t) ((COMPx == COMP1) ? ((~COMP12->OR) & 0x7FFUL) : (COMP12->OR & 0x7FFUL));
  649. }
  650. /**
  651. * @}
  652. */
  653. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  654. * @{
  655. */
  656. /**
  657. * @brief Enable comparator instance.
  658. * @note After enable from off state, comparator requires a delay
  659. * to reach reach propagation delay specification.
  660. * Refer to device datasheet, parameter "tSTART".
  661. * @rmtoll CFGR EN LL_COMP_Enable
  662. * @param COMPx Comparator instance
  663. * @retval None
  664. */
  665. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  666. {
  667. SET_BIT(COMPx->CFGR, COMP_CFGRx_EN);
  668. }
  669. /**
  670. * @brief Disable comparator instance.
  671. * @rmtoll CFGR EN LL_COMP_Disable
  672. * @param COMPx Comparator instance
  673. * @retval None
  674. */
  675. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  676. {
  677. CLEAR_BIT(COMPx->CFGR, COMP_CFGRx_EN);
  678. }
  679. /**
  680. * @brief Get comparator enable state
  681. * (0: COMP is disabled, 1: COMP is enabled)
  682. * @rmtoll CFGR EN LL_COMP_IsEnabled
  683. * @param COMPx Comparator instance
  684. * @retval State of bit (1 or 0).
  685. */
  686. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  687. {
  688. return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_EN) == (COMP_CFGRx_EN)) ? 1UL : 0UL);
  689. }
  690. /**
  691. * @brief Lock comparator instance.
  692. * @note Once locked, comparator configuration can be accessed in read-only.
  693. * @note The only way to unlock the comparator is a device hardware reset.
  694. * @rmtoll CFGR LOCK LL_COMP_Lock
  695. * @param COMPx Comparator instance
  696. * @retval None
  697. */
  698. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  699. {
  700. SET_BIT(COMPx->CFGR, COMP_CFGRx_LOCK);
  701. }
  702. /**
  703. * @brief Get comparator lock state
  704. * (0: COMP is unlocked, 1: COMP is locked).
  705. * @note Once locked, comparator configuration can be accessed in read-only.
  706. * @note The only way to unlock the comparator is a device hardware reset.
  707. * @rmtoll CFGR LOCK LL_COMP_IsLocked
  708. * @param COMPx Comparator instance
  709. * @retval State of bit (1 or 0).
  710. */
  711. __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
  712. {
  713. return ((READ_BIT(COMPx->CFGR, COMP_CFGRx_LOCK) == (COMP_CFGRx_LOCK)) ? 1UL : 0UL);
  714. }
  715. /**
  716. * @brief Read comparator instance output level.
  717. * @note The comparator output level depends on the selected polarity
  718. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  719. * If the comparator polarity is not inverted:
  720. * - Comparator output is low when the input plus
  721. * is at a lower voltage than the input minus
  722. * - Comparator output is high when the input plus
  723. * is at a higher voltage than the input minus
  724. * If the comparator polarity is inverted:
  725. * - Comparator output is high when the input plus
  726. * is at a lower voltage than the input minus
  727. * - Comparator output is low when the input plus
  728. * is at a higher voltage than the input minus
  729. * @rmtoll CFGR VALUE LL_COMP_ReadOutputLevel
  730. * @param COMPx Comparator instance
  731. * @retval Returned value can be one of the following values:
  732. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  733. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  734. */
  735. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  736. {
  737. if (COMPx == COMP1)
  738. {
  739. return (uint32_t)(READ_BIT(COMP12->SR, COMP_SR_C1VAL));
  740. }
  741. else
  742. {
  743. return (uint32_t)((READ_BIT(COMP12->SR, COMP_SR_C2VAL))>> 1);
  744. }
  745. }
  746. /**
  747. * @}
  748. */
  749. #if defined(USE_FULL_LL_DRIVER)
  750. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  751. * @{
  752. */
  753. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  754. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  755. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  756. /**
  757. * @}
  758. */
  759. #endif /* USE_FULL_LL_DRIVER */
  760. /**
  761. * @}
  762. */
  763. /**
  764. * @}
  765. */
  766. #endif /* COMP1 || COMP2 */
  767. /**
  768. * @}
  769. */
  770. #ifdef __cplusplus
  771. }
  772. #endif
  773. #endif /* __STM32H7xx_LL_COMP_H */
  774. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/