Subversion Repositories ScreenTimer

Rev

Blame | Last modification | View Log | Download | RSS feed

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