mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
155:8435094ec241
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

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