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.
 
 
 

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