mbed library sources

Dependents:   bare

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Mar 19 10:15:22 2014 +0000
Revision:
125:23cc3068a9e4
Synchronized with git revision ace35dfba3748c7cdc102eb38ec6b9e1067c3252

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

[NUCLEO_F302R8] Add cmsis and hal files + change F401RE clock to 84MHz

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 125:23cc3068a9e4 1 /**
mbed_official 125:23cc3068a9e4 2 ******************************************************************************
mbed_official 125:23cc3068a9e4 3 * @file stm32f30x_comp.c
mbed_official 125:23cc3068a9e4 4 * @author MCD Application Team
mbed_official 125:23cc3068a9e4 5 * @version V1.1.0
mbed_official 125:23cc3068a9e4 6 * @date 27-February-2014
mbed_official 125:23cc3068a9e4 7 * @brief This file provides firmware functions to manage the following
mbed_official 125:23cc3068a9e4 8 * functionalities of the 7 analog comparators (COMP1, COMP2...COMP7) peripheral:
mbed_official 125:23cc3068a9e4 9 * + Comparators configuration
mbed_official 125:23cc3068a9e4 10 * + Window mode control
mbed_official 125:23cc3068a9e4 11 *
mbed_official 125:23cc3068a9e4 12 @verbatim
mbed_official 125:23cc3068a9e4 13
mbed_official 125:23cc3068a9e4 14 ==============================================================================
mbed_official 125:23cc3068a9e4 15 ##### COMP Peripheral features #####
mbed_official 125:23cc3068a9e4 16 ==============================================================================
mbed_official 125:23cc3068a9e4 17 [..]
mbed_official 125:23cc3068a9e4 18 The device integrates 7 analog comparators COMP1, COMP2...COMP7:
mbed_official 125:23cc3068a9e4 19 (#) The non inverting input and inverting input can be set to GPIO pins
mbed_official 125:23cc3068a9e4 20 as shown in table1. COMP Inputs below.
mbed_official 125:23cc3068a9e4 21
mbed_official 125:23cc3068a9e4 22 (#) The COMP output is internally is available using COMP_GetOutputLevel()
mbed_official 125:23cc3068a9e4 23 and can be set on GPIO pins. Refer to table 2. COMP Outputs below.
mbed_official 125:23cc3068a9e4 24
mbed_official 125:23cc3068a9e4 25 (#) The COMP output can be redirected to embedded timers (TIM1, TIM2, TIM3...)
mbed_official 125:23cc3068a9e4 26 Refer to table 3. COMP Outputs redirection to embedded timers below.
mbed_official 125:23cc3068a9e4 27
mbed_official 125:23cc3068a9e4 28 (#) The comparators COMP1 and COMP2, COMP3 and COMP4, COMP5 and COMP6 can be combined in window
mbed_official 125:23cc3068a9e4 29 mode and only COMP1, COMP3 and COMP5 non inverting input can be used as non-inverting input.
mbed_official 125:23cc3068a9e4 30
mbed_official 125:23cc3068a9e4 31 (#) The seven comparators have interrupt capability with wake-up
mbed_official 125:23cc3068a9e4 32 from Sleep and Stop modes (through the EXTI controller):
mbed_official 125:23cc3068a9e4 33 (++) COMP1 is internally connected to EXTI Line 21
mbed_official 125:23cc3068a9e4 34 (++) COMP2 is internally connected to EXTI Line 22
mbed_official 125:23cc3068a9e4 35 (++) COMP3 is internally connected to EXTI Line 29
mbed_official 125:23cc3068a9e4 36 (++) COMP4 is internally connected to EXTI Line 30
mbed_official 125:23cc3068a9e4 37 (++) COMP5 is internally connected to EXTI Line 31
mbed_official 125:23cc3068a9e4 38 (++) COMP6 is internally connected to EXTI Line 32
mbed_official 125:23cc3068a9e4 39 (++) COMP7 is internally connected to EXTI Line 33
mbed_official 125:23cc3068a9e4 40
mbed_official 125:23cc3068a9e4 41 [..] Table 1. COMP Inputs
mbed_official 125:23cc3068a9e4 42 +------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 43 | | | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
mbed_official 125:23cc3068a9e4 44 |-----------------|----------------|---------------|---------------------------------------|
mbed_official 125:23cc3068a9e4 45 | | 1/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 46 | | 1/2 VREFINT | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 47 | | 3/4 VREFINT | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 48 | Inverting Input | VREFINT | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 49 | | DAC1 OUT1(PA4) | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 50 | | DAC1 OUT2(PA5) | OK | OK | OK | OK | OK | OK | OK |
mbed_official 125:23cc3068a9e4 51 | | IO1 | PA0 | PA2 | PD15 | PE8 | PD13 | PD10 | PC0 |
mbed_official 125:23cc3068a9e4 52 | | IO2 | --- | --- | PB12 | PB2 | PB10 | PB15 | --- |
mbed_official 125:23cc3068a9e4 53 | | DAC2 OUT1(PA6) | --- | OK | --- | OK | --- | OK | --- |
mbed_official 125:23cc3068a9e4 54 |-----------------|----------------|-------|-------|-------|-------|-------|-------|-------|
mbed_official 125:23cc3068a9e4 55 | Non Inverting | IO1 | PA1 | PA7 | PB14 | PB0 | PD12 | PD11 | PA0 |
mbed_official 125:23cc3068a9e4 56 | Input | IO2 | --- | PA3 | PD14 | PE7 | PB13 | PB11 | PC1 |
mbed_official 125:23cc3068a9e4 57 +------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 58
mbed_official 125:23cc3068a9e4 59 [..] Table 2. COMP Outputs
mbed_official 125:23cc3068a9e4 60 +-------------------------------------------------------+
mbed_official 125:23cc3068a9e4 61 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
mbed_official 125:23cc3068a9e4 62 |-------|-------|-------|-------|-------|-------|-------|
mbed_official 125:23cc3068a9e4 63 | PA0 | PA2 | PB1 | PC8 | PC7 | PA10 | PC2 |
mbed_official 125:23cc3068a9e4 64 | PF4 | PA7 | --- | PA8 | PA9 | PC6 | --- |
mbed_official 125:23cc3068a9e4 65 | PA6 | PA12 | --- | --- | --- | --- | --- |
mbed_official 125:23cc3068a9e4 66 | PA11 | PB9 | --- | --- | --- | --- | --- |
mbed_official 125:23cc3068a9e4 67 | PB8 | --- | --- | --- | --- | --- | --- |
mbed_official 125:23cc3068a9e4 68 +-------------------------------------------------------+
mbed_official 125:23cc3068a9e4 69
mbed_official 125:23cc3068a9e4 70 [..] Table 3. COMP Outputs redirection to embedded timers
mbed_official 125:23cc3068a9e4 71 +----------------------------------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 72 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
mbed_official 125:23cc3068a9e4 73 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
mbed_official 125:23cc3068a9e4 74 | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN | TIM1 BKIN |
mbed_official 125:23cc3068a9e4 75 | | | | | | | |
mbed_official 125:23cc3068a9e4 76 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
mbed_official 125:23cc3068a9e4 77 | | | | | | | |
mbed_official 125:23cc3068a9e4 78 | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN | TIM8 BKIN |
mbed_official 125:23cc3068a9e4 79 | | | | | | | |
mbed_official 125:23cc3068a9e4 80 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 | TIM8 BKIN2 |
mbed_official 125:23cc3068a9e4 81 | | | | | | | |
mbed_official 125:23cc3068a9e4 82 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 | TIM1 BKIN2 |
mbed_official 125:23cc3068a9e4 83 | + | + | + | + | + | + | + |
mbed_official 125:23cc3068a9e4 84 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 | TIM8BKIN2 |
mbed_official 125:23cc3068a9e4 85 | | | | | | | |
mbed_official 125:23cc3068a9e4 86 | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM1 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM8 OCREFCLR | TIM1 OCREFCLR |
mbed_official 125:23cc3068a9e4 87 | | | | | | | |
mbed_official 125:23cc3068a9e4 88 | TIM1 IC1 | TIM1 IC1 | TIM2 OCREFCLR | TIM3 IC3 | TIM2 IC1 | TIM2 IC2 | TIM8 OCREFCLR |
mbed_official 125:23cc3068a9e4 89 | | | | | | | |
mbed_official 125:23cc3068a9e4 90 | TIM2 IC4 | TIM2 IC4 | TIM3 IC2 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM2 OCREFCLR | TIM2 IC3 |
mbed_official 125:23cc3068a9e4 91 | | | | | | | |
mbed_official 125:23cc3068a9e4 92 | TIM2 OCREFCLR | TIM2 OCREFCLR | TIM4 IC1 | TIM4 IC2 | TIM4 IC3 | TIM16 OCREFCLR| TIM1 IC2 |
mbed_official 125:23cc3068a9e4 93 | | | | | | | |
mbed_official 125:23cc3068a9e4 94 | TIM3 IC1 | TIM3 IC1 | TIM15 IC1 | TIM15 OCREFCLR| TIM16 BKIN | TIM16 IC1 | TIM17 OCREFCLR|
mbed_official 125:23cc3068a9e4 95 | | | | | | | |
mbed_official 125:23cc3068a9e4 96 | TIM3 OCREFCLR | TIM3 OCREFCLR | TIM15 BKIN | TIM15 IC2 | TIM17 IC1 | TIM4 IC4 | TIM17 BKIN |
mbed_official 125:23cc3068a9e4 97 +----------------------------------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 98
mbed_official 125:23cc3068a9e4 99 [..] Table 4. COMP Outputs blanking sources
mbed_official 125:23cc3068a9e4 100 +----------------------------------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 101 | COMP1 | COMP2 | COMP3 | COMP4 | COMP5 | COMP6 | COMP7 |
mbed_official 125:23cc3068a9e4 102 |----------------|----------------|----------------|----------------|----------------|----------------|----------------|
mbed_official 125:23cc3068a9e4 103 | TIM1 OC5 | TIM1 OC5 | TIM1 OC5 | TIM3 OC4 | TIM3 OC3 | TIM2 OC4 | TIM1 OC5 |
mbed_official 125:23cc3068a9e4 104 | | | | | | | |
mbed_official 125:23cc3068a9e4 105 | TIM2 OC3 | TIM2 OC3 | -------- | TIM8 OC5 | TIM8 OC5 | TIM8 OC5 | TIM8 OC5 |
mbed_official 125:23cc3068a9e4 106 | | | | | | | |
mbed_official 125:23cc3068a9e4 107 | TIM3 OC3 | TIM3 OC3 | TIM2 OC4 | TIM15 OC1 | TIM8 BKIN | TIM15 OC2 | TIM15 OC2 |
mbed_official 125:23cc3068a9e4 108 | | | | | | | |
mbed_official 125:23cc3068a9e4 109 +----------------------------------------------------------------------------------------------------------------------+
mbed_official 125:23cc3068a9e4 110
mbed_official 125:23cc3068a9e4 111
mbed_official 125:23cc3068a9e4 112 ##### How to use this driver #####
mbed_official 125:23cc3068a9e4 113 ==============================================================================
mbed_official 125:23cc3068a9e4 114 [..]
mbed_official 125:23cc3068a9e4 115 This driver provides functions to configure and program the Comparators
mbed_official 125:23cc3068a9e4 116 of all STM32F30x devices.
mbed_official 125:23cc3068a9e4 117
mbed_official 125:23cc3068a9e4 118 To use the comparator, perform the following steps:
mbed_official 125:23cc3068a9e4 119
mbed_official 125:23cc3068a9e4 120 (#) Enable the SYSCFG APB clock to get write access to comparator
mbed_official 125:23cc3068a9e4 121 register using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
mbed_official 125:23cc3068a9e4 122
mbed_official 125:23cc3068a9e4 123 (#) Configure the comparator input in analog mode using GPIO_Init()
mbed_official 125:23cc3068a9e4 124
mbed_official 125:23cc3068a9e4 125 (#) Configure the comparator output in alternate function mode
mbed_official 125:23cc3068a9e4 126 using GPIO_Init() and use GPIO_PinAFConfig() function to map the
mbed_official 125:23cc3068a9e4 127 comparator output to the GPIO pin
mbed_official 125:23cc3068a9e4 128
mbed_official 125:23cc3068a9e4 129 (#) Configure the comparator using COMP_Init() function:
mbed_official 125:23cc3068a9e4 130 (++) Select the inverting input
mbed_official 125:23cc3068a9e4 131 (++) Select the non-inverting input
mbed_official 125:23cc3068a9e4 132 (++) Select the output polarity
mbed_official 125:23cc3068a9e4 133 (++) Select the output redirection
mbed_official 125:23cc3068a9e4 134 (++) Select the hysteresis level
mbed_official 125:23cc3068a9e4 135 (++) Select the power mode
mbed_official 125:23cc3068a9e4 136
mbed_official 125:23cc3068a9e4 137 (#) Enable the comparator using COMP_Cmd() function
mbed_official 125:23cc3068a9e4 138
mbed_official 125:23cc3068a9e4 139 (#) If required enable the COMP interrupt by configuring and enabling
mbed_official 125:23cc3068a9e4 140 EXTI line in Interrupt mode and selecting the desired sensitivity
mbed_official 125:23cc3068a9e4 141 level using EXTI_Init() function. After that enable the comparator
mbed_official 125:23cc3068a9e4 142 interrupt vector using NVIC_Init() function.
mbed_official 125:23cc3068a9e4 143
mbed_official 125:23cc3068a9e4 144 @endverbatim
mbed_official 125:23cc3068a9e4 145 *
mbed_official 125:23cc3068a9e4 146 ******************************************************************************
mbed_official 125:23cc3068a9e4 147 * @attention
mbed_official 125:23cc3068a9e4 148 *
mbed_official 125:23cc3068a9e4 149 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 125:23cc3068a9e4 150 *
mbed_official 125:23cc3068a9e4 151 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 125:23cc3068a9e4 152 * are permitted provided that the following conditions are met:
mbed_official 125:23cc3068a9e4 153 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 125:23cc3068a9e4 154 * this list of conditions and the following disclaimer.
mbed_official 125:23cc3068a9e4 155 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 125:23cc3068a9e4 156 * this list of conditions and the following disclaimer in the documentation
mbed_official 125:23cc3068a9e4 157 * and/or other materials provided with the distribution.
mbed_official 125:23cc3068a9e4 158 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 125:23cc3068a9e4 159 * may be used to endorse or promote products derived from this software
mbed_official 125:23cc3068a9e4 160 * without specific prior written permission.
mbed_official 125:23cc3068a9e4 161 *
mbed_official 125:23cc3068a9e4 162 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 125:23cc3068a9e4 163 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 125:23cc3068a9e4 164 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 125:23cc3068a9e4 165 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 125:23cc3068a9e4 166 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 125:23cc3068a9e4 167 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 125:23cc3068a9e4 168 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 125:23cc3068a9e4 169 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 125:23cc3068a9e4 170 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 125:23cc3068a9e4 171 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 125:23cc3068a9e4 172 *
mbed_official 125:23cc3068a9e4 173 ******************************************************************************
mbed_official 125:23cc3068a9e4 174 */
mbed_official 125:23cc3068a9e4 175
mbed_official 125:23cc3068a9e4 176 /* Includes ------------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 177 #include "stm32f30x_comp.h"
mbed_official 125:23cc3068a9e4 178
mbed_official 125:23cc3068a9e4 179 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 125:23cc3068a9e4 180 * @{
mbed_official 125:23cc3068a9e4 181 */
mbed_official 125:23cc3068a9e4 182
mbed_official 125:23cc3068a9e4 183 /** @defgroup COMP
mbed_official 125:23cc3068a9e4 184 * @brief COMP driver modules
mbed_official 125:23cc3068a9e4 185 * @{
mbed_official 125:23cc3068a9e4 186 */
mbed_official 125:23cc3068a9e4 187
mbed_official 125:23cc3068a9e4 188 /* Private typedef -----------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 189 /* Private define ------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 190 /* CSR register Mask */
mbed_official 125:23cc3068a9e4 191 #define COMP_CSR_CLEAR_MASK ((uint32_t)0x00000003)
mbed_official 125:23cc3068a9e4 192
mbed_official 125:23cc3068a9e4 193 /* Private macro -------------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 194 /* Private variables ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 195 /* Private function prototypes -----------------------------------------------*/
mbed_official 125:23cc3068a9e4 196 /* Private functions ---------------------------------------------------------*/
mbed_official 125:23cc3068a9e4 197
mbed_official 125:23cc3068a9e4 198 /** @defgroup COMP_Private_Functions
mbed_official 125:23cc3068a9e4 199 * @{
mbed_official 125:23cc3068a9e4 200 */
mbed_official 125:23cc3068a9e4 201
mbed_official 125:23cc3068a9e4 202 /** @defgroup COMP_Group1 Initialization and Configuration functions
mbed_official 125:23cc3068a9e4 203 * @brief Initialization and Configuration functions
mbed_official 125:23cc3068a9e4 204 *
mbed_official 125:23cc3068a9e4 205 @verbatim
mbed_official 125:23cc3068a9e4 206 ===============================================================================
mbed_official 125:23cc3068a9e4 207 ##### Initialization and Configuration functions #####
mbed_official 125:23cc3068a9e4 208 ===============================================================================
mbed_official 125:23cc3068a9e4 209
mbed_official 125:23cc3068a9e4 210 @endverbatim
mbed_official 125:23cc3068a9e4 211 * @{
mbed_official 125:23cc3068a9e4 212 */
mbed_official 125:23cc3068a9e4 213
mbed_official 125:23cc3068a9e4 214 /**
mbed_official 125:23cc3068a9e4 215 * @brief Deinitializes COMP peripheral registers to their default reset values.
mbed_official 125:23cc3068a9e4 216 * @note Deinitialization can't be performed if the COMP configuration is locked.
mbed_official 125:23cc3068a9e4 217 * To unlock the configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 218 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 219 * This parameter can be COMP_Selection_COMPx where x can be 1 to 7
mbed_official 125:23cc3068a9e4 220 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 221 * @param None
mbed_official 125:23cc3068a9e4 222 * @retval None
mbed_official 125:23cc3068a9e4 223 */
mbed_official 125:23cc3068a9e4 224 void COMP_DeInit(uint32_t COMP_Selection)
mbed_official 125:23cc3068a9e4 225 {
mbed_official 125:23cc3068a9e4 226 /*!< Set COMP_CSR register to reset value */
mbed_official 125:23cc3068a9e4 227 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) = ((uint32_t)0x00000000);
mbed_official 125:23cc3068a9e4 228 }
mbed_official 125:23cc3068a9e4 229
mbed_official 125:23cc3068a9e4 230 /**
mbed_official 125:23cc3068a9e4 231 * @brief Initializes the COMP peripheral according to the specified parameters
mbed_official 125:23cc3068a9e4 232 * in COMP_InitStruct
mbed_official 125:23cc3068a9e4 233 * @note If the selected comparator is locked, initialization can't be performed.
mbed_official 125:23cc3068a9e4 234 * To unlock the configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 235 * @note By default, PA1 is selected as COMP1 non inverting input.
mbed_official 125:23cc3068a9e4 236 * To use PA4 as COMP1 non inverting input call COMP_SwitchCmd() after COMP_Init()
mbed_official 125:23cc3068a9e4 237 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 238 * This parameter can be COMP_Selection_COMPx where x can be 1 to 7
mbed_official 125:23cc3068a9e4 239 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 240 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains
mbed_official 125:23cc3068a9e4 241 * the configuration information for the specified COMP peripheral.
mbed_official 125:23cc3068a9e4 242 * - COMP_InvertingInput specifies the inverting input of COMP
mbed_official 125:23cc3068a9e4 243 * - COMP_NonInvertingInput specifies the non inverting input of COMP
mbed_official 125:23cc3068a9e4 244 * - COMP_Output connect COMP output to selected timer
mbed_official 125:23cc3068a9e4 245 * input (Input capture / Output Compare Reference Clear / Break Input)
mbed_official 125:23cc3068a9e4 246 * - COMP_BlankingSrce specifies the blanking source of COMP
mbed_official 125:23cc3068a9e4 247 * - COMP_OutputPol select output polarity
mbed_official 125:23cc3068a9e4 248 * - COMP_Hysteresis configures COMP hysteresis value
mbed_official 125:23cc3068a9e4 249 * - COMP_Mode configures COMP power mode
mbed_official 125:23cc3068a9e4 250 * @retval None
mbed_official 125:23cc3068a9e4 251 */
mbed_official 125:23cc3068a9e4 252 void COMP_Init(uint32_t COMP_Selection, COMP_InitTypeDef* COMP_InitStruct)
mbed_official 125:23cc3068a9e4 253 {
mbed_official 125:23cc3068a9e4 254 uint32_t tmpreg = 0;
mbed_official 125:23cc3068a9e4 255
mbed_official 125:23cc3068a9e4 256 /* Check the parameters */
mbed_official 125:23cc3068a9e4 257 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 125:23cc3068a9e4 258 assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput));
mbed_official 125:23cc3068a9e4 259 assert_param(IS_COMP_NONINVERTING_INPUT(COMP_InitStruct->COMP_NonInvertingInput));
mbed_official 125:23cc3068a9e4 260 assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_Output));
mbed_official 125:23cc3068a9e4 261 assert_param(IS_COMP_BLANKING_SOURCE(COMP_InitStruct->COMP_BlankingSrce));
mbed_official 125:23cc3068a9e4 262 assert_param(IS_COMP_OUTPUT_POL(COMP_InitStruct->COMP_OutputPol));
mbed_official 125:23cc3068a9e4 263 assert_param(IS_COMP_HYSTERESIS(COMP_InitStruct->COMP_Hysteresis));
mbed_official 125:23cc3068a9e4 264 assert_param(IS_COMP_MODE(COMP_InitStruct->COMP_Mode));
mbed_official 125:23cc3068a9e4 265
mbed_official 125:23cc3068a9e4 266 /*!< Get the COMPx_CSR register value */
mbed_official 125:23cc3068a9e4 267 tmpreg = *(__IO uint32_t *) (COMP_BASE + COMP_Selection);
mbed_official 125:23cc3068a9e4 268
mbed_official 125:23cc3068a9e4 269 /*!< Clear the COMP1SW1, COMPxINSEL, COMPxOUTSEL, COMPxPOL, COMPxHYST and COMPxMODE bits */
mbed_official 125:23cc3068a9e4 270 tmpreg &= (uint32_t) (COMP_CSR_CLEAR_MASK);
mbed_official 125:23cc3068a9e4 271
mbed_official 125:23cc3068a9e4 272 /*!< Configure COMP: inverting input, output redirection, hysteresis value and power mode */
mbed_official 125:23cc3068a9e4 273 /*!< Set COMPxINSEL bits according to COMP_InitStruct->COMP_InvertingInput value */
mbed_official 125:23cc3068a9e4 274 /*!< Set COMPxNONINSEL bits according to COMP_InitStruct->COMP_NonInvertingInput value */
mbed_official 125:23cc3068a9e4 275 /*!< Set COMPxBLANKING bits according to COMP_InitStruct->COMP_BlankingSrce value */
mbed_official 125:23cc3068a9e4 276 /*!< Set COMPxOUTSEL bits according to COMP_InitStruct->COMP_Output value */
mbed_official 125:23cc3068a9e4 277 /*!< Set COMPxPOL bit according to COMP_InitStruct->COMP_OutputPol value */
mbed_official 125:23cc3068a9e4 278 /*!< Set COMPxHYST bits according to COMP_InitStruct->COMP_Hysteresis value */
mbed_official 125:23cc3068a9e4 279 /*!< Set COMPxMODE bits according to COMP_InitStruct->COMP_Mode value */
mbed_official 125:23cc3068a9e4 280 tmpreg |= (uint32_t)(COMP_InitStruct->COMP_InvertingInput | COMP_InitStruct->COMP_NonInvertingInput |
mbed_official 125:23cc3068a9e4 281 COMP_InitStruct->COMP_Output | COMP_InitStruct->COMP_OutputPol | COMP_InitStruct->COMP_BlankingSrce |
mbed_official 125:23cc3068a9e4 282 COMP_InitStruct->COMP_Hysteresis | COMP_InitStruct->COMP_Mode);
mbed_official 125:23cc3068a9e4 283
mbed_official 125:23cc3068a9e4 284 /*!< Write to COMPx_CSR register */
mbed_official 125:23cc3068a9e4 285 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) = tmpreg;
mbed_official 125:23cc3068a9e4 286 }
mbed_official 125:23cc3068a9e4 287
mbed_official 125:23cc3068a9e4 288 /**
mbed_official 125:23cc3068a9e4 289 * @brief Fills each COMP_InitStruct member with its default value.
mbed_official 125:23cc3068a9e4 290 * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure which will
mbed_official 125:23cc3068a9e4 291 * be initialized.
mbed_official 125:23cc3068a9e4 292 * @retval None
mbed_official 125:23cc3068a9e4 293 */
mbed_official 125:23cc3068a9e4 294 void COMP_StructInit(COMP_InitTypeDef* COMP_InitStruct)
mbed_official 125:23cc3068a9e4 295 {
mbed_official 125:23cc3068a9e4 296 COMP_InitStruct->COMP_InvertingInput = COMP_InvertingInput_1_4VREFINT;
mbed_official 125:23cc3068a9e4 297 COMP_InitStruct->COMP_NonInvertingInput = COMP_NonInvertingInput_IO1;
mbed_official 125:23cc3068a9e4 298 COMP_InitStruct->COMP_Output = COMP_Output_None;
mbed_official 125:23cc3068a9e4 299 COMP_InitStruct->COMP_BlankingSrce = COMP_BlankingSrce_None;
mbed_official 125:23cc3068a9e4 300 COMP_InitStruct->COMP_OutputPol = COMP_OutputPol_NonInverted;
mbed_official 125:23cc3068a9e4 301 COMP_InitStruct->COMP_Hysteresis = COMP_Hysteresis_No;
mbed_official 125:23cc3068a9e4 302 COMP_InitStruct->COMP_Mode = COMP_Mode_UltraLowPower;
mbed_official 125:23cc3068a9e4 303 }
mbed_official 125:23cc3068a9e4 304
mbed_official 125:23cc3068a9e4 305 /**
mbed_official 125:23cc3068a9e4 306 * @brief Enable or disable the COMP peripheral.
mbed_official 125:23cc3068a9e4 307 * @note If the selected comparator is locked, enable/disable can't be performed.
mbed_official 125:23cc3068a9e4 308 * To unlock the configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 309 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 310 * This parameter can be COMP_Selection_COMPx where x can be 1 to 7
mbed_official 125:23cc3068a9e4 311 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 312 * @param NewState: new state of the COMP peripheral.
mbed_official 125:23cc3068a9e4 313 * This parameter can be: ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 314 * When enabled, the comparator compares the non inverting input with
mbed_official 125:23cc3068a9e4 315 * the inverting input and the comparison result is available
mbed_official 125:23cc3068a9e4 316 * on comparator output.
mbed_official 125:23cc3068a9e4 317 * When disabled, the comparator doesn't perform comparison and the
mbed_official 125:23cc3068a9e4 318 * output level is low.
mbed_official 125:23cc3068a9e4 319 * @retval None
mbed_official 125:23cc3068a9e4 320 */
mbed_official 125:23cc3068a9e4 321 void COMP_Cmd(uint32_t COMP_Selection, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 322 {
mbed_official 125:23cc3068a9e4 323 /* Check the parameters */
mbed_official 125:23cc3068a9e4 324 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 125:23cc3068a9e4 325 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 326
mbed_official 125:23cc3068a9e4 327 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 328 {
mbed_official 125:23cc3068a9e4 329 /* Enable the selected COMPx peripheral */
mbed_official 125:23cc3068a9e4 330 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMPxEN);
mbed_official 125:23cc3068a9e4 331 }
mbed_official 125:23cc3068a9e4 332 else
mbed_official 125:23cc3068a9e4 333 {
mbed_official 125:23cc3068a9e4 334 /* Disable the selected COMP peripheral */
mbed_official 125:23cc3068a9e4 335 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMPxEN);
mbed_official 125:23cc3068a9e4 336 }
mbed_official 125:23cc3068a9e4 337 }
mbed_official 125:23cc3068a9e4 338
mbed_official 125:23cc3068a9e4 339 /**
mbed_official 125:23cc3068a9e4 340 * @brief Close or Open the SW1 switch.
mbed_official 125:23cc3068a9e4 341 * @note If the COMP1 is locked, Close/Open the SW1 switch can't be performed.
mbed_official 125:23cc3068a9e4 342 * To unlock the configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 343 * @note This switch is solely intended to redirect signals onto high
mbed_official 125:23cc3068a9e4 344 * impedance input, such as COMP1 non-inverting input (highly resistive switch)
mbed_official 125:23cc3068a9e4 345 * @param NewState: New state of the analog switch.
mbed_official 125:23cc3068a9e4 346 * This parameter can be
mbed_official 125:23cc3068a9e4 347 * ENABLE so the SW1 is closed; PA1 is connected to PA4
mbed_official 125:23cc3068a9e4 348 * or DISABLE so the SW1 switch is open; PA1 is disconnected from PA4
mbed_official 125:23cc3068a9e4 349 * @retval None
mbed_official 125:23cc3068a9e4 350 */
mbed_official 125:23cc3068a9e4 351 void COMP_SwitchCmd(uint32_t COMP_Selection, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 352 {
mbed_official 125:23cc3068a9e4 353 /* Check the parameter */
mbed_official 125:23cc3068a9e4 354 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 355
mbed_official 125:23cc3068a9e4 356 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 357 {
mbed_official 125:23cc3068a9e4 358 /* Close SW1 switch */
mbed_official 125:23cc3068a9e4 359 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMP1SW1);
mbed_official 125:23cc3068a9e4 360 }
mbed_official 125:23cc3068a9e4 361 else
mbed_official 125:23cc3068a9e4 362 {
mbed_official 125:23cc3068a9e4 363 /* Open SW1 switch */
mbed_official 125:23cc3068a9e4 364 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMP1SW1);
mbed_official 125:23cc3068a9e4 365 }
mbed_official 125:23cc3068a9e4 366 }
mbed_official 125:23cc3068a9e4 367
mbed_official 125:23cc3068a9e4 368 /**
mbed_official 125:23cc3068a9e4 369 * @brief Return the output level (high or low) of the selected comparator.
mbed_official 125:23cc3068a9e4 370 * The output level depends on the selected polarity.
mbed_official 125:23cc3068a9e4 371 * If the polarity is not inverted:
mbed_official 125:23cc3068a9e4 372 * - Comparator output is low when the non-inverting input is at a lower
mbed_official 125:23cc3068a9e4 373 * voltage than the inverting input
mbed_official 125:23cc3068a9e4 374 * - Comparator output is high when the non-inverting input is at a higher
mbed_official 125:23cc3068a9e4 375 * voltage than the inverting input
mbed_official 125:23cc3068a9e4 376 * If the polarity is inverted:
mbed_official 125:23cc3068a9e4 377 * - Comparator output is high when the non-inverting input is at a lower
mbed_official 125:23cc3068a9e4 378 * voltage than the inverting input
mbed_official 125:23cc3068a9e4 379 * - Comparator output is low when the non-inverting input is at a higher
mbed_official 125:23cc3068a9e4 380 * voltage than the inverting input
mbed_official 125:23cc3068a9e4 381 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 382 * This parameter can be COMP_Selection_COMPx where x can be 1 to 7
mbed_official 125:23cc3068a9e4 383 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 384 * @retval Returns the selected comparator output level: low or high.
mbed_official 125:23cc3068a9e4 385 *
mbed_official 125:23cc3068a9e4 386 */
mbed_official 125:23cc3068a9e4 387 uint32_t COMP_GetOutputLevel(uint32_t COMP_Selection)
mbed_official 125:23cc3068a9e4 388 {
mbed_official 125:23cc3068a9e4 389 uint32_t compout = 0x0;
mbed_official 125:23cc3068a9e4 390
mbed_official 125:23cc3068a9e4 391 /* Check the parameters */
mbed_official 125:23cc3068a9e4 392 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 125:23cc3068a9e4 393
mbed_official 125:23cc3068a9e4 394 /* Check if selected comparator output is high */
mbed_official 125:23cc3068a9e4 395 if ((*(__IO uint32_t *) (COMP_BASE + COMP_Selection) & (COMP_CSR_COMPxOUT)) != 0)
mbed_official 125:23cc3068a9e4 396 {
mbed_official 125:23cc3068a9e4 397 compout = COMP_OutputLevel_High;
mbed_official 125:23cc3068a9e4 398 }
mbed_official 125:23cc3068a9e4 399 else
mbed_official 125:23cc3068a9e4 400 {
mbed_official 125:23cc3068a9e4 401 compout = COMP_OutputLevel_Low;
mbed_official 125:23cc3068a9e4 402 }
mbed_official 125:23cc3068a9e4 403
mbed_official 125:23cc3068a9e4 404 /* Return the comparator output level */
mbed_official 125:23cc3068a9e4 405 return (uint32_t)(compout);
mbed_official 125:23cc3068a9e4 406 }
mbed_official 125:23cc3068a9e4 407
mbed_official 125:23cc3068a9e4 408 /**
mbed_official 125:23cc3068a9e4 409 * @}
mbed_official 125:23cc3068a9e4 410 */
mbed_official 125:23cc3068a9e4 411
mbed_official 125:23cc3068a9e4 412 /** @defgroup COMP_Group2 Window mode control function
mbed_official 125:23cc3068a9e4 413 * @brief Window mode control function
mbed_official 125:23cc3068a9e4 414 *
mbed_official 125:23cc3068a9e4 415 @verbatim
mbed_official 125:23cc3068a9e4 416 ===============================================================================
mbed_official 125:23cc3068a9e4 417 ##### Window mode control function #####
mbed_official 125:23cc3068a9e4 418 ===============================================================================
mbed_official 125:23cc3068a9e4 419
mbed_official 125:23cc3068a9e4 420 @endverbatim
mbed_official 125:23cc3068a9e4 421 * @{
mbed_official 125:23cc3068a9e4 422 */
mbed_official 125:23cc3068a9e4 423
mbed_official 125:23cc3068a9e4 424 /**
mbed_official 125:23cc3068a9e4 425 * @brief Enables or disables the window mode.
mbed_official 125:23cc3068a9e4 426 * Window mode for comparators makes use of two comparators:
mbed_official 125:23cc3068a9e4 427 * COMP1 and COM2, COMP3 and COMP4, COMP5 and COMP6.
mbed_official 125:23cc3068a9e4 428 * In window mode, COMPx and COMPx-1 (where x can be 2, 4 or 6)
mbed_official 125:23cc3068a9e4 429 * non inverting inputs are connected together and only COMPx-1 non
mbed_official 125:23cc3068a9e4 430 * inverting input can be used.
mbed_official 125:23cc3068a9e4 431 * e.g When window mode enabled for COMP4, COMP3 non inverting input (PB14 or PD14)
mbed_official 125:23cc3068a9e4 432 * is to be used.
mbed_official 125:23cc3068a9e4 433 * @note If the COMPx is locked, ENABLE/DISABLE the window mode can't be performed.
mbed_official 125:23cc3068a9e4 434 * To unlock the configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 435 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 436 * This parameter can be COMP_Selection_COMPx where x can be 2, 4 or 6
mbed_official 125:23cc3068a9e4 437 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 438 * param NewState: new state of the window mode.
mbed_official 125:23cc3068a9e4 439 * This parameter can be ENABLE or DISABLE.
mbed_official 125:23cc3068a9e4 440 * When enbaled, COMPx and COMPx-1 non inverting inputs are connected together.
mbed_official 125:23cc3068a9e4 441 * When disabled, COMPx and COMPx-1 non inverting inputs are disconnected.
mbed_official 125:23cc3068a9e4 442 * @retval None
mbed_official 125:23cc3068a9e4 443 */
mbed_official 125:23cc3068a9e4 444 void COMP_WindowCmd(uint32_t COMP_Selection, FunctionalState NewState)
mbed_official 125:23cc3068a9e4 445 {
mbed_official 125:23cc3068a9e4 446 /* Check the parameters */
mbed_official 125:23cc3068a9e4 447 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 125:23cc3068a9e4 448 assert_param(IS_COMP_WINDOW(COMP_Selection));
mbed_official 125:23cc3068a9e4 449
mbed_official 125:23cc3068a9e4 450 if (NewState != DISABLE)
mbed_official 125:23cc3068a9e4 451 {
mbed_official 125:23cc3068a9e4 452 /* Enable the window mode */
mbed_official 125:23cc3068a9e4 453 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) COMP_CSR_COMPxWNDWEN;
mbed_official 125:23cc3068a9e4 454 }
mbed_official 125:23cc3068a9e4 455 else
mbed_official 125:23cc3068a9e4 456 {
mbed_official 125:23cc3068a9e4 457 /* Disable the window mode */
mbed_official 125:23cc3068a9e4 458 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) &= (uint32_t)(~COMP_CSR_COMPxWNDWEN);
mbed_official 125:23cc3068a9e4 459 }
mbed_official 125:23cc3068a9e4 460 }
mbed_official 125:23cc3068a9e4 461
mbed_official 125:23cc3068a9e4 462 /**
mbed_official 125:23cc3068a9e4 463 * @}
mbed_official 125:23cc3068a9e4 464 */
mbed_official 125:23cc3068a9e4 465
mbed_official 125:23cc3068a9e4 466 /** @defgroup COMP_Group3 COMP configuration locking function
mbed_official 125:23cc3068a9e4 467 * @brief COMP1, COMP2,...COMP7 configuration locking function
mbed_official 125:23cc3068a9e4 468 * COMP1, COMP2,...COMP7 configuration can be locked each separately.
mbed_official 125:23cc3068a9e4 469 * Unlocking is performed by system reset.
mbed_official 125:23cc3068a9e4 470 *
mbed_official 125:23cc3068a9e4 471 @verbatim
mbed_official 125:23cc3068a9e4 472 ===============================================================================
mbed_official 125:23cc3068a9e4 473 ##### Configuration Lock function #####
mbed_official 125:23cc3068a9e4 474 ===============================================================================
mbed_official 125:23cc3068a9e4 475
mbed_official 125:23cc3068a9e4 476 @endverbatim
mbed_official 125:23cc3068a9e4 477 * @{
mbed_official 125:23cc3068a9e4 478 */
mbed_official 125:23cc3068a9e4 479
mbed_official 125:23cc3068a9e4 480 /**
mbed_official 125:23cc3068a9e4 481 * @brief Lock the selected comparator (COMP1/COMP2) configuration.
mbed_official 125:23cc3068a9e4 482 * @note Locking the configuration means that all control bits are read-only.
mbed_official 125:23cc3068a9e4 483 * To unlock the comparator configuration, perform a system reset.
mbed_official 125:23cc3068a9e4 484 * @param COMP_Selection: the selected comparator.
mbed_official 125:23cc3068a9e4 485 * This parameter can be COMP_Selection_COMPx where x can be 1 to 7
mbed_official 125:23cc3068a9e4 486 * to select the COMP peripheral.
mbed_official 125:23cc3068a9e4 487 * @retval None
mbed_official 125:23cc3068a9e4 488 */
mbed_official 125:23cc3068a9e4 489 void COMP_LockConfig(uint32_t COMP_Selection)
mbed_official 125:23cc3068a9e4 490 {
mbed_official 125:23cc3068a9e4 491 /* Check the parameter */
mbed_official 125:23cc3068a9e4 492 assert_param(IS_COMP_ALL_PERIPH(COMP_Selection));
mbed_official 125:23cc3068a9e4 493
mbed_official 125:23cc3068a9e4 494 /* Set the lock bit corresponding to selected comparator */
mbed_official 125:23cc3068a9e4 495 *(__IO uint32_t *) (COMP_BASE + COMP_Selection) |= (uint32_t) (COMP_CSR_COMPxLOCK);
mbed_official 125:23cc3068a9e4 496 }
mbed_official 125:23cc3068a9e4 497
mbed_official 125:23cc3068a9e4 498 /**
mbed_official 125:23cc3068a9e4 499 * @}
mbed_official 125:23cc3068a9e4 500 */
mbed_official 125:23cc3068a9e4 501
mbed_official 125:23cc3068a9e4 502 /**
mbed_official 125:23cc3068a9e4 503 * @}
mbed_official 125:23cc3068a9e4 504 */
mbed_official 125:23cc3068a9e4 505
mbed_official 125:23cc3068a9e4 506 /**
mbed_official 125:23cc3068a9e4 507 * @}
mbed_official 125:23cc3068a9e4 508 */
mbed_official 125:23cc3068a9e4 509
mbed_official 125:23cc3068a9e4 510 /**
mbed_official 125:23cc3068a9e4 511 * @}
mbed_official 125:23cc3068a9e4 512 */
mbed_official 125:23cc3068a9e4 513
mbed_official 125:23cc3068a9e4 514 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/