stm32l1xx_ll_comp.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  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</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32L1xx_LL_COMP_H
  37. #define __STM32L1xx_LL_COMP_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32l1xx.h"
  43. /** @addtogroup STM32L1xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (COMP1) || defined (COMP2)
  47. /** @defgroup COMP_LL COMP
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  54. * @{
  55. */
  56. /* COMP registers bits positions */
  57. #define LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS ( 7U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1OUT) */
  58. #define LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS (13U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP2OUT) */
  59. #define LL_COMP_ENABLE_COMP1_BITOFFSET_POS ( 4U) /* Value equivalent to POSITION_VAL(COMP_CSR_CMP1EN) */
  60. /**
  61. * @}
  62. */
  63. /* Private macros ------------------------------------------------------------*/
  64. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  65. * @{
  66. */
  67. /**
  68. * @brief Driver macro reserved for internal use: if COMP instance selected
  69. * is odd (COMP1, COMP3, ...), return value '1', else return '0'.
  70. * @param __COMP_INSTANCE__ COMP instance
  71. * @retval If COMP instance is odd, value '1'. Else, value '0'.
  72. */
  73. #define __COMP_IS_INSTANCE_ODD(__COMP_INSTANCE__) \
  74. ((~((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)) & 0x00000001)
  75. /**
  76. * @brief Driver macro reserved for internal use: if COMP instance selected
  77. * is even (COMP2, COMP4, ...), return value '1', else return '0'.
  78. * @param __COMP_INSTANCE__ COMP instance
  79. * @retval If COMP instance is even, value '1'. Else, value '0'.
  80. */
  81. #define __COMP_IS_INSTANCE_EVEN(__COMP_INSTANCE__) \
  82. ((uint32_t)(__COMP_INSTANCE__) - COMP_BASE)
  83. /**
  84. * @}
  85. */
  86. /* Exported types ------------------------------------------------------------*/
  87. #if defined(USE_FULL_LL_DRIVER)
  88. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  89. * @{
  90. */
  91. /**
  92. * @brief Structure definition of some features of COMP instance.
  93. */
  94. typedef struct
  95. {
  96. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  97. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  98. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  99. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  100. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  101. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  102. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  103. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  104. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  105. uint32_t OutputSelection; /*!< Set comparator output selection.
  106. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_SELECTION
  107. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputSelection(). */
  108. } LL_COMP_InitTypeDef;
  109. /**
  110. * @}
  111. */
  112. #endif /* USE_FULL_LL_DRIVER */
  113. /* Exported constants --------------------------------------------------------*/
  114. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  115. * @{
  116. */
  117. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  118. * @{
  119. */
  120. #define LL_COMP_WINDOWMODE_DISABLE (0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  121. #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). */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  126. * @{
  127. */
  128. #define LL_COMP_POWERMODE_ULTRALOWPOWER (0x00000000U) /*!< COMP power mode to low speed (specific to COMP instance: COMP2) */
  129. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_SPEED) /*!< COMP power mode to fast speed (specific to COMP instance: COMP2) */
  130. /**
  131. * @}
  132. */
  133. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  134. * @{
  135. */
  136. #define LL_COMP_INPUT_PLUS_NONE (0x00000000U) /*!< Comparator input plus connected not connected */
  137. #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) */
  138. #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) */
  139. #if defined(RI_ASCR1_CH_31)
  140. #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) */
  141. #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) */
  142. #endif
  143. #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) */
  144. #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) */
  145. #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) */
  146. #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) */
  147. #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) */
  148. #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) */
  149. #define LL_COMP_INPUT_PLUS_IO11 (RI_ASCR1_CH_5) /*!< Comparator input plus connected to IO11 (pin PA5 for COMP1) (specific to COMP instance: COMP1) */
  150. #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) */
  151. #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) */
  152. #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) */
  153. #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) */
  154. #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) */
  155. #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) */
  156. #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) */
  157. #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) */
  158. #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) */
  159. #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) */
  160. #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) */
  161. #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) */
  162. #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) */
  163. #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) */
  164. #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) */
  165. #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) */
  166. #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) */
  167. #if defined(RI_ASCR1_CH_31)
  168. #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) */
  169. #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) */
  170. #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) */
  171. #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) */
  172. #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) */
  173. #endif
  174. #if defined(OPAMP1)
  175. #define LL_COMP_INPUT_PLUS_OPAMP1 (RI_ASCR1_CH_3) /*!< Comparator input plus connected to OPAMP1 output (specific to COMP instance: COMP1) */
  176. #define LL_COMP_INPUT_PLUS_OPAMP2 (RI_ASCR1_CH_8) /*!< Comparator input plus connected to OPAMP2 output (specific to COMP instance: COMP1) */
  177. #endif
  178. #if defined(OPAMP3)
  179. #define LL_COMP_INPUT_PLUS_OPAMP3 (RI_ASCR1_CH_13) /*!< Comparator input plus connected to OPAMP3 output (specific to COMP instance: COMP1) */
  180. #endif
  181. /**
  182. * @}
  183. */
  184. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  185. * @{
  186. */
  187. #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) */
  188. #define LL_COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_INSEL_2 ) /*!< Comparator input minus connected to 1/2 VrefInt (specific to COMP instance: COMP2) */
  189. #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) */
  190. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_INSEL_1 ) /*!< Comparator input minus connected to VrefInt */
  191. #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) */
  192. #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) */
  193. #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) */
  194. /**
  195. * @}
  196. */
  197. /** @defgroup COMP_LL_EC_INPUT_PULLING_RESISTOR Comparator input - Pulling resistor
  198. * @{
  199. */
  200. #define LL_COMP_INPUT_MINUS_PULL_NO (0x00000000U) /*!< Comparator input minus not connected to any pulling resistor */
  201. #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) */
  202. #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) */
  203. #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) */
  204. #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) */
  205. /**
  206. * @}
  207. */
  208. /** @defgroup COMP_LL_EC_OUTPUT_SELECTION Comparator output - Output selection
  209. * @{
  210. */
  211. #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) */
  212. #define LL_COMP_OUTPUT_TIM2_IC4 (0x00000000) /*!< COMP output connected to TIM2 input capture 4 (specific to COMP instance: COMP2) */
  213. #define LL_COMP_OUTPUT_TIM2_OCREFCLR ( COMP_CSR_OUTSEL_0) /*!< COMP output connected to TIM2 OCREF clear (specific to COMP instance: COMP2) */
  214. #define LL_COMP_OUTPUT_TIM3_IC4 ( COMP_CSR_OUTSEL_1 ) /*!< COMP output connected to TIM3 input capture 4 (specific to COMP instance: COMP2) */
  215. #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) */
  216. #define LL_COMP_OUTPUT_TIM4_IC4 (COMP_CSR_OUTSEL_2 ) /*!< COMP output connected to TIM4 input capture 4 (specific to COMP instance: COMP2) */
  217. #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) */
  218. #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) */
  219. /**
  220. * @}
  221. */
  222. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  223. * @{
  224. */
  225. #define LL_COMP_OUTPUT_LEVEL_LOW (0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  226. #define LL_COMP_OUTPUT_LEVEL_HIGH (0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  227. /**
  228. * @}
  229. */
  230. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  231. * @note Only COMP IP HW delays are defined in COMP LL driver driver,
  232. * not timeout values.
  233. * For details on delays values, refer to descriptions in source code
  234. * above each literal definition.
  235. * @{
  236. */
  237. /* Delay for comparator startup time. */
  238. /* Note: Delay required to reach propagation delay specification. */
  239. /* Literal set to maximum value (refer to device datasheet, */
  240. /* parameter "tSTART"). */
  241. /* Unit: us */
  242. #define LL_COMP_DELAY_STARTUP_US (25U) /*!< Delay for COMP startup time */
  243. /**
  244. * @}
  245. */
  246. /**
  247. * @}
  248. */
  249. /* Exported macro ------------------------------------------------------------*/
  250. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  251. * @{
  252. */
  253. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  254. * @{
  255. */
  256. /**
  257. * @brief Write a value in COMP register
  258. * @param __INSTANCE__ comparator instance
  259. * @param __REG__ Register to be written
  260. * @param __VALUE__ Value to be written in the register
  261. * @retval None
  262. */
  263. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  264. /**
  265. * @brief Read a value in COMP register
  266. * @param __INSTANCE__ comparator instance
  267. * @param __REG__ Register to be read
  268. * @retval Register value
  269. */
  270. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  271. /**
  272. * @}
  273. */
  274. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  275. * @{
  276. */
  277. /**
  278. * @brief Helper macro to select the COMP common instance
  279. * to which is belonging the selected COMP instance.
  280. * @note COMP common register instance can be used to
  281. * set parameters common to several COMP instances.
  282. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  283. * @param __COMPx__ COMP instance
  284. * @retval COMP common instance or value "0" if there is no COMP common instance.
  285. */
  286. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  287. (COMP12_COMMON)
  288. /**
  289. * @}
  290. */
  291. /**
  292. * @}
  293. */
  294. /* Exported functions --------------------------------------------------------*/
  295. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  296. * @{
  297. */
  298. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  299. * @{
  300. */
  301. /**
  302. * @brief Set window mode of a pair of comparators instances
  303. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  304. * @rmtoll CSR WNDWE LL_COMP_SetCommonWindowMode
  305. * @param COMPxy_COMMON Comparator common instance
  306. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  307. * @param WindowMode This parameter can be one of the following values:
  308. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  309. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  310. * @retval None
  311. */
  312. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  313. {
  314. MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WNDWE, WindowMode);
  315. }
  316. /**
  317. * @brief Get window mode of a pair of comparators instances
  318. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  319. * @rmtoll CSR WNDWE LL_COMP_GetCommonWindowMode
  320. * @param COMPxy_COMMON Comparator common instance
  321. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  322. * @retval Returned value can be one of the following values:
  323. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  324. * @arg @ref LL_COMP_WINDOWMODE_COMP2_INPUT_PLUS_COMMON
  325. */
  326. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  327. {
  328. return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WNDWE));
  329. }
  330. /**
  331. * @}
  332. */
  333. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  334. * @{
  335. */
  336. /**
  337. * @brief Set comparator instance operating mode to adjust power and speed.
  338. * @rmtoll COMP2_CSR SPEED LL_COMP_SetPowerMode
  339. * @param COMPx Comparator instance
  340. * @param PowerMode This parameter can be one of the following values:
  341. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  342. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  343. *
  344. * (1) Available only on COMP instance: COMP2.
  345. * @retval None
  346. */
  347. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  348. {
  349. MODIFY_REG(COMP->CSR, COMP_CSR_SPEED, PowerMode);
  350. }
  351. /**
  352. * @brief Get comparator instance operating mode to adjust power and speed.
  353. * @rmtoll COMP2_CSR SPEED LL_COMP_GetPowerMode
  354. * @param COMPx Comparator instance
  355. * @retval Returned value can be one of the following values:
  356. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  357. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  358. *
  359. * (1) Available only on COMP instance: COMP2.
  360. */
  361. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  362. {
  363. return (uint32_t)(READ_BIT(COMP->CSR, COMP_CSR_SPEED));
  364. }
  365. /**
  366. * @}
  367. */
  368. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  369. * @{
  370. */
  371. /**
  372. * @brief Set comparator input plus (non-inverting).
  373. * @note In case of comparator input selected to be connected to IO:
  374. * GPIO pins are specific to each comparator instance.
  375. * Refer to description of parameters or to reference manual.
  376. * @rmtoll RI RI_ASCR1_CH LL_COMP_SetInputPlus\n
  377. * RI RI_ASCR2_GR6 LL_COMP_SetInputPlus
  378. * @param COMPx Comparator instance
  379. * @param InputPlus This parameter can be one of the following values:
  380. * @arg @ref LL_COMP_INPUT_PLUS_NONE
  381. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
  382. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
  383. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
  384. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
  385. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  386. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
  387. * @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
  388. * @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
  389. * @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
  390. * @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
  391. * @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
  392. * @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
  393. * @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
  394. * @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
  395. * @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
  396. * @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
  397. * @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
  398. * @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
  399. * @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
  400. * @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
  401. * @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
  402. * @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
  403. * @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
  404. * @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
  405. * @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
  406. * @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
  407. * @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
  408. * @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
  409. * @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
  410. * @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
  411. * @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
  412. * @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
  413. * @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
  414. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
  415. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
  416. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
  417. *
  418. * (1) Available only on COMP instance: COMP1. \n
  419. * (2) Available only on COMP instance: COMP2. \n
  420. * (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  421. * (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  422. * (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
  423. * @retval None
  424. */
  425. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  426. {
  427. /* Set switch in routing interface (RI) register ASCR1 or ASCR2 */
  428. /* Note: If COMP instance COMP1 is selected, this function performs */
  429. /* necessary actions on routing interface: */
  430. /* - close switch netween comparator 1 and switch matrix */
  431. /* (RI_ASCR1_VCOMP) */
  432. /* - enable IO switch control mode (RI_ASCR1_SCM) */
  433. /* If ADC needs to be used afterwards, disable IO switch control */
  434. /* mode using function @ref LL_RI_DisableSwitchControlMode(). */
  435. register uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
  436. MODIFY_REG(*preg,
  437. (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx)),
  438. InputPlus | ((RI_ASCR1_VCOMP | RI_ASCR1_SCM) * __COMP_IS_INSTANCE_ODD(COMPx)));
  439. }
  440. /**
  441. * @brief Get comparator input plus (non-inverting).
  442. * @note In case of comparator input selected to be connected to IO:
  443. * GPIO pins are specific to each comparator instance.
  444. * Refer to description of parameters or to reference manual.
  445. * @rmtoll RI RI_ASCR1_CH LL_COMP_GetInputPlus\n
  446. * RI RI_ASCR2_GR6 LL_COMP_GetInputPlus
  447. * @param COMPx Comparator instance
  448. * @retval Returned value can be one of the following values:
  449. * @arg @ref LL_COMP_INPUT_PLUS_NONE
  450. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (2)
  451. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (2)
  452. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (2)(5)
  453. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (2)(5)
  454. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  455. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)
  456. * @arg @ref LL_COMP_INPUT_PLUS_IO7 (1)
  457. * @arg @ref LL_COMP_INPUT_PLUS_IO8 (1)
  458. * @arg @ref LL_COMP_INPUT_PLUS_IO9 (1)
  459. * @arg @ref LL_COMP_INPUT_PLUS_IO10 (1)
  460. * @arg @ref LL_COMP_INPUT_PLUS_IO11 (1)
  461. * @arg @ref LL_COMP_INPUT_PLUS_IO12 (1)
  462. * @arg @ref LL_COMP_INPUT_PLUS_IO13 (1)
  463. * @arg @ref LL_COMP_INPUT_PLUS_IO14 (1)
  464. * @arg @ref LL_COMP_INPUT_PLUS_IO15 (1)
  465. * @arg @ref LL_COMP_INPUT_PLUS_IO16 (1)
  466. * @arg @ref LL_COMP_INPUT_PLUS_IO17 (1)
  467. * @arg @ref LL_COMP_INPUT_PLUS_IO18 (1)
  468. * @arg @ref LL_COMP_INPUT_PLUS_IO19 (1)
  469. * @arg @ref LL_COMP_INPUT_PLUS_IO20 (1)
  470. * @arg @ref LL_COMP_INPUT_PLUS_IO21 (1)
  471. * @arg @ref LL_COMP_INPUT_PLUS_IO22 (1)
  472. * @arg @ref LL_COMP_INPUT_PLUS_IO23 (1)
  473. * @arg @ref LL_COMP_INPUT_PLUS_IO24 (1)
  474. * @arg @ref LL_COMP_INPUT_PLUS_IO25 (1)
  475. * @arg @ref LL_COMP_INPUT_PLUS_IO26 (1)
  476. * @arg @ref LL_COMP_INPUT_PLUS_IO27 (1)
  477. * @arg @ref LL_COMP_INPUT_PLUS_IO28 (1)
  478. * @arg @ref LL_COMP_INPUT_PLUS_IO29 (1)(4)
  479. * @arg @ref LL_COMP_INPUT_PLUS_IO30 (1)(4)
  480. * @arg @ref LL_COMP_INPUT_PLUS_IO31 (1)(4)
  481. * @arg @ref LL_COMP_INPUT_PLUS_IO32 (1)(4)
  482. * @arg @ref LL_COMP_INPUT_PLUS_IO33 (1)(4)
  483. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP1 (1)(3)
  484. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP2 (1)(3)
  485. * @arg @ref LL_COMP_INPUT_PLUS_OPAMP3 (1)(4)
  486. *
  487. * (1) Available only on COMP instance: COMP1. \n
  488. * (2) Available only on COMP instance: COMP2. \n
  489. * (3) Available on devices: STM32L100xB, STM32L151xB, STM32L152xB, STM32L100xBA, STM32L151xBA, STM32L152xBA, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  490. * (4) Available on devices: STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD \n
  491. * (5) Available on devices: STM32L100xC, STM32L151xC, STM32L152xC, STM32L162xC, STM32L151xCA, STM32L151xD, STM32L152xCA, STM32L152xD, STM32L162xCA, STM32L162xD) || defined(STM32L151xE) || defined(STM32L151xDX, STM32L152xE, STM32L152xDX, STM32L162xE, STM32L162xDX
  492. */
  493. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  494. {
  495. /* Get switch state in routing interface (RI) register ASCR1 or ASCR2 */
  496. register uint32_t *preg = ((uint32_t *)((uint32_t) ((uint32_t)(&(RI->ASCR1)) + ((__COMP_IS_INSTANCE_EVEN(COMPx)) << 2U))));
  497. return (uint32_t)(READ_BIT(*preg,
  498. (RI_ASCR1_CH * __COMP_IS_INSTANCE_ODD(COMPx)) | (RI_ASCR2_GR6 * __COMP_IS_INSTANCE_EVEN(COMPx))));
  499. }
  500. /**
  501. * @brief Set comparator input minus (inverting).
  502. * @note In case of comparator input selected to be connected to IO:
  503. * GPIO pins are specific to each comparator instance.
  504. * Refer to description of parameters or to reference manual.
  505. * @rmtoll CSR COMP_CSR_INSEL LL_COMP_SetInputMinus
  506. * @param COMPx Comparator instance
  507. * @param InputMinus This parameter can be one of the following values:
  508. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
  509. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
  510. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
  511. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  512. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1)
  513. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (1)
  514. * @arg @ref LL_COMP_INPUT_MINUS_IO1 (1)
  515. *
  516. * (1) Available only on COMP instance: COMP2.
  517. * @retval None
  518. */
  519. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  520. {
  521. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  522. /* VrefInt. Check of comparator instance is implemented to modify register */
  523. /* only if COMP2 is selected. */
  524. MODIFY_REG(COMP->CSR,
  525. COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
  526. InputMinus * __COMP_IS_INSTANCE_EVEN(COMPx));
  527. }
  528. /**
  529. * @brief Get comparator input minus (inverting).
  530. * @note In case of comparator input selected to be connected to IO:
  531. * GPIO pins are specific to each comparator instance.
  532. * Refer to description of parameters or to reference manual.
  533. * @rmtoll CSR COMP_CSR_INSEL LL_COMP_SetInputMinus
  534. * @param COMPx Comparator instance
  535. * @retval Returned value can be one of the following values:
  536. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (1)
  537. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (1)
  538. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (1)
  539. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  540. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1 (1)
  541. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2 (1)
  542. * @arg @ref LL_COMP_INPUT_MINUS_IO1 (1)
  543. *
  544. * (1) Available only on COMP instance: COMP2.
  545. */
  546. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  547. {
  548. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  549. /* VrefInt. Check of comparator instance is implemented to return */
  550. /* the comparator input plus depending on COMP instance selected. */
  551. return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_INSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
  552. | (LL_COMP_INPUT_MINUS_VREFINT * __COMP_IS_INSTANCE_ODD(COMPx)));
  553. }
  554. /**
  555. * @brief Set comparator input pulling resistor.
  556. * @rmtoll CSR 10KPU LL_COMP_SetInputPullingResistor\n
  557. * CSR 400KPU LL_COMP_SetInputPullingResistor\n
  558. * CSR 10KPD LL_COMP_SetInputPullingResistor\n
  559. * CSR 400KPD LL_COMP_SetInputPullingResistor
  560. * @param COMPx Comparator instance
  561. * @param InputPullingResistor This parameter can be one of the following values:
  562. * @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
  563. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K (1)
  564. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K (1)
  565. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K (1)
  566. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
  567. *
  568. * (1) Available only on COMP instance: COMP1.
  569. * @retval None
  570. */
  571. __STATIC_INLINE void LL_COMP_SetInputPullingResistor(COMP_TypeDef *COMPx, uint32_t InputPullingResistor)
  572. {
  573. /* On this STM32 serie, only COMP instance COMP1 has input pulling */
  574. /* resistor. Check of comparator instance is implemented to modify register */
  575. /* only if COMP1 is selected. */
  576. MODIFY_REG(COMP->CSR,
  577. (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD) * __COMP_IS_INSTANCE_ODD(COMPx),
  578. InputPullingResistor * __COMP_IS_INSTANCE_ODD(COMPx));
  579. }
  580. /**
  581. * @brief Get comparator input pulling resistor.
  582. * @rmtoll CSR 10KPU LL_COMP_SetInputPullingResistor\n
  583. * CSR 400KPU LL_COMP_SetInputPullingResistor\n
  584. * CSR 10KPD LL_COMP_SetInputPullingResistor\n
  585. * CSR 400KPD LL_COMP_SetInputPullingResistor
  586. * @param COMPx Comparator instance
  587. * @retval Returned value can be one of the following values:
  588. * @arg @ref LL_COMP_INPUT_MINUS_PULL_NO
  589. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_10K (1)
  590. * @arg @ref LL_COMP_INPUT_MINUS_PULL_UP_400K (1)
  591. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_10K (1)
  592. * @arg @ref LL_COMP_INPUT_MINUS_PULL_DOWN_400K (1)
  593. *
  594. * (1) Available only on COMP instance: COMP1.
  595. */
  596. __STATIC_INLINE uint32_t LL_COMP_GetInputPullingResistor(COMP_TypeDef *COMPx)
  597. {
  598. /* On this STM32 serie, only COMP instance COMP1 has input pulling */
  599. /* resistor. Check of comparator instance is implemented to return */
  600. /* the comparator input pulling resistor depending on COMP instance */
  601. /* selected. */
  602. /* On this STM32 serie, only COMP instance COMP1 input minus is fixed to */
  603. /* VrefInt. Check of comparator instance is implemented to return */
  604. /* the comparator input plus depending on COMP instance selected. */
  605. return (uint32_t)((READ_BIT(COMP->CSR, (COMP_CSR_10KPU | COMP_CSR_400KPU | COMP_CSR_10KPD | COMP_CSR_400KPD)) * __COMP_IS_INSTANCE_ODD(COMPx))
  606. | (LL_COMP_INPUT_MINUS_PULL_NO * __COMP_IS_INSTANCE_EVEN(COMPx)));
  607. }
  608. /**
  609. * @}
  610. */
  611. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  612. * @{
  613. */
  614. /**
  615. * @brief Set comparator output selection.
  616. * @note Availability of parameters of output selection to timer
  617. * depends on timers availability on the selected device.
  618. * @rmtoll CSR OUTSEL LL_COMP_SetOutputSelection
  619. * @param COMPx Comparator instance
  620. * @param OutputSelection This parameter can be one of the following values:
  621. * @arg @ref LL_COMP_OUTPUT_NONE
  622. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)(2)
  623. * @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
  624. * @arg @ref LL_COMP_OUTPUT_TIM3_IC4 (1)(2)
  625. * @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
  626. * @arg @ref LL_COMP_OUTPUT_TIM4_IC4 (1)(2)
  627. * @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
  628. * @arg @ref LL_COMP_OUTPUT_TIM10_IC1 (1)(2)
  629. *
  630. * (1) Parameter availability depending on timer availability
  631. * on the selected device.
  632. * (2) Available only on COMP instance: COMP2.
  633. * @retval None
  634. */
  635. __STATIC_INLINE void LL_COMP_SetOutputSelection(COMP_TypeDef *COMPx, uint32_t OutputSelection)
  636. {
  637. /* On this STM32 serie, only COMP instance COMP2 has feature output */
  638. /* selection. Check of comparator instance is implemented to modify register*/
  639. /* only if COMP2 is selected. */
  640. MODIFY_REG(COMP->CSR,
  641. COMP_CSR_OUTSEL * __COMP_IS_INSTANCE_EVEN(COMPx),
  642. OutputSelection * __COMP_IS_INSTANCE_EVEN(COMPx));
  643. }
  644. /**
  645. * @brief Get comparator output selection.
  646. * @note Availability of parameters of output selection to timer
  647. * depends on timers availability on the selected device.
  648. * @rmtoll CSR OUTSEL LL_COMP_GetOutputSelection
  649. * @param COMPx Comparator instance
  650. * @retval Returned value can be one of the following values:
  651. * @arg @ref LL_COMP_OUTPUT_NONE
  652. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)(2)
  653. * @arg @ref LL_COMP_OUTPUT_TIM2_OCREFCLR (1)(2)
  654. * @arg @ref LL_COMP_OUTPUT_TIM3_IC4 (1)(2)
  655. * @arg @ref LL_COMP_OUTPUT_TIM3_OCREFCLR (1)(2)
  656. * @arg @ref LL_COMP_OUTPUT_TIM4_IC4 (1)(2)
  657. * @arg @ref LL_COMP_OUTPUT_TIM4_OCREFCLR (1)(2)
  658. * @arg @ref LL_COMP_OUTPUT_TIM10_IC1 (1)(2)
  659. *
  660. * (1) Parameter availability depending on timer availability
  661. * on the selected device.
  662. * (2) Available only on COMP instance: COMP2.
  663. */
  664. __STATIC_INLINE uint32_t LL_COMP_GetOutputSelection(COMP_TypeDef *COMPx)
  665. {
  666. /* On this STM32 serie, only COMP instance COMP2 has feature output */
  667. /* selection. Check of comparator instance is implemented to return */
  668. /* the comparator output depending on COMP instance selected. */
  669. return (uint32_t)((READ_BIT(COMP->CSR, COMP_CSR_OUTSEL) * __COMP_IS_INSTANCE_EVEN(COMPx))
  670. | (LL_COMP_OUTPUT_NONE * __COMP_IS_INSTANCE_ODD(COMPx)));
  671. }
  672. /**
  673. * @}
  674. */
  675. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  676. * @{
  677. */
  678. /**
  679. * @brief Enable comparator instance.
  680. * @note After enable from off state, comparator requires a delay
  681. * to reach reach propagation delay specification.
  682. * Refer to device datasheet, parameter "tSTART".
  683. * @rmtoll CSR COMP1EN LL_COMP_Enable\n
  684. * CSR COMP_CSR_INSEL LL_COMP_Enable
  685. * @param COMPx Comparator instance (1)
  686. *
  687. * (1) On this STM32 serie, the only COMP instance that can be enabled
  688. * using this function is COMP1.
  689. * COMP2 is enabled by setting input minus.
  690. * Refer to function @ref LL_COMP_SetInputMinus().
  691. * @retval None
  692. */
  693. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  694. {
  695. /* On this STM32 serie, only COMP instance COMP1 has a dedicated bit */
  696. /* for comparator enable. Check of comparator instance is implemented */
  697. /* to modify register only if COMP1 is selected. */
  698. SET_BIT(COMP->CSR, __COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_ENABLE_COMP1_BITOFFSET_POS);
  699. }
  700. /**
  701. * @brief Disable comparator instance.
  702. * @note On this STM32 serie, COMP2 is disabled by clearing input minus
  703. * selection. If COMP2 must be enabled afterwards, input minus must
  704. * be set. Refer to function @ref LL_COMP_SetInputMinus().
  705. * @rmtoll CSR COMP1EN LL_COMP_Disable\n
  706. * CSR COMP_CSR_INSEL LL_COMP_Disable
  707. * @param COMPx Comparator instance
  708. * @retval None
  709. */
  710. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  711. {
  712. /* Note: On this STM32 serie, COMP2 is enabled by setting input minus. */
  713. /* Refer to function @ref LL_COMP_SetInputMinus(). */
  714. /* To disable COMP2, bitfield of input minus selection is reset. */
  715. CLEAR_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx)));
  716. }
  717. /**
  718. * @brief Get comparator enable state
  719. * (0: COMP is disabled, 1: COMP is enabled)
  720. * @rmtoll CSR COMP1EN LL_COMP_IsEnabled\n
  721. * CSR COMP_CSR_INSEL LL_COMP_IsEnabled
  722. * @param COMPx Comparator instance
  723. * @retval State of bit (1 or 0).
  724. */
  725. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  726. {
  727. return (READ_BIT(COMP->CSR, (COMP_CSR_CMP1EN * __COMP_IS_INSTANCE_ODD(COMPx)) | (COMP_CSR_INSEL * __COMP_IS_INSTANCE_EVEN(COMPx))) != (0U));
  728. }
  729. /**
  730. * @brief Read comparator instance output level.
  731. * @note On this STM32 serie, comparator polarity is not settable
  732. * and not inverted:
  733. * - Comparator output is low when the input plus
  734. * is at a lower voltage than the input minus
  735. * - Comparator output is high when the input plus
  736. * is at a higher voltage than the input minus
  737. * @rmtoll CSR CMP1OUT LL_COMP_ReadOutputLevel\n
  738. * CSR CMP2OUT LL_COMP_ReadOutputLevel
  739. * @param COMPx Comparator instance
  740. * @retval Returned value can be one of the following values:
  741. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  742. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  743. */
  744. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  745. {
  746. return (uint32_t)(READ_BIT(COMP->CSR,
  747. ((__COMP_IS_INSTANCE_ODD(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP1_BITOFFSET_POS) | (__COMP_IS_INSTANCE_EVEN(COMPx) << LL_COMP_OUTPUT_LEVEL_COMP2_BITOFFSET_POS)))
  748. >> (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)))
  749. );
  750. }
  751. /**
  752. * @}
  753. */
  754. #if defined(USE_FULL_LL_DRIVER)
  755. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  756. * @{
  757. */
  758. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  759. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  760. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  761. /**
  762. * @}
  763. */
  764. #endif /* USE_FULL_LL_DRIVER */
  765. /**
  766. * @}
  767. */
  768. /**
  769. * @}
  770. */
  771. #endif /* COMP1 || COMP2 */
  772. /**
  773. * @}
  774. */
  775. #ifdef __cplusplus
  776. }
  777. #endif
  778. #endif /* __STM32L1xx_LL_COMP_H */
  779. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/