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