stm32g4xx_ll_comp.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_ll_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 STM32G4xx_LL_COMP_H
  20. #define STM32G4xx_LL_COMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g4xx.h"
  26. /** @addtogroup STM32G4xx_LL_Driver
  27. * @{
  28. */
  29. /** @defgroup COMP_LL COMP
  30. * @{
  31. */
  32. /* Private types -------------------------------------------------------------*/
  33. /* Private variables ---------------------------------------------------------*/
  34. /* Private constants ---------------------------------------------------------*/
  35. /* Private macros ------------------------------------------------------------*/
  36. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  37. * @{
  38. */
  39. /**
  40. * @}
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. #if defined(USE_FULL_LL_DRIVER)
  44. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  45. * @{
  46. */
  47. /**
  48. * @brief Structure definition of some features of COMP instance.
  49. */
  50. typedef struct
  51. {
  52. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  53. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  54. This feature can be modified afterwards using unitary function
  55. @ref LL_COMP_SetInputPlus(). */
  56. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  57. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  58. This feature can be modified afterwards using unitary function
  59. @ref LL_COMP_SetInputMinus(). */
  60. uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
  61. This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
  62. This feature can be modified afterwards using unitary function
  63. @ref LL_COMP_SetInputHysteresis(). */
  64. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  65. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  66. This feature can be modified afterwards using unitary function
  67. @ref LL_COMP_SetOutputPolarity(). */
  68. uint32_t OutputBlankingSource; /*!< Set comparator blanking source.
  69. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_BLANKING_SOURCE
  70. This feature can be modified afterwards using unitary function
  71. @ref LL_COMP_SetOutputBlankingSource(). */
  72. } LL_COMP_InitTypeDef;
  73. /**
  74. * @}
  75. */
  76. #endif /* USE_FULL_LL_DRIVER */
  77. /* Exported constants --------------------------------------------------------*/
  78. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  79. * @{
  80. */
  81. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  82. * @{
  83. */
  84. #define LL_COMP_INPUT_PLUS_IO1 (0x00000000UL) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA7 for COMP2, pin PA0 for COMP3, pin PB0 for COMP4, pin PB13 for COMP5, pin PB11 for COMP6, pin PB14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
  85. #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_INPSEL) /*!< Comparator input plus connected to IO2 (pin PB1 for COMP1, pin PA3 for COMP2, pin PC1 for COMP3, pin PE7 for COMP4, pin PD12 for COMP5, pin PD11 for COMP6, pin PD14 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
  86. /**
  87. * @}
  88. */
  89. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  90. * @{
  91. */
  92. #define LL_COMP_INPUT_MINUS_1_4VREFINT ( COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/4 VrefInt */
  93. #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 1/2 VrefInt */
  94. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_SCALEN | COMP_CSR_BRGEN) /*!< Comparator input minus connected to 3/4 VrefInt */
  95. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INMSEL_1 | COMP_CSR_INMSEL_0 | COMP_CSR_SCALEN ) /*!< Comparator input minus connected to VrefInt */
  96. #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 Channel 1 for COMP1/3/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
  97. #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC1 Channel 2 for COMP2/5. Note: For COMPx & DACx instances availability, please refer to datasheet */
  98. #define LL_COMP_INPUT_MINUS_DAC2_CH1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_0) /*!< Comparator input minus connected to DAC2 Channel 1 for COMP6/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
  99. #define LL_COMP_INPUT_MINUS_DAC3_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC3 Channel 1 for COMP1/3. Note: For COMPx & DACx instances availability, please refer to datasheet */
  100. #define LL_COMP_INPUT_MINUS_DAC3_CH2 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC3 Channel 2 for COMP2/4. Note: For COMPx & DACx instances availability, please refer to datasheet */
  101. #define LL_COMP_INPUT_MINUS_DAC4_CH1 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC4 Channel 1 for COMP5/7. Note: For COMPx & DACx instances availability, please refer to datasheet */
  102. #define LL_COMP_INPUT_MINUS_DAC4_CH2 (COMP_CSR_INMSEL_2 ) /*!< Comparator input minus connected to DAC4 Channel 2 for COMP6. Note: For COMPx & DACx instances availability, please refer to datasheet */
  103. #define LL_COMP_INPUT_MINUS_IO1 (COMP_CSR_INMSEL_2 | COMP_CSR_INMSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PA4 for COMP1, pin PA5 for COMP2, pin PF1 for COMP3, pin PE8 for COMP4, pin PB10 for COMP5, pin PD10 for COMP6, pin PD15 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
  104. #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 PA0 for COMP1, pin PA2 for COMP2, pin PC0 for COMP3, pin PB2 for COMP4, pin PD13 for COMP5, pin PB15 for COMP6, pin PB12 for COMP7). Note: For COMPx instance availability, please refer to datasheet */
  105. /**
  106. * @}
  107. */
  108. /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
  109. * @{
  110. */
  111. #define LL_COMP_HYSTERESIS_NONE (0x00000000UL) /*!< No hysteresis */
  112. #define LL_COMP_HYSTERESIS_10MV ( COMP_CSR_HYST_0) /*!< Hysteresis level 10mV */
  113. #define LL_COMP_HYSTERESIS_20MV ( COMP_CSR_HYST_1 ) /*!< Hysteresis level 20mV */
  114. #define LL_COMP_HYSTERESIS_30MV ( COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 30mV */
  115. #define LL_COMP_HYSTERESIS_40MV (COMP_CSR_HYST_2 ) /*!< Hysteresis level 40mV */
  116. #define LL_COMP_HYSTERESIS_50MV (COMP_CSR_HYST_2 | COMP_CSR_HYST_0) /*!< Hysteresis level 50mV */
  117. #define LL_COMP_HYSTERESIS_60MV (COMP_CSR_HYST_2 | COMP_CSR_HYST_1 ) /*!< Hysteresis level 60mV */
  118. #define LL_COMP_HYSTERESIS_70MV (COMP_CSR_HYST_2 | COMP_CSR_HYST_1 | COMP_CSR_HYST_0) /*!< Hysteresis level 70mV */
  119. #define LL_COMP_HYSTERESIS_LOW LL_COMP_HYSTERESIS_10MV /*!< Hysteresis level low */
  120. #define LL_COMP_HYSTERESIS_MEDIUM LL_COMP_HYSTERESIS_40MV /*!< Hysteresis level medium */
  121. #define LL_COMP_HYSTERESIS_HIGH LL_COMP_HYSTERESIS_70MV /*!< Hysteresis level high */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  126. * @{
  127. */
  128. #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 */
  129. #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 */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup COMP_LL_EC_OUTPUT_BLANKING_SOURCE Comparator output - Blanking source
  134. * @{
  135. */
  136. #define LL_COMP_BLANKINGSRC_NONE (0x00000000UL) /*!<Comparator output without blanking */
  137. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
  138. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
  139. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
  140. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
  141. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
  142. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
  143. #define LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM1 OC5 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
  144. #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
  145. #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
  146. #define LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM2 OC3 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
  147. #define LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
  148. #define LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM2 OC4 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
  149. #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
  150. #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
  151. #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
  152. #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
  153. #define LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC3 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
  154. #define LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM3 OC4 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
  155. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP1). Note: For COMPx instance availability, please refer to datasheet */
  156. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP2). Note: For COMPx instance availability, please refer to datasheet */
  157. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP3). Note: For COMPx instance availability, please refer to datasheet */
  158. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
  159. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP5). Note: For COMPx instance availability, please refer to datasheet */
  160. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6 ( COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
  161. #define LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7 ( COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM8 OC5 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
  162. #define LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM15 OC1 (specific to COMP instance: COMP4). Note: For COMPx instance availability, please refer to datasheet */
  163. #define LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6 ( COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM15 OC2 (specific to COMP instance: COMP6). Note: For COMPx instance availability, please refer to datasheet */
  164. #define LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7 (COMP_CSR_BLANKING_2 ) /*!< Comparator output blanking source TIM15 OC3 (specific to COMP instance: COMP7). Note: For COMPx instance availability, please refer to datasheet */
  165. #define LL_COMP_BLANKINGSRC_TIM20_OC5 (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM20 OC5 (Common to all COMP instances). Note: For TIM20 instance availability, please refer to datasheet */
  166. #define LL_COMP_BLANKINGSRC_TIM15_OC1 (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1 ) /*!< Comparator output blanking source TIM15 OC1 (Common to all COMP instances). */
  167. #define LL_COMP_BLANKINGSRC_TIM4_OC3 (COMP_CSR_BLANKING_2 | COMP_CSR_BLANKING_1 | COMP_CSR_BLANKING_0) /*!< Comparator output blanking source TIM4 OC3 (Common to all COMP instances). */
  168. /**
  169. * @}
  170. */
  171. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  172. * @{
  173. */
  174. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000UL) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  175. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001UL) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  180. * @note Only COMP peripheral HW delays are defined in COMP LL driver driver,
  181. * not timeout values.
  182. * For details on delays values, refer to descriptions in source code
  183. * above each literal definition.
  184. * @{
  185. */
  186. /* Delay for comparator startup time. */
  187. /* Note: Delay required to reach propagation delay specification. */
  188. /* Literal set to maximum value (refer to device datasheet, */
  189. /* parameter "tSTART"). */
  190. /* Unit: us */
  191. #define LL_COMP_DELAY_STARTUP_US ( 5UL) /*!< Delay for COMP startup time */
  192. /* Delay for comparator voltage scaler stabilization time. */
  193. /* Note: Voltage scaler is used when selecting comparator input */
  194. /* based on VrefInt: VrefInt or subdivision of VrefInt. */
  195. /* Literal set to maximum value (refer to device datasheet, */
  196. /* parameter "tSTART_SCALER"). */
  197. /* Unit: us */
  198. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ( 200UL) /*!< Delay for COMP voltage scaler stabilization time */
  199. /**
  200. * @}
  201. */
  202. /**
  203. * @}
  204. */
  205. /* Exported macro ------------------------------------------------------------*/
  206. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  207. * @{
  208. */
  209. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  210. * @{
  211. */
  212. /**
  213. * @brief Write a value in COMP register
  214. * @param __INSTANCE__ comparator instance
  215. * @param __REG__ Register to be written
  216. * @param __VALUE__ Value to be written in the register
  217. * @retval None
  218. */
  219. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  220. /**
  221. * @brief Read a value in COMP register
  222. * @param __INSTANCE__ comparator instance
  223. * @param __REG__ Register to be read
  224. * @retval Register value
  225. */
  226. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  227. /**
  228. * @}
  229. */
  230. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  231. * @{
  232. */
  233. /**
  234. * @}
  235. */
  236. /**
  237. * @}
  238. */
  239. /* Exported functions --------------------------------------------------------*/
  240. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  241. * @{
  242. */
  243. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  244. * @{
  245. */
  246. /**
  247. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  248. * @note In case of comparator input selected to be connected to IO:
  249. * GPIO pins are specific to each comparator instance.
  250. * Refer to description of parameters or to reference manual.
  251. * @note On this STM32 series, scaler bridge is configurable:
  252. * to optimize power consumption, this function enables the
  253. * voltage scaler bridge only when required
  254. * (when selecting comparator input based on VrefInt: VrefInt or
  255. * subdivision of VrefInt).
  256. * - For scaler bridge power consumption values,
  257. * refer to device datasheet, parameter "IDDA(SCALER)".
  258. * - Voltage scaler requires a delay for voltage stabilization.
  259. * Refer to device datasheet, parameter "tSTART_SCALER".
  260. * - Scaler bridge is common for all comparator instances,
  261. * therefore if at least one of the comparator instance
  262. * is requiring the scaler bridge, it remains enabled.
  263. * @rmtoll CSR INMSEL LL_COMP_ConfigInputs\n
  264. * CSR INPSEL LL_COMP_ConfigInputs\n
  265. * CSR BRGEN LL_COMP_ConfigInputs\n
  266. * CSR SCALEN LL_COMP_ConfigInputs
  267. * @param COMPx Comparator instance
  268. * @param InputMinus This parameter can be one of the following values:
  269. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  270. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  271. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  272. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  273. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1,3,4)
  274. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (2,5)
  275. * @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1 (6,7)
  276. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1 (1,3)
  277. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2 (2,4)
  278. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1 (5,7)
  279. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2 (6)
  280. * (a,b...) Only available for COMPa, COMPb...
  281. * For COMPx & DACx instances availability, please refer to datasheet
  282. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  283. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  284. * @param InputPlus This parameter can be one of the following values:
  285. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  286. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  287. * @retval None
  288. */
  289. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  290. {
  291. MODIFY_REG(COMPx->CSR,
  292. COMP_CSR_INMSEL | COMP_CSR_INPSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN,
  293. InputMinus | InputPlus);
  294. }
  295. /**
  296. * @brief Set comparator input plus (non-inverting).
  297. * @note In case of comparator input selected to be connected to IO:
  298. * GPIO pins are specific to each comparator instance.
  299. * Refer to description of parameters or to reference manual.
  300. * @rmtoll CSR INPSEL LL_COMP_SetInputPlus
  301. * @param COMPx Comparator instance
  302. * @param InputPlus This parameter can be one of the following values:
  303. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  304. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  305. * @retval None
  306. */
  307. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  308. {
  309. MODIFY_REG(COMPx->CSR, COMP_CSR_INPSEL, InputPlus);
  310. }
  311. /**
  312. * @brief Get comparator input plus (non-inverting).
  313. * @note In case of comparator input selected to be connected to IO:
  314. * GPIO pins are specific to each comparator instance.
  315. * Refer to description of parameters or to reference manual.
  316. * @rmtoll CSR INPSEL LL_COMP_GetInputPlus
  317. * @param COMPx Comparator instance
  318. * @retval Returned value can be one of the following values:
  319. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  320. * @arg @ref LL_COMP_INPUT_PLUS_IO2
  321. */
  322. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(const COMP_TypeDef *COMPx)
  323. {
  324. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INPSEL));
  325. }
  326. /**
  327. * @brief Set comparator input minus (inverting).
  328. * @note In case of comparator input selected to be connected to IO:
  329. * GPIO pins are specific to each comparator instance.
  330. * Refer to description of parameters or to reference manual.
  331. * @note On this STM32 series, scaler bridge is configurable:
  332. * to optimize power consumption, this function enables the
  333. * voltage scaler bridge only when required
  334. * (when selecting comparator input based on VrefInt: VrefInt or
  335. * subdivision of VrefInt).
  336. * - For scaler bridge power consumption values,
  337. * refer to device datasheet, parameter "IDDA(SCALER)".
  338. * - Voltage scaler requires a delay for voltage stabilization.
  339. * Refer to device datasheet, parameter "tSTART_SCALER".
  340. * - Scaler bridge is common for all comparator instances,
  341. * therefore if at least one of the comparator instance
  342. * is requiring the scaler bridge, it remains enabled.
  343. * @rmtoll CSR INMSEL LL_COMP_SetInputMinus\n
  344. * CSR BRGEN LL_COMP_SetInputMinus\n
  345. * CSR SCALEN LL_COMP_SetInputMinus
  346. * @param COMPx Comparator instance
  347. * @param InputMinus This parameter can be one of the following values:
  348. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  349. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  350. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  351. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  352. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1,3,4)
  353. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (2,5)
  354. * @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1 (6,7)
  355. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1 (1,3)
  356. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2 (2,4)
  357. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1 (5,7)
  358. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2 (6)
  359. * (a,b...) Only available for COMPa, COMPb...
  360. * For COMPx & DACx instances availability, please refer to datasheet
  361. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  362. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  363. * @retval None
  364. */
  365. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  366. {
  367. MODIFY_REG(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN, InputMinus);
  368. }
  369. /**
  370. * @brief Get comparator input minus (inverting).
  371. * @note In case of comparator input selected to be connected to IO:
  372. * GPIO pins are specific to each comparator instance.
  373. * Refer to description of parameters or to reference manual.
  374. * @rmtoll CSR INMSEL LL_COMP_GetInputMinus\n
  375. * CSR BRGEN LL_COMP_GetInputMinus\n
  376. * CSR SCALEN LL_COMP_GetInputMinus
  377. * @param COMPx Comparator instance
  378. * @retval Returned value can be one of the following values:
  379. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  380. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  381. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  382. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  383. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1,3,4)
  384. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (2,5)
  385. * @arg @ref LL_COMP_INPUT_MINUS_DAC2_CH1 (6,7)
  386. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH1 (1,3)
  387. * @arg @ref LL_COMP_INPUT_MINUS_DAC3_CH2 (2,4)
  388. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH1 (5,7)
  389. * @arg @ref LL_COMP_INPUT_MINUS_DAC4_CH2 (6)
  390. * (a,b...) Only available for COMPa, COMPb...
  391. * For COMPx & DACx instances availability, please refer to datasheet
  392. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  393. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  394. */
  395. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(const COMP_TypeDef *COMPx)
  396. {
  397. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_INMSEL | COMP_CSR_SCALEN | COMP_CSR_BRGEN));
  398. }
  399. /**
  400. * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
  401. * @rmtoll CSR HYST LL_COMP_SetInputHysteresis
  402. * @param COMPx Comparator instance
  403. * @param InputHysteresis This parameter can be one of the following values:
  404. * @arg @ref LL_COMP_HYSTERESIS_NONE
  405. * @arg @ref LL_COMP_HYSTERESIS_10MV
  406. * @arg @ref LL_COMP_HYSTERESIS_20MV
  407. * @arg @ref LL_COMP_HYSTERESIS_30MV
  408. * @arg @ref LL_COMP_HYSTERESIS_40MV
  409. * @arg @ref LL_COMP_HYSTERESIS_50MV
  410. * @arg @ref LL_COMP_HYSTERESIS_60MV
  411. * @arg @ref LL_COMP_HYSTERESIS_70MV
  412. * @arg @ref LL_COMP_HYSTERESIS_LOW
  413. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  414. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  415. * @retval None
  416. */
  417. __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
  418. {
  419. MODIFY_REG(COMPx->CSR, COMP_CSR_HYST, InputHysteresis);
  420. }
  421. /**
  422. * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
  423. * @rmtoll CSR HYST LL_COMP_GetInputHysteresis
  424. * @param COMPx Comparator instance
  425. * @retval Returned value can be one of the following values:
  426. * @arg @ref LL_COMP_HYSTERESIS_NONE
  427. * @arg @ref LL_COMP_HYSTERESIS_10MV
  428. * @arg @ref LL_COMP_HYSTERESIS_20MV
  429. * @arg @ref LL_COMP_HYSTERESIS_30MV
  430. * @arg @ref LL_COMP_HYSTERESIS_40MV
  431. * @arg @ref LL_COMP_HYSTERESIS_50MV
  432. * @arg @ref LL_COMP_HYSTERESIS_60MV
  433. * @arg @ref LL_COMP_HYSTERESIS_70MV
  434. */
  435. __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(const COMP_TypeDef *COMPx)
  436. {
  437. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_HYST));
  438. }
  439. /**
  440. * @}
  441. */
  442. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  443. * @{
  444. */
  445. /**
  446. * @brief Set comparator instance output polarity.
  447. * @rmtoll CSR POLARITY LL_COMP_SetOutputPolarity
  448. * @param COMPx Comparator instance
  449. * @param OutputPolarity This parameter can be one of the following values:
  450. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  451. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  452. * @retval None
  453. */
  454. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  455. {
  456. MODIFY_REG(COMPx->CSR, COMP_CSR_POLARITY, OutputPolarity);
  457. }
  458. /**
  459. * @brief Get comparator instance output polarity.
  460. * @rmtoll CSR POLARITY LL_COMP_GetOutputPolarity
  461. * @param COMPx Comparator instance
  462. * @retval Returned value can be one of the following values:
  463. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  464. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  465. */
  466. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(const COMP_TypeDef *COMPx)
  467. {
  468. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_POLARITY));
  469. }
  470. /**
  471. * @brief Set comparator instance blanking source.
  472. * @note Blanking source may be specific to each comparator instance.
  473. * Refer to description of parameters or to reference manual.
  474. * @note Availability of parameters of blanking source from timer
  475. * depends on timers availability on the selected device.
  476. * @rmtoll CSR BLANKING LL_COMP_SetOutputBlankingSource
  477. * @param COMPx Comparator instance
  478. * @param BlankingSource This parameter can be one of the following values:
  479. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  480. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1
  481. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2
  482. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3
  483. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4
  484. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5
  485. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6
  486. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7
  487. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1
  488. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2
  489. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5
  490. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3
  491. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6
  492. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1
  493. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2
  494. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3
  495. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5
  496. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7
  497. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4
  498. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1
  499. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2
  500. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3
  501. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4
  502. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5
  503. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6
  504. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7
  505. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4
  506. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6
  507. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7
  508. * @arg @ref LL_COMP_BLANKINGSRC_TIM20_OC5
  509. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
  510. * @arg @ref LL_COMP_BLANKINGSRC_TIM4_OC3
  511. *
  512. * On STM32G4 series, blanking sources are linked to COMP instance (except
  513. * those without COMPx suffix that are common to all instances)
  514. * Note: For COMPx & TIMx instances availability, please refer to datasheet
  515. * @retval None
  516. */
  517. __STATIC_INLINE void LL_COMP_SetOutputBlankingSource(COMP_TypeDef *COMPx, uint32_t BlankingSource)
  518. {
  519. MODIFY_REG(COMPx->CSR, COMP_CSR_BLANKING, BlankingSource);
  520. }
  521. /**
  522. * @brief Get comparator instance blanking source.
  523. * @note Availability of parameters of blanking source from timer
  524. * depends on timers availability on the selected device.
  525. * @note Blanking source may be specific to each comparator instance.
  526. * Refer to description of parameters or to reference manual.
  527. * @rmtoll CSR BLANKING LL_COMP_GetOutputBlankingSource
  528. * @param COMPx Comparator instance
  529. * @retval Returned value can be one of the following values:
  530. * @arg @ref LL_COMP_BLANKINGSRC_NONE
  531. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP1
  532. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP2
  533. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP3
  534. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP4
  535. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP5
  536. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP6
  537. * @arg @ref LL_COMP_BLANKINGSRC_TIM1_OC5_COMP7
  538. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP1
  539. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP2
  540. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC3_COMP5
  541. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP3
  542. * @arg @ref LL_COMP_BLANKINGSRC_TIM2_OC4_COMP6
  543. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP1
  544. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP2
  545. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP3
  546. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP5
  547. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC3_COMP7
  548. * @arg @ref LL_COMP_BLANKINGSRC_TIM3_OC4_COMP4
  549. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP1
  550. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP2
  551. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP3
  552. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP4
  553. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP5
  554. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP6
  555. * @arg @ref LL_COMP_BLANKINGSRC_TIM8_OC5_COMP7
  556. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1_COMP4
  557. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP6
  558. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC2_COMP7
  559. * @arg @ref LL_COMP_BLANKINGSRC_TIM20_OC5
  560. * @arg @ref LL_COMP_BLANKINGSRC_TIM15_OC1
  561. * @arg @ref LL_COMP_BLANKINGSRC_TIM4_OC3
  562. *
  563. * On STM32G4 series, blanking sources are linked to COMP instance (except
  564. * those without COMPx suffix that are common to all instances)
  565. * Note: For COMPx & TIMx instances availability, please refer to datasheet
  566. */
  567. __STATIC_INLINE uint32_t LL_COMP_GetOutputBlankingSource(const COMP_TypeDef *COMPx)
  568. {
  569. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_BLANKING));
  570. }
  571. /**
  572. * @}
  573. */
  574. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  575. * @{
  576. */
  577. /**
  578. * @brief Enable comparator instance.
  579. * @note After enable from off state, comparator requires a delay
  580. * to reach reach propagation delay specification.
  581. * Refer to device datasheet, parameter "tSTART".
  582. * @rmtoll CSR EN LL_COMP_Enable
  583. * @param COMPx Comparator instance
  584. * @retval None
  585. */
  586. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  587. {
  588. SET_BIT(COMPx->CSR, COMP_CSR_EN);
  589. }
  590. /**
  591. * @brief Disable comparator instance.
  592. * @rmtoll CSR EN LL_COMP_Disable
  593. * @param COMPx Comparator instance
  594. * @retval None
  595. */
  596. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  597. {
  598. CLEAR_BIT(COMPx->CSR, COMP_CSR_EN);
  599. }
  600. /**
  601. * @brief Get comparator enable state
  602. * (0: COMP is disabled, 1: COMP is enabled)
  603. * @rmtoll CSR EN LL_COMP_IsEnabled
  604. * @param COMPx Comparator instance
  605. * @retval State of bit (1 or 0).
  606. */
  607. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(const COMP_TypeDef *COMPx)
  608. {
  609. return ((READ_BIT(COMPx->CSR, COMP_CSR_EN) == (COMP_CSR_EN)) ? 1UL : 0UL);
  610. }
  611. /**
  612. * @brief Lock comparator instance.
  613. * @note Once locked, comparator configuration can be accessed in read-only.
  614. * @note The only way to unlock the comparator is a device hardware reset.
  615. * @rmtoll CSR LOCK LL_COMP_Lock
  616. * @param COMPx Comparator instance
  617. * @retval None
  618. */
  619. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  620. {
  621. SET_BIT(COMPx->CSR, COMP_CSR_LOCK);
  622. }
  623. /**
  624. * @brief Get comparator lock state
  625. * (0: COMP is unlocked, 1: COMP is locked).
  626. * @note Once locked, comparator configuration can be accessed in read-only.
  627. * @note The only way to unlock the comparator is a device hardware reset.
  628. * @rmtoll CSR LOCK LL_COMP_IsLocked
  629. * @param COMPx Comparator instance
  630. * @retval State of bit (1 or 0).
  631. */
  632. __STATIC_INLINE uint32_t LL_COMP_IsLocked(const COMP_TypeDef *COMPx)
  633. {
  634. return ((READ_BIT(COMPx->CSR, COMP_CSR_LOCK) == (COMP_CSR_LOCK)) ? 1UL : 0UL);
  635. }
  636. /**
  637. * @brief Read comparator instance output level.
  638. * @note On this STM32 series, comparator 'value' is taken before
  639. * polarity and blanking are applied, thus:
  640. * - Comparator output is low when the input plus
  641. * is at a lower voltage than the input minus
  642. * - Comparator output is high when the input plus
  643. * is at a higher voltage than the input minus
  644. * @rmtoll CSR VALUE LL_COMP_ReadOutputLevel
  645. * @param COMPx Comparator instance
  646. * @retval Returned value can be one of the following values:
  647. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  648. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  649. */
  650. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(const COMP_TypeDef *COMPx)
  651. {
  652. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_VALUE)
  653. >> COMP_CSR_VALUE_Pos);
  654. }
  655. /**
  656. * @}
  657. */
  658. #if defined(USE_FULL_LL_DRIVER)
  659. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  660. * @{
  661. */
  662. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  663. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, const LL_COMP_InitTypeDef *COMP_InitStruct);
  664. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  665. /**
  666. * @}
  667. */
  668. #endif /* USE_FULL_LL_DRIVER */
  669. /**
  670. * @}
  671. */
  672. /**
  673. * @}
  674. */
  675. /**
  676. * @}
  677. */
  678. /**
  679. * @}
  680. */
  681. #ifdef __cplusplus
  682. }
  683. #endif
  684. #endif /* STM32G4xx_LL_COMP_H */