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