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.
 
 
 

848 lines
36 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_ll_comp.h
  4. * @author MCD Application Team
  5. * @brief Header file of COMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F0xx_LL_COMP_H
  37. #define __STM32F0xx_LL_COMP_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx.h"
  43. /** @addtogroup STM32F0xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (COMP1) || defined (COMP2)
  47. /** @defgroup COMP_LL COMP
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. /** @defgroup COMP_LL_Private_Constants COMP Private Constants
  54. * @{
  55. */
  56. /* Differentiation between COMP instances */
  57. /* Note: Value not corresponding to a register offset since both */
  58. /* COMP instances are sharing the same register) . */
  59. #define COMPX_BASE COMP_BASE
  60. #define COMPX (COMP1 - COMP2)
  61. /* COMP registers bits positions */
  62. #define LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS ((uint32_t)14U) /* Value equivalent to POSITION_VAL(COMP_CSR_COMP1OUT) */
  63. /**
  64. * @}
  65. */
  66. /* Private macros ------------------------------------------------------------*/
  67. /** @defgroup COMP_LL_Private_Macros COMP Private Macros
  68. * @{
  69. */
  70. /**
  71. * @brief Driver macro reserved for internal use: if COMP instance selected
  72. * is odd (COMP1, COMP3, ...), return value '1', else return '0'.
  73. * @param __COMP_INSTANCE__ COMP instance
  74. * @retval If COMP instance is odd, value '1'. Else, value '0'.
  75. */
  76. #define __COMP_IS_INSTANCE_ODD(__COMP_INSTANCE__) \
  77. ((~(((uint32_t)(__COMP_INSTANCE__) - COMP_BASE) >> 1U)) & 0x00000001)
  78. /**
  79. * @brief Driver macro reserved for internal use: if COMP instance selected
  80. * is even (COMP2, COMP4, ...), return value '1', else return '0'.
  81. * @param __COMP_INSTANCE__ COMP instance
  82. * @retval If COMP instance is even, value '1'. Else, value '0'.
  83. */
  84. #define __COMP_IS_INSTANCE_EVEN(__COMP_INSTANCE__) \
  85. (((uint32_t)(__COMP_INSTANCE__) - COMP_BASE) >> 1U)
  86. /**
  87. * @brief Driver macro reserved for internal use: from COMP instance
  88. * selected, set offset of bits into COMP register.
  89. * @note Since both COMP instances are sharing the same register
  90. * with 2 area of bits with an offset of 16 bits, this function
  91. * returns value "0" if COMP1 is selected and "16" if COMP2 is
  92. * selected.
  93. * @param __COMP_INSTANCE__ COMP instance
  94. * @retval Bits offset in register 32 bits
  95. */
  96. #define __COMP_BITOFFSET_INSTANCE(__COMP_INSTANCE__) \
  97. (((uint32_t)(__COMP_INSTANCE__) - COMP_BASE) << 3U)
  98. /**
  99. * @}
  100. */
  101. /* Exported types ------------------------------------------------------------*/
  102. #if defined(USE_FULL_LL_DRIVER)
  103. /** @defgroup COMP_LL_ES_INIT COMP Exported Init structure
  104. * @{
  105. */
  106. /**
  107. * @brief Structure definition of some features of COMP instance.
  108. */
  109. typedef struct
  110. {
  111. uint32_t PowerMode; /*!< Set comparator operating mode to adjust power and speed.
  112. This parameter can be a value of @ref COMP_LL_EC_POWERMODE
  113. This feature can be modified afterwards using unitary function @ref LL_COMP_SetPowerMode(). */
  114. uint32_t InputPlus; /*!< Set comparator input plus (non-inverting input).
  115. This parameter can be a value of @ref COMP_LL_EC_INPUT_PLUS
  116. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputPlus(). */
  117. uint32_t InputMinus; /*!< Set comparator input minus (inverting input).
  118. This parameter can be a value of @ref COMP_LL_EC_INPUT_MINUS
  119. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputMinus(). */
  120. uint32_t InputHysteresis; /*!< Set comparator hysteresis mode of the input minus.
  121. This parameter can be a value of @ref COMP_LL_EC_INPUT_HYSTERESIS
  122. This feature can be modified afterwards using unitary function @ref LL_COMP_SetInputHysteresis(). */
  123. uint32_t OutputSelection; /*!< Set comparator output selection.
  124. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_SELECTION
  125. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputSelection(). */
  126. uint32_t OutputPolarity; /*!< Set comparator output polarity.
  127. This parameter can be a value of @ref COMP_LL_EC_OUTPUT_POLARITY
  128. This feature can be modified afterwards using unitary function @ref LL_COMP_SetOutputPolarity(). */
  129. } LL_COMP_InitTypeDef;
  130. /**
  131. * @}
  132. */
  133. #endif /* USE_FULL_LL_DRIVER */
  134. /* Exported constants --------------------------------------------------------*/
  135. /** @defgroup COMP_LL_Exported_Constants COMP Exported Constants
  136. * @{
  137. */
  138. /** @defgroup COMP_LL_EC_COMMON_WINDOWMODE Comparator common modes - Window mode
  139. * @{
  140. */
  141. #define LL_COMP_WINDOWMODE_DISABLE ((uint32_t)0x00000000U) /*!< Window mode disable: Comparators 1 and 2 are independent */
  142. #define LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON (COMP_CSR_WNDWEN) /*!< 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). */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup COMP_LL_EC_POWERMODE Comparator modes - Power mode
  147. * @{
  148. */
  149. #define LL_COMP_POWERMODE_HIGHSPEED ((uint32_t)0x00000000U) /*!< COMP power mode to high speed */
  150. #define LL_COMP_POWERMODE_MEDIUMSPEED (COMP_CSR_COMP1MODE_0) /*!< COMP power mode to medium speed */
  151. #define LL_COMP_POWERMODE_LOWPOWER (COMP_CSR_COMP1MODE_1) /*!< COMP power mode to low power */
  152. #define LL_COMP_POWERMODE_ULTRALOWPOWER (COMP_CSR_COMP1MODE_1 | COMP_CSR_COMP1MODE_0) /*!< COMP power mode to ultra-low power */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup COMP_LL_EC_INPUT_PLUS Comparator inputs - Input plus (input non-inverting) selection
  157. * @{
  158. */
  159. #define LL_COMP_INPUT_PLUS_IO1 ((uint32_t)0x00000000U) /*!< Comparator input plus connected to IO1 (pin PA1 for COMP1, pin PA3 for COMP2) */
  160. #define LL_COMP_INPUT_PLUS_DAC1_CH1 (COMP_CSR_COMP1SW1) /*!< Comparator input plus connected to DAC1 channel 1 (DAC_OUT1), through dedicated switch (Note: this switch is solely intended to redirect signals onto high impedance input, such as COMP1 input plus (highly resistive switch)) (specific to COMP instance: COMP1) */
  161. /**
  162. * @}
  163. */
  164. /** @defgroup COMP_LL_EC_INPUT_MINUS Comparator inputs - Input minus (input inverting) selection
  165. * @{
  166. */
  167. #define LL_COMP_INPUT_MINUS_1_4VREFINT ((uint32_t)0x00000000U) /*!< Comparator input minus connected to 1/4 VrefInt */
  168. #define LL_COMP_INPUT_MINUS_1_2VREFINT ( COMP_CSR_COMP1INSEL_0) /*!< Comparator input minus connected to 1/2 VrefInt */
  169. #define LL_COMP_INPUT_MINUS_3_4VREFINT ( COMP_CSR_COMP1INSEL_1 ) /*!< Comparator input minus connected to 3/4 VrefInt */
  170. #define LL_COMP_INPUT_MINUS_VREFINT ( COMP_CSR_COMP1INSEL_1 | COMP_CSR_COMP1INSEL_0) /*!< Comparator input minus connected to VrefInt */
  171. #define LL_COMP_INPUT_MINUS_DAC1_CH1 (COMP_CSR_COMP1INSEL_2 ) /*!< Comparator input minus connected to DAC1 channel 1 (DAC_OUT1) */
  172. #define LL_COMP_INPUT_MINUS_DAC1_CH2 (COMP_CSR_COMP1INSEL_2 | COMP_CSR_COMP1INSEL_0) /*!< Comparator input minus connected to DAC1 channel 2 (DAC_OUT2) */
  173. #define LL_COMP_INPUT_MINUS_IO1 (COMP_CSR_COMP1INSEL_2 | COMP_CSR_COMP1INSEL_1 ) /*!< Comparator input minus connected to IO1 (pin PA0 for COMP1, pin PA2 for COMP2) */
  174. /**
  175. * @}
  176. */
  177. /** @defgroup COMP_LL_EC_INPUT_HYSTERESIS Comparator input - Hysteresis
  178. * @{
  179. */
  180. #define LL_COMP_HYSTERESIS_NONE ((uint32_t)0x00000000U) /*!< No hysteresis */
  181. #define LL_COMP_HYSTERESIS_LOW ( COMP_CSR_COMP1HYST_0) /*!< Hysteresis level low */
  182. #define LL_COMP_HYSTERESIS_MEDIUM (COMP_CSR_COMP1HYST_1 ) /*!< Hysteresis level medium */
  183. #define LL_COMP_HYSTERESIS_HIGH (COMP_CSR_COMP1HYST_1 | COMP_CSR_COMP1HYST_0) /*!< Hysteresis level high */
  184. /**
  185. * @}
  186. */
  187. /** @defgroup COMP_LL_EC_OUTPUT_SELECTION Comparator output - Output selection
  188. * @{
  189. */
  190. /* Note: Output redirection is common for COMP1 and COMP2 */
  191. #define LL_COMP_OUTPUT_NONE ((uint32_t)0x00000000U) /*!< COMP output is not connected to other peripherals (except GPIO and EXTI that are always connected to COMP output) */
  192. #define LL_COMP_OUTPUT_TIM1_BKIN (COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 break input (BKIN) */
  193. #define LL_COMP_OUTPUT_TIM1_IC1 (COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM1 input capture 1 */
  194. #define LL_COMP_OUTPUT_TIM1_OCCLR (COMP_CSR_COMP1OUTSEL_1 | COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM1 OCREF clear */
  195. #define LL_COMP_OUTPUT_TIM2_IC4 (COMP_CSR_COMP1OUTSEL_2) /*!< COMP output connected to TIM2 input capture 4 */
  196. #define LL_COMP_OUTPUT_TIM2_OCCLR (COMP_CSR_COMP1OUTSEL_2 | COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM2 OCREF clear */
  197. #define LL_COMP_OUTPUT_TIM3_IC1 (COMP_CSR_COMP1OUTSEL_2 | COMP_CSR_COMP1OUTSEL_1) /*!< COMP output connected to TIM3 input capture 1 */
  198. #define LL_COMP_OUTPUT_TIM3_OCCLR (COMP_CSR_COMP1OUTSEL_2 | COMP_CSR_COMP1OUTSEL_1 | COMP_CSR_COMP1OUTSEL_0) /*!< COMP output connected to TIM3 OCREF clear */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup COMP_LL_EC_OUTPUT_POLARITY Comparator output - Output polarity
  203. * @{
  204. */
  205. #define LL_COMP_OUTPUTPOL_NONINVERTED ((uint32_t)0x00000000U) /*!< COMP output polarity is not inverted: comparator output is high when the plus (non-inverting) input is at a higher voltage than the minus (inverting) input */
  206. #define LL_COMP_OUTPUTPOL_INVERTED (COMP_CSR_COMP1POL) /*!< 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 */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup COMP_LL_EC_OUTPUT_LEVEL Comparator output - Output level
  211. * @{
  212. */
  213. #define LL_COMP_OUTPUT_LEVEL_LOW ((uint32_t)0x00000000U) /*!< Comparator output level low (if the polarity is not inverted, otherwise to be complemented) */
  214. #define LL_COMP_OUTPUT_LEVEL_HIGH ((uint32_t)0x00000001U) /*!< Comparator output level high (if the polarity is not inverted, otherwise to be complemented) */
  215. /**
  216. * @}
  217. */
  218. /** @defgroup COMP_LL_EC_HW_DELAYS Definitions of COMP hardware constraints delays
  219. * @note Only COMP IP HW delays are defined in COMP LL driver driver,
  220. * not timeout values.
  221. * For details on delays values, refer to descriptions in source code
  222. * above each literal definition.
  223. * @{
  224. */
  225. /* Delay for comparator startup time. */
  226. /* Note: Delay required to reach propagation delay specification. */
  227. /* Literal set to maximum value (refer to device datasheet, */
  228. /* parameter "tSTART"). */
  229. /* Unit: us */
  230. #define LL_COMP_DELAY_STARTUP_US ((uint32_t) 60U) /*!< Delay for COMP startup time */
  231. /* Delay for comparator voltage scaler stabilization time */
  232. /* (voltage from VrefInt, delay based on VrefInt startup time). */
  233. /* Literal set to maximum value (refer to device datasheet, */
  234. /* parameter "tS_SC"). */
  235. /* Unit: us */
  236. #define LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t) 200U) /*!< Delay for COMP voltage scaler stabilization time */
  237. /**
  238. * @}
  239. */
  240. /**
  241. * @}
  242. */
  243. /* Exported macro ------------------------------------------------------------*/
  244. /** @defgroup COMP_LL_Exported_Macros COMP Exported Macros
  245. * @{
  246. */
  247. /** @defgroup COMP_LL_EM_WRITE_READ Common write and read registers macro
  248. * @{
  249. */
  250. /**
  251. * @brief Write a value in COMP register
  252. * @param __INSTANCE__ comparator instance
  253. * @param __REG__ Register to be written
  254. * @param __VALUE__ Value to be written in the register
  255. * @retval None
  256. */
  257. #define LL_COMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  258. /**
  259. * @brief Read a value in COMP register
  260. * @param __INSTANCE__ comparator instance
  261. * @param __REG__ Register to be read
  262. * @retval Register value
  263. */
  264. #define LL_COMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  265. /**
  266. * @}
  267. */
  268. /** @defgroup COMP_LL_EM_HELPER_MACRO COMP helper macro
  269. * @{
  270. */
  271. /**
  272. * @brief Helper macro to select the COMP common instance
  273. * to which is belonging the selected COMP instance.
  274. * @note COMP common register instance can be used to
  275. * set parameters common to several COMP instances.
  276. * Refer to functions having argument "COMPxy_COMMON" as parameter.
  277. * @param __COMPx__ COMP instance
  278. * @retval COMP common instance or value "0" if there is no COMP common instance.
  279. */
  280. #define __LL_COMP_COMMON_INSTANCE(__COMPx__) \
  281. (COMP12_COMMON)
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. /* Exported functions --------------------------------------------------------*/
  289. /** @defgroup COMP_LL_Exported_Functions COMP Exported Functions
  290. * @{
  291. */
  292. /** @defgroup COMP_LL_EF_Configuration_comparator_common Configuration of COMP hierarchical scope: common to several COMP instances
  293. * @{
  294. */
  295. /**
  296. * @brief Set window mode of a pair of comparators instances
  297. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  298. * @rmtoll CSR WNDWEN LL_COMP_SetCommonWindowMode
  299. * @param COMPxy_COMMON Comparator common instance
  300. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  301. * @param WindowMode This parameter can be one of the following values:
  302. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  303. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  304. * @retval None
  305. */
  306. __STATIC_INLINE void LL_COMP_SetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON, uint32_t WindowMode)
  307. {
  308. MODIFY_REG(COMPxy_COMMON->CSR, COMP_CSR_WNDWEN, WindowMode);
  309. }
  310. /**
  311. * @brief Get window mode of a pair of comparators instances
  312. * (2 consecutive COMP instances odd and even COMP<x> and COMP<x+1>).
  313. * @rmtoll CSR WNDWEN LL_COMP_GetCommonWindowMode
  314. * @param COMPxy_COMMON Comparator common instance
  315. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_COMP_COMMON_INSTANCE() )
  316. * @retval Returned value can be one of the following values:
  317. * @arg @ref LL_COMP_WINDOWMODE_DISABLE
  318. * @arg @ref LL_COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON
  319. */
  320. __STATIC_INLINE uint32_t LL_COMP_GetCommonWindowMode(COMP_Common_TypeDef *COMPxy_COMMON)
  321. {
  322. return (uint32_t)(READ_BIT(COMPxy_COMMON->CSR, COMP_CSR_WNDWEN));
  323. }
  324. /**
  325. * @}
  326. */
  327. /** @defgroup COMP_LL_EF_Configuration_comparator_modes Configuration of comparator modes
  328. * @{
  329. */
  330. /**
  331. * @brief Set comparator instance operating mode to adjust power and speed.
  332. * @rmtoll CSR COMP1MODE LL_COMP_SetPowerMode\n
  333. * COMP2MODE LL_COMP_SetPowerMode
  334. * @param COMPx Comparator instance
  335. * @param PowerMode This parameter can be one of the following values:
  336. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  337. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  338. * @arg @ref LL_COMP_POWERMODE_LOWPOWER
  339. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
  340. * @retval None
  341. */
  342. __STATIC_INLINE void LL_COMP_SetPowerMode(COMP_TypeDef *COMPx, uint32_t PowerMode)
  343. {
  344. MODIFY_REG(COMP->CSR,
  345. COMP_CSR_COMP1MODE << __COMP_BITOFFSET_INSTANCE(COMPx),
  346. PowerMode << __COMP_BITOFFSET_INSTANCE(COMPx) );
  347. }
  348. /**
  349. * @brief Get comparator instance operating mode to adjust power and speed.
  350. * @rmtoll CSR COMP1MODE LL_COMP_GetPowerMode\n
  351. * COMP2MODE LL_COMP_GetPowerMode
  352. * @param COMPx Comparator instance
  353. * @retval Returned value can be one of the following values:
  354. * @arg @ref LL_COMP_POWERMODE_HIGHSPEED
  355. * @arg @ref LL_COMP_POWERMODE_MEDIUMSPEED
  356. * @arg @ref LL_COMP_POWERMODE_LOWPOWER
  357. * @arg @ref LL_COMP_POWERMODE_ULTRALOWPOWER
  358. */
  359. __STATIC_INLINE uint32_t LL_COMP_GetPowerMode(COMP_TypeDef *COMPx)
  360. {
  361. return (uint32_t)(READ_BIT(COMP->CSR,
  362. COMP_CSR_COMP1MODE << __COMP_BITOFFSET_INSTANCE(COMPx))
  363. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  364. );
  365. }
  366. /**
  367. * @}
  368. */
  369. /** @defgroup COMP_LL_EF_Configuration_comparator_inputs Configuration of comparator inputs
  370. * @{
  371. */
  372. /**
  373. * @brief Set comparator inputs minus (inverting) and 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 COMP1INSEL LL_COMP_ConfigInputs\n
  378. * CSR COMP2INSEL LL_COMP_ConfigInputs\n
  379. * CSR COMP1SW1 LL_COMP_ConfigInputs
  380. * @param COMPx Comparator instance
  381. * @param InputMinus This parameter can be one of the following values:
  382. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  383. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  384. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  385. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  386. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  387. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  388. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  389. * @param InputPlus This parameter can be one of the following values:
  390. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  391. * @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1 (1)
  392. *
  393. * (1) Parameter available only on COMP instance: COMP1.
  394. * @retval None
  395. */
  396. __STATIC_INLINE void LL_COMP_ConfigInputs(COMP_TypeDef *COMPx, uint32_t InputMinus, uint32_t InputPlus)
  397. {
  398. /* Note: Connection switch is applicable only to COMP instance COMP1, */
  399. /* therefore if COMP2 is selected the equivalent bit is */
  400. /* kept unmodified. */
  401. MODIFY_REG(COMP->CSR,
  402. (COMP_CSR_COMP1INSEL | (COMP_CSR_COMP1SW1 * __COMP_IS_INSTANCE_ODD(COMPx))) << __COMP_BITOFFSET_INSTANCE(COMPx),
  403. (InputMinus | InputPlus) << __COMP_BITOFFSET_INSTANCE(COMPx) );
  404. }
  405. /**
  406. * @brief Set comparator input plus (non-inverting).
  407. * @note In case of comparator input selected to be connected to IO:
  408. * GPIO pins are specific to each comparator instance.
  409. * Refer to description of parameters or to reference manual.
  410. * @rmtoll CSR COMP1INSEL LL_COMP_SetInputPlus\n
  411. * CSR COMP2INSEL LL_COMP_SetInputPlus
  412. * @param COMPx Comparator instance
  413. * @param InputPlus This parameter can be one of the following values:
  414. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  415. * @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1 (1)
  416. *
  417. * (1) Parameter available only on COMP instance: COMP1.
  418. * @retval None
  419. */
  420. __STATIC_INLINE void LL_COMP_SetInputPlus(COMP_TypeDef *COMPx, uint32_t InputPlus)
  421. {
  422. /* Note: Connection switch is applicable only to COMP instance COMP1, */
  423. /* therefore if COMP2 is selected the equivalent bit is */
  424. /* kept unmodified. */
  425. MODIFY_REG(COMP->CSR,
  426. (COMP_CSR_COMP1SW1 * __COMP_IS_INSTANCE_ODD(COMPx)) << __COMP_BITOFFSET_INSTANCE(COMPx),
  427. InputPlus << __COMP_BITOFFSET_INSTANCE(COMPx) );
  428. }
  429. /**
  430. * @brief Get comparator input plus (non-inverting).
  431. * @note In case of comparator input selected to be connected to IO:
  432. * GPIO pins are specific to each comparator instance.
  433. * Refer to description of parameters or to reference manual.
  434. * @rmtoll CSR COMP1INSEL LL_COMP_GetInputPlus\n
  435. * CSR COMP2INSEL LL_COMP_GetInputPlus
  436. * @param COMPx Comparator instance
  437. * @retval Returned value can be one of the following values:
  438. * @arg @ref LL_COMP_INPUT_PLUS_IO1
  439. * @arg @ref LL_COMP_INPUT_PLUS_DAC1_CH1 (1)
  440. *
  441. * (1) Parameter available only on COMP instance: COMP1.
  442. */
  443. __STATIC_INLINE uint32_t LL_COMP_GetInputPlus(COMP_TypeDef *COMPx)
  444. {
  445. /* Note: Connection switch is applicable only to COMP instance COMP1, */
  446. /* therefore is COMP2 is selected the returned value will be null. */
  447. return (uint32_t)(READ_BIT(COMP->CSR,
  448. COMP_CSR_COMP1SW1 << __COMP_BITOFFSET_INSTANCE(COMPx))
  449. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  450. );
  451. }
  452. /**
  453. * @brief Set comparator input minus (inverting).
  454. * @note In case of comparator input selected to be connected to IO:
  455. * GPIO pins are specific to each comparator instance.
  456. * Refer to description of parameters or to reference manual.
  457. * @rmtoll CSR COMP1SW1 LL_COMP_SetInputMinus
  458. * @param COMPx Comparator instance
  459. * @param InputMinus This parameter can be one of the following values:
  460. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  461. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  462. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  463. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  464. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  465. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  466. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  467. * @retval None
  468. */
  469. __STATIC_INLINE void LL_COMP_SetInputMinus(COMP_TypeDef *COMPx, uint32_t InputMinus)
  470. {
  471. MODIFY_REG(COMP->CSR,
  472. COMP_CSR_COMP1INSEL << __COMP_BITOFFSET_INSTANCE(COMPx),
  473. InputMinus << __COMP_BITOFFSET_INSTANCE(COMPx) );
  474. }
  475. /**
  476. * @brief Get comparator input minus (inverting).
  477. * @note In case of comparator input selected to be connected to IO:
  478. * GPIO pins are specific to each comparator instance.
  479. * Refer to description of parameters or to reference manual.
  480. * @rmtoll CSR COMP1SW1 LL_COMP_GetInputMinus
  481. * @param COMPx Comparator instance
  482. * @retval Returned value can be one of the following values:
  483. * @arg @ref LL_COMP_INPUT_MINUS_1_4VREFINT
  484. * @arg @ref LL_COMP_INPUT_MINUS_1_2VREFINT
  485. * @arg @ref LL_COMP_INPUT_MINUS_3_4VREFINT
  486. * @arg @ref LL_COMP_INPUT_MINUS_VREFINT
  487. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH1
  488. * @arg @ref LL_COMP_INPUT_MINUS_DAC1_CH2
  489. * @arg @ref LL_COMP_INPUT_MINUS_IO1
  490. */
  491. __STATIC_INLINE uint32_t LL_COMP_GetInputMinus(COMP_TypeDef *COMPx)
  492. {
  493. return (uint32_t)(READ_BIT(COMP->CSR,
  494. COMP_CSR_COMP1INSEL << __COMP_BITOFFSET_INSTANCE(COMPx))
  495. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  496. );
  497. }
  498. /**
  499. * @brief Set comparator instance hysteresis mode of the input minus (inverting input).
  500. * @rmtoll CSR COMP1HYST LL_COMP_SetInputHysteresis\n
  501. * COMP2HYST LL_COMP_SetInputHysteresis
  502. * @param COMPx Comparator instance
  503. * @param InputHysteresis This parameter can be one of the following values:
  504. * @arg @ref LL_COMP_HYSTERESIS_NONE
  505. * @arg @ref LL_COMP_HYSTERESIS_LOW
  506. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  507. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  508. * @retval None
  509. */
  510. __STATIC_INLINE void LL_COMP_SetInputHysteresis(COMP_TypeDef *COMPx, uint32_t InputHysteresis)
  511. {
  512. MODIFY_REG(COMP->CSR,
  513. COMP_CSR_COMP1HYST << __COMP_BITOFFSET_INSTANCE(COMPx),
  514. InputHysteresis << __COMP_BITOFFSET_INSTANCE(COMPx) );
  515. }
  516. /**
  517. * @brief Get comparator instance hysteresis mode of the minus (inverting) input.
  518. * @rmtoll CSR COMP1HYST LL_COMP_GetInputHysteresis\n
  519. * COMP2HYST LL_COMP_GetInputHysteresis
  520. * @param COMPx Comparator instance
  521. * @retval Returned value can be one of the following values:
  522. * @arg @ref LL_COMP_HYSTERESIS_NONE
  523. * @arg @ref LL_COMP_HYSTERESIS_LOW
  524. * @arg @ref LL_COMP_HYSTERESIS_MEDIUM
  525. * @arg @ref LL_COMP_HYSTERESIS_HIGH
  526. */
  527. __STATIC_INLINE uint32_t LL_COMP_GetInputHysteresis(COMP_TypeDef *COMPx)
  528. {
  529. return (uint32_t)(READ_BIT(COMP->CSR,
  530. COMP_CSR_COMP1HYST << __COMP_BITOFFSET_INSTANCE(COMPx))
  531. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  532. );
  533. }
  534. /**
  535. * @}
  536. */
  537. /** @defgroup COMP_LL_EF_Configuration_comparator_output Configuration of comparator output
  538. * @{
  539. */
  540. /**
  541. * @brief Set comparator output selection.
  542. * @note Availability of parameters of output selection to timer
  543. * depends on timers availability on the selected device.
  544. * @rmtoll CSR COMP1OUTSEL LL_COMP_SetOutputSelection\n
  545. * COMP2OUTSEL LL_COMP_SetOutputSelection
  546. * @param COMPx Comparator instance
  547. * @param OutputSelection This parameter can be one of the following values:
  548. * @arg @ref LL_COMP_OUTPUT_NONE
  549. * @arg @ref LL_COMP_OUTPUT_TIM1_BKIN (1)
  550. * @arg @ref LL_COMP_OUTPUT_TIM1_IC1 (1)
  551. * @arg @ref LL_COMP_OUTPUT_TIM1_OCCLR (1)
  552. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)
  553. * @arg @ref LL_COMP_OUTPUT_TIM2_OCCLR (1)
  554. * @arg @ref LL_COMP_OUTPUT_TIM3_IC1 (1)
  555. * @arg @ref LL_COMP_OUTPUT_TIM3_OCCLR (1)
  556. *
  557. * (1) Parameter availability depending on timer availability
  558. * on the selected device.
  559. * @retval None
  560. */
  561. __STATIC_INLINE void LL_COMP_SetOutputSelection(COMP_TypeDef *COMPx, uint32_t OutputSelection)
  562. {
  563. MODIFY_REG(COMP->CSR,
  564. COMP_CSR_COMP1OUTSEL << __COMP_BITOFFSET_INSTANCE(COMPx),
  565. OutputSelection << __COMP_BITOFFSET_INSTANCE(COMPx) );
  566. }
  567. /**
  568. * @brief Get comparator output selection.
  569. * @note Availability of parameters of output selection to timer
  570. * depends on timers availability on the selected device.
  571. * @rmtoll CSR COMP1OUTSEL LL_COMP_GetOutputSelection\n
  572. * COMP2OUTSEL LL_COMP_GetOutputSelection
  573. * @param COMPx Comparator instance
  574. * @retval Returned value can be one of the following values:
  575. * @arg @ref LL_COMP_OUTPUT_NONE
  576. * @arg @ref LL_COMP_OUTPUT_TIM1_BKIN (1)
  577. * @arg @ref LL_COMP_OUTPUT_TIM1_IC1 (1)
  578. * @arg @ref LL_COMP_OUTPUT_TIM1_OCCLR (1)
  579. * @arg @ref LL_COMP_OUTPUT_TIM2_IC4 (1)
  580. * @arg @ref LL_COMP_OUTPUT_TIM2_OCCLR (1)
  581. * @arg @ref LL_COMP_OUTPUT_TIM3_IC1 (1)
  582. * @arg @ref LL_COMP_OUTPUT_TIM3_OCCLR (1)
  583. *
  584. * (1) Parameter availability depending on timer availability
  585. * on the selected device.
  586. */
  587. __STATIC_INLINE uint32_t LL_COMP_GetOutputSelection(COMP_TypeDef *COMPx)
  588. {
  589. return (uint32_t)(READ_BIT(COMP->CSR,
  590. COMP_CSR_COMP1OUTSEL << __COMP_BITOFFSET_INSTANCE(COMPx))
  591. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  592. );
  593. }
  594. /**
  595. * @brief Set comparator instance output polarity.
  596. * @rmtoll CSR COMP1POL LL_COMP_SetOutputPolarity\n
  597. * COMP2POL LL_COMP_SetOutputPolarity
  598. * @param COMPx Comparator instance
  599. * @param OutputPolarity This parameter can be one of the following values:
  600. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  601. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  602. * @retval None
  603. */
  604. __STATIC_INLINE void LL_COMP_SetOutputPolarity(COMP_TypeDef *COMPx, uint32_t OutputPolarity)
  605. {
  606. MODIFY_REG(COMP->CSR,
  607. COMP_CSR_COMP1POL << __COMP_BITOFFSET_INSTANCE(COMPx),
  608. OutputPolarity << __COMP_BITOFFSET_INSTANCE(COMPx) );
  609. }
  610. /**
  611. * @brief Get comparator instance output polarity.
  612. * @rmtoll CSR COMP1POL LL_COMP_GetOutputPolarity\n
  613. * COMP2POL LL_COMP_GetOutputPolarity
  614. * @param COMPx Comparator instance
  615. * @retval Returned value can be one of the following values:
  616. * @arg @ref LL_COMP_OUTPUTPOL_NONINVERTED
  617. * @arg @ref LL_COMP_OUTPUTPOL_INVERTED
  618. */
  619. __STATIC_INLINE uint32_t LL_COMP_GetOutputPolarity(COMP_TypeDef *COMPx)
  620. {
  621. return (uint32_t)(READ_BIT(COMP->CSR,
  622. COMP_CSR_COMP1POL << __COMP_BITOFFSET_INSTANCE(COMPx))
  623. >> __COMP_BITOFFSET_INSTANCE(COMPx)
  624. );
  625. }
  626. /**
  627. * @}
  628. */
  629. /** @defgroup COMP_LL_EF_Operation Operation on comparator instance
  630. * @{
  631. */
  632. /**
  633. * @brief Enable comparator instance.
  634. * @note After enable from off state, comparator requires a delay
  635. * to reach reach propagation delay specification.
  636. * Refer to device datasheet, parameter "tSTART".
  637. * @rmtoll CSR COMP1EN LL_COMP_Enable\n
  638. * CSR COMP2EN LL_COMP_Enable
  639. * @param COMPx Comparator instance
  640. * @retval None
  641. */
  642. __STATIC_INLINE void LL_COMP_Enable(COMP_TypeDef *COMPx)
  643. {
  644. SET_BIT(COMP->CSR, COMP_CSR_COMP1EN << __COMP_BITOFFSET_INSTANCE(COMPx));
  645. }
  646. /**
  647. * @brief Disable comparator instance.
  648. * @rmtoll CSR COMP1EN LL_COMP_Disable\n
  649. * CSR COMP2EN LL_COMP_Disable
  650. * @param COMPx Comparator instance
  651. * @retval None
  652. */
  653. __STATIC_INLINE void LL_COMP_Disable(COMP_TypeDef *COMPx)
  654. {
  655. CLEAR_BIT(COMP->CSR, COMP_CSR_COMP1EN << __COMP_BITOFFSET_INSTANCE(COMPx));
  656. }
  657. /**
  658. * @brief Get comparator enable state
  659. * (0: COMP is disabled, 1: COMP is enabled)
  660. * @rmtoll CSR COMP1EN LL_COMP_IsEnabled\n
  661. * CSR COMP2EN LL_COMP_IsEnabled
  662. * @param COMPx Comparator instance
  663. * @retval State of bit (1 or 0).
  664. */
  665. __STATIC_INLINE uint32_t LL_COMP_IsEnabled(COMP_TypeDef *COMPx)
  666. {
  667. return (READ_BIT(COMP->CSR, COMP_CSR_COMP1EN << __COMP_BITOFFSET_INSTANCE(COMPx)) == COMP_CSR_COMP1EN << __COMP_BITOFFSET_INSTANCE(COMPx));
  668. }
  669. /**
  670. * @brief Lock comparator instance.
  671. * @note Once locked, comparator configuration can be accessed in read-only.
  672. * @note The only way to unlock the comparator is a device hardware reset.
  673. * @rmtoll CSR COMP1LOCK LL_COMP_Lock\n
  674. * CSR COMP2LOCK LL_COMP_Lock
  675. * @param COMPx Comparator instance
  676. * @retval None
  677. */
  678. __STATIC_INLINE void LL_COMP_Lock(COMP_TypeDef *COMPx)
  679. {
  680. SET_BIT(COMP->CSR, COMP_CSR_COMP1LOCK << __COMP_BITOFFSET_INSTANCE(COMPx));
  681. }
  682. /**
  683. * @brief Get comparator lock state
  684. * (0: COMP is unlocked, 1: COMP is locked).
  685. * @note Once locked, comparator configuration can be accessed in read-only.
  686. * @note The only way to unlock the comparator is a device hardware reset.
  687. * @rmtoll CSR COMP1LOCK LL_COMP_IsLocked\n
  688. * CSR COMP2LOCK LL_COMP_IsLocked
  689. * @param COMPx Comparator instance
  690. * @retval State of bit (1 or 0).
  691. */
  692. __STATIC_INLINE uint32_t LL_COMP_IsLocked(COMP_TypeDef *COMPx)
  693. {
  694. return (READ_BIT(COMP->CSR, COMP_CSR_COMP1LOCK << __COMP_BITOFFSET_INSTANCE(COMPx)) == COMP_CSR_COMP1LOCK << __COMP_BITOFFSET_INSTANCE(COMPx));
  695. }
  696. /**
  697. * @brief Read comparator instance output level.
  698. * @note The comparator output level depends on the selected polarity
  699. * (Refer to function @ref LL_COMP_SetOutputPolarity()).
  700. * If the comparator polarity is not inverted:
  701. * - Comparator output is low when the input plus
  702. * is at a lower voltage than the input minus
  703. * - Comparator output is high when the input plus
  704. * is at a higher voltage than the input minus
  705. * If the comparator polarity is inverted:
  706. * - Comparator output is high when the input plus
  707. * is at a lower voltage than the input minus
  708. * - Comparator output is low when the input plus
  709. * is at a higher voltage than the input minus
  710. * @rmtoll CSR COMP1OUT LL_COMP_ReadOutputLevel\n
  711. * CSR COMP2OUT LL_COMP_ReadOutputLevel
  712. * @param COMPx Comparator instance
  713. * @retval Returned value can be one of the following values:
  714. * @arg @ref LL_COMP_OUTPUT_LEVEL_LOW
  715. * @arg @ref LL_COMP_OUTPUT_LEVEL_HIGH
  716. */
  717. __STATIC_INLINE uint32_t LL_COMP_ReadOutputLevel(COMP_TypeDef *COMPx)
  718. {
  719. return (uint32_t)(READ_BIT(COMP->CSR,
  720. COMP_CSR_COMP1OUT << __COMP_BITOFFSET_INSTANCE(COMPx))
  721. >> (__COMP_BITOFFSET_INSTANCE(COMPx) + LL_COMP_OUTPUT_LEVEL_BITOFFSET_POS)
  722. );
  723. }
  724. /**
  725. * @}
  726. */
  727. #if defined(USE_FULL_LL_DRIVER)
  728. /** @defgroup COMP_LL_EF_Init Initialization and de-initialization functions
  729. * @{
  730. */
  731. ErrorStatus LL_COMP_DeInit(COMP_TypeDef *COMPx);
  732. ErrorStatus LL_COMP_Init(COMP_TypeDef *COMPx, LL_COMP_InitTypeDef *COMP_InitStruct);
  733. void LL_COMP_StructInit(LL_COMP_InitTypeDef *COMP_InitStruct);
  734. /**
  735. * @}
  736. */
  737. #endif /* USE_FULL_LL_DRIVER */
  738. /**
  739. * @}
  740. */
  741. /**
  742. * @}
  743. */
  744. #endif /* COMP1 || COMP2 */
  745. /**
  746. * @}
  747. */
  748. #ifdef __cplusplus
  749. }
  750. #endif
  751. #endif /* __STM32F0xx_LL_COMP_H */
  752. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/