stm32g0xx_ll_comp.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G0xx_LL_COMP_H
  20. #define STM32G0xx_LL_COMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g0xx.h"
  26. /** @addtogroup STM32G0xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (COMP1) || defined (COMP2)
  30. /** @defgroup COMP_LL COMP
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  37. * @{
  38. */
  39. /* Internal mask for pair of comparators instances window mode: */
  40. /* To select into literals LL_COMP_WINDOWMODE_COMPx_INPUT_PLUS_COMMON */
  41. /* the relevant bits for: */
  42. /* (concatenation of multiple bits used in different registers) */
  43. /* - Comparator instance selected as master for window mode : register offset */
  44. /* - Window mode enable or disable: bit value */
  45. #define LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK (0x00000000UL) /* Register of COMP instance odd (COMP1_CSR, ...)
  46. defined as reference register */
  47. #define LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK (0x00000001UL) /* Register of COMP instance even (COMP2_CSR, ...)
  48. offset vs register of COMP instance odd */
  49. #define LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK (LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK \
  50. | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
  51. #define LL_COMP_WINDOWMODE_COMPX_SETTING_MASK (COMP_CSR_WINMODE)
  52. #define LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK (COMP_CSR_WINOUT)
  53. #define LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK (COMP_CSR_WINOUT << 1UL)
  54. #define LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW (1UL)
  55. /* COMP registers bits positions */
  56. #define LL_COMP_WINDOWMODE_BITOFFSET_POS (11UL) /* Value equivalent to POSITION_VAL(COMP_CSR_WINMODE) */
  57. #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS (30UL) /* Value equivalent to POSITION_VAL(COMP_CSR_VALUE) */
  58. /**
  59. * @}
  60. */
  61. /* Private macros ------------------------------------------------------------*/
  62. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  63. * @{
  64. */
  65. /**
  66. * @brief Driver macro reserved for internal use: set a pointer to
  67. * a register from a register basis from which an offset
  68. * is applied.
  69. * @param __REG__ Register basis from which the offset is applied.
  70. * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
  71. * @retval Pointer to register address
  72. */
  73. #define __COMP_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
  74. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
  75. /**
  76. * @}
  77. */
  78. /* Exported types ------------------------------------------------------------*/
  79. #if defined(USE_FULL_LL_DRIVER)
  80. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  81. * @{
  82. */
  83. /**
  84. * @brief Structure definition of some features of COMP instance.
  85. */
  86. typedef struct
  87. {
  88. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  89. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  90. This feature can be modified afterwards using unitary
  91. function @ref LL_COMP_SetPowerMode(). */
  92. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  93. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  94. This feature can be modified afterwards using unitary function
  95. @ref LL_COMP_SetInputPlus(). */
  96. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  97. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  98. This feature can be modified afterwards using unitary function
  99. @ref LL_COMP_SetInputMinus(). */
  100. uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
  101. This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
  102. This feature can be modified afterwards using unitary function
  103. @ref LL_COMP_SetInputHysteresis(). */
  104. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  105. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  106. This feature can be modified afterwards using unitary function
  107. @ref LL_COMP_SetOutputPolarity(). */
  108. uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
  109. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
  110. This feature can be modified afterwards using unitary function
  111. @ref LL_COMP_SetOutputBlankingSource(). */
  112. } LL_COMP_InitTypeDef;
  113. /**
  114. * @}
  115. */
  116. #endif /* USE_FULL_LL_DRIVER */
  117. /* Exported constants --------------------------------------------------------*/
  118. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  119. * @{
  120. */
  121. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  122. * @{
  123. */
  124. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000UL) /*!< Window mode disable: Comparators 1 and 2 are independent */
  125. #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< 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). */
  126. #define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WINMODE | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window mode enable: if used from COMP1 or COMP2 instance, comparators instances pair COMP1 and COMP2 have their input plus connected together, the common input is COMP2 input plus (COMP1 input plus is no more accessible). If used from COMP3 instance (when available), comparators instances pair COMP2 and COMP3 have their input plus connected together, the common input is COMP2 input plus (COMP3 input plus is no more accessible). */
  127. /**
  128. * @}
  129. */
  130. /** @defgroup COMP_LL_EC_COMMON_WINDOWOUTPUT Comparator common modes - Window output
  131. * @{
  132. */
  133. #define LL_COMP_WINDOWOUTPUT_EACH_COMP (0x00000000UL) /*!< Window output default mode: Comparators output are indicating each their own state. To know window mode state: each comparator output must be read, if "((COMPx exclusive or COMPy) == 1)" then monitored signal is within comparators window. The same way, if both comparators output are high, then monitored signal is below window. */
  134. #define LL_COMP_WINDOWOUTPUT_COMP1 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window output synthesized on COMP1 output: COMP1 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Note: impacts only comparator output signal level (COMPx_OUT propagated to GPIO, EXTI lines, timers, ...), does not impact output digital state of comparator (COMPx_VALUE) always reflecting each comparator output state.*/
  135. #define LL_COMP_WINDOWOUTPUT_COMP2 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK) /*!< Window output synthesized on COMP2 output: COMP2 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Note: impacts only comparator output signal level (COMPx_OUT propagated to GPIO, EXTI lines, timers, ...), does not impact output digital state of comparator (COMPx_VALUE) always reflecting each comparator output state.*/
  136. #if defined(COMP3)
  137. #define LL_COMP_WINDOWOUTPUT_COMP3 (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_ODD_REGOFFSET_MASK) /*!< Window output synthesized on COMP3 output: COMP3 output is no more indicating its own state, but global window mode state (logical high means monitored signal is within comparators window). Available only on devices featuring COMP3 instance. */
  138. #endif /* COMP3 */
  139. #define LL_COMP_WINDOWOUTPUT_BOTH (COMP_CSR_WINOUT | LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK | LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) /*!< Window output synthesized on both comparators output of pair of comparator selected (COMP1 and COMP2, or COMP2 and COMP3 for devices featuring COMP3 instance): both comparators outputs are no more indicating their own state, but global window mode state (logical high means monitored signal is within comparators window). This is a specific configuration (technically possible but not relevant from application point of view: 2 comparators output used for the same signal level), standard configuration for window mode is one of the settings above. */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  144. * @{
  145. */
  146. #define LL_COMP_POWERMODE_HIGHSPEED (0x00000000UL) /*!< COMP power mode to high speed */
  147. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_PWRMODE_0) /*!< COMP power mode to medium speed */
  148. /**
  149. * @}
  150. */
  151. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  152. * @{
  153. */
  154. #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PC5 for COMP1, pin PB4 for COMP2, pin PB0 for COMP3 (for devices featuring COMP3 instance)) */
  155. #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB2 for COMP1, pin PB6 for COMP2, pin PC1 for COMP3 (for devices featuring COMP3 instance)) */
  156. #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA1 for COMP1, pin PA3 for COMP2, pin PE7 for COMP3 (for devices featuring COMP3 instance)) */
  157. /**
  158. * @}
  159. */
  160. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  161. * @{
  162. */
  163. #define LL_COMP_INPUT_MINUS_1_4VREFINT (0x00000000UL) /*!< Comparator input minus connected to 1/4 VrefInt */
  164. #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
  165. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
  166. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to VrefInt */
  167. #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  168. #define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  169. #define LL_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, pin PB2 for COMP3 (for devices featuring COMP3 instance)) */
  170. #define LL_COMP_INPUT_MINUS_IO2 ( COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to IO2 (pin PC4 for COMP1, pin PB7 for COMP2, pin PC0 for COMP3 (for devices featuring COMP3 instance)) */
  171. #define LL_COMP_INPUT_MINUS_IO3 (COMP_CSR_INMSEL_3 ) /*!< Comparator input minus connected to IO3 (pin PA0 for COMP1, pin PA2 for COMP2, pin PE8 for COMP3 (for devices featuring COMP3 instance)) */
  172. /**
  173. * @}
  174. */
  175. /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
  176. * @{
  177. */
  178. #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
  179. #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_HYST_0) /*!< Hysteresis level low */
  180. #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_HYST_1 ) /*!< Hysteresis level medium */
  181. #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level high */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  186. * @{
  187. */
  188. #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 */
  189. #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_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 */
  190. /**
  191. * @}
  192. */
  193. /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
  194. * @{
  195. */
  196. #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
  197. /* Note: Output blanking source common to all COMP instances */
  198. #define LL_COMP_BLANKINGSRC_TIM1_OC4 (COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC4 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
  199. #define LL_COMP_BLANKINGSRC_TIM1_OC5 (COMP_CSR_BLANKING_1) /*!< Comparator output blanking source TIM1 OC5 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
  200. #define LL_COMP_BLANKINGSRC_TIM2_OC3 (COMP_CSR_BLANKING_2) /*!< Comparator output blanking source TIM2 OC3 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
  201. #define LL_COMP_BLANKINGSRC_TIM3_OC3 (COMP_CSR_BLANKING_3) /*!< Comparator output blanking source TIM3 OC3 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
  202. #define LL_COMP_BLANKINGSRC_TIM15_OC2 (COMP_CSR_BLANKING_4) /*!< Comparator output blanking source TIM15 OC2 (common to all COMP instances: COMP1, COMP2, COMP3 (when available)) */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  207. * @{
  208. */
  209. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  210. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  211. /**
  212. * @}
  213. */
  214. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  215. * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
  216. * not timeout values.
  217. * For details on delays values, refer to descriptions in source code
  218. * above each literal definition.
  219. * @{
  220. */
  221. /* Delay for comparator startup time. */
  222. /* Note: Delay required to reach propagation delay specification. */
  223. /* Literal set to maximum value (refer to device datasheet, */
  224. /* parameter "tSTART"). */
  225. /* Unit: us */
  226. #define LL_COMP_DELAY_STARTUP_US ( 80UL) /*!< Delay for COMP startup time */
  227. /* Delay for comparator voltage scaler stabilization time. */
  228. /* Note: Voltage scaler is used when selecting comparator input */
  229. /* based on VrefInt: VrefInt or subdivision of VrefInt. */
  230. /* Literal set to maximum value (refer to device datasheet, */
  231. /* parameter "tSTART_SCALER"). */
  232. /* Unit: us */
  233. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
  234. /**
  235. * @}
  236. */
  237. /**
  238. * @}
  239. */
  240. /* Exported macro ------------------------------------------------------------*/
  241. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  242. * @{
  243. */
  244. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  245. * @{
  246. */
  247. /**
  248. * @brief Write a value in COMP register
  249. * @param __INSTANCE__ comparator instance
  250. * @param __REG__ Register to be written
  251. * @param __VALUE__ Value to be written in the register
  252. * @retval None
  253. */
  254. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  255. /**
  256. * @brief Read a value in COMP register
  257. * @param __INSTANCE__ comparator instance
  258. * @param __REG__ Register to be read
  259. * @retval Register value
  260. */
  261. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  262. /**
  263. * @}
  264. */
  265. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  266. * @{
  267. */
  268. /**
  269. * @brief Helper macro to select the COMP common instance
  270. * to which is belonging the selected COMP instance.
  271. * @note COMP common register instance can be used to
  272. * set parameters common to several COMP instances.
  273. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  274. * @param __COMPx__ COMP instance
  275. * @retval COMP common instance or value "0" if there is no COMP common instance.
  276. */
  277. #if defined(COMP3)
  278. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  279. ((((__COMPx__) == COMP3)) \
  280. ? ( \
  281. (COMP23_COMMON) \
  282. ) \
  283. : \
  284. ( \
  285. (COMP12_COMMON) \
  286. ) \
  287. )
  288. #else
  289. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  290. (COMP12_COMMON)
  291. #endif /* COMP3 */
  292. /**
  293. * @}
  294. */
  295. /**
  296. * @}
  297. */
  298. /* Exported functions --------------------------------------------------------*/
  299. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  300. * @{
  301. */
  302. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope:
  303. * common to several COMP instances
  304. * @{
  305. */
  306. /**
  307. * @brief Set window mode of a pair of comparators instances
  308. * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
  309. * @rmtoll CSR WINMODE LL_COMP_SetCommonWindowMode
  310. * @param COMPxy_COMMON Comparator common instance
  311. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  312. * @param WindowMode This parameter can be one of the following values:
  313. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  314. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (1)
  315. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (1)(2)
  316. *
  317. * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
  318. * (2) Parameter specificity on devices STM32G0B1xx and STM32G0C1xx: only parameter that can be used only with comparator common instance COMP23_COMMON
  319. * @retval None
  320. */
  321. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  322. {
  323. uint32_t window_mode_tmp = WindowMode;
  324. /* Note: On this STM32 series, window mode can be set from any instance */
  325. /* of the pair of comparator instances. */
  326. #if defined(COMP3)
  327. /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
  328. /* group of COMP2 and COMP3, instances odd and even are inverted. */
  329. /* Perform switch of parameter selected. */
  330. if (COMPxy_COMMON == COMP23_COMMON)
  331. {
  332. if (WindowMode == LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON)
  333. {
  334. window_mode_tmp = LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;
  335. }
  336. }
  337. #endif /* COMP3 */
  338. __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD,
  339. (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
  340. /* Clear the potential previous setting of window mode */
  341. __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD,
  342. (~(window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
  343. CLEAR_BIT(*preg_clear,
  344. COMP_CSR_WINMODE
  345. );
  346. /* Set window mode */
  347. MODIFY_REG(*preg,
  348. COMP_CSR_WINMODE,
  349. (window_mode_tmp & LL_COMP_WINDOWMODE_COMPX_SETTING_MASK)
  350. );
  351. }
  352. /**
  353. * @brief Get window mode of a pair of comparators instances
  354. * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
  355. * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowMode
  356. * @param COMPxy_COMMON Comparator common instance
  357. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  358. * @retval Returned value can be one of the following values:
  359. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  360. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (1)
  361. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (1)(2)
  362. *
  363. * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
  364. * (2) Parameter specificity on devices STM32G0B1xx and STM32G0C1xx: only parameter that can be used only with comparator common instance COMP23_COMMON
  365. */
  366. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(const COMP_Common_TypeDef *COMPxy_COMMON)
  367. {
  368. /* Note: On this STM32 series, window mode can be set from any instance */
  369. /* of the pair of comparator instances. */
  370. #if defined(COMP3)
  371. uint32_t window_mode_comp_odd;
  372. uint32_t window_mode_comp_even;
  373. /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
  374. /* group of COMP2 and COMP3, instances odd and even are inverted. */
  375. /* Perform switch of parameter selected. */
  376. if (COMPxy_COMMON == COMP23_COMMON)
  377. {
  378. window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
  379. window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
  380. }
  381. else
  382. {
  383. window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
  384. window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
  385. }
  386. #else
  387. const uint32_t window_mode_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINMODE);
  388. const uint32_t window_mode_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINMODE);
  389. #endif /* COMP3 */
  390. return (uint32_t)(window_mode_comp_odd
  391. | window_mode_comp_even
  392. | ((window_mode_comp_even >> LL_COMP_WINDOWMODE_BITOFFSET_POS)
  393. * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
  394. );
  395. }
  396. /**
  397. * @brief Set window output of a pair of comparators instances
  398. * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
  399. * @rmtoll CSR WINOUT LL_COMP_SetCommonWindowOutput
  400. * @param COMPxy_COMMON Comparator common instance
  401. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  402. * @param WindowOutput This parameter can be one of the following values:
  403. * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
  404. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1 (1)
  405. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2 (1)
  406. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP3 (2)
  407. * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
  408. *
  409. * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
  410. * (2) Parameter available only on devices STM32G0B1xx and STM32G0C1xx, must be used with comparator common instance COMP23_COMMON
  411. * @retval None
  412. */
  413. __STATIC_INLINE void LL_COMP_SetCommonWindowOutput(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowOutput)
  414. {
  415. uint32_t window_output_tmp = WindowOutput;
  416. #if defined(COMP3)
  417. /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
  418. /* group of COMP2 and COMP3, instances odd and even are inverted. */
  419. /* Perform switch of parameter selected. */
  420. if (COMPxy_COMMON == COMP23_COMMON)
  421. {
  422. if (WindowOutput == LL_COMP_WINDOWOUTPUT_COMP2)
  423. {
  424. window_output_tmp = LL_COMP_WINDOWOUTPUT_COMP3;
  425. }
  426. else if (WindowOutput == LL_COMP_WINDOWOUTPUT_COMP3)
  427. {
  428. window_output_tmp = LL_COMP_WINDOWOUTPUT_COMP2;
  429. }
  430. else
  431. {
  432. /* No modification of other parameters */
  433. }
  434. }
  435. #endif /* COMP3 */
  436. __IO uint32_t *preg = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (window_output_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK));
  437. /* Clear the potential previous setting of window output on the relevant comparator instance */
  438. /* (clear bit of window output unless specific case of setting of comparator both output selected) */
  439. __IO uint32_t *preg_clear = __COMP_PTR_REG_OFFSET(COMPxy_COMMON->CSR_ODD, (~(window_output_tmp & LL_COMP_WINDOWMODE_COMPX_REGOFFSET_MASK) & 0x1UL));
  440. MODIFY_REG(*preg_clear,
  441. COMP_CSR_WINOUT,
  442. ((window_output_tmp & LL_COMP_WINDOWOUTPUT_BOTH_SETTING_MASK) >> LL_COMP_WINDOWOUTPUT_BOTH_POS_VS_WINDOW)
  443. );
  444. /* Set window output */
  445. MODIFY_REG(*preg,
  446. COMP_CSR_WINOUT,
  447. (window_output_tmp & LL_COMP_WINDOWOUTPUT_COMPX_SETTING_MASK)
  448. );
  449. }
  450. /**
  451. * @brief Get window output of a pair of comparators instances
  452. * (2 consecutive COMP instances COMP<x> and COMP<x+1>).
  453. * @rmtoll CSR WINMODE LL_COMP_GetCommonWindowOutput
  454. * @param COMPxy_COMMON Comparator common instance
  455. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  456. * @retval Returned value can be one of the following values:
  457. * @arg @ref LL_COMP_WINDOWOUTPUT_EACH_COMP
  458. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP1 (1)
  459. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP2 (1)
  460. * @arg @ref LL_COMP_WINDOWOUTPUT_COMP3 (2)
  461. * @arg @ref LL_COMP_WINDOWOUTPUT_BOTH
  462. *
  463. * (1) Parameter available on all STM32G0 devices, must be used with comparator common instance COMP12_COMMON
  464. * (2) Parameter available only on devices STM32G0B1xx and STM32G0C1xx, must be used with comparator common instance COMP23_COMMON
  465. */
  466. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowOutput(const COMP_Common_TypeDef *COMPxy_COMMON)
  467. {
  468. #if defined(COMP3)
  469. uint32_t window_output_comp_odd;
  470. uint32_t window_output_comp_even;
  471. /* Note: Exception for STM32G0 devices featuring ADC3 instance: in common */
  472. /* group of COMP2 and COMP3, instances odd and even are inverted. */
  473. /* Perform switch of parameter selected. */
  474. if (COMPxy_COMMON == COMP23_COMMON)
  475. {
  476. window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
  477. window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
  478. }
  479. else
  480. {
  481. window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
  482. window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
  483. }
  484. #else
  485. const uint32_t window_output_comp_odd = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_ODD, COMP_CSR_WINOUT);
  486. const uint32_t window_output_comp_even = (uint32_t)READ_BIT(COMPxy_COMMON->CSR_EVEN, COMP_CSR_WINOUT);
  487. #endif /* COMP3 */
  488. /* Construct value corresponding to LL_COMP_WINDOWOUTPUT_xxx */
  489. return (uint32_t)(window_output_comp_odd
  490. | window_output_comp_even
  491. | ((window_output_comp_even >> COMP_CSR_WINOUT_Pos) * LL_COMP_WINDOWMODE_COMP_EVEN_REGOFFSET_MASK)
  492. | (window_output_comp_odd + window_output_comp_even));
  493. }
  494. /**
  495. * @}
  496. */
  497. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  498. * @{
  499. */
  500. /**
  501. * @brief Set comparator instance operating mode to adjust power and speed.
  502. * @rmtoll CSR PWRMODE LL_COMP_SetPowerMode
  503. * @param COMPx Comparator instance
  504. * @param PowerMode This parameter can be one of the following values:
  505. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  506. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  507. * @retval None
  508. */
  509. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  510. {
  511. MODIFY_REG(COMPx->CSR, COMP_CSR_PWRMODE, PowerMode);
  512. }
  513. /**
  514. * @brief Get comparator instance operating mode to adjust power and speed.
  515. * @rmtoll CSR PWRMODE LL_COMP_GetPowerMode
  516. * @param COMPx Comparator instance
  517. * @retval Returned value can be one of the following values:
  518. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  519. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  520. */
  521. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(const COMP_TypeDef *COMPx)
  522. {
  523. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_PWRMODE));
  524. }
  525. /**
  526. * @}
  527. */
  528. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  529. * @{
  530. */
  531. /**
  532. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  533. * @note In case of comparator input selected to be connected to IO:
  534. * GPIO pins are specific to each comparator instance.
  535. * Refer to description of parameters or to reference manual.
  536. * @note On this STM32 series, a voltage scaler is used
  537. * when COMP input is based on VrefInt (VrefInt or subdivision
  538. * of VrefInt):
  539. * Voltage scaler requires a delay for voltage stabilization.
  540. * Refer to device datasheet, parameter "tSTART_SCALER".
  541. * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
  542. * CSR INPSEL LL_COMP_ConfigInputs\n
  543. * @param COMPx Comparator instance
  544. * @param InputMinus This parameter can be one of the following values:
  545. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  546. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  547. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  548. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  549. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  550. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  551. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  552. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  553. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  554. * @param InputPlus This parameter can be one of the following values:
  555. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  556. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  557. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  558. * @retval None
  559. */
  560. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  561. {
  562. MODIFY_REG(COMPx->CSR,
  563. COMP_CSR_INMSEL | COMP_CSR_INPSEL,
  564. InputMinus | InputPlus);
  565. }
  566. /**
  567. * @brief Set comparator input plus (non-inverting).
  568. * @note In case of comparator input selected to be connected to IO:
  569. * GPIO pins are specific to each comparator instance.
  570. * Refer to description of parameters or to reference manual.
  571. * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
  572. * @param COMPx Comparator instance
  573. * @param InputPlus This parameter can be one of the following values:
  574. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  575. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  576. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  577. * @retval None
  578. */
  579. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  580. {
  581. MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
  582. }
  583. /**
  584. * @brief Get comparator input plus (non-inverting).
  585. * @note In case of comparator input selected to be connected to IO:
  586. * GPIO pins are specific to each comparator instance.
  587. * Refer to description of parameters or to reference manual.
  588. * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
  589. * @param COMPx Comparator instance
  590. * @retval Returned value can be one of the following values:
  591. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  592. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  593. * @arg @ref LL_COMP_INPUT_PLUS_IO3
  594. */
  595. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
  596. {
  597. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
  598. }
  599. /**
  600. * @brief Set comparator input minus (inverting).
  601. * @note In case of comparator input selected to be connected to IO:
  602. * GPIO pins are specific to each comparator instance.
  603. * Refer to description of parameters or to reference manual.
  604. * @note On this STM32 series, a voltage scaler is used
  605. * when COMP input is based on VrefInt (VrefInt or subdivision
  606. * of VrefInt):
  607. * Voltage scaler requires a delay for voltage stabilization.
  608. * Refer to device datasheet, parameter "tSTART_SCALER".
  609. * @rmtoll CSR INMSEL LL_COMP_SetInputMinus
  610. * @param COMPx Comparator instance
  611. * @param InputMinus This parameter can be one of the following values:
  612. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  613. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  614. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  615. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  616. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  617. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  618. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  619. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  620. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  621. * @retval None
  622. */
  623. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  624. {
  625. MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL, InputMinus);
  626. }
  627. /**
  628. * @brief Get comparator input minus (inverting).
  629. * @note In case of comparator input selected to be connected to IO:
  630. * GPIO pins are specific to each comparator instance.
  631. * Refer to description of parameters or to reference manual.
  632. * @rmtoll CSR INMSEL LL_COMP_GetInputMinus
  633. * @param COMPx Comparator instance
  634. * @retval Returned value can be one of the following values:
  635. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  636. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  637. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  638. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  639. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  640. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  641. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  642. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  643. * @arg @ref LL_COMP_INPUT_MINUS_IO3
  644. */
  645. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
  646. {
  647. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL));
  648. }
  649. /**
  650. * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
  651. * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
  652. * @param COMPx Comparator instance
  653. * @param InputHysteresis This parameter can be one of the following values:
  654. * @arg @ref LL_COMP_HYSTERESIS_NONE
  655. * @arg @ref LL_COMP_HYSTERESIS_LOW
  656. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  657. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  658. * @retval None
  659. */
  660. __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
  661. {
  662. MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
  663. }
  664. /**
  665. * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
  666. * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
  667. * @param COMPx Comparator instance
  668. * @retval Returned value can be one of the following values:
  669. * @arg @ref LL_COMP_HYSTERESIS_NONE
  670. * @arg @ref LL_COMP_HYSTERESIS_LOW
  671. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  672. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  673. */
  674. __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
  675. {
  676. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
  677. }
  678. /**
  679. * @}
  680. */
  681. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  682. * @{
  683. */
  684. /**
  685. * @brief Set comparator instance output polarity.
  686. * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
  687. * @param COMPx Comparator instance
  688. * @param OutputPolarity This parameter can be one of the following values:
  689. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  690. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  691. * @retval None
  692. */
  693. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  694. {
  695. MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
  696. }
  697. /**
  698. * @brief Get comparator instance output polarity.
  699. * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
  700. * @param COMPx Comparator instance
  701. * @retval Returned value can be one of the following values:
  702. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  703. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  704. */
  705. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
  706. {
  707. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
  708. }
  709. /**
  710. * @brief Set comparator instance blanking source.
  711. * @note Blanking source may be specific to each comparator instance.
  712. * Refer to description of parameters or to reference manual.
  713. * @note Availability of parameters of blanking source from timer
  714. * depends on timers availability on the selected device.
  715. * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
  716. * @param COMPx Comparator instance
  717. * @param BlankingSource This parameter can be one of the following values:
  718. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  719. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
  720. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
  721. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
  722. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
  723. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
  724. *
  725. * (1) Parameter availability depending on timer availability
  726. * on the selected device.
  727. * @retval None
  728. */
  729. __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
  730. {
  731. MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
  732. }
  733. /**
  734. * @brief Get comparator instance blanking source.
  735. * @note Availability of parameters of blanking source from timer
  736. * depends on timers availability on the selected device.
  737. * @note Blanking source may be specific to each comparator instance.
  738. * Refer to description of parameters or to reference manual.
  739. * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
  740. * @param COMPx Comparator instance
  741. * @retval Returned value can be one of the following values:
  742. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  743. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC4 (1)
  744. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5 (1)
  745. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3 (1)
  746. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3 (1)
  747. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2 (1)
  748. *
  749. * (1) Parameter availability depending on timer availability
  750. * on the selected device.
  751. */
  752. __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
  753. {
  754. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
  755. }
  756. /**
  757. * @}
  758. */
  759. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  760. * @{
  761. */
  762. /**
  763. * @brief Enable comparator instance.
  764. * @note After enable from off state, comparator requires a delay
  765. * to reach reach propagation delay specification.
  766. * Refer to device datasheet, parameter "tSTART".
  767. * @rmtoll CSR EN LL_COMP_Enable
  768. * @param COMPx Comparator instance
  769. * @retval None
  770. */
  771. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  772. {
  773. SET_BIT(COMPx->CSR, COMP_CSR_EN);
  774. }
  775. /**
  776. * @brief Disable comparator instance.
  777. * @rmtoll CSR EN LL_COMP_Disable
  778. * @param COMPx Comparator instance
  779. * @retval None
  780. */
  781. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  782. {
  783. CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
  784. }
  785. /**
  786. * @brief Get comparator enable state
  787. * (0: COMP is disabled, 1: COMP is enabled)
  788. * @rmtoll CSR EN LL_COMP_IsEnabled
  789. * @param COMPx Comparator instance
  790. * @retval State of bit (1 or 0).
  791. */
  792. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
  793. {
  794. return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
  795. }
  796. /**
  797. * @brief Lock comparator instance.
  798. * @note Once locked, comparator configuration can be accessed in read-only.
  799. * @note The only way to unlock the comparator is a device hardware reset.
  800. * @rmtoll CSR LOCK LL_COMP_Lock
  801. * @param COMPx Comparator instance
  802. * @retval None
  803. */
  804. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  805. {
  806. SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
  807. }
  808. /**
  809. * @brief Get comparator lock state
  810. * (0: COMP is unlocked, 1: COMP is locked).
  811. * @note Once locked, comparator configuration can be accessed in read-only.
  812. * @note The only way to unlock the comparator is a device hardware reset.
  813. * @rmtoll CSR LOCK LL_COMP_IsLocked
  814. * @param COMPx Comparator instance
  815. * @retval State of bit (1 or 0).
  816. */
  817. __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
  818. {
  819. return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
  820. }
  821. /**
  822. * @brief Read comparator instance output level.
  823. * @note The comparator output level depends on the selected polarity
  824. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  825. * If the comparator polarity is not inverted:
  826. * - Comparator output is low when the input plus
  827. * is at a lower voltage than the input minus
  828. * - Comparator output is high when the input plus
  829. * is at a higher voltage than the input minus
  830. * If the comparator polarity is inverted:
  831. * - Comparator output is high when the input plus
  832. * is at a lower voltage than the input minus
  833. * - Comparator output is low when the input plus
  834. * is at a higher voltage than the input minus
  835. * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
  836. * @param COMPx Comparator instance
  837. * @retval Returned value can be one of the following values:
  838. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  839. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  840. */
  841. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
  842. {
  843. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
  844. >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
  845. }
  846. /**
  847. * @}
  848. */
  849. #if defined(USE_FULL_LL_DRIVER)
  850. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  851. * @{
  852. */
  853. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  854. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
  855. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  856. /**
  857. * @}
  858. */
  859. #endif /* USE_FULL_LL_DRIVER */
  860. /**
  861. * @}
  862. */
  863. /**
  864. * @}
  865. */
  866. /**
  867. * @}
  868. */
  869. #endif /* COMP1 || COMP2 */
  870. /**
  871. * @}
  872. */
  873. #ifdef __cplusplus
  874. }
  875. #endif
  876. #endif /* STM32G0xx_LL_COMP_H */