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.
 
 
 

706 lines
29 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_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) 2016 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 __STM32L0xx_LL_COMP_H
  21. #define __STM32L0xx_LL_COMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx.h"
  27. /** @addtogroup STM32L0xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (COMP1) || defined (COMP2)
  31. /** @defgroup COMP_LL COMP
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  38. * @{
  39. */
  40. /* COMP registers bits positions */
  41. #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS ((uint32_t)30U) /* Value equivalent to POSITION_VAL(COMP_CSR_COMP1VALUE) */
  42. /**
  43. * @}
  44. */
  45. /* Private macros ------------------------------------------------------------*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  49. * @{
  50. */
  51. /**
  52. * @brief Structure definition of some features of COMP instance.
  53. */
  54. typedef struct
  55. {
  56. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  57. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  58. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  59. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  60. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  61. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  62. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  63. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  64. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  65. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  66. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  67. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
  68. } LL_COMP_InitTypeDef;
  69. /**
  70. * @}
  71. */
  72. #endif /* USE_FULL_LL_DRIVER */
  73. /* Exported constants --------------------------------------------------------*/
  74. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  75. * @{
  76. */
  77. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  78. * @{
  79. */
  80. #define LL_COMP_WINDOWMODE_DISABLE ((uint32_t)0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  81. #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_COMP1WM) /*!< Window mode enable: Comparators instances pair COMP1 and COMP2 have their input plus connected together. The common input is COMP1 input plus (COMP2 input plus is no more accessible). */
  82. /**
  83. * @}
  84. */
  85. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  86. * @{
  87. */
  88. #define LL_COMP_POWERMODE_ULTRALOWPOWER ((uint32_t)0x00000000U) /*!< COMP power mode to low speed (specific to COMP instance: COMP2) */
  89. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_COMP2SPEED) /*!< COMP power mode to fast speed (specific to COMP instance: COMP2) */
  90. /**
  91. * @}
  92. */
  93. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  94. * @{
  95. */
  96. #define LL_COMP_INPUT_PLUS_IO1 ((uint32_t)0x00000000U) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */
  97. #define LL_COMP_INPUT_PLUS_IO2 (COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO2 (pin PB4 for COMP2) (specific to COMP instance: COMP2) */
  98. #define LL_COMP_INPUT_PLUS_IO3 (COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO3 (pin PA5 for COMP2) (specific to COMP instance: COMP2) */
  99. #define LL_COMP_INPUT_PLUS_IO4 (COMP_CSR_COMP2INPSEL_0 | COMP_CSR_COMP2INPSEL_1) /*!< Comparator input plus connected to IO4 (pin PB6 for COMP2) (specific to COMP instance: COMP2) */
  100. #define LL_COMP_INPUT_PLUS_IO5 (COMP_CSR_COMP2INPSEL_2) /*!< Comparator input plus connected to IO5 (pin PB7 for COMP2) (specific to COMP instance: COMP2) */
  101. #if defined (STM32L011xx) || defined (STM32L021xx)
  102. #define LL_COMP_INPUT_PLUS_IO6 (COMP_CSR_COMP2INPSEL_2 | COMP_CSR_COMP2INPSEL_0) /*!< Comparator input plus connected to IO6 (pin PA7 for COMP2) (specific to COMP instance: COMP2) (Available only on devices STM32L0 category 1) */
  103. #endif
  104. /**
  105. * @}
  106. */
  107. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  108. * @{
  109. */
  110. #define LL_COMP_INPUT_MINUS_1_4VREFINT (COMP_CSR_COMP2INNSEL_2 ) /*!< Comparator input minus connected to 1/4 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
  111. #define LL_COMP_INPUT_MINUS_1_2VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
  112. #define LL_COMP_INPUT_MINUS_3_4VREFINT (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) (specific to COMP instance: COMP2) */
  113. #define LL_COMP_INPUT_MINUS_VREFINT ((uint32_t)0x00000000U) /*!< Comparator input minus connected to VrefInt (specifity of COMP2 related to path to enable via SYSCFG: refer to comment in function @ref LL_COMP_SetInputMinus() ) */
  114. #define LL_COMP_INPUT_MINUS_DAC1_CH1 ( COMP_CSR_COMP2INNSEL_1 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  115. #define LL_COMP_INPUT_MINUS_DAC1_CH2 ( COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  116. #define LL_COMP_INPUT_MINUS_IO1 ( COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */
  117. #define LL_COMP_INPUT_MINUS_IO2 (COMP_CSR_COMP2INNSEL_2 | COMP_CSR_COMP2INNSEL_1 | COMP_CSR_COMP2INNSEL_0) /*!< Comparator input minus connected to IO2 (pin PB3 for COMP2) (specific to COMP instance: COMP2) */
  118. /**
  119. * @}
  120. */
  121. /** @defgroup COMP_LL_EC_OUTPUT_SELECTION_LPTIM Comparator output - Output selection specific to LPTIM peripheral
  122. * @{
  123. */
  124. #define LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (COMP_CSR_COMP1LPTIM1IN1) /*!< COMP output connected to TIM2 input capture 4 */
  125. #define LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (COMP_CSR_COMP2LPTIM1IN1) /*!< COMP output connected to TIM2 input capture 4 */
  126. #define LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (COMP_CSR_COMP2LPTIM1IN2) /*!< COMP output connected to TIM2 input capture 4 */
  127. /**
  128. * @}
  129. */
  130. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  131. * @{
  132. */
  133. #define LL_COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000U) /*!< 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 */
  134. #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_COMP1POLARITY) /*!< 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 */
  135. /**
  136. * @}
  137. */
  138. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  139. * @{
  140. */
  141. #define LL_COMP_OUTPUT_LEVEL_LOW ((uint32_t)0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  142. #define LL_COMP_OUTPUT_LEVEL_HIGH ((uint32_t)0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  147. * @note Only COMP IP HW delays are defined in COMP LL driver driver,
  148. * not timeout values.
  149. * For details on delays values, refer to descriptions in source code
  150. * above each literal definition.
  151. * @{
  152. */
  153. /* Delay for comparator startup time. */
  154. /* Note: Delay required to reach propagation delay specification. */
  155. /* Literal set to maximum value (refer to device datasheet, */
  156. /* parameter "tSTART"). */
  157. /* Unit: us */
  158. #define LL_COMP_DELAY_STARTUP_US ((uint32_t) 25U) /*!< Delay for COMP startup time */
  159. /* Delay for comparator voltage scaler stabilization time */
  160. /* (voltage from VrefInt, delay based on VrefInt startup time). */
  161. /* Literal set to maximum value (refer to device datasheet, */
  162. /* parameter "TVREFINT"). */
  163. /* Unit: us */
  164. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t)3000U) /*!< Delay for COMP voltage scaler stabilization time */
  165. /**
  166. * @}
  167. */
  168. /**
  169. * @}
  170. */
  171. /* Exported macro ------------------------------------------------------------*/
  172. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  173. * @{
  174. */
  175. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  176. * @{
  177. */
  178. /**
  179. * @brief Write a value in COMP register
  180. * @param __INSTANCE__ comparator instance
  181. * @param __REG__ Register to be written
  182. * @param __VALUE__ Value to be written in the register
  183. * @retval None
  184. */
  185. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  186. /**
  187. * @brief Read a value in COMP register
  188. * @param __INSTANCE__ comparator instance
  189. * @param __REG__ Register to be read
  190. * @retval Register value
  191. */
  192. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  193. /**
  194. * @}
  195. */
  196. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  197. * @{
  198. */
  199. /**
  200. * @brief Helper macro to select the COMP common instance
  201. * to which is belonging the selected COMP instance.
  202. * @note COMP common register instance can be used to
  203. * set parameters common to several COMP instances.
  204. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  205. * @param __COMPx__ COMP instance
  206. * @retval COMP common instance or value "0" if there is no COMP common instance.
  207. */
  208. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  209. (COMP12_COMMON)
  210. /**
  211. * @}
  212. */
  213. /**
  214. * @}
  215. */
  216. /* Exported functions --------------------------------------------------------*/
  217. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  218. * @{
  219. */
  220. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  221. * @{
  222. */
  223. /**
  224. * @brief Set window mode of a pair of comparators instances
  225. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  226. * @rmtoll COMP1_CSR COMP1WM LL_COMP_SetCommonWindowMode
  227. * @param COMPxy_COMMON Comparator common instance
  228. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  229. * @param WindowMode This parameter can be one of the following values:
  230. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  231. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  232. * @retval None
  233. */
  234. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  235. {
  236. MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_COMP1WM, WindowMode);
  237. }
  238. /**
  239. * @brief Get window mode of a pair of comparators instances
  240. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  241. * @rmtoll COMP1_CSR COMP1WM LL_COMP_GetCommonWindowMode
  242. * @param COMPxy_COMMON Comparator common instance
  243. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  244. * @retval Returned value can be one of the following values:
  245. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  246. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  247. */
  248. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  249. {
  250. return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_COMP1WM));
  251. }
  252. /**
  253. * @}
  254. */
  255. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  256. * @{
  257. */
  258. /**
  259. * @brief Set comparator instance operating mode to adjust power and speed.
  260. * @rmtoll COMP2_CSR COMP2SPEED LL_COMP_SetPowerMode
  261. * @param COMPx Comparator instance
  262. * @param PowerMode This parameter can be one of the following values:
  263. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  264. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  265. *
  266. * (1) Available only on COMP instance: COMP2.
  267. * @retval None
  268. */
  269. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  270. {
  271. MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2SPEED, PowerMode);
  272. }
  273. /**
  274. * @brief Get comparator instance operating mode to adjust power and speed.
  275. * @note Available only on COMP instance: COMP2.
  276. * @rmtoll COMP2_CSR COMP2SPEED LL_COMP_GetPowerMode\n
  277. * @param COMPx Comparator instance
  278. * @retval Returned value can be one of the following values:
  279. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED (1)
  280. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER (1)
  281. *
  282. * (1) Available only on COMP instance: COMP2.
  283. */
  284. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  285. {
  286. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2SPEED));
  287. }
  288. /**
  289. * @}
  290. */
  291. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  292. * @{
  293. */
  294. /**
  295. * @brief Set comparator inputs minus (inverting) and plus (non-inverting).
  296. * @note This function shall only be used for COMP2.
  297. * For setting COMP1 input it is recommended to use LL_COMP_SetInputMinus()
  298. * Plus (non-inverting) input is not configurable on COMP1.
  299. * Using this function for COMP1 will corrupt COMP1WM register
  300. * @note On this STM32 serie, specificity if using COMP instance COMP2
  301. * with COMP input based on VrefInt (VrefInt or subdivision
  302. * of VrefInt): scaler bridge is based on VrefInt and requires
  303. * to enable path from VrefInt (refer to literal
  304. * SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP).
  305. * @rmtoll COMP2_CSR COMP2INNSEL LL_COMP_ConfigInputs\n
  306. * COMP2_CSR COMP2INPSEL LL_COMP_ConfigInputs
  307. * @param COMPx Comparator instance
  308. * @param InputMinus This parameter can be one of the following values:
  309. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  310. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  311. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  312. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  313. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  314. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  315. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  316. * @arg @ref LL_COMP_INPUT_MINUS_IO2
  317. * @param InputPlus This parameter can be one of the following values:
  318. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
  319. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
  320. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
  321. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
  322. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  323. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
  324. *
  325. * (1) Available only on COMP instance: COMP2.
  326. * (2) Available only on devices STM32L0 category 1.
  327. * @retval None
  328. */
  329. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  330. {
  331. MODIFY_REG(COMPx->CSR,
  332. COMP_CSR_COMP2INNSEL | COMP_CSR_COMP2INPSEL,
  333. InputMinus | InputPlus);
  334. }
  335. /**
  336. * @brief Set comparator input plus (non-inverting).
  337. * @note Only COMP2 allows to set the input plus (non-inverting).
  338. * For COMP1 it is always PA1 IO, except when Windows Mode is selected.
  339. * @rmtoll COMP2_CSR COMP2INPSEL LL_COMP_SetInputPlus
  340. * @param COMPx Comparator instance
  341. * @param InputPlus This parameter can be one of the following values:
  342. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
  343. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
  344. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
  345. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
  346. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  347. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
  348. *
  349. * (1) Available only on COMP instance: COMP2.
  350. * (2) Available only on devices STM32L0 category 1.
  351. * @retval None
  352. */
  353. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  354. {
  355. MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2INPSEL, InputPlus);
  356. }
  357. /**
  358. * @brief Get comparator input plus (non-inverting).
  359. * @note Only COMP2 allows to set the input plus (non-inverting).
  360. * For COMP1 it is always PA1 IO, except when Windows Mode is selected.
  361. * @rmtoll COMP2_CSR COMP2INPSEL LL_COMP_GetInputPlus
  362. * @param COMPx Comparator instance
  363. * @retval Returned value can be one of the following values:
  364. * @arg @ref LL_COMP_INPUT_PLUS_IO1 (1)
  365. * @arg @ref LL_COMP_INPUT_PLUS_IO2 (1)
  366. * @arg @ref LL_COMP_INPUT_PLUS_IO3 (1)
  367. * @arg @ref LL_COMP_INPUT_PLUS_IO4 (1)
  368. * @arg @ref LL_COMP_INPUT_PLUS_IO5 (1)
  369. * @arg @ref LL_COMP_INPUT_PLUS_IO6 (1)(2)
  370. *
  371. * (1) Available only on COMP instance: COMP2.
  372. * (2) Available only on devices STM32L0 category 1.
  373. */
  374. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  375. {
  376. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2INPSEL));
  377. }
  378. /**
  379. * @brief Set comparator input minus (inverting).
  380. * @note In case of comparator input selected to be connected to IO:
  381. * GPIO pins are specific to each comparator instance.
  382. * Refer to description of parameters or to reference manual.
  383. * @note On this STM32 serie, specificity if using COMP instance COMP2
  384. * with COMP input based on VrefInt (VrefInt or subdivision
  385. * of VrefInt): scaler bridge is based on VrefInt and requires
  386. * to enable path from VrefInt (refer to literal
  387. * SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP).
  388. * @rmtoll COMP1_CSR COMP1INNSEL LL_COMP_SetInputMinus\n
  389. * COMP2_CSR COMP2INNSEL LL_COMP_SetInputMinus
  390. * @param COMPx Comparator instance
  391. * @param InputMinus This parameter can be one of the following values:
  392. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  393. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  394. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  395. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  396. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (*)
  397. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (*)
  398. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (*)
  399. * @arg @ref LL_COMP_INPUT_MINUS_IO2 (*)
  400. *
  401. * (*) Available only on COMP instance: COMP2.
  402. * @retval None
  403. */
  404. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  405. {
  406. MODIFY_REG(COMPx->CSR, COMP_CSR_COMP2INNSEL, InputMinus);
  407. }
  408. /**
  409. * @brief Get comparator input minus (inverting).
  410. * @note In case of comparator input selected to be connected to IO:
  411. * GPIO pins are specific to each comparator instance.
  412. * Refer to description of parameters or to reference manual.
  413. * @rmtoll COMP1_CSR COMP1INNSEL LL_COMP_GetInputMinus\n
  414. * COMP2_CSR COMP2INNSEL LL_COMP_GetInputMinus
  415. * @param COMPx Comparator instance
  416. * @retval Returned value can be one of the following values:
  417. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  418. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  419. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  420. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  421. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT (*)
  422. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT (*)
  423. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT (*)
  424. * @arg @ref LL_COMP_INPUT_MINUS_IO2 (*)
  425. *
  426. * (*) Available only on COMP instance: COMP2.
  427. */
  428. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  429. {
  430. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMP2INNSEL));
  431. }
  432. /**
  433. * @}
  434. */
  435. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  436. * @{
  437. */
  438. /**
  439. * @brief Set comparator output LPTIM.
  440. * @rmtoll COMP1_CSR COMP1LPTIMIN1 LL_COMP_SetOutputLPTIM\n
  441. * COMP2_CSR COMP2LPTIMIN1 LL_COMP_SetOutputLPTIM\n
  442. * COMP2_CSR COMP2LPTIMIN2 LL_COMP_SetOutputLPTIM
  443. * @param COMPx Comparator instance
  444. * @param OutputLptim This parameter can be one of the following values:
  445. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (*)
  446. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (**)
  447. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (**)
  448. *
  449. * (*) Available only on COMP instance: COMP1.\n
  450. * (**) Available only on COMP instance: COMP2.
  451. * @retval None
  452. */
  453. __STATIC_INLINE void LL_COMP_SetOutputLPTIM(COMP_TypeDef *COMPx, uint32_t OutputLptim)
  454. {
  455. MODIFY_REG(COMPx->CSR, (COMP_CSR_COMP1LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN2), OutputLptim);
  456. }
  457. /**
  458. * @brief Get comparator output LPTIM.
  459. * @rmtoll COMP1_CSR COMP1LPTIMIN1 LL_COMP_GetOutputLPTIM\n
  460. * COMP2_CSR COMP2LPTIMIN1 LL_COMP_GetOutputLPTIM\n
  461. * COMP2_CSR COMP2LPTIMIN2 LL_COMP_GetOutputLPTIM
  462. * @param COMPx Comparator instance
  463. * @retval Returned value can be one of the following values:
  464. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP1 (*)
  465. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN1_COMP2 (**)
  466. * @arg @ref LL_COMP_OUTPUT_LPTIM1_IN2_COMP2 (**)
  467. *
  468. * (*) Available only on COMP instance: COMP1.\n
  469. * (**) Available only on COMP instance: COMP2.
  470. */
  471. __STATIC_INLINE uint32_t LL_COMP_GetOutputLPTIM(COMP_TypeDef *COMPx)
  472. {
  473. return (uint32_t)(READ_BIT(COMPx->CSR, (COMP_CSR_COMP1LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN1 | COMP_CSR_COMP2LPTIM1IN2)));
  474. }
  475. /**
  476. * @brief Set comparator instance output polarity.
  477. * @rmtoll COMP COMP1POLARITY LL_COMP_SetOutputPolarity
  478. * @param COMPx Comparator instance
  479. * @param OutputPolarity This parameter can be one of the following values:
  480. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  481. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  482. * @retval None
  483. */
  484. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  485. {
  486. MODIFY_REG(COMPx->CSR, COMP_CSR_COMPxPOLARITY, OutputPolarity);
  487. }
  488. /**
  489. * @brief Get comparator instance output polarity.
  490. * @rmtoll COMP COMP1POLARITY LL_COMP_GetOutputPolarity
  491. * @param COMPx Comparator instance
  492. * @retval Returned value can be one of the following values:
  493. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  494. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  495. */
  496. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
  497. {
  498. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMPxPOLARITY));
  499. }
  500. /**
  501. * @}
  502. */
  503. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  504. * @{
  505. */
  506. /**
  507. * @brief Enable comparator instance.
  508. * @note After enable from off state, comparator requires a delay
  509. * to reach reach propagation delay specification.
  510. * Refer to device datasheet, parameter "tSTART".
  511. * @rmtoll COMP1_CSR COMP1EN LL_COMP_Enable\n
  512. * COMP2_CSR COMP2EN LL_COMP_Enable
  513. * @param COMPx Comparator instance
  514. * @retval None
  515. */
  516. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  517. {
  518. SET_BIT(COMPx->CSR, COMP_CSR_COMPxEN);
  519. }
  520. /**
  521. * @brief Disable comparator instance.
  522. * @rmtoll COMP1_CSR COMP1EN LL_COMP_Disable\n
  523. * COMP2_CSR COMP2EN LL_COMP_Disable
  524. * @param COMPx Comparator instance
  525. * @retval None
  526. */
  527. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  528. {
  529. CLEAR_BIT(COMPx->CSR, COMP_CSR_COMPxEN);
  530. }
  531. /**
  532. * @brief Get comparator enable state
  533. * (0: COMP is disabled, 1: COMP is enabled)
  534. * @rmtoll COMP1_CSR COMP1EN LL_COMP_IsEnabled\n
  535. * COMP2_CSR COMP2EN LL_COMP_IsEnabled
  536. * @param COMPx Comparator instance
  537. * @retval State of bit (1 or 0).
  538. */
  539. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  540. {
  541. return (READ_BIT(COMPx->CSR, COMP_CSR_COMPxEN) == (COMP_CSR_COMPxEN));
  542. }
  543. /**
  544. * @brief Lock comparator instance.
  545. * @note Once locked, comparator configuration can be accessed in read-only.
  546. * @note The only way to unlock the comparator is a device hardware reset.
  547. * @rmtoll COMP1_CSR COMP1LOCK LL_COMP_Lock\n
  548. * COMP2_CSR COMP2LOCK LL_COMP_Lock
  549. * @param COMPx Comparator instance
  550. * @retval None
  551. */
  552. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  553. {
  554. SET_BIT(COMPx->CSR, COMP_CSR_COMPxLOCK);
  555. }
  556. /**
  557. * @brief Get comparator lock state
  558. * (0: COMP is unlocked, 1: COMP is locked).
  559. * @note Once locked, comparator configuration can be accessed in read-only.
  560. * @note The only way to unlock the comparator is a device hardware reset.
  561. * @rmtoll COMP1_CSR COMP1LOCK LL_COMP_IsLocked\n
  562. * COMP2_CSR COMP2LOCK LL_COMP_IsLocked
  563. * @param COMPx Comparator instance
  564. * @retval State of bit (1 or 0).
  565. */
  566. __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
  567. {
  568. return (READ_BIT(COMPx->CSR, COMP_CSR_COMPxLOCK) == (COMP_CSR_COMPxLOCK));
  569. }
  570. /**
  571. * @brief Read comparator instance output level.
  572. * @note The comparator output level depends on the selected polarity
  573. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  574. * If the comparator polarity is not inverted:
  575. * - Comparator output is low when the input plus
  576. * is at a lower voltage than the input minus
  577. * - Comparator output is high when the input plus
  578. * is at a higher voltage than the input minus
  579. * If the comparator polarity is inverted:
  580. * - Comparator output is high when the input plus
  581. * is at a lower voltage than the input minus
  582. * - Comparator output is low when the input plus
  583. * is at a higher voltage than the input minus
  584. * @rmtoll COMP1_CSR COMP1VALUE LL_COMP_ReadOutputLevel\n
  585. * COMP2_CSR COMP2VALUE LL_COMP_ReadOutputLevel
  586. * @param COMPx Comparator instance
  587. * @retval Returned value can be one of the following values:
  588. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  589. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  590. */
  591. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  592. {
  593. return (uint32_t)(READ_BIT(COMPx->CSR, COMP_CSR_COMPxOUTVALUE)
  594. >> LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS);
  595. }
  596. /**
  597. * @}
  598. */
  599. #if defined(USE_FULL_LL_DRIVER)
  600. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  601. * @{
  602. */
  603. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  604. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  605. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  606. /**
  607. * @}
  608. */
  609. #endif /* USE_FULL_LL_DRIVER */
  610. /**
  611. * @}
  612. */
  613. /**
  614. * @}
  615. */
  616. #endif /* COMP1 || COMP2 */
  617. /**
  618. * @}
  619. */
  620. #ifdef __cplusplus
  621. }
  622. #endif
  623. #endif /* __STM32L0xx_LL_COMP_H */
  624. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/