mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Feb 26 09:45:12 2014 +0000
Revision:
106:ced8cbb51063
Parent:
76:aeb1df146756
Synchronized with git revision 4222735eff5868389433f0e9271976b39c8115cd

Full URL: https://github.com/mbedmicro/mbed/commit/4222735eff5868389433f0e9271976b39c8115cd/

[NUCLEO_xxx] Update STM32CubeF4 driver V1.0.0 + update license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32f0xx_comp.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 76:aeb1df146756 5 * @version V1.3.0
mbed_official 76:aeb1df146756 6 * @date 16-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the comparators (COMP1 and COMP2) peripheral
mbed_official 76:aeb1df146756 9 * applicable only on STM32F051 and STM32F072 devices:
mbed_official 76:aeb1df146756 10 * + Comparators configuration
mbed_official 76:aeb1df146756 11 * + Window mode control
mbed_official 76:aeb1df146756 12 *
mbed_official 76:aeb1df146756 13 * @verbatim
mbed_official 76:aeb1df146756 14 *
mbed_official 76:aeb1df146756 15 ===============================================================================
mbed_official 76:aeb1df146756 16 ##### How to use this driver #####
mbed_official 76:aeb1df146756 17 ===============================================================================
mbed_official 76:aeb1df146756 18 [..]
mbed_official 76:aeb1df146756 19
mbed_official 76:aeb1df146756 20 The device integrates two analog comparators COMP1 and COMP2:
mbed_official 76:aeb1df146756 21 (+) The non inverting input is set to PA1 for COMP1 and to PA3
mbed_official 76:aeb1df146756 22 for COMP2.
mbed_official 76:aeb1df146756 23
mbed_official 76:aeb1df146756 24 (+) The inverting input can be selected among: DAC1_OUT, DAC2_OUT
mbed_official 76:aeb1df146756 25 1/4 VREFINT, 1/2 VERFINT, 3/4 VREFINT, VREFINT,
mbed_official 76:aeb1df146756 26 I/O (PA0 for COMP1 and PA2 for COMP2)
mbed_official 76:aeb1df146756 27
mbed_official 76:aeb1df146756 28 (+) The COMP output is internally is available using COMP_GetOutputLevel()
mbed_official 76:aeb1df146756 29 and can be set on GPIO pins: PA0, PA6, PA11 for COMP1
mbed_official 76:aeb1df146756 30 and PA2, PA7, PA12 for COMP2
mbed_official 76:aeb1df146756 31
mbed_official 76:aeb1df146756 32 (+) The COMP output can be redirected to embedded timers (TIM1, TIM2
mbed_official 76:aeb1df146756 33 and TIM3)
mbed_official 76:aeb1df146756 34
mbed_official 76:aeb1df146756 35 (+) The two comparators COMP1 and COMP2 can be combined in window
mbed_official 76:aeb1df146756 36 mode and only COMP1 non inverting (PA1) can be used as non-
mbed_official 76:aeb1df146756 37 inverting input.
mbed_official 76:aeb1df146756 38
mbed_official 76:aeb1df146756 39 (+) The two comparators COMP1 and COMP2 have interrupt capability
mbed_official 76:aeb1df146756 40 with wake-up from Sleep and Stop modes (through the EXTI controller).
mbed_official 76:aeb1df146756 41 COMP1 and COMP2 outputs are internally connected to EXTI Line 21
mbed_official 76:aeb1df146756 42 and EXTI Line 22 respectively.
mbed_official 76:aeb1df146756 43
mbed_official 76:aeb1df146756 44
mbed_official 76:aeb1df146756 45 ##### How to configure the comparator #####
mbed_official 76:aeb1df146756 46 ===============================================================================
mbed_official 76:aeb1df146756 47 [..]
mbed_official 76:aeb1df146756 48 This driver provides functions to configure and program the Comparators
mbed_official 76:aeb1df146756 49 of all STM32F0xx devices.
mbed_official 76:aeb1df146756 50
mbed_official 76:aeb1df146756 51 [..] To use the comparator, perform the following steps:
mbed_official 76:aeb1df146756 52
mbed_official 76:aeb1df146756 53 (#) Enable the SYSCFG APB clock to get write access to comparator
mbed_official 76:aeb1df146756 54 register using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
mbed_official 76:aeb1df146756 55
mbed_official 76:aeb1df146756 56 (#) Configure the comparator input in analog mode using GPIO_Init()
mbed_official 76:aeb1df146756 57
mbed_official 76:aeb1df146756 58 (#) Configure the comparator output in alternate function mode
mbed_official 76:aeb1df146756 59 using GPIO_Init() and use GPIO_PinAFConfig() function to map the
mbed_official 76:aeb1df146756 60 comparator output to the GPIO pin
mbed_official 76:aeb1df146756 61
mbed_official 76:aeb1df146756 62 (#) Configure the comparator using COMP_Init() function:
mbed_official 76:aeb1df146756 63 (++) Select the inverting input
mbed_official 76:aeb1df146756 64 (++) Select the output polarity
mbed_official 76:aeb1df146756 65 (++) Select the output redirection
mbed_official 76:aeb1df146756 66 (++) Select the hysteresis level
mbed_official 76:aeb1df146756 67 (++) Select the power mode
mbed_official 76:aeb1df146756 68
mbed_official 76:aeb1df146756 69 (#) Enable the comparator using COMP_Cmd() function
mbed_official 76:aeb1df146756 70
mbed_official 76:aeb1df146756 71 (#) If required enable the COMP interrupt by configuring and enabling
mbed_official 76:aeb1df146756 72 EXTI line in Interrupt mode and selecting the desired sensitivity
mbed_official 76:aeb1df146756 73 level using EXTI_Init() function. After that enable the comparator
mbed_official 76:aeb1df146756 74 interrupt vector using NVIC_Init() function.
mbed_official 76:aeb1df146756 75
mbed_official 76:aeb1df146756 76 @endverbatim
mbed_official 76:aeb1df146756 77 *
mbed_official 76:aeb1df146756 78 ******************************************************************************
mbed_official 76:aeb1df146756 79 * @attention
mbed_official 76:aeb1df146756 80 *
mbed_official 106:ced8cbb51063 81 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 82 *
mbed_official 106:ced8cbb51063 83 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 106:ced8cbb51063 84 * are permitted provided that the following conditions are met:
mbed_official 106:ced8cbb51063 85 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 106:ced8cbb51063 86 * this list of conditions and the following disclaimer.
mbed_official 106:ced8cbb51063 87 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 106:ced8cbb51063 88 * this list of conditions and the following disclaimer in the documentation
mbed_official 106:ced8cbb51063 89 * and/or other materials provided with the distribution.
mbed_official 106:ced8cbb51063 90 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 106:ced8cbb51063 91 * may be used to endorse or promote products derived from this software
mbed_official 106:ced8cbb51063 92 * without specific prior written permission.
mbed_official 76:aeb1df146756 93 *
mbed_official 106:ced8cbb51063 94 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 106:ced8cbb51063 95 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 106:ced8cbb51063 96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 106:ced8cbb51063 97 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 106:ced8cbb51063 98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 106:ced8cbb51063 99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 106:ced8cbb51063 100 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 106:ced8cbb51063 101 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 106:ced8cbb51063 102 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 106:ced8cbb51063 103 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 104 *
mbed_official 76:aeb1df146756 105 ******************************************************************************
mbed_official 76:aeb1df146756 106 */
mbed_official 76:aeb1df146756 107
mbed_official 76:aeb1df146756 108 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 109 #include "stm32f0xx_comp.h"
mbed_official 76:aeb1df146756 110
mbed_official 76:aeb1df146756 111 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 112 * @{
mbed_official 76:aeb1df146756 113 */
mbed_official 76:aeb1df146756 114
mbed_official 76:aeb1df146756 115 /** @defgroup COMP
mbed_official 76:aeb1df146756 116 * @brief COMP driver modules
mbed_official 76:aeb1df146756 117 * @{
mbed_official 76:aeb1df146756 118 */
mbed_official 76:aeb1df146756 119
mbed_official 76:aeb1df146756 120 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 121 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 122 /* CSR register Mask */
mbed_official 76:aeb1df146756 123 #define COMP_CSR_CLEAR_MASK ((uint32_t)0x00003FFE)
mbed_official 76:aeb1df146756 124
mbed_official 76:aeb1df146756 125 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 126 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 127 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 128 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 129
mbed_official 76:aeb1df146756 130 /** @defgroup COMP_Private_Functions
mbed_official 76:aeb1df146756 131 * @{
mbed_official 76:aeb1df146756 132 */
mbed_official 76:aeb1df146756 133
mbed_official 76:aeb1df146756 134 /** @defgroup COMP_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 135 * @brief Initialization and Configuration functions
mbed_official 76:aeb1df146756 136 *
mbed_official 76:aeb1df146756 137 @verbatim
mbed_official 76:aeb1df146756 138 ===============================================================================
mbed_official 76:aeb1df146756 139 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 140 ===============================================================================
mbed_official 76:aeb1df146756 141
mbed_official 76:aeb1df146756 142 @endverbatim
mbed_official 76:aeb1df146756 143 * @{
mbed_official 76:aeb1df146756 144 */
mbed_official 76:aeb1df146756 145
mbed_official 76:aeb1df146756 146 /**
mbed_official 76:aeb1df146756 147 * @brief Deinitializes COMP peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 148 * @note Deinitialization can't be performed if the COMP configuration is locked.
mbed_official 76:aeb1df146756 149 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 150 * @param None
mbed_official 76:aeb1df146756 151 * @retval None
mbed_official 76:aeb1df146756 152 */
mbed_official 76:aeb1df146756 153 void COMP_DeInit(void)
mbed_official 76:aeb1df146756 154 {
mbed_official 76:aeb1df146756 155 COMP->CSR = ((uint32_t)0x00000000); /*!< Set COMP_CSR register to reset value */
mbed_official 76:aeb1df146756 156 }
mbed_official 76:aeb1df146756 157
mbed_official 76:aeb1df146756 158 /**
mbed_official 76:aeb1df146756 159 * @brief Initializes the COMP peripheral according to the specified parameters
mbed_official 76:aeb1df146756 160 * in COMP_InitStruct
mbed_official 76:aeb1df146756 161 * @note If the selected comparator is locked, initialization can't be performed.
mbed_official 76:aeb1df146756 162 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 163 * @note By default, PA1 is selected as COMP1 non inverting input.
mbed_official 76:aeb1df146756 164 * To use PA4 as COMP1 non inverting input call COMP_SwitchCmd() after COMP_Init()
mbed_official 76:aeb1df146756 165 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 166 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 167 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 168 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 169 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains
mbed_official 76:aeb1df146756 170 * the configuration information for the specified COMP peripheral.
mbed_official 76:aeb1df146756 171 * @retval None
mbed_official 76:aeb1df146756 172 */
mbed_official 76:aeb1df146756 173 void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct)
mbed_official 76:aeb1df146756 174 {
mbed_official 76:aeb1df146756 175 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 176
mbed_official 76:aeb1df146756 177 /* Check the parameters */
mbed_official 76:aeb1df146756 178 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 179 assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput));
mbed_official 76:aeb1df146756 180 assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_Output));
mbed_official 76:aeb1df146756 181 assert_param(IS_COMP_OUTPUT_POL(COMP_InitStruct->COMP_OutputPol));
mbed_official 76:aeb1df146756 182 assert_param(IS_COMP_HYSTERESIS(COMP_InitStruct->COMP_Hysteresis));
mbed_official 76:aeb1df146756 183 assert_param(IS_COMP_MODE(COMP_InitStruct->COMP_Mode));
mbed_official 76:aeb1df146756 184
mbed_official 76:aeb1df146756 185 /*!< Get the COMP_CSR register value */
mbed_official 76:aeb1df146756 186 tmpreg = COMP->CSR;
mbed_official 76:aeb1df146756 187
mbed_official 76:aeb1df146756 188 /*!< Clear the COMP1SW1, COMPx_IN_SEL, COMPx_OUT_TIM_SEL, COMPx_POL, COMPx_HYST and COMPx_PWR_MODE bits */
mbed_official 76:aeb1df146756 189 tmpreg &= (uint32_t) ~(COMP_CSR_CLEAR_MASK<<COMP_Selection);
mbed_official 76:aeb1df146756 190
mbed_official 76:aeb1df146756 191 /*!< Configure COMP: inverting input, output redirection, hysteresis value and power mode */
mbed_official 76:aeb1df146756 192 /*!< Set COMPxINSEL bits according to COMP_InitStruct->COMP_InvertingInput value */
mbed_official 76:aeb1df146756 193 /*!< Set COMPxOUTSEL bits according to COMP_InitStruct->COMP_Output value */
mbed_official 76:aeb1df146756 194 /*!< Set COMPxPOL bit according to COMP_InitStruct->COMP_OutputPol value */
mbed_official 76:aeb1df146756 195 /*!< Set COMPxHYST bits according to COMP_InitStruct->COMP_Hysteresis value */
mbed_official 76:aeb1df146756 196 /*!< Set COMPxMODE bits according to COMP_InitStruct->COMP_Mode value */
mbed_official 76:aeb1df146756 197 tmpreg |= (uint32_t)((COMP_InitStruct->COMP_InvertingInput | COMP_InitStruct->COMP_Output |
mbed_official 76:aeb1df146756 198 COMP_InitStruct->COMP_OutputPol | COMP_InitStruct->COMP_Hysteresis |
mbed_official 76:aeb1df146756 199 COMP_InitStruct->COMP_Mode)<<COMP_Selection);
mbed_official 76:aeb1df146756 200
mbed_official 76:aeb1df146756 201 /*!< Write to COMP_CSR register */
mbed_official 76:aeb1df146756 202 COMP->CSR = tmpreg;
mbed_official 76:aeb1df146756 203 }
mbed_official 76:aeb1df146756 204
mbed_official 76:aeb1df146756 205 /**
mbed_official 76:aeb1df146756 206 * @brief Fills each COMP_InitStruct member with its default value.
mbed_official 76:aeb1df146756 207 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure which will
mbed_official 76:aeb1df146756 208 * be initialized.
mbed_official 76:aeb1df146756 209 * @retval None
mbed_official 76:aeb1df146756 210 */
mbed_official 76:aeb1df146756 211 void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct)
mbed_official 76:aeb1df146756 212 {
mbed_official 76:aeb1df146756 213 COMP_InitStruct->COMP_InvertingInput = COMP_InvertingInput_1_4VREFINT;
mbed_official 76:aeb1df146756 214 COMP_InitStruct->COMP_Output = COMP_Output_None;
mbed_official 76:aeb1df146756 215 COMP_InitStruct->COMP_OutputPol = COMP_OutputPol_NonInverted;
mbed_official 76:aeb1df146756 216 COMP_InitStruct->COMP_Hysteresis = COMP_Hysteresis_No;
mbed_official 76:aeb1df146756 217 COMP_InitStruct->COMP_Mode = COMP_Mode_UltraLowPower;
mbed_official 76:aeb1df146756 218 }
mbed_official 76:aeb1df146756 219
mbed_official 76:aeb1df146756 220 /**
mbed_official 76:aeb1df146756 221 * @brief Enable or disable the COMP peripheral.
mbed_official 76:aeb1df146756 222 * @note If the selected comparator is locked, enable/disable can't be performed.
mbed_official 76:aeb1df146756 223 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 224 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 225 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 226 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 227 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 228 * @param NewState: new state of the COMP peripheral.
mbed_official 76:aeb1df146756 229 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 230 * @note When enabled, the comparator compares the non inverting input with
mbed_official 76:aeb1df146756 231 * the inverting input and the comparison result is available on comparator output.
mbed_official 76:aeb1df146756 232 * @note When disabled, the comparator doesn't perform comparison and the
mbed_official 76:aeb1df146756 233 * output level is low.
mbed_official 76:aeb1df146756 234 * @retval None
mbed_official 76:aeb1df146756 235 */
mbed_official 76:aeb1df146756 236 void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState)
mbed_official 76:aeb1df146756 237 {
mbed_official 76:aeb1df146756 238 /* Check the parameters */
mbed_official 76:aeb1df146756 239 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 240 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 241
mbed_official 76:aeb1df146756 242 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 243 {
mbed_official 76:aeb1df146756 244 /* Enable the selected COMP peripheral */
mbed_official 76:aeb1df146756 245 COMP->CSR |= (uint32_t) (1<<COMP_Selection);
mbed_official 76:aeb1df146756 246 }
mbed_official 76:aeb1df146756 247 else
mbed_official 76:aeb1df146756 248 {
mbed_official 76:aeb1df146756 249 /* Disable the selected COMP peripheral */
mbed_official 76:aeb1df146756 250 COMP->CSR &= (uint32_t)(~((uint32_t)1<<COMP_Selection));
mbed_official 76:aeb1df146756 251 }
mbed_official 76:aeb1df146756 252 }
mbed_official 76:aeb1df146756 253
mbed_official 76:aeb1df146756 254 /**
mbed_official 76:aeb1df146756 255 * @brief Close or Open the SW1 switch.
mbed_official 76:aeb1df146756 256 * @note This switch is solely intended to redirect signals onto high
mbed_official 76:aeb1df146756 257 * impedance input, such as COMP1 non-inverting input (highly resistive switch)
mbed_official 76:aeb1df146756 258 * @param NewState: New state of the analog switch.
mbed_official 76:aeb1df146756 259 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 260 * @note When enabled, the SW1 is closed; PA1 is connected to PA4
mbed_official 76:aeb1df146756 261 * @note When disabled, the SW1 switch is open; PA1 is disconnected from PA4
mbed_official 76:aeb1df146756 262 * @retval None
mbed_official 76:aeb1df146756 263 */
mbed_official 76:aeb1df146756 264 void COMP_SwitchCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 265 {
mbed_official 76:aeb1df146756 266 /* Check the parameter */
mbed_official 76:aeb1df146756 267 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 268
mbed_official 76:aeb1df146756 269 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 270 {
mbed_official 76:aeb1df146756 271 /* Close SW1 switch */
mbed_official 76:aeb1df146756 272 COMP->CSR |= (uint32_t) (COMP_CSR_COMP1SW1);
mbed_official 76:aeb1df146756 273 }
mbed_official 76:aeb1df146756 274 else
mbed_official 76:aeb1df146756 275 {
mbed_official 76:aeb1df146756 276 /* Open SW1 switch */
mbed_official 76:aeb1df146756 277 COMP->CSR &= (uint32_t)(~COMP_CSR_COMP1SW1);
mbed_official 76:aeb1df146756 278 }
mbed_official 76:aeb1df146756 279 }
mbed_official 76:aeb1df146756 280
mbed_official 76:aeb1df146756 281 /**
mbed_official 76:aeb1df146756 282 * @brief Return the output level (high or low) of the selected comparator.
mbed_official 76:aeb1df146756 283 * @note The output level depends on the selected polarity.
mbed_official 76:aeb1df146756 284 * @note If the polarity is not inverted:
mbed_official 76:aeb1df146756 285 * - Comparator output is low when the non-inverting input is at a lower
mbed_official 76:aeb1df146756 286 * voltage than the inverting input
mbed_official 76:aeb1df146756 287 * - Comparator output is high when the non-inverting input is at a higher
mbed_official 76:aeb1df146756 288 * voltage than the inverting input
mbed_official 76:aeb1df146756 289 * @note If the polarity is inverted:
mbed_official 76:aeb1df146756 290 * - Comparator output is high when the non-inverting input is at a lower
mbed_official 76:aeb1df146756 291 * voltage than the inverting input
mbed_official 76:aeb1df146756 292 * - Comparator output is low when the non-inverting input is at a higher
mbed_official 76:aeb1df146756 293 * voltage than the inverting input
mbed_official 76:aeb1df146756 294 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 295 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 296 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 297 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 298 * @retval Returns the selected comparator output level: low or high.
mbed_official 76:aeb1df146756 299 *
mbed_official 76:aeb1df146756 300 */
mbed_official 76:aeb1df146756 301 uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection)
mbed_official 76:aeb1df146756 302 {
mbed_official 76:aeb1df146756 303 uint32_t compout = 0x0;
mbed_official 76:aeb1df146756 304
mbed_official 76:aeb1df146756 305 /* Check the parameters */
mbed_official 76:aeb1df146756 306 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 307
mbed_official 76:aeb1df146756 308 /* Check if selected comparator output is high */
mbed_official 76:aeb1df146756 309 if ((COMP->CSR & (COMP_CSR_COMP1OUT<<COMP_Selection)) != 0)
mbed_official 76:aeb1df146756 310 {
mbed_official 76:aeb1df146756 311 compout = COMP_OutputLevel_High;
mbed_official 76:aeb1df146756 312 }
mbed_official 76:aeb1df146756 313 else
mbed_official 76:aeb1df146756 314 {
mbed_official 76:aeb1df146756 315 compout = COMP_OutputLevel_Low;
mbed_official 76:aeb1df146756 316 }
mbed_official 76:aeb1df146756 317
mbed_official 76:aeb1df146756 318 /* Return the comparator output level */
mbed_official 76:aeb1df146756 319 return (uint32_t)(compout);
mbed_official 76:aeb1df146756 320 }
mbed_official 76:aeb1df146756 321
mbed_official 76:aeb1df146756 322 /**
mbed_official 76:aeb1df146756 323 * @}
mbed_official 76:aeb1df146756 324 */
mbed_official 76:aeb1df146756 325
mbed_official 76:aeb1df146756 326 /** @defgroup COMP_Group2 Window mode control function
mbed_official 76:aeb1df146756 327 * @brief Window mode control function
mbed_official 76:aeb1df146756 328 *
mbed_official 76:aeb1df146756 329 @verbatim
mbed_official 76:aeb1df146756 330 ===============================================================================
mbed_official 76:aeb1df146756 331 ##### Window mode control function #####
mbed_official 76:aeb1df146756 332 ===============================================================================
mbed_official 76:aeb1df146756 333
mbed_official 76:aeb1df146756 334 @endverbatim
mbed_official 76:aeb1df146756 335 * @{
mbed_official 76:aeb1df146756 336 */
mbed_official 76:aeb1df146756 337
mbed_official 76:aeb1df146756 338 /**
mbed_official 76:aeb1df146756 339 * @brief Enables or disables the window mode.
mbed_official 76:aeb1df146756 340 * @note In window mode, COMP1 and COMP2 non inverting inputs are connected
mbed_official 76:aeb1df146756 341 * together and only COMP1 non inverting input (PA1) can be used.
mbed_official 76:aeb1df146756 342 * @param NewState: new state of the window mode.
mbed_official 76:aeb1df146756 343 * This parameter can be :
mbed_official 76:aeb1df146756 344 * @arg ENABLE: COMP1 and COMP2 non inverting inputs are connected together.
mbed_official 76:aeb1df146756 345 * @arg DISABLE: OMP1 and COMP2 non inverting inputs are disconnected.
mbed_official 76:aeb1df146756 346 * @retval None
mbed_official 76:aeb1df146756 347 */
mbed_official 76:aeb1df146756 348 void COMP_WindowCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 349 {
mbed_official 76:aeb1df146756 350 /* Check the parameters */
mbed_official 76:aeb1df146756 351 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 352
mbed_official 76:aeb1df146756 353 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 354 {
mbed_official 76:aeb1df146756 355 /* Enable the window mode */
mbed_official 76:aeb1df146756 356 COMP->CSR |= (uint32_t) COMP_CSR_WNDWEN;
mbed_official 76:aeb1df146756 357 }
mbed_official 76:aeb1df146756 358 else
mbed_official 76:aeb1df146756 359 {
mbed_official 76:aeb1df146756 360 /* Disable the window mode */
mbed_official 76:aeb1df146756 361 COMP->CSR &= (uint32_t)(~COMP_CSR_WNDWEN);
mbed_official 76:aeb1df146756 362 }
mbed_official 76:aeb1df146756 363 }
mbed_official 76:aeb1df146756 364
mbed_official 76:aeb1df146756 365 /**
mbed_official 76:aeb1df146756 366 * @}
mbed_official 76:aeb1df146756 367 */
mbed_official 76:aeb1df146756 368
mbed_official 76:aeb1df146756 369 /** @defgroup COMP_Group3 COMP configuration locking function
mbed_official 76:aeb1df146756 370 * @brief COMP1 and COMP2 configuration locking function
mbed_official 76:aeb1df146756 371 * COMP1 and COMP2 configuration can be locked each separately.
mbed_official 76:aeb1df146756 372 * Unlocking is performed by system reset.
mbed_official 76:aeb1df146756 373 *
mbed_official 76:aeb1df146756 374 @verbatim
mbed_official 76:aeb1df146756 375 ===============================================================================
mbed_official 76:aeb1df146756 376 ##### Configuration Lock function #####
mbed_official 76:aeb1df146756 377 ===============================================================================
mbed_official 76:aeb1df146756 378
mbed_official 76:aeb1df146756 379 @endverbatim
mbed_official 76:aeb1df146756 380 * @{
mbed_official 76:aeb1df146756 381 */
mbed_official 76:aeb1df146756 382
mbed_official 76:aeb1df146756 383 /**
mbed_official 76:aeb1df146756 384 * @brief Lock the selected comparator (COMP1/COMP2) configuration.
mbed_official 76:aeb1df146756 385 * @note Locking the configuration means that all control bits are read-only.
mbed_official 76:aeb1df146756 386 * To unlock the comparator configuration, perform a system reset.
mbed_official 76:aeb1df146756 387 * @param COMP_Selection: selects the comparator to be locked
mbed_official 76:aeb1df146756 388 * This parameter can be a value of the following values:
mbed_official 76:aeb1df146756 389 * @arg COMP_Selection_COMP1: COMP1 configuration is locked.
mbed_official 76:aeb1df146756 390 * @arg COMP_Selection_COMP2: COMP2 configuration is locked.
mbed_official 76:aeb1df146756 391 * @retval None
mbed_official 76:aeb1df146756 392 */
mbed_official 76:aeb1df146756 393 void COMP_LockConfig(uint32_t COMP_Selection)
mbed_official 76:aeb1df146756 394 {
mbed_official 76:aeb1df146756 395 /* Check the parameter */
mbed_official 76:aeb1df146756 396 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 397
mbed_official 76:aeb1df146756 398 /* Set the lock bit corresponding to selected comparator */
mbed_official 76:aeb1df146756 399 COMP->CSR |= (uint32_t) (COMP_CSR_COMP1LOCK<<COMP_Selection);
mbed_official 76:aeb1df146756 400 }
mbed_official 76:aeb1df146756 401
mbed_official 76:aeb1df146756 402 /**
mbed_official 76:aeb1df146756 403 * @}
mbed_official 76:aeb1df146756 404 */
mbed_official 76:aeb1df146756 405
mbed_official 76:aeb1df146756 406 /**
mbed_official 76:aeb1df146756 407 * @}
mbed_official 76:aeb1df146756 408 */
mbed_official 76:aeb1df146756 409
mbed_official 76:aeb1df146756 410 /**
mbed_official 76:aeb1df146756 411 * @}
mbed_official 76:aeb1df146756 412 */
mbed_official 76:aeb1df146756 413
mbed_official 76:aeb1df146756 414 /**
mbed_official 76:aeb1df146756 415 * @}
mbed_official 76:aeb1df146756 416 */
mbed_official 76:aeb1df146756 417
mbed_official 76:aeb1df146756 418 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/