mbed library with additional peripherals for ST F401 board
Fork of mbed-src by
This mbed LIB has additional peripherals for ST F401 board
- UART2 : PA_3 rx, PA_2 tx
- UART3 : PC_7 rx, PC_6 tx
- I2C2 : PB_3 SDA, PB_10 SCL
- I2C3 : PB_4 SDA, PA_8 SCL
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L152RE/stm32l1xx_comp.c@76:aeb1df146756, 2014-01-27 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Jan 27 14:30:07 2014 +0000
- Revision:
- 76:aeb1df146756
- Child:
- 80:66393a7b209d
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd
Full URL: https://github.com/mbedmicro/mbed/commit/a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd/
Add NUCLEO_L152RE
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 | 76:aeb1df146756 | 5 | * @version V1.2.0 |
mbed_official | 76:aeb1df146756 | 6 | * @date 22-February-2013 |
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 | 76:aeb1df146756 | 59 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
mbed_official | 76:aeb1df146756 | 60 | * |
mbed_official | 76:aeb1df146756 | 61 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
mbed_official | 76:aeb1df146756 | 62 | * You may not use this file except in compliance with the License. |
mbed_official | 76:aeb1df146756 | 63 | * You may obtain a copy of the License at: |
mbed_official | 76:aeb1df146756 | 64 | * |
mbed_official | 76:aeb1df146756 | 65 | * http://www.st.com/software_license_agreement_liberty_v2 |
mbed_official | 76:aeb1df146756 | 66 | * |
mbed_official | 76:aeb1df146756 | 67 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 76:aeb1df146756 | 68 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 76:aeb1df146756 | 69 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 76:aeb1df146756 | 70 | * See the License for the specific language governing permissions and |
mbed_official | 76:aeb1df146756 | 71 | * limitations under the License. |
mbed_official | 76:aeb1df146756 | 72 | * |
mbed_official | 76:aeb1df146756 | 73 | ****************************************************************************** |
mbed_official | 76:aeb1df146756 | 74 | */ |
mbed_official | 76:aeb1df146756 | 75 | |
mbed_official | 76:aeb1df146756 | 76 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 77 | #include "stm32l1xx_comp.h" |
mbed_official | 76:aeb1df146756 | 78 | |
mbed_official | 76:aeb1df146756 | 79 | /** @addtogroup STM32L1xx_StdPeriph_Driver |
mbed_official | 76:aeb1df146756 | 80 | * @{ |
mbed_official | 76:aeb1df146756 | 81 | */ |
mbed_official | 76:aeb1df146756 | 82 | |
mbed_official | 76:aeb1df146756 | 83 | /** @defgroup COMP |
mbed_official | 76:aeb1df146756 | 84 | * @brief COMP driver modules. |
mbed_official | 76:aeb1df146756 | 85 | * @{ |
mbed_official | 76:aeb1df146756 | 86 | */ |
mbed_official | 76:aeb1df146756 | 87 | |
mbed_official | 76:aeb1df146756 | 88 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 89 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 90 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 91 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 92 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 93 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 76:aeb1df146756 | 94 | |
mbed_official | 76:aeb1df146756 | 95 | /** @defgroup COMP_Private_Functions |
mbed_official | 76:aeb1df146756 | 96 | * @{ |
mbed_official | 76:aeb1df146756 | 97 | */ |
mbed_official | 76:aeb1df146756 | 98 | |
mbed_official | 76:aeb1df146756 | 99 | /** @defgroup COMP_Group1 Initialization and Configuration functions |
mbed_official | 76:aeb1df146756 | 100 | * @brief Initialization and Configuration functions. |
mbed_official | 76:aeb1df146756 | 101 | * |
mbed_official | 76:aeb1df146756 | 102 | @verbatim |
mbed_official | 76:aeb1df146756 | 103 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 104 | ##### Initialization and Configuration functions ##### |
mbed_official | 76:aeb1df146756 | 105 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 106 | |
mbed_official | 76:aeb1df146756 | 107 | @endverbatim |
mbed_official | 76:aeb1df146756 | 108 | * @{ |
mbed_official | 76:aeb1df146756 | 109 | */ |
mbed_official | 76:aeb1df146756 | 110 | |
mbed_official | 76:aeb1df146756 | 111 | /** |
mbed_official | 76:aeb1df146756 | 112 | * @brief Deinitializes COMP peripheral registers to their default reset values. |
mbed_official | 76:aeb1df146756 | 113 | * @param None |
mbed_official | 76:aeb1df146756 | 114 | * @retval None |
mbed_official | 76:aeb1df146756 | 115 | */ |
mbed_official | 76:aeb1df146756 | 116 | void COMP_DeInit(void) |
mbed_official | 76:aeb1df146756 | 117 | { |
mbed_official | 76:aeb1df146756 | 118 | COMP->CSR = ((uint32_t)0x00000000); /*!< Set COMP->CSR to reset value */ |
mbed_official | 76:aeb1df146756 | 119 | } |
mbed_official | 76:aeb1df146756 | 120 | |
mbed_official | 76:aeb1df146756 | 121 | /** |
mbed_official | 76:aeb1df146756 | 122 | * @brief Initializes the COMP2 peripheral according to the specified parameters |
mbed_official | 76:aeb1df146756 | 123 | * in the COMP_InitStruct. |
mbed_official | 76:aeb1df146756 | 124 | * @note This function configures only COMP2. |
mbed_official | 76:aeb1df146756 | 125 | * @note COMP2 comparator is enabled as soon as the INSEL[2:0] bits are |
mbed_official | 76:aeb1df146756 | 126 | * different from "000". |
mbed_official | 76:aeb1df146756 | 127 | * @param COMP_InitStruct: pointer to an COMP_InitTypeDef structure that contains |
mbed_official | 76:aeb1df146756 | 128 | * the configuration information for the specified COMP peripheral. |
mbed_official | 76:aeb1df146756 | 129 | * @retval None |
mbed_official | 76:aeb1df146756 | 130 | */ |
mbed_official | 76:aeb1df146756 | 131 | void COMP_Init(COMP_InitTypeDef* COMP_InitStruct) |
mbed_official | 76:aeb1df146756 | 132 | { |
mbed_official | 76:aeb1df146756 | 133 | uint32_t tmpreg = 0; |
mbed_official | 76:aeb1df146756 | 134 | |
mbed_official | 76:aeb1df146756 | 135 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 136 | assert_param(IS_COMP_INVERTING_INPUT(COMP_InitStruct->COMP_InvertingInput)); |
mbed_official | 76:aeb1df146756 | 137 | assert_param(IS_COMP_OUTPUT(COMP_InitStruct->COMP_OutputSelect)); |
mbed_official | 76:aeb1df146756 | 138 | assert_param(IS_COMP_SPEED(COMP_InitStruct->COMP_Speed)); |
mbed_official | 76:aeb1df146756 | 139 | |
mbed_official | 76:aeb1df146756 | 140 | /*!< Get the COMP CSR value */ |
mbed_official | 76:aeb1df146756 | 141 | tmpreg = COMP->CSR; |
mbed_official | 76:aeb1df146756 | 142 | |
mbed_official | 76:aeb1df146756 | 143 | /*!< Clear the INSEL[2:0], OUTSEL[1:0] and SPEED bits */ |
mbed_official | 76:aeb1df146756 | 144 | tmpreg &= (uint32_t) (~(uint32_t) (COMP_CSR_OUTSEL | COMP_CSR_INSEL | COMP_CSR_SPEED)); |
mbed_official | 76:aeb1df146756 | 145 | |
mbed_official | 76:aeb1df146756 | 146 | /*!< Configure COMP: speed, inversion input selection and output redirection */ |
mbed_official | 76:aeb1df146756 | 147 | /*!< Set SPEED bit according to COMP_InitStruct->COMP_Speed value */ |
mbed_official | 76:aeb1df146756 | 148 | /*!< Set INSEL bits according to COMP_InitStruct->COMP_InvertingInput value */ |
mbed_official | 76:aeb1df146756 | 149 | /*!< Set OUTSEL bits according to COMP_InitStruct->COMP_OutputSelect value */ |
mbed_official | 76:aeb1df146756 | 150 | tmpreg |= (uint32_t)((COMP_InitStruct->COMP_Speed | COMP_InitStruct->COMP_InvertingInput |
mbed_official | 76:aeb1df146756 | 151 | | COMP_InitStruct->COMP_OutputSelect)); |
mbed_official | 76:aeb1df146756 | 152 | |
mbed_official | 76:aeb1df146756 | 153 | /*!< The COMP2 comparator is enabled as soon as the INSEL[2:0] bits value are |
mbed_official | 76:aeb1df146756 | 154 | different from "000" */ |
mbed_official | 76:aeb1df146756 | 155 | /*!< Write to COMP_CSR register */ |
mbed_official | 76:aeb1df146756 | 156 | COMP->CSR = tmpreg; |
mbed_official | 76:aeb1df146756 | 157 | } |
mbed_official | 76:aeb1df146756 | 158 | |
mbed_official | 76:aeb1df146756 | 159 | /** |
mbed_official | 76:aeb1df146756 | 160 | * @brief Enable or disable the COMP1 peripheral. |
mbed_official | 76:aeb1df146756 | 161 | * @note After enabling COMP1, the following functions should be called to |
mbed_official | 76:aeb1df146756 | 162 | * connect the selected GPIO input to COMP1 non inverting input: |
mbed_official | 76:aeb1df146756 | 163 | * @note Enable switch control mode using SYSCFG_RISwitchControlModeCmd() |
mbed_official | 76:aeb1df146756 | 164 | * @note Close VCOMP switch using SYSCFG_RIIOSwitchConfig() |
mbed_official | 76:aeb1df146756 | 165 | * @note Close the I/O switch number n corresponding to the I/O |
mbed_official | 76:aeb1df146756 | 166 | * using SYSCFG_RIIOSwitchConfig() |
mbed_official | 76:aeb1df146756 | 167 | * @param NewState: new state of the COMP1 peripheral. |
mbed_official | 76:aeb1df146756 | 168 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 169 | * @note This function enables/disables only the COMP1. |
mbed_official | 76:aeb1df146756 | 170 | * @retval None |
mbed_official | 76:aeb1df146756 | 171 | */ |
mbed_official | 76:aeb1df146756 | 172 | void COMP_Cmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 173 | { |
mbed_official | 76:aeb1df146756 | 174 | /* Check the parameter */ |
mbed_official | 76:aeb1df146756 | 175 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 176 | |
mbed_official | 76:aeb1df146756 | 177 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 178 | { |
mbed_official | 76:aeb1df146756 | 179 | /* Enable the COMP1 */ |
mbed_official | 76:aeb1df146756 | 180 | COMP->CSR |= (uint32_t) COMP_CSR_CMP1EN; |
mbed_official | 76:aeb1df146756 | 181 | } |
mbed_official | 76:aeb1df146756 | 182 | else |
mbed_official | 76:aeb1df146756 | 183 | { |
mbed_official | 76:aeb1df146756 | 184 | /* Disable the COMP1 */ |
mbed_official | 76:aeb1df146756 | 185 | COMP->CSR &= (uint32_t)(~COMP_CSR_CMP1EN); |
mbed_official | 76:aeb1df146756 | 186 | } |
mbed_official | 76:aeb1df146756 | 187 | } |
mbed_official | 76:aeb1df146756 | 188 | |
mbed_official | 76:aeb1df146756 | 189 | /** |
mbed_official | 76:aeb1df146756 | 190 | * @brief Return the output level (high or low) of the selected comparator. |
mbed_official | 76:aeb1df146756 | 191 | * @note Comparator output is low when the noninverting input is at a lower |
mbed_official | 76:aeb1df146756 | 192 | * voltage than the inverting input. |
mbed_official | 76:aeb1df146756 | 193 | * @note Comparator output is high when the noninverting input is at a higher |
mbed_official | 76:aeb1df146756 | 194 | * voltage than the inverting input. |
mbed_official | 76:aeb1df146756 | 195 | * @note Comparators outputs aren't available on GPIO (outputs levels are |
mbed_official | 76:aeb1df146756 | 196 | * only internal). The COMP1 and COMP2 outputs are connected internally |
mbed_official | 76:aeb1df146756 | 197 | * to the EXTI Line 21 and Line 22 respectively. |
mbed_official | 76:aeb1df146756 | 198 | * @param COMP_Selection: the selected comparator. |
mbed_official | 76:aeb1df146756 | 199 | * This parameter can be one of the following values: |
mbed_official | 76:aeb1df146756 | 200 | * @arg COMP_Selection_COMP1: COMP1 selected |
mbed_official | 76:aeb1df146756 | 201 | * @arg COMP_Selection_COMP2: COMP2 selected |
mbed_official | 76:aeb1df146756 | 202 | * @retval Returns the selected comparator output level. |
mbed_official | 76:aeb1df146756 | 203 | */ |
mbed_official | 76:aeb1df146756 | 204 | uint8_t COMP_GetOutputLevel(uint32_t COMP_Selection) |
mbed_official | 76:aeb1df146756 | 205 | { |
mbed_official | 76:aeb1df146756 | 206 | uint8_t compout = 0x0; |
mbed_official | 76:aeb1df146756 | 207 | |
mbed_official | 76:aeb1df146756 | 208 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 209 | assert_param(IS_COMP_ALL_PERIPH(COMP_Selection)); |
mbed_official | 76:aeb1df146756 | 210 | |
mbed_official | 76:aeb1df146756 | 211 | /* Check if Comparator 1 is selected */ |
mbed_official | 76:aeb1df146756 | 212 | if(COMP_Selection == COMP_Selection_COMP1) |
mbed_official | 76:aeb1df146756 | 213 | { |
mbed_official | 76:aeb1df146756 | 214 | /* Check if comparator 1 output level is high */ |
mbed_official | 76:aeb1df146756 | 215 | if((COMP->CSR & COMP_CSR_CMP1OUT) != (uint8_t) RESET) |
mbed_official | 76:aeb1df146756 | 216 | { |
mbed_official | 76:aeb1df146756 | 217 | /* Get Comparator 1 output level */ |
mbed_official | 76:aeb1df146756 | 218 | compout = (uint8_t) COMP_OutputLevel_High; |
mbed_official | 76:aeb1df146756 | 219 | } |
mbed_official | 76:aeb1df146756 | 220 | /* comparator 1 output level is low */ |
mbed_official | 76:aeb1df146756 | 221 | else |
mbed_official | 76:aeb1df146756 | 222 | { |
mbed_official | 76:aeb1df146756 | 223 | /* Get Comparator 1 output level */ |
mbed_official | 76:aeb1df146756 | 224 | compout = (uint8_t) COMP_OutputLevel_Low; |
mbed_official | 76:aeb1df146756 | 225 | } |
mbed_official | 76:aeb1df146756 | 226 | } |
mbed_official | 76:aeb1df146756 | 227 | /* Comparator 2 is selected */ |
mbed_official | 76:aeb1df146756 | 228 | else |
mbed_official | 76:aeb1df146756 | 229 | { |
mbed_official | 76:aeb1df146756 | 230 | /* Check if comparator 2 output level is high */ |
mbed_official | 76:aeb1df146756 | 231 | if((COMP->CSR & COMP_CSR_CMP2OUT) != (uint8_t) RESET) |
mbed_official | 76:aeb1df146756 | 232 | { |
mbed_official | 76:aeb1df146756 | 233 | /* Get Comparator output level */ |
mbed_official | 76:aeb1df146756 | 234 | compout = (uint8_t) COMP_OutputLevel_High; |
mbed_official | 76:aeb1df146756 | 235 | } |
mbed_official | 76:aeb1df146756 | 236 | /* comparator 2 output level is low */ |
mbed_official | 76:aeb1df146756 | 237 | else |
mbed_official | 76:aeb1df146756 | 238 | { |
mbed_official | 76:aeb1df146756 | 239 | /* Get Comparator 2 output level */ |
mbed_official | 76:aeb1df146756 | 240 | compout = (uint8_t) COMP_OutputLevel_Low; |
mbed_official | 76:aeb1df146756 | 241 | } |
mbed_official | 76:aeb1df146756 | 242 | } |
mbed_official | 76:aeb1df146756 | 243 | /* Return the comparator output level */ |
mbed_official | 76:aeb1df146756 | 244 | return (uint8_t)(compout); |
mbed_official | 76:aeb1df146756 | 245 | } |
mbed_official | 76:aeb1df146756 | 246 | |
mbed_official | 76:aeb1df146756 | 247 | /** |
mbed_official | 76:aeb1df146756 | 248 | * @brief Close or Open the SW1 switch. |
mbed_official | 76:aeb1df146756 | 249 | * @param NewState: new state of the SW1 switch. |
mbed_official | 76:aeb1df146756 | 250 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 251 | * @note ENABLE to close the SW1 switch |
mbed_official | 76:aeb1df146756 | 252 | * @note DISABLE to open the SW1 switch |
mbed_official | 76:aeb1df146756 | 253 | * @retval None. |
mbed_official | 76:aeb1df146756 | 254 | */ |
mbed_official | 76:aeb1df146756 | 255 | void COMP_SW1SwitchConfig(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 256 | { |
mbed_official | 76:aeb1df146756 | 257 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 258 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 259 | |
mbed_official | 76:aeb1df146756 | 260 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 261 | { |
mbed_official | 76:aeb1df146756 | 262 | /* Close SW1 switch */ |
mbed_official | 76:aeb1df146756 | 263 | COMP->CSR |= (uint32_t) COMP_CSR_SW1; |
mbed_official | 76:aeb1df146756 | 264 | } |
mbed_official | 76:aeb1df146756 | 265 | else |
mbed_official | 76:aeb1df146756 | 266 | { |
mbed_official | 76:aeb1df146756 | 267 | /* Open SW1 switch */ |
mbed_official | 76:aeb1df146756 | 268 | COMP->CSR &= (uint32_t)(~COMP_CSR_SW1); |
mbed_official | 76:aeb1df146756 | 269 | } |
mbed_official | 76:aeb1df146756 | 270 | } |
mbed_official | 76:aeb1df146756 | 271 | |
mbed_official | 76:aeb1df146756 | 272 | /** |
mbed_official | 76:aeb1df146756 | 273 | * @} |
mbed_official | 76:aeb1df146756 | 274 | */ |
mbed_official | 76:aeb1df146756 | 275 | |
mbed_official | 76:aeb1df146756 | 276 | /** @defgroup COMP_Group2 Window mode control function |
mbed_official | 76:aeb1df146756 | 277 | * @brief Window mode control function. |
mbed_official | 76:aeb1df146756 | 278 | * |
mbed_official | 76:aeb1df146756 | 279 | @verbatim |
mbed_official | 76:aeb1df146756 | 280 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 281 | ##### Window mode control function ##### |
mbed_official | 76:aeb1df146756 | 282 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 283 | |
mbed_official | 76:aeb1df146756 | 284 | @endverbatim |
mbed_official | 76:aeb1df146756 | 285 | * @{ |
mbed_official | 76:aeb1df146756 | 286 | */ |
mbed_official | 76:aeb1df146756 | 287 | |
mbed_official | 76:aeb1df146756 | 288 | /** |
mbed_official | 76:aeb1df146756 | 289 | * @brief Enables or disables the window mode. |
mbed_official | 76:aeb1df146756 | 290 | * In window mode: |
mbed_official | 76:aeb1df146756 | 291 | * @note COMP1 inverting input is fixed to VREFINT defining the first |
mbed_official | 76:aeb1df146756 | 292 | * threshold. |
mbed_official | 76:aeb1df146756 | 293 | * @note COMP2 inverting input is configurable (DAC_OUT1, DAC_OUT2, VREFINT |
mbed_official | 76:aeb1df146756 | 294 | * sub-multiples, PB3) defining the second threshold. |
mbed_official | 76:aeb1df146756 | 295 | * @note COMP1 and COMP2 non inverting inputs are connected together. |
mbed_official | 76:aeb1df146756 | 296 | * @note In window mode, only the Group 6 (PB4 or PB5) can be used as |
mbed_official | 76:aeb1df146756 | 297 | * noninverting inputs. |
mbed_official | 76:aeb1df146756 | 298 | * @param NewState: new state of the window mode. |
mbed_official | 76:aeb1df146756 | 299 | * This parameter can be ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 300 | * @retval None |
mbed_official | 76:aeb1df146756 | 301 | */ |
mbed_official | 76:aeb1df146756 | 302 | void COMP_WindowCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 303 | { |
mbed_official | 76:aeb1df146756 | 304 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 305 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 306 | |
mbed_official | 76:aeb1df146756 | 307 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 308 | { |
mbed_official | 76:aeb1df146756 | 309 | /* Enable the window mode */ |
mbed_official | 76:aeb1df146756 | 310 | COMP->CSR |= (uint32_t) COMP_CSR_WNDWE; |
mbed_official | 76:aeb1df146756 | 311 | } |
mbed_official | 76:aeb1df146756 | 312 | else |
mbed_official | 76:aeb1df146756 | 313 | { |
mbed_official | 76:aeb1df146756 | 314 | /* Disable the window mode */ |
mbed_official | 76:aeb1df146756 | 315 | COMP->CSR &= (uint32_t)(~COMP_CSR_WNDWE); |
mbed_official | 76:aeb1df146756 | 316 | } |
mbed_official | 76:aeb1df146756 | 317 | } |
mbed_official | 76:aeb1df146756 | 318 | |
mbed_official | 76:aeb1df146756 | 319 | /** |
mbed_official | 76:aeb1df146756 | 320 | * @} |
mbed_official | 76:aeb1df146756 | 321 | */ |
mbed_official | 76:aeb1df146756 | 322 | |
mbed_official | 76:aeb1df146756 | 323 | /** @defgroup COMP_Group3 Internal Reference Voltage output function |
mbed_official | 76:aeb1df146756 | 324 | * @brief Internal Reference Voltage (VREFINT) output function. |
mbed_official | 76:aeb1df146756 | 325 | * |
mbed_official | 76:aeb1df146756 | 326 | @verbatim |
mbed_official | 76:aeb1df146756 | 327 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 328 | ##### Internal Reference Voltage (VREFINT) output function ##### |
mbed_official | 76:aeb1df146756 | 329 | =============================================================================== |
mbed_official | 76:aeb1df146756 | 330 | |
mbed_official | 76:aeb1df146756 | 331 | @endverbatim |
mbed_official | 76:aeb1df146756 | 332 | * @{ |
mbed_official | 76:aeb1df146756 | 333 | */ |
mbed_official | 76:aeb1df146756 | 334 | |
mbed_official | 76:aeb1df146756 | 335 | /** |
mbed_official | 76:aeb1df146756 | 336 | * @brief Enables or disables the output of internal reference voltage (VREFINT). |
mbed_official | 76:aeb1df146756 | 337 | * The VREFINT output can be routed to any I/O in group 3: CH8 (PB0) or |
mbed_official | 76:aeb1df146756 | 338 | * CH9 (PB1). |
mbed_official | 76:aeb1df146756 | 339 | * To correctly use this function, the SYSCFG_RIIOSwitchConfig() function |
mbed_official | 76:aeb1df146756 | 340 | * should be called after. |
mbed_official | 76:aeb1df146756 | 341 | * @param NewState: new state of the Vrefint output. |
mbed_official | 76:aeb1df146756 | 342 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 76:aeb1df146756 | 343 | * @retval None |
mbed_official | 76:aeb1df146756 | 344 | */ |
mbed_official | 76:aeb1df146756 | 345 | void COMP_VrefintOutputCmd(FunctionalState NewState) |
mbed_official | 76:aeb1df146756 | 346 | { |
mbed_official | 76:aeb1df146756 | 347 | /* Check the parameters */ |
mbed_official | 76:aeb1df146756 | 348 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 76:aeb1df146756 | 349 | |
mbed_official | 76:aeb1df146756 | 350 | if (NewState != DISABLE) |
mbed_official | 76:aeb1df146756 | 351 | { |
mbed_official | 76:aeb1df146756 | 352 | /* Enable the output of internal reference voltage */ |
mbed_official | 76:aeb1df146756 | 353 | COMP->CSR |= (uint32_t) COMP_CSR_VREFOUTEN; |
mbed_official | 76:aeb1df146756 | 354 | } |
mbed_official | 76:aeb1df146756 | 355 | else |
mbed_official | 76:aeb1df146756 | 356 | { |
mbed_official | 76:aeb1df146756 | 357 | /* Disable the output of internal reference voltage */ |
mbed_official | 76:aeb1df146756 | 358 | COMP->CSR &= (uint32_t) (~COMP_CSR_VREFOUTEN); |
mbed_official | 76:aeb1df146756 | 359 | } |
mbed_official | 76:aeb1df146756 | 360 | } |
mbed_official | 76:aeb1df146756 | 361 | |
mbed_official | 76:aeb1df146756 | 362 | /** |
mbed_official | 76:aeb1df146756 | 363 | * @} |
mbed_official | 76:aeb1df146756 | 364 | */ |
mbed_official | 76:aeb1df146756 | 365 | |
mbed_official | 76:aeb1df146756 | 366 | /** |
mbed_official | 76:aeb1df146756 | 367 | * @} |
mbed_official | 76:aeb1df146756 | 368 | */ |
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 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |