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.
 
 
 

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