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.
 
 
 

771 lines
31 KiB

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