mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/

Add NUCLEO_L152RE

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 76:aeb1df146756 81 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 82 *
mbed_official 76:aeb1df146756 83 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 84 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 85 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 86 *
mbed_official 76:aeb1df146756 87 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 88 *
mbed_official 76:aeb1df146756 89 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 90 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 91 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 92 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 93 * limitations under the License.
mbed_official 76:aeb1df146756 94 *
mbed_official 76:aeb1df146756 95 ******************************************************************************
mbed_official 76:aeb1df146756 96 */
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 99 #include "stm32f0xx_comp.h"
mbed_official 76:aeb1df146756 100
mbed_official 76:aeb1df146756 101 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 102 * @{
mbed_official 76:aeb1df146756 103 */
mbed_official 76:aeb1df146756 104
mbed_official 76:aeb1df146756 105 /** @defgroup COMP
mbed_official 76:aeb1df146756 106 * @brief COMP driver modules
mbed_official 76:aeb1df146756 107 * @{
mbed_official 76:aeb1df146756 108 */
mbed_official 76:aeb1df146756 109
mbed_official 76:aeb1df146756 110 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 111 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 112 /* CSR register Mask */
mbed_official 76:aeb1df146756 113 #define COMP_CSR_CLEAR_MASK ((uint32_t)0x00003FFE)
mbed_official 76:aeb1df146756 114
mbed_official 76:aeb1df146756 115 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 116 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 117 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 118 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 119
mbed_official 76:aeb1df146756 120 /** @defgroup COMP_Private_Functions
mbed_official 76:aeb1df146756 121 * @{
mbed_official 76:aeb1df146756 122 */
mbed_official 76:aeb1df146756 123
mbed_official 76:aeb1df146756 124 /** @defgroup COMP_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 125 * @brief Initialization and Configuration functions
mbed_official 76:aeb1df146756 126 *
mbed_official 76:aeb1df146756 127 @verbatim
mbed_official 76:aeb1df146756 128 ===============================================================================
mbed_official 76:aeb1df146756 129 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 130 ===============================================================================
mbed_official 76:aeb1df146756 131
mbed_official 76:aeb1df146756 132 @endverbatim
mbed_official 76:aeb1df146756 133 * @{
mbed_official 76:aeb1df146756 134 */
mbed_official 76:aeb1df146756 135
mbed_official 76:aeb1df146756 136 /**
mbed_official 76:aeb1df146756 137 * @brief Deinitializes COMP peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 138 * @note Deinitialization can't be performed if the COMP configuration is locked.
mbed_official 76:aeb1df146756 139 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 140 * @param None
mbed_official 76:aeb1df146756 141 * @retval None
mbed_official 76:aeb1df146756 142 */
mbed_official 76:aeb1df146756 143 void COMP_DeInit(void)
mbed_official 76:aeb1df146756 144 {
mbed_official 76:aeb1df146756 145 COMP->CSR = ((uint32_t)0x00000000); /*!< Set COMP_CSR register to reset value */
mbed_official 76:aeb1df146756 146 }
mbed_official 76:aeb1df146756 147
mbed_official 76:aeb1df146756 148 /**
mbed_official 76:aeb1df146756 149 * @brief Initializes the COMP peripheral according to the specified parameters
mbed_official 76:aeb1df146756 150 * in COMP_InitStruct
mbed_official 76:aeb1df146756 151 * @note If the selected comparator is locked, initialization can't be performed.
mbed_official 76:aeb1df146756 152 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 153 * @note By default, PA1 is selected as COMP1 non inverting input.
mbed_official 76:aeb1df146756 154 * To use PA4 as COMP1 non inverting input call COMP_SwitchCmd() after COMP_Init()
mbed_official 76:aeb1df146756 155 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 156 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 157 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 158 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 159 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains
mbed_official 76:aeb1df146756 160 * the configuration information for the specified COMP peripheral.
mbed_official 76:aeb1df146756 161 * @retval None
mbed_official 76:aeb1df146756 162 */
mbed_official 76:aeb1df146756 163 void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct)
mbed_official 76:aeb1df146756 164 {
mbed_official 76:aeb1df146756 165 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 166
mbed_official 76:aeb1df146756 167 /* Check the parameters */
mbed_official 76:aeb1df146756 168 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 169 assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput));
mbed_official 76:aeb1df146756 170 assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_Output));
mbed_official 76:aeb1df146756 171 assert_param(IS_COMP_OUTPUT_POL(COMP_InitStruct->COMP_OutputPol));
mbed_official 76:aeb1df146756 172 assert_param(IS_COMP_HYSTERESIS(COMP_InitStruct->COMP_Hysteresis));
mbed_official 76:aeb1df146756 173 assert_param(IS_COMP_MODE(COMP_InitStruct->COMP_Mode));
mbed_official 76:aeb1df146756 174
mbed_official 76:aeb1df146756 175 /*!< Get the COMP_CSR register value */
mbed_official 76:aeb1df146756 176 tmpreg = COMP->CSR;
mbed_official 76:aeb1df146756 177
mbed_official 76:aeb1df146756 178 /*!< Clear the COMP1SW1, COMPx_IN_SEL, COMPx_OUT_TIM_SEL, COMPx_POL, COMPx_HYST and COMPx_PWR_MODE bits */
mbed_official 76:aeb1df146756 179 tmpreg &= (uint32_t) ~(COMP_CSR_CLEAR_MASK<<COMP_Selection);
mbed_official 76:aeb1df146756 180
mbed_official 76:aeb1df146756 181 /*!< Configure COMP: inverting input, output redirection, hysteresis value and power mode */
mbed_official 76:aeb1df146756 182 /*!< Set COMPxINSEL bits according to COMP_InitStruct->COMP_InvertingInput value */
mbed_official 76:aeb1df146756 183 /*!< Set COMPxOUTSEL bits according to COMP_InitStruct->COMP_Output value */
mbed_official 76:aeb1df146756 184 /*!< Set COMPxPOL bit according to COMP_InitStruct->COMP_OutputPol value */
mbed_official 76:aeb1df146756 185 /*!< Set COMPxHYST bits according to COMP_InitStruct->COMP_Hysteresis value */
mbed_official 76:aeb1df146756 186 /*!< Set COMPxMODE bits according to COMP_InitStruct->COMP_Mode value */
mbed_official 76:aeb1df146756 187 tmpreg |= (uint32_t)((COMP_InitStruct->COMP_InvertingInput | COMP_InitStruct->COMP_Output |
mbed_official 76:aeb1df146756 188 COMP_InitStruct->COMP_OutputPol | COMP_InitStruct->COMP_Hysteresis |
mbed_official 76:aeb1df146756 189 COMP_InitStruct->COMP_Mode)<<COMP_Selection);
mbed_official 76:aeb1df146756 190
mbed_official 76:aeb1df146756 191 /*!< Write to COMP_CSR register */
mbed_official 76:aeb1df146756 192 COMP->CSR = tmpreg;
mbed_official 76:aeb1df146756 193 }
mbed_official 76:aeb1df146756 194
mbed_official 76:aeb1df146756 195 /**
mbed_official 76:aeb1df146756 196 * @brief Fills each COMP_InitStruct member with its default value.
mbed_official 76:aeb1df146756 197 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure which will
mbed_official 76:aeb1df146756 198 * be initialized.
mbed_official 76:aeb1df146756 199 * @retval None
mbed_official 76:aeb1df146756 200 */
mbed_official 76:aeb1df146756 201 void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct)
mbed_official 76:aeb1df146756 202 {
mbed_official 76:aeb1df146756 203 COMP_InitStruct->COMP_InvertingInput = COMP_InvertingInput_1_4VREFINT;
mbed_official 76:aeb1df146756 204 COMP_InitStruct->COMP_Output = COMP_Output_None;
mbed_official 76:aeb1df146756 205 COMP_InitStruct->COMP_OutputPol = COMP_OutputPol_NonInverted;
mbed_official 76:aeb1df146756 206 COMP_InitStruct->COMP_Hysteresis = COMP_Hysteresis_No;
mbed_official 76:aeb1df146756 207 COMP_InitStruct->COMP_Mode = COMP_Mode_UltraLowPower;
mbed_official 76:aeb1df146756 208 }
mbed_official 76:aeb1df146756 209
mbed_official 76:aeb1df146756 210 /**
mbed_official 76:aeb1df146756 211 * @brief Enable or disable the COMP peripheral.
mbed_official 76:aeb1df146756 212 * @note If the selected comparator is locked, enable/disable can't be performed.
mbed_official 76:aeb1df146756 213 * To unlock the configuration, perform a system reset.
mbed_official 76:aeb1df146756 214 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 215 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 216 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 217 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 218 * @param NewState: new state of the COMP peripheral.
mbed_official 76:aeb1df146756 219 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 220 * @note When enabled, the comparator compares the non inverting input with
mbed_official 76:aeb1df146756 221 * the inverting input and the comparison result is available on comparator output.
mbed_official 76:aeb1df146756 222 * @note When disabled, the comparator doesn't perform comparison and the
mbed_official 76:aeb1df146756 223 * output level is low.
mbed_official 76:aeb1df146756 224 * @retval None
mbed_official 76:aeb1df146756 225 */
mbed_official 76:aeb1df146756 226 void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState)
mbed_official 76:aeb1df146756 227 {
mbed_official 76:aeb1df146756 228 /* Check the parameters */
mbed_official 76:aeb1df146756 229 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 230 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 231
mbed_official 76:aeb1df146756 232 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 233 {
mbed_official 76:aeb1df146756 234 /* Enable the selected COMP peripheral */
mbed_official 76:aeb1df146756 235 COMP->CSR |= (uint32_t) (1<<COMP_Selection);
mbed_official 76:aeb1df146756 236 }
mbed_official 76:aeb1df146756 237 else
mbed_official 76:aeb1df146756 238 {
mbed_official 76:aeb1df146756 239 /* Disable the selected COMP peripheral */
mbed_official 76:aeb1df146756 240 COMP->CSR &= (uint32_t)(~((uint32_t)1<<COMP_Selection));
mbed_official 76:aeb1df146756 241 }
mbed_official 76:aeb1df146756 242 }
mbed_official 76:aeb1df146756 243
mbed_official 76:aeb1df146756 244 /**
mbed_official 76:aeb1df146756 245 * @brief Close or Open the SW1 switch.
mbed_official 76:aeb1df146756 246 * @note This switch is solely intended to redirect signals onto high
mbed_official 76:aeb1df146756 247 * impedance input, such as COMP1 non-inverting input (highly resistive switch)
mbed_official 76:aeb1df146756 248 * @param NewState: New state of the analog switch.
mbed_official 76:aeb1df146756 249 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 250 * @note When enabled, the SW1 is closed; PA1 is connected to PA4
mbed_official 76:aeb1df146756 251 * @note When disabled, the SW1 switch is open; PA1 is disconnected from PA4
mbed_official 76:aeb1df146756 252 * @retval None
mbed_official 76:aeb1df146756 253 */
mbed_official 76:aeb1df146756 254 void COMP_SwitchCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 255 {
mbed_official 76:aeb1df146756 256 /* Check the parameter */
mbed_official 76:aeb1df146756 257 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 258
mbed_official 76:aeb1df146756 259 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 260 {
mbed_official 76:aeb1df146756 261 /* Close SW1 switch */
mbed_official 76:aeb1df146756 262 COMP->CSR |= (uint32_t) (COMP_CSR_COMP1SW1);
mbed_official 76:aeb1df146756 263 }
mbed_official 76:aeb1df146756 264 else
mbed_official 76:aeb1df146756 265 {
mbed_official 76:aeb1df146756 266 /* Open SW1 switch */
mbed_official 76:aeb1df146756 267 COMP->CSR &= (uint32_t)(~COMP_CSR_COMP1SW1);
mbed_official 76:aeb1df146756 268 }
mbed_official 76:aeb1df146756 269 }
mbed_official 76:aeb1df146756 270
mbed_official 76:aeb1df146756 271 /**
mbed_official 76:aeb1df146756 272 * @brief Return the output level (high or low) of the selected comparator.
mbed_official 76:aeb1df146756 273 * @note The output level depends on the selected polarity.
mbed_official 76:aeb1df146756 274 * @note If the polarity is not inverted:
mbed_official 76:aeb1df146756 275 * - Comparator output is low when the non-inverting input is at a lower
mbed_official 76:aeb1df146756 276 * voltage than the inverting input
mbed_official 76:aeb1df146756 277 * - Comparator output is high when the non-inverting input is at a higher
mbed_official 76:aeb1df146756 278 * voltage than the inverting input
mbed_official 76:aeb1df146756 279 * @note If the polarity is inverted:
mbed_official 76:aeb1df146756 280 * - Comparator output is high when the non-inverting input is at a lower
mbed_official 76:aeb1df146756 281 * voltage than the inverting input
mbed_official 76:aeb1df146756 282 * - Comparator output is low when the non-inverting input is at a higher
mbed_official 76:aeb1df146756 283 * voltage than the inverting input
mbed_official 76:aeb1df146756 284 * @param COMP_Selection: the selected comparator.
mbed_official 76:aeb1df146756 285 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 286 * @arg COMP_Selection_COMP1: COMP1 selected
mbed_official 76:aeb1df146756 287 * @arg COMP_Selection_COMP2: COMP2 selected
mbed_official 76:aeb1df146756 288 * @retval Returns the selected comparator output level: low or high.
mbed_official 76:aeb1df146756 289 *
mbed_official 76:aeb1df146756 290 */
mbed_official 76:aeb1df146756 291 uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection)
mbed_official 76:aeb1df146756 292 {
mbed_official 76:aeb1df146756 293 uint32_t compout = 0x0;
mbed_official 76:aeb1df146756 294
mbed_official 76:aeb1df146756 295 /* Check the parameters */
mbed_official 76:aeb1df146756 296 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 297
mbed_official 76:aeb1df146756 298 /* Check if selected comparator output is high */
mbed_official 76:aeb1df146756 299 if ((COMP->CSR & (COMP_CSR_COMP1OUT<<COMP_Selection)) != 0)
mbed_official 76:aeb1df146756 300 {
mbed_official 76:aeb1df146756 301 compout = COMP_OutputLevel_High;
mbed_official 76:aeb1df146756 302 }
mbed_official 76:aeb1df146756 303 else
mbed_official 76:aeb1df146756 304 {
mbed_official 76:aeb1df146756 305 compout = COMP_OutputLevel_Low;
mbed_official 76:aeb1df146756 306 }
mbed_official 76:aeb1df146756 307
mbed_official 76:aeb1df146756 308 /* Return the comparator output level */
mbed_official 76:aeb1df146756 309 return (uint32_t)(compout);
mbed_official 76:aeb1df146756 310 }
mbed_official 76:aeb1df146756 311
mbed_official 76:aeb1df146756 312 /**
mbed_official 76:aeb1df146756 313 * @}
mbed_official 76:aeb1df146756 314 */
mbed_official 76:aeb1df146756 315
mbed_official 76:aeb1df146756 316 /** @defgroup COMP_Group2 Window mode control function
mbed_official 76:aeb1df146756 317 * @brief Window mode control function
mbed_official 76:aeb1df146756 318 *
mbed_official 76:aeb1df146756 319 @verbatim
mbed_official 76:aeb1df146756 320 ===============================================================================
mbed_official 76:aeb1df146756 321 ##### Window mode control function #####
mbed_official 76:aeb1df146756 322 ===============================================================================
mbed_official 76:aeb1df146756 323
mbed_official 76:aeb1df146756 324 @endverbatim
mbed_official 76:aeb1df146756 325 * @{
mbed_official 76:aeb1df146756 326 */
mbed_official 76:aeb1df146756 327
mbed_official 76:aeb1df146756 328 /**
mbed_official 76:aeb1df146756 329 * @brief Enables or disables the window mode.
mbed_official 76:aeb1df146756 330 * @note In window mode, COMP1 and COMP2 non inverting inputs are connected
mbed_official 76:aeb1df146756 331 * together and only COMP1 non inverting input (PA1) can be used.
mbed_official 76:aeb1df146756 332 * @param NewState: new state of the window mode.
mbed_official 76:aeb1df146756 333 * This parameter can be :
mbed_official 76:aeb1df146756 334 * @arg ENABLE: COMP1 and COMP2 non inverting inputs are connected together.
mbed_official 76:aeb1df146756 335 * @arg DISABLE: OMP1 and COMP2 non inverting inputs are disconnected.
mbed_official 76:aeb1df146756 336 * @retval None
mbed_official 76:aeb1df146756 337 */
mbed_official 76:aeb1df146756 338 void COMP_WindowCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 339 {
mbed_official 76:aeb1df146756 340 /* Check the parameters */
mbed_official 76:aeb1df146756 341 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 342
mbed_official 76:aeb1df146756 343 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 344 {
mbed_official 76:aeb1df146756 345 /* Enable the window mode */
mbed_official 76:aeb1df146756 346 COMP->CSR |= (uint32_t) COMP_CSR_WNDWEN;
mbed_official 76:aeb1df146756 347 }
mbed_official 76:aeb1df146756 348 else
mbed_official 76:aeb1df146756 349 {
mbed_official 76:aeb1df146756 350 /* Disable the window mode */
mbed_official 76:aeb1df146756 351 COMP->CSR &= (uint32_t)(~COMP_CSR_WNDWEN);
mbed_official 76:aeb1df146756 352 }
mbed_official 76:aeb1df146756 353 }
mbed_official 76:aeb1df146756 354
mbed_official 76:aeb1df146756 355 /**
mbed_official 76:aeb1df146756 356 * @}
mbed_official 76:aeb1df146756 357 */
mbed_official 76:aeb1df146756 358
mbed_official 76:aeb1df146756 359 /** @defgroup COMP_Group3 COMP configuration locking function
mbed_official 76:aeb1df146756 360 * @brief COMP1 and COMP2 configuration locking function
mbed_official 76:aeb1df146756 361 * COMP1 and COMP2 configuration can be locked each separately.
mbed_official 76:aeb1df146756 362 * Unlocking is performed by system reset.
mbed_official 76:aeb1df146756 363 *
mbed_official 76:aeb1df146756 364 @verbatim
mbed_official 76:aeb1df146756 365 ===============================================================================
mbed_official 76:aeb1df146756 366 ##### Configuration Lock function #####
mbed_official 76:aeb1df146756 367 ===============================================================================
mbed_official 76:aeb1df146756 368
mbed_official 76:aeb1df146756 369 @endverbatim
mbed_official 76:aeb1df146756 370 * @{
mbed_official 76:aeb1df146756 371 */
mbed_official 76:aeb1df146756 372
mbed_official 76:aeb1df146756 373 /**
mbed_official 76:aeb1df146756 374 * @brief Lock the selected comparator (COMP1/COMP2) configuration.
mbed_official 76:aeb1df146756 375 * @note Locking the configuration means that all control bits are read-only.
mbed_official 76:aeb1df146756 376 * To unlock the comparator configuration, perform a system reset.
mbed_official 76:aeb1df146756 377 * @param COMP_Selection: selects the comparator to be locked
mbed_official 76:aeb1df146756 378 * This parameter can be a value of the following values:
mbed_official 76:aeb1df146756 379 * @arg COMP_Selection_COMP1: COMP1 configuration is locked.
mbed_official 76:aeb1df146756 380 * @arg COMP_Selection_COMP2: COMP2 configuration is locked.
mbed_official 76:aeb1df146756 381 * @retval None
mbed_official 76:aeb1df146756 382 */
mbed_official 76:aeb1df146756 383 void COMP_LockConfig(uint32_t COMP_Selection)
mbed_official 76:aeb1df146756 384 {
mbed_official 76:aeb1df146756 385 /* Check the parameter */
mbed_official 76:aeb1df146756 386 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 76:aeb1df146756 387
mbed_official 76:aeb1df146756 388 /* Set the lock bit corresponding to selected comparator */
mbed_official 76:aeb1df146756 389 COMP->CSR |= (uint32_t) (COMP_CSR_COMP1LOCK<<COMP_Selection);
mbed_official 76:aeb1df146756 390 }
mbed_official 76:aeb1df146756 391
mbed_official 76:aeb1df146756 392 /**
mbed_official 76:aeb1df146756 393 * @}
mbed_official 76:aeb1df146756 394 */
mbed_official 76:aeb1df146756 395
mbed_official 76:aeb1df146756 396 /**
mbed_official 76:aeb1df146756 397 * @}
mbed_official 76:aeb1df146756 398 */
mbed_official 76:aeb1df146756 399
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 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/