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.

stm32l1xx_ll_comp.h 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_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 __STM32L1xx_LL_COMP_H
  21. #define __STM32L1xx_LL_COMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l1xx.h"
  27. /** @addtogroup STM32L1xx_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_COMP1_BITOFFSET_POS ( 7U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1OUT) */
  42. #define LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS (13U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP2OUT) */
  43. #define LL_COMP_ENABLE_COMP1_BITOFFSET_POS ( 4U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1EN) */
  44. /**
  45. * @}
  46. */
  47. /* Private macros ------------------------------------------------------------*/
  48. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  49. * @{
  50. */
  51. /**
  52. * @brief Driver macro reserved for internal use: if COMP instance selected
  53. * is odd (COMP1, COMP3, ...), return value '1', else return '0'.
  54. * @param __COMP_INSTANCE__ COMP instance
  55. * @retval If COMP instance is odd, value '1'. Else, value '0'.
  56. */
  57. #define __COMP_IS_INSTANCE_ODD(__COMP_INSTANCE__) \
  58. ((~((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)) & 0x00000001)
  59. /**
  60. * @brief Driver macro reserved for internal use: if COMP instance selected
  61. * is even (COMP2, COMP4, ...), return value '1', else return '0'.
  62. * @param __COMP_INSTANCE__ COMP instance
  63. * @retval If COMP instance is even, value '1'. Else, value '0'.
  64. */
  65. #define __COMP_IS_INSTANCE_EVEN(__COMP_INSTANCE__) \
  66. ((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)
  67. /**
  68. * @}
  69. */
  70. /* Exported types ------------------------------------------------------------*/
  71. #if defined(USE_FULL_LL_DRIVER)
  72. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  73. * @{
  74. */
  75. /**
  76. * @brief Structure definition of some features of COMP instance.
  77. */
  78. typedef struct
  79. {
  80. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  81. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  82. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  83. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  84. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  85. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  86. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  87. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  88. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  89. uint32_t OutputSelection; /*!< Set comparator output selection.
  90. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_SELECTION
  91. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputSelection(). */
  92. } LL_COMP_InitTypeDef;
  93. /**
  94. * @}
  95. */
  96. #endif /* USE_FULL_LL_DRIVER */
  97. /* Exported constants --------------------------------------------------------*/
  98. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  99. * @{
  100. */
  101. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  102. * @{
  103. */
  104. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  105. #define LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON (COMP_CSR_WNDWE) /*!< Window mode enable: 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, either from GPIO and from ADC channel VCOMP). */
  106. /**
  107. * @}
  108. */
  109. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  110. * @{
  111. */
  112. #define LL_COMP_POWERMODE_ULTRALOWPOWER (0x00000000U) /*!< COMP power mode to low speed (specific to COMP instance: COMP2) */
  113. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_SPEED) /*!< COMP power mode to fast speed (specific to COMP instance: COMP2) */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  118. * @{
  119. */
  120. #define LL_COMP_INPUT_PLUS_NONE (0x00000000U) /*!< Comparator input plus connected not connected */
  121. #define LL_COMP_INPUT_PLUS_IO1 (RI_ASCR2_GR6_1) /*!< Comparator input plus connected to IO1 (pin PB4 for COMP2) (specific to COMP instance: COMP2) */
  122. #define LL_COMP_INPUT_PLUS_IO2 (RI_ASCR2_GR6_2) /*!< Comparator input plus connected to IO1 (pin PB5 for COMP2) (specific to COMP instance: COMP2) */
  123. #if defined(RI_ASCR1_CH_31)
  124. #define LL_COMP_INPUT_PLUS_IO3 (RI_ASCR2_GR6_3) /*!< Comparator input plus connected to IO1 (pin PB6 for COMP2) (specific to COMP instance: COMP2) */
  125. #define LL_COMP_INPUT_PLUS_IO4 (RI_ASCR2_GR6_4) /*!< Comparator input plus connected to IO1 (pin PB7 for COMP2) (specific to COMP instance: COMP2) */
  126. #endif
  127. #define LL_COMP_INPUT_PLUS_IO5 (RI_ASCR1_CH_0) /*!< Comparator input plus connected to IO5 (pin PA0 for COMP1) (specific to COMP instance: COMP1) */
  128. #define LL_COMP_INPUT_PLUS_IO6 (RI_ASCR1_CH_1) /*!< Comparator input plus connected to IO6 (pin PA1 for COMP1) (specific to COMP instance: COMP1) */
  129. #define LL_COMP_INPUT_PLUS_IO7 (RI_ASCR1_CH_2) /*!< Comparator input plus connected to IO7 (pin PA2 for COMP1) (specific to COMP instance: COMP1) */
  130. #define LL_COMP_INPUT_PLUS_IO8 (RI_ASCR1_CH_3) /*!< Comparator input plus connected to IO8 (pin PA3 for COMP1) (specific to COMP instance: COMP1) */
  131. #define LL_COMP_INPUT_PLUS_IO9 (RI_ASCR1_CH_4) /*!< Comparator input plus connected to IO9 (pin PA4 for COMP1) (specific to COMP instance: COMP1) */
  132. #define LL_COMP_INPUT_PLUS_IO10 (RI_ASCR1_CH_5) /*!< Comparator input plus connected to IO10 (pin PA5 for COMP1) (specific to COMP instance: COMP1) */
  133. #define LL_COMP_INPUT_PLUS_IO11 (RI_ASCR1_CH_6) /*!< Comparator input plus connected to IO11 (pin PA6 for COMP1) (specific to COMP instance: COMP1) */
  134. #define LL_COMP_INPUT_PLUS_IO12 (RI_ASCR1_CH_7) /*!< Comparator input plus connected to IO12 (pin PA7 for COMP1) (specific to COMP instance: COMP1) */
  135. #define LL_COMP_INPUT_PLUS_IO13 (RI_ASCR1_CH_8) /*!< Comparator input plus connected to IO13 (pin PB0 for COMP1) (specific to COMP instance: COMP1) */
  136. #define LL_COMP_INPUT_PLUS_IO14 (RI_ASCR1_CH_9) /*!< Comparator input plus connected to IO14 (pin PB1 for COMP1) (specific to COMP instance: COMP1) */
  137. #define LL_COMP_INPUT_PLUS_IO15 (RI_ASCR1_CH_10) /*!< Comparator input plus connected to IO15 (pin PC0 for COMP1) (specific to COMP instance: COMP1) */
  138. #define LL_COMP_INPUT_PLUS_IO16 (RI_ASCR1_CH_11) /*!< Comparator input plus connected to IO16 (pin PC1 for COMP1) (specific to COMP instance: COMP1) */
  139. #define LL_COMP_INPUT_PLUS_IO17 (RI_ASCR1_CH_12) /*!< Comparator input plus connected to IO17 (pin PC2 for COMP1) (specific to COMP instance: COMP1) */
  140. #define LL_COMP_INPUT_PLUS_IO18 (RI_ASCR1_CH_13) /*!< Comparator input plus connected to IO18 (pin PC3 for COMP1) (specific to COMP instance: COMP1) */
  141. #define LL_COMP_INPUT_PLUS_IO19 (RI_ASCR1_CH_14) /*!< Comparator input plus connected to IO19 (pin PC4 for COMP1) (specific to COMP instance: COMP1) */
  142. #define LL_COMP_INPUT_PLUS_IO20 (RI_ASCR1_CH_15) /*!< Comparator input plus connected to IO20 (pin PC5 for COMP1) (specific to COMP instance: COMP1) */
  143. #define LL_COMP_INPUT_PLUS_IO21 (RI_ASCR1_CH_18) /*!< Comparator input plus connected to IO21 (pin PB12 for COMP1) (specific to COMP instance: COMP1) */
  144. #define LL_COMP_INPUT_PLUS_IO22 (RI_ASCR1_CH_19) /*!< Comparator input plus connected to IO22 (pin PB13 for COMP1) (specific to COMP instance: COMP1) */
  145. #define LL_COMP_INPUT_PLUS_IO23 (RI_ASCR1_CH_20) /*!< Comparator input plus connected to IO23 (pin PB14 for COMP1) (specific to COMP instance: COMP1) */
  146. #define LL_COMP_INPUT_PLUS_IO24 (RI_ASCR1_CH_21) /*!< Comparator input plus connected to IO24 (pin PB15 for COMP1) (specific to COMP instance: COMP1) */
  147. #define LL_COMP_INPUT_PLUS_IO25 (RI_ASCR1_CH_22) /*!< Comparator input plus connected to IO25 (pin PE7 for COMP1) (specific to COMP instance: COMP1) */
  148. #define LL_COMP_INPUT_PLUS_IO26 (RI_ASCR1_CH_23) /*!< Comparator input plus connected to IO26 (pin PE8 for COMP1) (specific to COMP instance: COMP1) */
  149. #define LL_COMP_INPUT_PLUS_IO27 (RI_ASCR1_CH_24) /*!< Comparator input plus connected to IO27 (pin PE9 for COMP1) (specific to COMP instance: COMP1) */
  150. #define LL_COMP_INPUT_PLUS_IO28 (RI_ASCR1_CH_25) /*!< Comparator input plus connected to IO28 (pin PE10 for COMP1) (specific to COMP instance: COMP1) */
  151. #if defined(RI_ASCR1_CH_31)
  152. #define LL_COMP_INPUT_PLUS_IO29 (RI_ASCR1_CH_27) /*!< Comparator input plus connected to IO29 (pin PF6 for COMP1) (specific to COMP instance: COMP1) */
  153. #define LL_COMP_INPUT_PLUS_IO30 (RI_ASCR1_CH_28) /*!< Comparator input plus connected to IO30 (pin PF7 for COMP1) (specific to COMP instance: COMP1) */
  154. #define LL_COMP_INPUT_PLUS_IO31 (RI_ASCR1_CH_29) /*!< Comparator input plus connected to IO31 (pin PF8 for COMP1) (specific to COMP instance: COMP1) */
  155. #define LL_COMP_INPUT_PLUS_IO32 (RI_ASCR1_CH_30) /*!< Comparator input plus connected to IO32 (pin PF9 for COMP1) (specific to COMP instance: COMP1) */
  156. #define LL_COMP_INPUT_PLUS_IO33 (RI_ASCR1_CH_31) /*!< Comparator input plus connected to IO33 (pin PF10 for COMP1) (specific to COMP instance: COMP1) */
  157. #endif
  158. #if defined(OPAMP1)
  159. #define LL_COMP_INPUT_PLUS_OPAMP1 (RI_ASCR1_CH_3) /*!< Comparator input plus connected to OPAMP1 output (specific to COMP instance: COMP1) */
  160. #define LL_COMP_INPUT_PLUS_OPAMP2 (RI_ASCR1_CH_8) /*!< Comparator input plus connected to OPAMP2 output (specific to COMP instance: COMP1) */
  161. #endif
  162. #if defined(OPAMP3)
  163. #define LL_COMP_INPUT_PLUS_OPAMP3 (RI_ASCR1_CH_13) /*!< Comparator input plus connected to OPAMP3 output (specific to COMP instance: COMP1) */
  164. #endif
  165. /**
  166. * @}
  167. */
  168. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  169. * @{
  170. */
  171. #define LL_COMP_INPUT_MINUS_1_4VREFINT (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to 1/4 VrefInt (specific to COMP instance: COMP2) */
  172. #define LL_COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_INSEL_2 ) /*!< Comparator input minus connected to 1/2 VrefInt (specific to COMP instance: COMP2) */
  173. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to 3/4 VrefInt (specific to COMP instance: COMP2) */
  174. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INSEL_1 ) /*!< Comparator input minus connected to VrefInt */
  175. #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) (specific to COMP instance: COMP2) */
  176. #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_INSEL_2 | COMP_CSR_INSEL_1 | COMP_CSR_INSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) (specific to COMP instance: COMP2) */
  177. #define LL_COMP_INPUT_MINUS_IO1 ( COMP_CSR_INSEL_0) /*!< Comparator input minus connected to IO1 (pin PB3 for COMP2) (specific to COMP instance: COMP2) */
  178. /**
  179. * @}
  180. */
  181. /** @defgroup COMP_LL_EC_INPUT_PULLING_RESISTOR Comparator input - Pulling resistor
  182. * @{
  183. */
  184. #define LL_COMP_INPUT_MINUS_PULL_NO (0x00000000U) /*!< Comparator input minus not connected to any pulling resistor */
  185. #define LL_COMP_INPUT_MINUS_PULL_UP_10K (COMP_CSR_10KPU) /*!< Comparator input minus connected to pull-up resistor of 10kOhm (specific to COMP instance: COMP1) */
  186. #define LL_COMP_INPUT_MINUS_PULL_UP_400K (COMP_CSR_400KPU) /*!< Comparator input minus connected to pull-up resistor of 400kOhm (specific to COMP instance: COMP1) */
  187. #define LL_COMP_INPUT_MINUS_PULL_DOWN_10K (COMP_CSR_10KPD) /*!< Comparator input minus connected to pull-down resistor of 10kOhm (specific to COMP instance: COMP1) */
  188. #define LL_COMP_INPUT_MINUS_PULL_DOWN_400K (COMP_CSR_400KPD) /*!< Comparator input minus connected to pull-down resistor of 400kOhm (specific to COMP instance: COMP1) */
  189. /**
  190. * @}
  191. */
  192. /** @defgroup COMP_LL_EC_OUTPUT_SELECTION Comparator output - Output selection
  193. * @{
  194. */
  195. #define LL_COMP_OUTPUT_NONE (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP output is not connected to other peripherals (except GPIO and EXTI that are always connected to COMP output) (specific to COMP instance: COMP2) */
  196. #define LL_COMP_OUTPUT_TIM2_IC4 (0x00000000) /*!< COMP output connected to TIM2 input capture 4 (specific to COMP instance: COMP2) */
  197. #define LL_COMP_OUTPUT_TIM2_OCREFCLR ( COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM2 OCREF clear (specific to COMP instance: COMP2) */
  198. #define LL_COMP_OUTPUT_TIM3_IC4 ( COMP_CSR_OUTSEL_1 ) /*!< COMP output connected to TIM3 input capture 4 (specific to COMP instance: COMP2) */
  199. #define LL_COMP_OUTPUT_TIM3_OCREFCLR ( COMP_CSR_OUTSEL_1 | COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM3 OCREF clear (specific to COMP instance: COMP2) */
  200. #define LL_COMP_OUTPUT_TIM4_IC4 (COMP_CSR_OUTSEL_2 ) /*!< COMP output connected to TIM4 input capture 4 (specific to COMP instance: COMP2) */
  201. #define LL_COMP_OUTPUT_TIM4_OCREFCLR (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM4 OCREF clear (specific to COMP instance: COMP2) */
  202. #define LL_COMP_OUTPUT_TIM10_IC1 (COMP_CSR_OUTSEL_2 | COMP_CSR_OUTSEL_1 ) /*!< COMP output connected to TIM10 input capture 1 (specific to COMP instance: COMP2) */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  207. * @{
  208. */
  209. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  210. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001U) /*!< 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 IP 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 (25U) /*!< Delay for COMP startup time */
  227. /**
  228. * @}
  229. */
  230. /**
  231. * @}
  232. */
  233. /* Exported macro ------------------------------------------------------------*/
  234. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  235. * @{
  236. */
  237. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  238. * @{
  239. */
  240. /**
  241. * @brief Write a value in COMP register
  242. * @param __INSTANCE__ comparator instance
  243. * @param __REG__ Register to be written
  244. * @param __VALUE__ Value to be written in the register
  245. * @retval None
  246. */
  247. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  248. /**
  249. * @brief Read a value in COMP register
  250. * @param __INSTANCE__ comparator instance
  251. * @param __REG__ Register to be read
  252. * @retval Register value
  253. */
  254. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  255. /**
  256. * @}
  257. */
  258. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  259. * @{
  260. */
  261. /**
  262. * @brief Helper macro to select the COMP common instance
  263. * to which is belonging the selected COMP instance.
  264. * @note COMP common register instance can be used to
  265. * set parameters common to several COMP instances.
  266. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  267. * @param __COMPx__ COMP instance
  268. * @retval COMP common instance or value "0" if there is no COMP common instance.
  269. */
  270. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  271. (COMP12_COMMON)
  272. /**
  273. * @}
  274. */
  275. /**
  276. * @}
  277. */
  278. /* Exported functions --------------------------------------------------------*/
  279. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  280. * @{
  281. */
  282. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  283. * @{
  284. */
  285. /**
  286. * @brief Set window mode of a pair of comparators instances
  287. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  288. * @rmtoll CSR WNDWE LL_COMP_SetCommonWindowMode
  289. * @param COMPxy_COMMON Comparator common instance
  290. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  291. * @param WindowMode This parameter can be one of the following values:
  292. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  293. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  294. * @retval None
  295. */
  296. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  297. {
  298. MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WNDWE, WindowMode);
  299. }
  300. /**
  301. * @brief Get window mode of a pair of comparators instances
  302. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  303. * @rmtoll CSR WNDWE LL_COMP_GetCommonWindowMode
  304. * @param COMPxy_COMMON Comparator common instance
  305. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  306. * @retval Returned value can be one of the following values:
  307. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  308. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  309. */
  310. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  311. {
  312. return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WNDWE));
  313. }
  314. /**
  315. * @}
  316. */
  317. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  318. * @{
  319. */
  320. /**
  321. * @brief Set comparator instance operating mode to adjust power and speed.
  322. * @rmtoll COMP2_CSR SPEED LL_COMP_SetPowerMode
  323. * @param COMPx Comparator instance
  324. * @param PowerMode This parameter can be one of the following values:
  325. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  326. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  327. *
  328. * (1) Available only on COMP instance: COMP2.
  329. * @retval None
  330. */
  331. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  332. {
  333. MODIFY_REG(COMP->CSR, COMP_CSR_SPEED, PowerMode);
  334. }
  335. /**
  336. * @brief Get comparator instance operating mode to adjust power and speed.
  337. * @rmtoll COMP2_CSR SPEED LL_COMP_GetPowerMode
  338. * @param COMPx Comparator instance
  339. * @retval Returned value can be one of the following values:
  340. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  341. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  342. *
  343. * (1) Available only on COMP instance: COMP2.
  344. */
  345. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  346. {
  347. return (uint32_t)(READ_BIT(COMP->CSR, COMP_CSR_SPEED));
  348. }
  349. /**
  350. * @}
  351. */
  352. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  353. * @{
  354. */
  355. /**
  356. * @brief Set comparator input plus (non-inverting).
  357. * @note In case of comparator input selected to be connected to IO:
  358. * GPIO pins are specific to each comparator instance.
  359. * Refer to description of parameters or to reference manual.
  360. * @rmtoll RI RI_ASCR1_CH LL_COMP_SetInputPlus\n
  361. * RI RI_ASCR2_GR6 LL_COMP_SetInputPlus
  362. * @param COMPx Comparator instance
  363. * @param InputPlus This parameter can be one of the following values:
  364. * @arg @ref LL_COMP_INPUT_PLUS_NONE
  365. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
  366. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
  367. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
  368. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
  369. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  370. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
  371. * @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
  372. * @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
  373. * @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
  374. * @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
  375. * @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
  376. * @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
  377. * @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
  378. * @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
  379. * @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
  380. * @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
  381. * @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
  382. * @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
  383. * @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
  384. * @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
  385. * @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
  386. * @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
  387. * @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
  388. * @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
  389. * @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
  390. * @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
  391. * @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
  392. * @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
  393. * @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
  394. * @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
  395. * @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
  396. * @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
  397. * @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
  398. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
  399. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
  400. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
  401. *
  402. * (1) Available only on COMP instance: COMP1. \n
  403. * (2) Available only on COMP instance: COMP2. \n
  404. * (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  405. * (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  406. * (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
  407. * @retval None
  408. */
  409. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  410. {
  411. /* Set switch in routing interface (RI) register ASCR1 or ASCR2 */
  412. /* Note: If COMP instance COMP1 is selected, this function performs */
  413. /* necessary actions on routing interface: */
  414. /* - close switch netween comparator 1 and switch matrix */
  415. /* (RI_ASCR1_VCOMP) */
  416. /* - enable IO switch control mode (RI_ASCR1_SCM) */
  417. /* If ADC needs to be used afterwards, disable IO switch control */
  418. /* mode using function @ref LL_RI_DisableSwitchControlMode(). */
  419. register uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
  420. MODIFY_REG(*preg,
  421. (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx)),
  422. InputPlus | ((RI_ASCR1_VCOMP | RI_ASCR1_SCM) * __COMP_IS_INSTANCE_ODD(COMPx)));
  423. }
  424. /**
  425. * @brief Get comparator input plus (non-inverting).
  426. * @note In case of comparator input selected to be connected to IO:
  427. * GPIO pins are specific to each comparator instance.
  428. * Refer to description of parameters or to reference manual.
  429. * @rmtoll RI RI_ASCR1_CH LL_COMP_GetInputPlus\n
  430. * RI RI_ASCR2_GR6 LL_COMP_GetInputPlus
  431. * @param COMPx Comparator instance
  432. * @retval Returned value can be one of the following values:
  433. * @arg @ref LL_COMP_INPUT_PLUS_NONE
  434. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
  435. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
  436. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
  437. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
  438. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  439. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
  440. * @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
  441. * @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
  442. * @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
  443. * @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
  444. * @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
  445. * @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
  446. * @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
  447. * @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
  448. * @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
  449. * @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
  450. * @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
  451. * @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
  452. * @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
  453. * @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
  454. * @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
  455. * @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
  456. * @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
  457. * @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
  458. * @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
  459. * @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
  460. * @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
  461. * @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
  462. * @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
  463. * @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
  464. * @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
  465. * @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
  466. * @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
  467. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
  468. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
  469. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
  470. *
  471. * (1) Available only on COMP instance: COMP1. \n
  472. * (2) Available only on COMP instance: COMP2. \n
  473. * (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  474. * (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  475. * (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
  476. */
  477. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  478. {
  479. /* Get switch state in routing interface (RI) register ASCR1 or ASCR2 */
  480. register uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
  481. return (uint32_t)(READ_BIT(*preg,
  482. (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx))));
  483. }
  484. /**
  485. * @brief Set comparator input minus (inverting).
  486. * @note In case of comparator input selected to be connected to IO:
  487. * GPIO pins are specific to each comparator instance.
  488. * Refer to description of parameters or to reference manual.
  489. * @rmtoll CSR COMP_CSR_INSEL LL_COMP_SetInputMinus
  490. * @param COMPx Comparator instance
  491. * @param InputMinus This parameter can be one of the following values:
  492. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
  493. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
  494. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
  495. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  496. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1)
  497. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (1)
  498. * @arg @ref LL_COMP_INPUT_MINUS_IO1 (1)
  499. *
  500. * (1) Available only on COMP instance: COMP2.
  501. * @retval None
  502. */
  503. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  504. {
  505. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  506. /* VrefInt. Check of comparator instance is implemented to modify register */
  507. /* only if COMP2 is selected. */
  508. MODIFY_REG(COMP->CSR,
  509. COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
  510. InputMinus * __COMP_IS_INSTANCE_EVEN(COMPx));
  511. }
  512. /**
  513. * @brief Get comparator input minus (inverting).
  514. * @note In case of comparator input selected to be connected to IO:
  515. * GPIO pins are specific to each comparator instance.
  516. * Refer to description of parameters or to reference manual.
  517. * @rmtoll CSR COMP_CSR_INSEL LL_COMP_SetInputMinus
  518. * @param COMPx Comparator instance
  519. * @retval Returned value can be one of the following values:
  520. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
  521. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
  522. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
  523. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  524. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1)
  525. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (1)
  526. * @arg @ref LL_COMP_INPUT_MINUS_IO1 (1)
  527. *
  528. * (1) Available only on COMP instance: COMP2.
  529. */
  530. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  531. {
  532. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  533. /* VrefInt. Check of comparator instance is implemented to return */
  534. /* the comparator input plus depending on COMP instance selected. */
  535. return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_INSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
  536. | (LL_COMP_INPUT_MINUS_VREFINT * __COMP_IS_INSTANCE_ODD(COMPx)));
  537. }
  538. /**
  539. * @brief Set comparator input pulling resistor.
  540. * @rmtoll CSR 10KPU LL_COMP_SetInputPullingResistor\n
  541. * CSR 400KPU LL_COMP_SetInputPullingResistor\n
  542. * CSR 10KPD LL_COMP_SetInputPullingResistor\n
  543. * CSR 400KPD LL_COMP_SetInputPullingResistor
  544. * @param COMPx Comparator instance
  545. * @param InputPullingResistor This parameter can be one of the following values:
  546. * @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
  547. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K (1)
  548. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K (1)
  549. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K (1)
  550. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
  551. *
  552. * (1) Available only on COMP instance: COMP1.
  553. * @retval None
  554. */
  555. __STATIC_INLINE void LL_COMP_SetInputPullingResistor(COMP_TypeDef *COMPx, uint32_t InputPullingResistor)
  556. {
  557. /* On this STM32 serie, only COMP instance COMP1 has input pulling */
  558. /* resistor. Check of comparator instance is implemented to modify register */
  559. /* only if COMP1 is selected. */
  560. MODIFY_REG(COMP->CSR,
  561. (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD) * __COMP_IS_INSTANCE_ODD(COMPx),
  562. InputPullingResistor * __COMP_IS_INSTANCE_ODD(COMPx));
  563. }
  564. /**
  565. * @brief Get comparator input pulling resistor.
  566. * @rmtoll CSR 10KPU LL_COMP_SetInputPullingResistor\n
  567. * CSR 400KPU LL_COMP_SetInputPullingResistor\n
  568. * CSR 10KPD LL_COMP_SetInputPullingResistor\n
  569. * CSR 400KPD LL_COMP_SetInputPullingResistor
  570. * @param COMPx Comparator instance
  571. * @retval Returned value can be one of the following values:
  572. * @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
  573. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K (1)
  574. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K (1)
  575. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K (1)
  576. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
  577. *
  578. * (1) Available only on COMP instance: COMP1.
  579. */
  580. __STATIC_INLINE uint32_t LL_COMP_GetInputPullingResistor(COMP_TypeDef *COMPx)
  581. {
  582. /* On this STM32 serie, only COMP instance COMP1 has input pulling */
  583. /* resistor. Check of comparator instance is implemented to return */
  584. /* the comparator input pulling resistor depending on COMP instance */
  585. /* selected. */
  586. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  587. /* VrefInt. Check of comparator instance is implemented to return */
  588. /* the comparator input plus depending on COMP instance selected. */
  589. return (uint32_t)((READ_BIT(COMP->CSR, (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD)) * __COMP_IS_INSTANCE_ODD(COMPx))
  590. | (LL_COMP_INPUT_MINUS_PULL_NO * __COMP_IS_INSTANCE_EVEN(COMPx)));
  591. }
  592. /**
  593. * @}
  594. */
  595. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  596. * @{
  597. */
  598. /**
  599. * @brief Set comparator output selection.
  600. * @note Availability of parameters of output selection to timer
  601. * depends on timers availability on the selected device.
  602. * @rmtoll CSR OUTSEL LL_COMP_SetOutputSelection
  603. * @param COMPx Comparator instance
  604. * @param OutputSelection This parameter can be one of the following values:
  605. * @arg @ref LL_COMP_OUTPUT_NONE
  606. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)(2)
  607. * @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
  608. * @arg @ref LL_COMP_OUTPUT_TIM3_IC4 (1)(2)
  609. * @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
  610. * @arg @ref LL_COMP_OUTPUT_TIM4_IC4 (1)(2)
  611. * @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
  612. * @arg @ref LL_COMP_OUTPUT_TIM10_IC1 (1)(2)
  613. *
  614. * (1) Parameter availability depending on timer availability
  615. * on the selected device.
  616. * (2) Available only on COMP instance: COMP2.
  617. * @retval None
  618. */
  619. __STATIC_INLINE void LL_COMP_SetOutputSelection(COMP_TypeDef *COMPx, uint32_t OutputSelection)
  620. {
  621. /* On this STM32 serie, only COMP instance COMP2 has feature output */
  622. /* selection. Check of comparator instance is implemented to modify register*/
  623. /* only if COMP2 is selected. */
  624. MODIFY_REG(COMP->CSR,
  625. COMP_CSR_OUTSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
  626. OutputSelection * __COMP_IS_INSTANCE_EVEN(COMPx));
  627. }
  628. /**
  629. * @brief Get comparator output selection.
  630. * @note Availability of parameters of output selection to timer
  631. * depends on timers availability on the selected device.
  632. * @rmtoll CSR OUTSEL LL_COMP_GetOutputSelection
  633. * @param COMPx Comparator instance
  634. * @retval Returned value can be one of the following values:
  635. * @arg @ref LL_COMP_OUTPUT_NONE
  636. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)(2)
  637. * @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
  638. * @arg @ref LL_COMP_OUTPUT_TIM3_IC4 (1)(2)
  639. * @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
  640. * @arg @ref LL_COMP_OUTPUT_TIM4_IC4 (1)(2)
  641. * @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
  642. * @arg @ref LL_COMP_OUTPUT_TIM10_IC1 (1)(2)
  643. *
  644. * (1) Parameter availability depending on timer availability
  645. * on the selected device.
  646. * (2) Available only on COMP instance: COMP2.
  647. */
  648. __STATIC_INLINE uint32_t LL_COMP_GetOutputSelection(COMP_TypeDef *COMPx)
  649. {
  650. /* On this STM32 serie, only COMP instance COMP2 has feature output */
  651. /* selection. Check of comparator instance is implemented to return */
  652. /* the comparator output depending on COMP instance selected. */
  653. return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_OUTSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
  654. | (LL_COMP_OUTPUT_NONE * __COMP_IS_INSTANCE_ODD(COMPx)));
  655. }
  656. /**
  657. * @}
  658. */
  659. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  660. * @{
  661. */
  662. /**
  663. * @brief Enable comparator instance.
  664. * @note After enable from off state, comparator requires a delay
  665. * to reach reach propagation delay specification.
  666. * Refer to device datasheet, parameter "tSTART".
  667. * @rmtoll CSR COMP1EN LL_COMP_Enable\n
  668. * CSR COMP_CSR_INSEL LL_COMP_Enable
  669. * @param COMPx Comparator instance (1)
  670. *
  671. * (1) On this STM32 serie, the only COMP instance that can be enabled
  672. * using this function is COMP1.
  673. * COMP2 is enabled by setting input minus.
  674. * Refer to function @ref LL_COMP_SetInputMinus().
  675. * @retval None
  676. */
  677. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  678. {
  679. /* On this STM32 serie, only COMP instance COMP1 has a dedicated bit */
  680. /* for comparator enable. Check of comparator instance is implemented */
  681. /* to modify register only if COMP1 is selected. */
  682. SET_BIT(COMP->CSR, __COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_ENABLE_COMP1_BITOFFSET_POS);
  683. }
  684. /**
  685. * @brief Disable comparator instance.
  686. * @note On this STM32 serie, COMP2 is disabled by clearing input minus
  687. * selection. If COMP2 must be enabled afterwards, input minus must
  688. * be set. Refer to function @ref LL_COMP_SetInputMinus().
  689. * @rmtoll CSR COMP1EN LL_COMP_Disable\n
  690. * CSR COMP_CSR_INSEL LL_COMP_Disable
  691. * @param COMPx Comparator instance
  692. * @retval None
  693. */
  694. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  695. {
  696. /* Note: On this STM32 serie, COMP2 is enabled by setting input minus. */
  697. /* Refer to function @ref LL_COMP_SetInputMinus(). */
  698. /* To disable COMP2, bitfield of input minus selection is reset. */
  699. CLEAR_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx)));
  700. }
  701. /**
  702. * @brief Get comparator enable state
  703. * (0: COMP is disabled, 1: COMP is enabled)
  704. * @rmtoll CSR COMP1EN LL_COMP_IsEnabled\n
  705. * CSR COMP_CSR_INSEL LL_COMP_IsEnabled
  706. * @param COMPx Comparator instance
  707. * @retval State of bit (1 or 0).
  708. */
  709. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  710. {
  711. return (READ_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx))) != (0U));
  712. }
  713. /**
  714. * @brief Read comparator instance output level.
  715. * @note On this STM32 serie, comparator polarity is not settable
  716. * and not inverted:
  717. * - Comparator output is low when the input plus
  718. * is at a lower voltage than the input minus
  719. * - Comparator output is high when the input plus
  720. * is at a higher voltage than the input minus
  721. * @rmtoll CSR CMP1OUT LL_COMP_ReadOutputLevel\n
  722. * CSR CMP2OUT LL_COMP_ReadOutputLevel
  723. * @param COMPx Comparator instance
  724. * @retval Returned value can be one of the following values:
  725. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  726. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  727. */
  728. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  729. {
  730. return (uint32_t)(READ_BIT(COMP->CSR,
  731. ((__COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS) | (__COMP_IS_INSTANCE_EVEN(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS)))
  732. >> (LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS + ((LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS - LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS) * __COMP_IS_INSTANCE_EVEN(COMPx)))
  733. );
  734. }
  735. /**
  736. * @}
  737. */
  738. #if defined(USE_FULL_LL_DRIVER)
  739. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  740. * @{
  741. */
  742. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  743. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  744. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  745. /**
  746. * @}
  747. */
  748. #endif /* USE_FULL_LL_DRIVER */
  749. /**
  750. * @}
  751. */
  752. /**
  753. * @}
  754. */
  755. #endif /* COMP1 || COMP2 */
  756. /**
  757. * @}
  758. */
  759. #ifdef __cplusplus
  760. }
  761. #endif
  762. #endif /* __STM32L1xx_LL_COMP_H */
  763. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/