mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_comp.c@308:59cc78a25982, 2014-09-05 (annotated)
- Committer:
- todotani
- Date:
- Fri Sep 05 14:20:33 2014 +0000
- Revision:
- 308:59cc78a25982
- Parent:
- 106:ced8cbb51063
BLE_Health_Thermometer for mbed HRM1017 with BLE library 0.1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 76:aeb1df146756 | 1 | /** |
mbed_official | 76:aeb1df146756 | 2 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 3 | * @file stm32l1xx_comp.c |
mbed_official | 76:aeb1df146756 | 4 | * @author MCD Application Team |
mbed_official | 80:66393a7b209d | 5 | * @version V1.3.0 |
mbed_official | 80:66393a7b209d | 6 | * @date 31-January-2014 |
mbed_official | 76:aeb1df146756 | 7 | * @brief This file provides firmware functions to manage the following |
mbed_official | 76:aeb1df146756 | 8 | * functionalities of the comparators (COMP1 and COMP2) peripheral: |
mbed_official | 76:aeb1df146756 | 9 | * + Comparators configuration |
mbed_official | 76:aeb1df146756 | 10 | * + Window mode control |
mbed_official | 76:aeb1df146756 | 11 | * + Internal Reference Voltage (VREFINT) output |
mbed_official | 76:aeb1df146756 | 12 | * |
mbed_official | 76:aeb1df146756 | 13 | * @verbatim |
mbed_official | 76:aeb1df146756 | 14 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 15 | ##### How to use this driver ##### |
mbed_official | 76:aeb1df146756 | 16 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 17 | [..] The device integrates two analog comparators COMP1 and COMP2: |
mbed_official | 76:aeb1df146756 | 18 | (+) COMP1 is a fixed threshold (VREFINT) that shares the non inverting |
mbed_official | 76:aeb1df146756 | 19 | input with the ADC channels. |
mbed_official | 76:aeb1df146756 | 20 | (+) COMP2 is a rail-to-rail comparator whose the inverting input can be |
mbed_official | 76:aeb1df146756 | 21 | selected among: DAC_OUT1, DAC_OUT2, 1/4 VREFINT, 1/2 VERFINT, 3/4 |
mbed_official | 76:aeb1df146756 | 22 | VREFINT, VREFINT, PB3 and whose the output can be redirected to |
mbed_official | 76:aeb1df146756 | 23 | embedded timers: TIM2, TIM3, TIM4, TIM10. |
mbed_official | 76:aeb1df146756 | 24 | |
mbed_official | 76:aeb1df146756 | 25 | (+) The two comparators COMP1 and COMP2 can be combined in window mode. |
mbed_official | 76:aeb1df146756 | 26 | |
mbed_official | 76:aeb1df146756 | 27 | -@- |
mbed_official | 76:aeb1df146756 | 28 | (#@) Comparator APB clock must be enabled to get write access |
mbed_official | 76:aeb1df146756 | 29 | to comparator register using |
mbed_official | 76:aeb1df146756 | 30 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_COMP, ENABLE). |
mbed_official | 76:aeb1df146756 | 31 | |
mbed_official | 76:aeb1df146756 | 32 | (#@) COMP1 comparator and ADC can't be used at the same time since |
mbed_official | 76:aeb1df146756 | 33 | they share the same ADC switch matrix (analog switches). |
mbed_official | 76:aeb1df146756 | 34 | |
mbed_official | 76:aeb1df146756 | 35 | (#@) When an I/O is used as comparator input, the corresponding GPIO |
mbed_official | 76:aeb1df146756 | 36 | registers should be configured in analog mode. |
mbed_official | 76:aeb1df146756 | 37 | |
mbed_official | 76:aeb1df146756 | 38 | (#@) Comparators outputs (CMP1OUT and CMP2OUT) are not mapped on |
mbed_official | 76:aeb1df146756 | 39 | GPIO pin. They are only internal. |
mbed_official | 76:aeb1df146756 | 40 | To get the comparator output level, use COMP_GetOutputLevel(). |
mbed_official | 76:aeb1df146756 | 41 | |
mbed_official | 76:aeb1df146756 | 42 | (#@) COMP1 and COMP2 outputs are internally connected to EXTI Line 21 |
mbed_official | 76:aeb1df146756 | 43 | and EXTI Line 22 respectively. |
mbed_official | 76:aeb1df146756 | 44 | Interrupts can be used by configuring the EXTI Line using the |
mbed_official | 76:aeb1df146756 | 45 | EXTI peripheral driver. |
mbed_official | 76:aeb1df146756 | 46 | |
mbed_official | 76:aeb1df146756 | 47 | (#@) After enabling the comparator (COMP1 or COMP2), user should wait |
mbed_official | 76:aeb1df146756 | 48 | for start-up time (tSTART) to get right output levels. |
mbed_official | 76:aeb1df146756 | 49 | Please refer to product datasheet for more information on tSTART. |
mbed_official | 76:aeb1df146756 | 50 | |
mbed_official | 76:aeb1df146756 | 51 | (#@) Comparators cannot be used to exit the device from Sleep or Stop |
mbed_official | 76:aeb1df146756 | 52 | mode when the internal reference voltage is switched off using |
mbed_official | 76:aeb1df146756 | 53 | the PWR_UltraLowPowerCmd() function (ULP bit in the PWR_CR register). |
mbed_official | 76:aeb1df146756 | 54 | |
mbed_official | 76:aeb1df146756 | 55 | @endverbatim |
mbed_official | 76:aeb1df146756 | 56 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 57 | * @attention |
mbed_official | 76:aeb1df146756 | 58 | * |
mbed_official | 106:ced8cbb51063 | 59 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 60 | * |
mbed_official | 106:ced8cbb51063 | 61 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 106:ced8cbb51063 | 62 | * are permitted provided that the following conditions are met: |
mbed_official | 106:ced8cbb51063 | 63 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 64 | * this list of conditions and the following disclaimer. |
mbed_official | 106:ced8cbb51063 | 65 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 106:ced8cbb51063 | 66 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 106:ced8cbb51063 | 67 | * and/or other materials provided with the distribution. |
mbed_official | 106:ced8cbb51063 | 68 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 106:ced8cbb51063 | 69 | * may be used to endorse or promote products derived from this software |
mbed_official | 106:ced8cbb51063 | 70 | * without specific prior written permission. |
mbed_official | 76:aeb1df146756 | 71 | * |
mbed_official | 106:ced8cbb51063 | 72 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 106:ced8cbb51063 | 73 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 106:ced8cbb51063 | 74 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 106:ced8cbb51063 | 75 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 106:ced8cbb51063 | 76 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 106:ced8cbb51063 | 77 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 106:ced8cbb51063 | 78 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 106:ced8cbb51063 | 79 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 106:ced8cbb51063 | 80 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 106:ced8cbb51063 | 81 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 76:aeb1df146756 | 82 | * |
mbed_official | 76:aeb1df146756 | 83 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 84 | */ |
mbed_official | 76:aeb1df146756 | 85 | |
mbed_official | 76:aeb1df146756 | 86 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 87 | #include "stm32l1xx_comp.h" |
mbed_official | 76:aeb1df146756 | 88 | |
mbed_official | 76:aeb1df146756 | 89 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 90 | * @{ |
mbed_official | 76:aeb1df146756 | 91 | */ |
mbed_official | 76:aeb1df146756 | 92 | |
mbed_official | 76:aeb1df146756 | 93 | /** @defgroup COMP |
mbed_official | 76:aeb1df146756 | 94 | * @brief COMP driver modules. |
mbed_official | 76:aeb1df146756 | 95 | * @{ |
mbed_official | 76:aeb1df146756 | 96 | */ |
mbed_official | 76:aeb1df146756 | 97 | |
mbed_official | 76:aeb1df146756 | 98 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 99 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 100 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 101 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 102 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 103 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 104 | |
mbed_official | 76:aeb1df146756 | 105 | /** @defgroup COMP_Private_Functions |
mbed_official | 76:aeb1df146756 | 106 | * @{ |
mbed_official | 76:aeb1df146756 | 107 | */ |
mbed_official | 76:aeb1df146756 | 108 | |
mbed_official | 76:aeb1df146756 | 109 | /** @defgroup COMP_Group1 Initialization and Configuration functions |
mbed_official | 76:aeb1df146756 | 110 | * @brief Initialization and Configuration functions. |
mbed_official | 76:aeb1df146756 | 111 | * |
mbed_official | 76:aeb1df146756 | 112 | @verbatim |
mbed_official | 76:aeb1df146756 | 113 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 114 | ##### Initialization and Configuration functions ##### |
mbed_official | 76:aeb1df146756 | 115 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 116 | |
mbed_official | 76:aeb1df146756 | 117 | @endverbatim |
mbed_official | 76:aeb1df146756 | 118 | * @{ |
mbed_official | 76:aeb1df146756 | 119 | */ |
mbed_official | 76:aeb1df146756 | 120 | |
mbed_official | 76:aeb1df146756 | 121 | /** |
mbed_official | 76:aeb1df146756 | 122 | * @brief Deinitializes COMP peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 123 | * @param None |
mbed_official | 76:aeb1df146756 | 124 | * @retval None |
mbed_official | 76:aeb1df146756 | 125 | */ |
mbed_official | 76:aeb1df146756 | 126 | void COMP_DeInit(void) |
mbed_official | 76:aeb1df146756 | 127 | { |
mbed_official | 76:aeb1df146756 | 128 | COMP->CSR = ((uint32_t)0x00000000); /*!< Set COMP->CSR to reset value */ |
mbed_official | 76:aeb1df146756 | 129 | } |
mbed_official | 76:aeb1df146756 | 130 | |
mbed_official | 76:aeb1df146756 | 131 | /** |
mbed_official | 76:aeb1df146756 | 132 | * @brief Initializes the COMP2 peripheral according to the specified parameters |
mbed_official | 76:aeb1df146756 | 133 | * in the COMP_InitStruct. |
mbed_official | 76:aeb1df146756 | 134 | * @note This function configures only COMP2. |
mbed_official | 76:aeb1df146756 | 135 | * @note COMP2 comparator is enabled as soon as the INSEL[2:0] bits are |
mbed_official | 76:aeb1df146756 | 136 | * different from "000". |
mbed_official | 76:aeb1df146756 | 137 | * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 138 | * the configuration information for the specified COMP peripheral. |
mbed_official | 76:aeb1df146756 | 139 | * @retval None |
mbed_official | 76:aeb1df146756 | 140 | */ |
mbed_official | 76:aeb1df146756 | 141 | void COMP_Init(COMP_InitTypeDef* COMP_InitStruct) |
mbed_official | 76:aeb1df146756 | 142 | { |
mbed_official | 76:aeb1df146756 | 143 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 144 | |
mbed_official | 76:aeb1df146756 | 145 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 146 | assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput)); |
mbed_official | 76:aeb1df146756 | 147 | assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_OutputSelect)); |
mbed_official | 76:aeb1df146756 | 148 | assert_param(IS_COMP_SPEED(COMP_InitStruct->COMP_Speed)); |
mbed_official | 76:aeb1df146756 | 149 | |
mbed_official | 76:aeb1df146756 | 150 | /*!< Get the COMP CSR value */ |
mbed_official | 76:aeb1df146756 | 151 | tmpreg = COMP->CSR; |
mbed_official | 76:aeb1df146756 | 152 | |
mbed_official | 76:aeb1df146756 | 153 | /*!< Clear the INSEL[2:0], OUTSEL[1:0] and SPEED bits */ |
mbed_official | 76:aeb1df146756 | 154 | tmpreg &= (uint32_t) (~(uint32_t) (COMP_CSR_OUTSEL | COMP_CSR_INSEL | COMP_CSR_SPEED)); |
mbed_official | 76:aeb1df146756 | 155 | |
mbed_official | 76:aeb1df146756 | 156 | /*!< Configure COMP: speed, inversion input selection and output redirection */ |
mbed_official | 76:aeb1df146756 | 157 | /*!< Set SPEED bit according to COMP_InitStruct->COMP_Speed value */ |
mbed_official | 76:aeb1df146756 | 158 | /*!< Set INSEL bits according to COMP_InitStruct->COMP_InvertingInput value */ |
mbed_official | 76:aeb1df146756 | 159 | /*!< Set OUTSEL bits according to COMP_InitStruct->COMP_OutputSelect value */ |
mbed_official | 76:aeb1df146756 | 160 | tmpreg |= (uint32_t)((COMP_InitStruct->COMP_Speed | COMP_InitStruct->COMP_InvertingInput |
mbed_official | 76:aeb1df146756 | 161 | | COMP_InitStruct->COMP_OutputSelect)); |
mbed_official | 76:aeb1df146756 | 162 | |
mbed_official | 76:aeb1df146756 | 163 | /*!< The COMP2 comparator is enabled as soon as the INSEL[2:0] bits value are |
mbed_official | 76:aeb1df146756 | 164 | different from "000" */ |
mbed_official | 76:aeb1df146756 | 165 | /*!< Write to COMP_CSR register */ |
mbed_official | 76:aeb1df146756 | 166 | COMP->CSR = tmpreg; |
mbed_official | 76:aeb1df146756 | 167 | } |
mbed_official | 76:aeb1df146756 | 168 | |
mbed_official | 76:aeb1df146756 | 169 | /** |
mbed_official | 76:aeb1df146756 | 170 | * @brief Enable or disable the COMP1 peripheral. |
mbed_official | 76:aeb1df146756 | 171 | * @note After enabling COMP1, the following functions should be called to |
mbed_official | 76:aeb1df146756 | 172 | * connect the selected GPIO input to COMP1 non inverting input: |
mbed_official | 76:aeb1df146756 | 173 | * @note Enable switch control mode using SYSCFG_RISwitchControlModeCmd() |
mbed_official | 76:aeb1df146756 | 174 | * @note Close VCOMP switch using SYSCFG_RIIOSwitchConfig() |
mbed_official | 76:aeb1df146756 | 175 | * @note Close the I/O switch number n corresponding to the I/O |
mbed_official | 76:aeb1df146756 | 176 | * using SYSCFG_RIIOSwitchConfig() |
mbed_official | 76:aeb1df146756 | 177 | * @param NewState: new state of the COMP1 peripheral. |
mbed_official | 76:aeb1df146756 | 178 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 179 | * @note This function enables/disables only the COMP1. |
mbed_official | 76:aeb1df146756 | 180 | * @retval None |
mbed_official | 76:aeb1df146756 | 181 | */ |
mbed_official | 76:aeb1df146756 | 182 | void COMP_Cmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 183 | { |
mbed_official | 76:aeb1df146756 | 184 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 185 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 186 | |
mbed_official | 76:aeb1df146756 | 187 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 188 | { |
mbed_official | 76:aeb1df146756 | 189 | /* Enable the COMP1 */ |
mbed_official | 76:aeb1df146756 | 190 | COMP->CSR |= (uint32_t) COMP_CSR_CMP1EN; |
mbed_official | 76:aeb1df146756 | 191 | } |
mbed_official | 76:aeb1df146756 | 192 | else |
mbed_official | 76:aeb1df146756 | 193 | { |
mbed_official | 76:aeb1df146756 | 194 | /* Disable the COMP1 */ |
mbed_official | 76:aeb1df146756 | 195 | COMP->CSR &= (uint32_t)(~COMP_CSR_CMP1EN); |
mbed_official | 76:aeb1df146756 | 196 | } |
mbed_official | 76:aeb1df146756 | 197 | } |
mbed_official | 76:aeb1df146756 | 198 | |
mbed_official | 76:aeb1df146756 | 199 | /** |
mbed_official | 76:aeb1df146756 | 200 | * @brief Return the output level (high or low) of the selected comparator. |
mbed_official | 76:aeb1df146756 | 201 | * @note Comparator output is low when the noninverting input is at a lower |
mbed_official | 76:aeb1df146756 | 202 | * voltage than the inverting input. |
mbed_official | 76:aeb1df146756 | 203 | * @note Comparator output is high when the noninverting input is at a higher |
mbed_official | 76:aeb1df146756 | 204 | * voltage than the inverting input. |
mbed_official | 76:aeb1df146756 | 205 | * @note Comparators outputs aren't available on GPIO (outputs levels are |
mbed_official | 76:aeb1df146756 | 206 | * only internal). The COMP1 and COMP2 outputs are connected internally |
mbed_official | 76:aeb1df146756 | 207 | * to the EXTI Line 21 and Line 22 respectively. |
mbed_official | 76:aeb1df146756 | 208 | * @param COMP_Selection: the selected comparator. |
mbed_official | 76:aeb1df146756 | 209 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 210 | * @arg COMP_Selection_COMP1: COMP1 selected |
mbed_official | 76:aeb1df146756 | 211 | * @arg COMP_Selection_COMP2: COMP2 selected |
mbed_official | 76:aeb1df146756 | 212 | * @retval Returns the selected comparator output level. |
mbed_official | 76:aeb1df146756 | 213 | */ |
mbed_official | 76:aeb1df146756 | 214 | uint8_t COMP_GetOutputLevel(uint32_t COMP_Selection) |
mbed_official | 76:aeb1df146756 | 215 | { |
mbed_official | 76:aeb1df146756 | 216 | uint8_t compout = 0x0; |
mbed_official | 76:aeb1df146756 | 217 | |
mbed_official | 76:aeb1df146756 | 218 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 219 | assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); |
mbed_official | 76:aeb1df146756 | 220 | |
mbed_official | 76:aeb1df146756 | 221 | /* Check if Comparator 1 is selected */ |
mbed_official | 76:aeb1df146756 | 222 | if(COMP_Selection == COMP_Selection_COMP1) |
mbed_official | 76:aeb1df146756 | 223 | { |
mbed_official | 76:aeb1df146756 | 224 | /* Check if comparator 1 output level is high */ |
mbed_official | 76:aeb1df146756 | 225 | if((COMP->CSR & COMP_CSR_CMP1OUT) != (uint8_t) RESET) |
mbed_official | 76:aeb1df146756 | 226 | { |
mbed_official | 76:aeb1df146756 | 227 | /* Get Comparator 1 output level */ |
mbed_official | 76:aeb1df146756 | 228 | compout = (uint8_t) COMP_OutputLevel_High; |
mbed_official | 76:aeb1df146756 | 229 | } |
mbed_official | 76:aeb1df146756 | 230 | /* comparator 1 output level is low */ |
mbed_official | 76:aeb1df146756 | 231 | else |
mbed_official | 76:aeb1df146756 | 232 | { |
mbed_official | 76:aeb1df146756 | 233 | /* Get Comparator 1 output level */ |
mbed_official | 76:aeb1df146756 | 234 | compout = (uint8_t) COMP_OutputLevel_Low; |
mbed_official | 76:aeb1df146756 | 235 | } |
mbed_official | 76:aeb1df146756 | 236 | } |
mbed_official | 76:aeb1df146756 | 237 | /* Comparator 2 is selected */ |
mbed_official | 76:aeb1df146756 | 238 | else |
mbed_official | 76:aeb1df146756 | 239 | { |
mbed_official | 76:aeb1df146756 | 240 | /* Check if comparator 2 output level is high */ |
mbed_official | 76:aeb1df146756 | 241 | if((COMP->CSR & COMP_CSR_CMP2OUT) != (uint8_t) RESET) |
mbed_official | 76:aeb1df146756 | 242 | { |
mbed_official | 76:aeb1df146756 | 243 | /* Get Comparator output level */ |
mbed_official | 76:aeb1df146756 | 244 | compout = (uint8_t) COMP_OutputLevel_High; |
mbed_official | 76:aeb1df146756 | 245 | } |
mbed_official | 76:aeb1df146756 | 246 | /* comparator 2 output level is low */ |
mbed_official | 76:aeb1df146756 | 247 | else |
mbed_official | 76:aeb1df146756 | 248 | { |
mbed_official | 76:aeb1df146756 | 249 | /* Get Comparator 2 output level */ |
mbed_official | 76:aeb1df146756 | 250 | compout = (uint8_t) COMP_OutputLevel_Low; |
mbed_official | 76:aeb1df146756 | 251 | } |
mbed_official | 76:aeb1df146756 | 252 | } |
mbed_official | 76:aeb1df146756 | 253 | /* Return the comparator output level */ |
mbed_official | 76:aeb1df146756 | 254 | return (uint8_t)(compout); |
mbed_official | 76:aeb1df146756 | 255 | } |
mbed_official | 76:aeb1df146756 | 256 | |
mbed_official | 76:aeb1df146756 | 257 | /** |
mbed_official | 76:aeb1df146756 | 258 | * @brief Close or Open the SW1 switch. |
mbed_official | 76:aeb1df146756 | 259 | * @param NewState: new state of the SW1 switch. |
mbed_official | 76:aeb1df146756 | 260 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 261 | * @note ENABLE to close the SW1 switch |
mbed_official | 76:aeb1df146756 | 262 | * @note DISABLE to open the SW1 switch |
mbed_official | 76:aeb1df146756 | 263 | * @retval None. |
mbed_official | 76:aeb1df146756 | 264 | */ |
mbed_official | 76:aeb1df146756 | 265 | void COMP_SW1SwitchConfig(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 266 | { |
mbed_official | 76:aeb1df146756 | 267 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 268 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 269 | |
mbed_official | 76:aeb1df146756 | 270 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 271 | { |
mbed_official | 76:aeb1df146756 | 272 | /* Close SW1 switch */ |
mbed_official | 76:aeb1df146756 | 273 | COMP->CSR |= (uint32_t) COMP_CSR_SW1; |
mbed_official | 76:aeb1df146756 | 274 | } |
mbed_official | 76:aeb1df146756 | 275 | else |
mbed_official | 76:aeb1df146756 | 276 | { |
mbed_official | 76:aeb1df146756 | 277 | /* Open SW1 switch */ |
mbed_official | 76:aeb1df146756 | 278 | COMP->CSR &= (uint32_t)(~COMP_CSR_SW1); |
mbed_official | 76:aeb1df146756 | 279 | } |
mbed_official | 76:aeb1df146756 | 280 | } |
mbed_official | 76:aeb1df146756 | 281 | |
mbed_official | 76:aeb1df146756 | 282 | /** |
mbed_official | 76:aeb1df146756 | 283 | * @} |
mbed_official | 76:aeb1df146756 | 284 | */ |
mbed_official | 76:aeb1df146756 | 285 | |
mbed_official | 76:aeb1df146756 | 286 | /** @defgroup COMP_Group2 Window mode control function |
mbed_official | 76:aeb1df146756 | 287 | * @brief Window mode control function. |
mbed_official | 76:aeb1df146756 | 288 | * |
mbed_official | 76:aeb1df146756 | 289 | @verbatim |
mbed_official | 76:aeb1df146756 | 290 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 291 | ##### Window mode control function ##### |
mbed_official | 76:aeb1df146756 | 292 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 293 | |
mbed_official | 76:aeb1df146756 | 294 | @endverbatim |
mbed_official | 76:aeb1df146756 | 295 | * @{ |
mbed_official | 76:aeb1df146756 | 296 | */ |
mbed_official | 76:aeb1df146756 | 297 | |
mbed_official | 76:aeb1df146756 | 298 | /** |
mbed_official | 76:aeb1df146756 | 299 | * @brief Enables or disables the window mode. |
mbed_official | 76:aeb1df146756 | 300 | * In window mode: |
mbed_official | 76:aeb1df146756 | 301 | * @note COMP1 inverting input is fixed to VREFINT defining the first |
mbed_official | 76:aeb1df146756 | 302 | * threshold. |
mbed_official | 76:aeb1df146756 | 303 | * @note COMP2 inverting input is configurable (DAC_OUT1, DAC_OUT2, VREFINT |
mbed_official | 76:aeb1df146756 | 304 | * sub-multiples, PB3) defining the second threshold. |
mbed_official | 76:aeb1df146756 | 305 | * @note COMP1 and COMP2 non inverting inputs are connected together. |
mbed_official | 76:aeb1df146756 | 306 | * @note In window mode, only the Group 6 (PB4 or PB5) can be used as |
mbed_official | 76:aeb1df146756 | 307 | * noninverting inputs. |
mbed_official | 76:aeb1df146756 | 308 | * @param NewState: new state of the window mode. |
mbed_official | 76:aeb1df146756 | 309 | * This parameter can be ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 310 | * @retval None |
mbed_official | 76:aeb1df146756 | 311 | */ |
mbed_official | 76:aeb1df146756 | 312 | void COMP_WindowCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 313 | { |
mbed_official | 76:aeb1df146756 | 314 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 315 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 316 | |
mbed_official | 76:aeb1df146756 | 317 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 318 | { |
mbed_official | 76:aeb1df146756 | 319 | /* Enable the window mode */ |
mbed_official | 76:aeb1df146756 | 320 | COMP->CSR |= (uint32_t) COMP_CSR_WNDWE; |
mbed_official | 76:aeb1df146756 | 321 | } |
mbed_official | 76:aeb1df146756 | 322 | else |
mbed_official | 76:aeb1df146756 | 323 | { |
mbed_official | 76:aeb1df146756 | 324 | /* Disable the window mode */ |
mbed_official | 76:aeb1df146756 | 325 | COMP->CSR &= (uint32_t)(~COMP_CSR_WNDWE); |
mbed_official | 76:aeb1df146756 | 326 | } |
mbed_official | 76:aeb1df146756 | 327 | } |
mbed_official | 76:aeb1df146756 | 328 | |
mbed_official | 76:aeb1df146756 | 329 | /** |
mbed_official | 76:aeb1df146756 | 330 | * @} |
mbed_official | 76:aeb1df146756 | 331 | */ |
mbed_official | 76:aeb1df146756 | 332 | |
mbed_official | 76:aeb1df146756 | 333 | /** @defgroup COMP_Group3 Internal Reference Voltage output function |
mbed_official | 76:aeb1df146756 | 334 | * @brief Internal Reference Voltage (VREFINT) output function. |
mbed_official | 76:aeb1df146756 | 335 | * |
mbed_official | 76:aeb1df146756 | 336 | @verbatim |
mbed_official | 76:aeb1df146756 | 337 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 338 | ##### Internal Reference Voltage (VREFINT) output function ##### |
mbed_official | 76:aeb1df146756 | 339 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 340 | |
mbed_official | 76:aeb1df146756 | 341 | @endverbatim |
mbed_official | 76:aeb1df146756 | 342 | * @{ |
mbed_official | 76:aeb1df146756 | 343 | */ |
mbed_official | 76:aeb1df146756 | 344 | |
mbed_official | 76:aeb1df146756 | 345 | /** |
mbed_official | 76:aeb1df146756 | 346 | * @brief Enables or disables the output of internal reference voltage (VREFINT). |
mbed_official | 76:aeb1df146756 | 347 | * The VREFINT output can be routed to any I/O in group 3: CH8 (PB0) or |
mbed_official | 76:aeb1df146756 | 348 | * CH9 (PB1). |
mbed_official | 76:aeb1df146756 | 349 | * To correctly use this function, the SYSCFG_RIIOSwitchConfig() function |
mbed_official | 76:aeb1df146756 | 350 | * should be called after. |
mbed_official | 76:aeb1df146756 | 351 | * @param NewState: new state of the Vrefint output. |
mbed_official | 76:aeb1df146756 | 352 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 353 | * @retval None |
mbed_official | 76:aeb1df146756 | 354 | */ |
mbed_official | 76:aeb1df146756 | 355 | void COMP_VrefintOutputCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 356 | { |
mbed_official | 76:aeb1df146756 | 357 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 358 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 359 | |
mbed_official | 76:aeb1df146756 | 360 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 361 | { |
mbed_official | 76:aeb1df146756 | 362 | /* Enable the output of internal reference voltage */ |
mbed_official | 76:aeb1df146756 | 363 | COMP->CSR |= (uint32_t) COMP_CSR_VREFOUTEN; |
mbed_official | 76:aeb1df146756 | 364 | } |
mbed_official | 76:aeb1df146756 | 365 | else |
mbed_official | 76:aeb1df146756 | 366 | { |
mbed_official | 76:aeb1df146756 | 367 | /* Disable the output of internal reference voltage */ |
mbed_official | 76:aeb1df146756 | 368 | COMP->CSR &= (uint32_t) (~COMP_CSR_VREFOUTEN); |
mbed_official | 76:aeb1df146756 | 369 | } |
mbed_official | 76:aeb1df146756 | 370 | } |
mbed_official | 76:aeb1df146756 | 371 | |
mbed_official | 76:aeb1df146756 | 372 | /** |
mbed_official | 76:aeb1df146756 | 373 | * @} |
mbed_official | 76:aeb1df146756 | 374 | */ |
mbed_official | 76:aeb1df146756 | 375 | |
mbed_official | 76:aeb1df146756 | 376 | /** |
mbed_official | 76:aeb1df146756 | 377 | * @} |
mbed_official | 76:aeb1df146756 | 378 | */ |
mbed_official | 76:aeb1df146756 | 379 | |
mbed_official | 76:aeb1df146756 | 380 | /** |
mbed_official | 76:aeb1df146756 | 381 | * @} |
mbed_official | 76:aeb1df146756 | 382 | */ |
mbed_official | 76:aeb1df146756 | 383 | |
mbed_official | 76:aeb1df146756 | 384 | /** |
mbed_official | 76:aeb1df146756 | 385 | * @} |
mbed_official | 76:aeb1df146756 | 386 | */ |
mbed_official | 76:aeb1df146756 | 387 | |
mbed_official | 76:aeb1df146756 | 388 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |