mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F103RB/stm32f10x_adc.c@84:f54042cbc282, 2014-02-03 (annotated)
- Committer:
- mbed_official
- Date:
- Mon Feb 03 09:30:05 2014 +0000
- Revision:
- 84:f54042cbc282
- Parent:
- 70:c1fbde68b492
Synchronized with git revision bbbd8699601c42149ccf0c37bc42bb6856ccc4c6
Full URL: https://github.com/mbedmicro/mbed/commit/bbbd8699601c42149ccf0c37bc42bb6856ccc4c6/
[NUCLEO_L152RE/F030_R8] SPI, I2C, Ticker, PWM updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 52:a51c77007319 | 1 | /** |
mbed_official | 52:a51c77007319 | 2 | ****************************************************************************** |
mbed_official | 52:a51c77007319 | 3 | * @file stm32f10x_adc.c |
mbed_official | 52:a51c77007319 | 4 | * @author MCD Application Team |
mbed_official | 84:f54042cbc282 | 5 | * @version V3.6.1 |
mbed_official | 84:f54042cbc282 | 6 | * @date 05-March-2012 |
mbed_official | 52:a51c77007319 | 7 | * @brief This file provides all the ADC firmware functions. |
mbed_official | 70:c1fbde68b492 | 8 | ******************************************************************************* |
mbed_official | 70:c1fbde68b492 | 9 | * Copyright (c) 2014, STMicroelectronics |
mbed_official | 70:c1fbde68b492 | 10 | * All rights reserved. |
mbed_official | 70:c1fbde68b492 | 11 | * |
mbed_official | 70:c1fbde68b492 | 12 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 70:c1fbde68b492 | 13 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 70:c1fbde68b492 | 14 | * |
mbed_official | 70:c1fbde68b492 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 70:c1fbde68b492 | 16 | * this list of conditions and the following disclaimer. |
mbed_official | 70:c1fbde68b492 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 70:c1fbde68b492 | 18 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 70:c1fbde68b492 | 19 | * and/or other materials provided with the distribution. |
mbed_official | 70:c1fbde68b492 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 70:c1fbde68b492 | 21 | * may be used to endorse or promote products derived from this software |
mbed_official | 70:c1fbde68b492 | 22 | * without specific prior written permission. |
mbed_official | 70:c1fbde68b492 | 23 | * |
mbed_official | 70:c1fbde68b492 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 70:c1fbde68b492 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 70:c1fbde68b492 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 70:c1fbde68b492 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 70:c1fbde68b492 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 70:c1fbde68b492 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 70:c1fbde68b492 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 70:c1fbde68b492 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 70:c1fbde68b492 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 70:c1fbde68b492 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 70:c1fbde68b492 | 34 | ******************************************************************************* |
mbed_official | 70:c1fbde68b492 | 35 | */ |
mbed_official | 52:a51c77007319 | 36 | |
mbed_official | 52:a51c77007319 | 37 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 52:a51c77007319 | 38 | #include "stm32f10x_adc.h" |
mbed_official | 52:a51c77007319 | 39 | #include "stm32f10x_rcc.h" |
mbed_official | 52:a51c77007319 | 40 | |
mbed_official | 52:a51c77007319 | 41 | /** @addtogroup STM32F10x_StdPeriph_Driver |
mbed_official | 52:a51c77007319 | 42 | * @{ |
mbed_official | 52:a51c77007319 | 43 | */ |
mbed_official | 52:a51c77007319 | 44 | |
mbed_official | 52:a51c77007319 | 45 | /** @defgroup ADC |
mbed_official | 52:a51c77007319 | 46 | * @brief ADC driver modules |
mbed_official | 52:a51c77007319 | 47 | * @{ |
mbed_official | 52:a51c77007319 | 48 | */ |
mbed_official | 52:a51c77007319 | 49 | |
mbed_official | 52:a51c77007319 | 50 | /** @defgroup ADC_Private_TypesDefinitions |
mbed_official | 52:a51c77007319 | 51 | * @{ |
mbed_official | 52:a51c77007319 | 52 | */ |
mbed_official | 52:a51c77007319 | 53 | |
mbed_official | 52:a51c77007319 | 54 | /** |
mbed_official | 52:a51c77007319 | 55 | * @} |
mbed_official | 52:a51c77007319 | 56 | */ |
mbed_official | 52:a51c77007319 | 57 | |
mbed_official | 52:a51c77007319 | 58 | /** @defgroup ADC_Private_Defines |
mbed_official | 52:a51c77007319 | 59 | * @{ |
mbed_official | 52:a51c77007319 | 60 | */ |
mbed_official | 52:a51c77007319 | 61 | |
mbed_official | 52:a51c77007319 | 62 | /* ADC DISCNUM mask */ |
mbed_official | 52:a51c77007319 | 63 | #define CR1_DISCNUM_Reset ((uint32_t)0xFFFF1FFF) |
mbed_official | 52:a51c77007319 | 64 | |
mbed_official | 52:a51c77007319 | 65 | /* ADC DISCEN mask */ |
mbed_official | 52:a51c77007319 | 66 | #define CR1_DISCEN_Set ((uint32_t)0x00000800) |
mbed_official | 52:a51c77007319 | 67 | #define CR1_DISCEN_Reset ((uint32_t)0xFFFFF7FF) |
mbed_official | 52:a51c77007319 | 68 | |
mbed_official | 52:a51c77007319 | 69 | /* ADC JAUTO mask */ |
mbed_official | 52:a51c77007319 | 70 | #define CR1_JAUTO_Set ((uint32_t)0x00000400) |
mbed_official | 52:a51c77007319 | 71 | #define CR1_JAUTO_Reset ((uint32_t)0xFFFFFBFF) |
mbed_official | 52:a51c77007319 | 72 | |
mbed_official | 52:a51c77007319 | 73 | /* ADC JDISCEN mask */ |
mbed_official | 52:a51c77007319 | 74 | #define CR1_JDISCEN_Set ((uint32_t)0x00001000) |
mbed_official | 52:a51c77007319 | 75 | #define CR1_JDISCEN_Reset ((uint32_t)0xFFFFEFFF) |
mbed_official | 52:a51c77007319 | 76 | |
mbed_official | 52:a51c77007319 | 77 | /* ADC AWDCH mask */ |
mbed_official | 52:a51c77007319 | 78 | #define CR1_AWDCH_Reset ((uint32_t)0xFFFFFFE0) |
mbed_official | 52:a51c77007319 | 79 | |
mbed_official | 52:a51c77007319 | 80 | /* ADC Analog watchdog enable mode mask */ |
mbed_official | 52:a51c77007319 | 81 | #define CR1_AWDMode_Reset ((uint32_t)0xFF3FFDFF) |
mbed_official | 52:a51c77007319 | 82 | |
mbed_official | 52:a51c77007319 | 83 | /* CR1 register Mask */ |
mbed_official | 52:a51c77007319 | 84 | #define CR1_CLEAR_Mask ((uint32_t)0xFFF0FEFF) |
mbed_official | 52:a51c77007319 | 85 | |
mbed_official | 52:a51c77007319 | 86 | /* ADC ADON mask */ |
mbed_official | 52:a51c77007319 | 87 | #define CR2_ADON_Set ((uint32_t)0x00000001) |
mbed_official | 52:a51c77007319 | 88 | #define CR2_ADON_Reset ((uint32_t)0xFFFFFFFE) |
mbed_official | 52:a51c77007319 | 89 | |
mbed_official | 52:a51c77007319 | 90 | /* ADC DMA mask */ |
mbed_official | 52:a51c77007319 | 91 | #define CR2_DMA_Set ((uint32_t)0x00000100) |
mbed_official | 52:a51c77007319 | 92 | #define CR2_DMA_Reset ((uint32_t)0xFFFFFEFF) |
mbed_official | 52:a51c77007319 | 93 | |
mbed_official | 52:a51c77007319 | 94 | /* ADC RSTCAL mask */ |
mbed_official | 52:a51c77007319 | 95 | #define CR2_RSTCAL_Set ((uint32_t)0x00000008) |
mbed_official | 52:a51c77007319 | 96 | |
mbed_official | 52:a51c77007319 | 97 | /* ADC CAL mask */ |
mbed_official | 52:a51c77007319 | 98 | #define CR2_CAL_Set ((uint32_t)0x00000004) |
mbed_official | 52:a51c77007319 | 99 | |
mbed_official | 52:a51c77007319 | 100 | /* ADC SWSTART mask */ |
mbed_official | 52:a51c77007319 | 101 | #define CR2_SWSTART_Set ((uint32_t)0x00400000) |
mbed_official | 52:a51c77007319 | 102 | |
mbed_official | 52:a51c77007319 | 103 | /* ADC EXTTRIG mask */ |
mbed_official | 52:a51c77007319 | 104 | #define CR2_EXTTRIG_Set ((uint32_t)0x00100000) |
mbed_official | 52:a51c77007319 | 105 | #define CR2_EXTTRIG_Reset ((uint32_t)0xFFEFFFFF) |
mbed_official | 52:a51c77007319 | 106 | |
mbed_official | 52:a51c77007319 | 107 | /* ADC Software start mask */ |
mbed_official | 52:a51c77007319 | 108 | #define CR2_EXTTRIG_SWSTART_Set ((uint32_t)0x00500000) |
mbed_official | 52:a51c77007319 | 109 | #define CR2_EXTTRIG_SWSTART_Reset ((uint32_t)0xFFAFFFFF) |
mbed_official | 52:a51c77007319 | 110 | |
mbed_official | 52:a51c77007319 | 111 | /* ADC JEXTSEL mask */ |
mbed_official | 52:a51c77007319 | 112 | #define CR2_JEXTSEL_Reset ((uint32_t)0xFFFF8FFF) |
mbed_official | 52:a51c77007319 | 113 | |
mbed_official | 52:a51c77007319 | 114 | /* ADC JEXTTRIG mask */ |
mbed_official | 52:a51c77007319 | 115 | #define CR2_JEXTTRIG_Set ((uint32_t)0x00008000) |
mbed_official | 52:a51c77007319 | 116 | #define CR2_JEXTTRIG_Reset ((uint32_t)0xFFFF7FFF) |
mbed_official | 52:a51c77007319 | 117 | |
mbed_official | 52:a51c77007319 | 118 | /* ADC JSWSTART mask */ |
mbed_official | 52:a51c77007319 | 119 | #define CR2_JSWSTART_Set ((uint32_t)0x00200000) |
mbed_official | 52:a51c77007319 | 120 | |
mbed_official | 52:a51c77007319 | 121 | /* ADC injected software start mask */ |
mbed_official | 52:a51c77007319 | 122 | #define CR2_JEXTTRIG_JSWSTART_Set ((uint32_t)0x00208000) |
mbed_official | 52:a51c77007319 | 123 | #define CR2_JEXTTRIG_JSWSTART_Reset ((uint32_t)0xFFDF7FFF) |
mbed_official | 52:a51c77007319 | 124 | |
mbed_official | 52:a51c77007319 | 125 | /* ADC TSPD mask */ |
mbed_official | 52:a51c77007319 | 126 | #define CR2_TSVREFE_Set ((uint32_t)0x00800000) |
mbed_official | 52:a51c77007319 | 127 | #define CR2_TSVREFE_Reset ((uint32_t)0xFF7FFFFF) |
mbed_official | 52:a51c77007319 | 128 | |
mbed_official | 52:a51c77007319 | 129 | /* CR2 register Mask */ |
mbed_official | 52:a51c77007319 | 130 | #define CR2_CLEAR_Mask ((uint32_t)0xFFF1F7FD) |
mbed_official | 52:a51c77007319 | 131 | |
mbed_official | 52:a51c77007319 | 132 | /* ADC SQx mask */ |
mbed_official | 52:a51c77007319 | 133 | #define SQR3_SQ_Set ((uint32_t)0x0000001F) |
mbed_official | 52:a51c77007319 | 134 | #define SQR2_SQ_Set ((uint32_t)0x0000001F) |
mbed_official | 52:a51c77007319 | 135 | #define SQR1_SQ_Set ((uint32_t)0x0000001F) |
mbed_official | 52:a51c77007319 | 136 | |
mbed_official | 52:a51c77007319 | 137 | /* SQR1 register Mask */ |
mbed_official | 52:a51c77007319 | 138 | #define SQR1_CLEAR_Mask ((uint32_t)0xFF0FFFFF) |
mbed_official | 52:a51c77007319 | 139 | |
mbed_official | 52:a51c77007319 | 140 | /* ADC JSQx mask */ |
mbed_official | 52:a51c77007319 | 141 | #define JSQR_JSQ_Set ((uint32_t)0x0000001F) |
mbed_official | 52:a51c77007319 | 142 | |
mbed_official | 52:a51c77007319 | 143 | /* ADC JL mask */ |
mbed_official | 52:a51c77007319 | 144 | #define JSQR_JL_Set ((uint32_t)0x00300000) |
mbed_official | 52:a51c77007319 | 145 | #define JSQR_JL_Reset ((uint32_t)0xFFCFFFFF) |
mbed_official | 52:a51c77007319 | 146 | |
mbed_official | 52:a51c77007319 | 147 | /* ADC SMPx mask */ |
mbed_official | 52:a51c77007319 | 148 | #define SMPR1_SMP_Set ((uint32_t)0x00000007) |
mbed_official | 52:a51c77007319 | 149 | #define SMPR2_SMP_Set ((uint32_t)0x00000007) |
mbed_official | 52:a51c77007319 | 150 | |
mbed_official | 52:a51c77007319 | 151 | /* ADC JDRx registers offset */ |
mbed_official | 52:a51c77007319 | 152 | #define JDR_Offset ((uint8_t)0x28) |
mbed_official | 52:a51c77007319 | 153 | |
mbed_official | 52:a51c77007319 | 154 | /* ADC1 DR register base address */ |
mbed_official | 52:a51c77007319 | 155 | #define DR_ADDRESS ((uint32_t)0x4001244C) |
mbed_official | 52:a51c77007319 | 156 | |
mbed_official | 52:a51c77007319 | 157 | /** |
mbed_official | 52:a51c77007319 | 158 | * @} |
mbed_official | 52:a51c77007319 | 159 | */ |
mbed_official | 52:a51c77007319 | 160 | |
mbed_official | 52:a51c77007319 | 161 | /** @defgroup ADC_Private_Macros |
mbed_official | 52:a51c77007319 | 162 | * @{ |
mbed_official | 52:a51c77007319 | 163 | */ |
mbed_official | 52:a51c77007319 | 164 | |
mbed_official | 52:a51c77007319 | 165 | /** |
mbed_official | 52:a51c77007319 | 166 | * @} |
mbed_official | 52:a51c77007319 | 167 | */ |
mbed_official | 52:a51c77007319 | 168 | |
mbed_official | 52:a51c77007319 | 169 | /** @defgroup ADC_Private_Variables |
mbed_official | 52:a51c77007319 | 170 | * @{ |
mbed_official | 52:a51c77007319 | 171 | */ |
mbed_official | 52:a51c77007319 | 172 | |
mbed_official | 52:a51c77007319 | 173 | /** |
mbed_official | 52:a51c77007319 | 174 | * @} |
mbed_official | 52:a51c77007319 | 175 | */ |
mbed_official | 52:a51c77007319 | 176 | |
mbed_official | 52:a51c77007319 | 177 | /** @defgroup ADC_Private_FunctionPrototypes |
mbed_official | 52:a51c77007319 | 178 | * @{ |
mbed_official | 52:a51c77007319 | 179 | */ |
mbed_official | 52:a51c77007319 | 180 | |
mbed_official | 52:a51c77007319 | 181 | /** |
mbed_official | 52:a51c77007319 | 182 | * @} |
mbed_official | 52:a51c77007319 | 183 | */ |
mbed_official | 52:a51c77007319 | 184 | |
mbed_official | 52:a51c77007319 | 185 | /** @defgroup ADC_Private_Functions |
mbed_official | 52:a51c77007319 | 186 | * @{ |
mbed_official | 52:a51c77007319 | 187 | */ |
mbed_official | 52:a51c77007319 | 188 | |
mbed_official | 52:a51c77007319 | 189 | /** |
mbed_official | 52:a51c77007319 | 190 | * @brief Deinitializes the ADCx peripheral registers to their default reset values. |
mbed_official | 52:a51c77007319 | 191 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 192 | * @retval None |
mbed_official | 52:a51c77007319 | 193 | */ |
mbed_official | 52:a51c77007319 | 194 | void ADC_DeInit(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 195 | { |
mbed_official | 52:a51c77007319 | 196 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 197 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 198 | |
mbed_official | 52:a51c77007319 | 199 | if (ADCx == ADC1) |
mbed_official | 52:a51c77007319 | 200 | { |
mbed_official | 52:a51c77007319 | 201 | /* Enable ADC1 reset state */ |
mbed_official | 52:a51c77007319 | 202 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE); |
mbed_official | 52:a51c77007319 | 203 | /* Release ADC1 from reset state */ |
mbed_official | 52:a51c77007319 | 204 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE); |
mbed_official | 52:a51c77007319 | 205 | } |
mbed_official | 52:a51c77007319 | 206 | else if (ADCx == ADC2) |
mbed_official | 52:a51c77007319 | 207 | { |
mbed_official | 52:a51c77007319 | 208 | /* Enable ADC2 reset state */ |
mbed_official | 52:a51c77007319 | 209 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, ENABLE); |
mbed_official | 52:a51c77007319 | 210 | /* Release ADC2 from reset state */ |
mbed_official | 52:a51c77007319 | 211 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, DISABLE); |
mbed_official | 52:a51c77007319 | 212 | } |
mbed_official | 52:a51c77007319 | 213 | else |
mbed_official | 52:a51c77007319 | 214 | { |
mbed_official | 52:a51c77007319 | 215 | if (ADCx == ADC3) |
mbed_official | 52:a51c77007319 | 216 | { |
mbed_official | 52:a51c77007319 | 217 | /* Enable ADC3 reset state */ |
mbed_official | 52:a51c77007319 | 218 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, ENABLE); |
mbed_official | 52:a51c77007319 | 219 | /* Release ADC3 from reset state */ |
mbed_official | 52:a51c77007319 | 220 | RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3, DISABLE); |
mbed_official | 52:a51c77007319 | 221 | } |
mbed_official | 52:a51c77007319 | 222 | } |
mbed_official | 52:a51c77007319 | 223 | } |
mbed_official | 52:a51c77007319 | 224 | |
mbed_official | 52:a51c77007319 | 225 | /** |
mbed_official | 52:a51c77007319 | 226 | * @brief Initializes the ADCx peripheral according to the specified parameters |
mbed_official | 52:a51c77007319 | 227 | * in the ADC_InitStruct. |
mbed_official | 52:a51c77007319 | 228 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 229 | * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains |
mbed_official | 52:a51c77007319 | 230 | * the configuration information for the specified ADC peripheral. |
mbed_official | 52:a51c77007319 | 231 | * @retval None |
mbed_official | 52:a51c77007319 | 232 | */ |
mbed_official | 52:a51c77007319 | 233 | void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct) |
mbed_official | 52:a51c77007319 | 234 | { |
mbed_official | 52:a51c77007319 | 235 | uint32_t tmpreg1 = 0; |
mbed_official | 52:a51c77007319 | 236 | uint8_t tmpreg2 = 0; |
mbed_official | 52:a51c77007319 | 237 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 238 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 239 | assert_param(IS_ADC_MODE(ADC_InitStruct->ADC_Mode)); |
mbed_official | 52:a51c77007319 | 240 | assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ScanConvMode)); |
mbed_official | 52:a51c77007319 | 241 | assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode)); |
mbed_official | 52:a51c77007319 | 242 | assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv)); |
mbed_official | 52:a51c77007319 | 243 | assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign)); |
mbed_official | 52:a51c77007319 | 244 | assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfChannel)); |
mbed_official | 52:a51c77007319 | 245 | |
mbed_official | 52:a51c77007319 | 246 | /*---------------------------- ADCx CR1 Configuration -----------------*/ |
mbed_official | 52:a51c77007319 | 247 | /* Get the ADCx CR1 value */ |
mbed_official | 52:a51c77007319 | 248 | tmpreg1 = ADCx->CR1; |
mbed_official | 52:a51c77007319 | 249 | /* Clear DUALMOD and SCAN bits */ |
mbed_official | 52:a51c77007319 | 250 | tmpreg1 &= CR1_CLEAR_Mask; |
mbed_official | 52:a51c77007319 | 251 | /* Configure ADCx: Dual mode and scan conversion mode */ |
mbed_official | 52:a51c77007319 | 252 | /* Set DUALMOD bits according to ADC_Mode value */ |
mbed_official | 52:a51c77007319 | 253 | /* Set SCAN bit according to ADC_ScanConvMode value */ |
mbed_official | 52:a51c77007319 | 254 | tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_Mode | ((uint32_t)ADC_InitStruct->ADC_ScanConvMode << 8)); |
mbed_official | 52:a51c77007319 | 255 | /* Write to ADCx CR1 */ |
mbed_official | 52:a51c77007319 | 256 | ADCx->CR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 257 | |
mbed_official | 52:a51c77007319 | 258 | /*---------------------------- ADCx CR2 Configuration -----------------*/ |
mbed_official | 52:a51c77007319 | 259 | /* Get the ADCx CR2 value */ |
mbed_official | 52:a51c77007319 | 260 | tmpreg1 = ADCx->CR2; |
mbed_official | 52:a51c77007319 | 261 | /* Clear CONT, ALIGN and EXTSEL bits */ |
mbed_official | 52:a51c77007319 | 262 | tmpreg1 &= CR2_CLEAR_Mask; |
mbed_official | 52:a51c77007319 | 263 | /* Configure ADCx: external trigger event and continuous conversion mode */ |
mbed_official | 52:a51c77007319 | 264 | /* Set ALIGN bit according to ADC_DataAlign value */ |
mbed_official | 52:a51c77007319 | 265 | /* Set EXTSEL bits according to ADC_ExternalTrigConv value */ |
mbed_official | 52:a51c77007319 | 266 | /* Set CONT bit according to ADC_ContinuousConvMode value */ |
mbed_official | 52:a51c77007319 | 267 | tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv | |
mbed_official | 52:a51c77007319 | 268 | ((uint32_t)ADC_InitStruct->ADC_ContinuousConvMode << 1)); |
mbed_official | 52:a51c77007319 | 269 | /* Write to ADCx CR2 */ |
mbed_official | 52:a51c77007319 | 270 | ADCx->CR2 = tmpreg1; |
mbed_official | 52:a51c77007319 | 271 | |
mbed_official | 52:a51c77007319 | 272 | /*---------------------------- ADCx SQR1 Configuration -----------------*/ |
mbed_official | 52:a51c77007319 | 273 | /* Get the ADCx SQR1 value */ |
mbed_official | 52:a51c77007319 | 274 | tmpreg1 = ADCx->SQR1; |
mbed_official | 52:a51c77007319 | 275 | /* Clear L bits */ |
mbed_official | 52:a51c77007319 | 276 | tmpreg1 &= SQR1_CLEAR_Mask; |
mbed_official | 52:a51c77007319 | 277 | /* Configure ADCx: regular channel sequence length */ |
mbed_official | 52:a51c77007319 | 278 | /* Set L bits according to ADC_NbrOfChannel value */ |
mbed_official | 52:a51c77007319 | 279 | tmpreg2 |= (uint8_t) (ADC_InitStruct->ADC_NbrOfChannel - (uint8_t)1); |
mbed_official | 52:a51c77007319 | 280 | tmpreg1 |= (uint32_t)tmpreg2 << 20; |
mbed_official | 52:a51c77007319 | 281 | /* Write to ADCx SQR1 */ |
mbed_official | 52:a51c77007319 | 282 | ADCx->SQR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 283 | } |
mbed_official | 52:a51c77007319 | 284 | |
mbed_official | 52:a51c77007319 | 285 | /** |
mbed_official | 52:a51c77007319 | 286 | * @brief Fills each ADC_InitStruct member with its default value. |
mbed_official | 52:a51c77007319 | 287 | * @param ADC_InitStruct : pointer to an ADC_InitTypeDef structure which will be initialized. |
mbed_official | 52:a51c77007319 | 288 | * @retval None |
mbed_official | 52:a51c77007319 | 289 | */ |
mbed_official | 52:a51c77007319 | 290 | void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct) |
mbed_official | 52:a51c77007319 | 291 | { |
mbed_official | 52:a51c77007319 | 292 | /* Reset ADC init structure parameters values */ |
mbed_official | 52:a51c77007319 | 293 | /* Initialize the ADC_Mode member */ |
mbed_official | 52:a51c77007319 | 294 | ADC_InitStruct->ADC_Mode = ADC_Mode_Independent; |
mbed_official | 52:a51c77007319 | 295 | /* initialize the ADC_ScanConvMode member */ |
mbed_official | 52:a51c77007319 | 296 | ADC_InitStruct->ADC_ScanConvMode = DISABLE; |
mbed_official | 52:a51c77007319 | 297 | /* Initialize the ADC_ContinuousConvMode member */ |
mbed_official | 52:a51c77007319 | 298 | ADC_InitStruct->ADC_ContinuousConvMode = DISABLE; |
mbed_official | 52:a51c77007319 | 299 | /* Initialize the ADC_ExternalTrigConv member */ |
mbed_official | 52:a51c77007319 | 300 | ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; |
mbed_official | 52:a51c77007319 | 301 | /* Initialize the ADC_DataAlign member */ |
mbed_official | 52:a51c77007319 | 302 | ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right; |
mbed_official | 52:a51c77007319 | 303 | /* Initialize the ADC_NbrOfChannel member */ |
mbed_official | 52:a51c77007319 | 304 | ADC_InitStruct->ADC_NbrOfChannel = 1; |
mbed_official | 52:a51c77007319 | 305 | } |
mbed_official | 52:a51c77007319 | 306 | |
mbed_official | 52:a51c77007319 | 307 | /** |
mbed_official | 52:a51c77007319 | 308 | * @brief Enables or disables the specified ADC peripheral. |
mbed_official | 52:a51c77007319 | 309 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 310 | * @param NewState: new state of the ADCx peripheral. |
mbed_official | 52:a51c77007319 | 311 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 312 | * @retval None |
mbed_official | 52:a51c77007319 | 313 | */ |
mbed_official | 52:a51c77007319 | 314 | void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 315 | { |
mbed_official | 52:a51c77007319 | 316 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 317 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 318 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 319 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 320 | { |
mbed_official | 52:a51c77007319 | 321 | /* Set the ADON bit to wake up the ADC from power down mode */ |
mbed_official | 52:a51c77007319 | 322 | ADCx->CR2 |= CR2_ADON_Set; |
mbed_official | 52:a51c77007319 | 323 | } |
mbed_official | 52:a51c77007319 | 324 | else |
mbed_official | 52:a51c77007319 | 325 | { |
mbed_official | 52:a51c77007319 | 326 | /* Disable the selected ADC peripheral */ |
mbed_official | 52:a51c77007319 | 327 | ADCx->CR2 &= CR2_ADON_Reset; |
mbed_official | 52:a51c77007319 | 328 | } |
mbed_official | 52:a51c77007319 | 329 | } |
mbed_official | 52:a51c77007319 | 330 | |
mbed_official | 52:a51c77007319 | 331 | /** |
mbed_official | 52:a51c77007319 | 332 | * @brief Enables or disables the specified ADC DMA request. |
mbed_official | 52:a51c77007319 | 333 | * @param ADCx: where x can be 1 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 334 | * Note: ADC2 hasn't a DMA capability. |
mbed_official | 52:a51c77007319 | 335 | * @param NewState: new state of the selected ADC DMA transfer. |
mbed_official | 52:a51c77007319 | 336 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 337 | * @retval None |
mbed_official | 52:a51c77007319 | 338 | */ |
mbed_official | 52:a51c77007319 | 339 | void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 340 | { |
mbed_official | 52:a51c77007319 | 341 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 342 | assert_param(IS_ADC_DMA_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 343 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 344 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 345 | { |
mbed_official | 52:a51c77007319 | 346 | /* Enable the selected ADC DMA request */ |
mbed_official | 52:a51c77007319 | 347 | ADCx->CR2 |= CR2_DMA_Set; |
mbed_official | 52:a51c77007319 | 348 | } |
mbed_official | 52:a51c77007319 | 349 | else |
mbed_official | 52:a51c77007319 | 350 | { |
mbed_official | 52:a51c77007319 | 351 | /* Disable the selected ADC DMA request */ |
mbed_official | 52:a51c77007319 | 352 | ADCx->CR2 &= CR2_DMA_Reset; |
mbed_official | 52:a51c77007319 | 353 | } |
mbed_official | 52:a51c77007319 | 354 | } |
mbed_official | 52:a51c77007319 | 355 | |
mbed_official | 52:a51c77007319 | 356 | /** |
mbed_official | 52:a51c77007319 | 357 | * @brief Enables or disables the specified ADC interrupts. |
mbed_official | 52:a51c77007319 | 358 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 359 | * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled. |
mbed_official | 52:a51c77007319 | 360 | * This parameter can be any combination of the following values: |
mbed_official | 52:a51c77007319 | 361 | * @arg ADC_IT_EOC: End of conversion interrupt mask |
mbed_official | 52:a51c77007319 | 362 | * @arg ADC_IT_AWD: Analog watchdog interrupt mask |
mbed_official | 52:a51c77007319 | 363 | * @arg ADC_IT_JEOC: End of injected conversion interrupt mask |
mbed_official | 52:a51c77007319 | 364 | * @param NewState: new state of the specified ADC interrupts. |
mbed_official | 52:a51c77007319 | 365 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 366 | * @retval None |
mbed_official | 52:a51c77007319 | 367 | */ |
mbed_official | 52:a51c77007319 | 368 | void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 369 | { |
mbed_official | 52:a51c77007319 | 370 | uint8_t itmask = 0; |
mbed_official | 52:a51c77007319 | 371 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 372 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 373 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 374 | assert_param(IS_ADC_IT(ADC_IT)); |
mbed_official | 52:a51c77007319 | 375 | /* Get the ADC IT index */ |
mbed_official | 52:a51c77007319 | 376 | itmask = (uint8_t)ADC_IT; |
mbed_official | 52:a51c77007319 | 377 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 378 | { |
mbed_official | 52:a51c77007319 | 379 | /* Enable the selected ADC interrupts */ |
mbed_official | 52:a51c77007319 | 380 | ADCx->CR1 |= itmask; |
mbed_official | 52:a51c77007319 | 381 | } |
mbed_official | 52:a51c77007319 | 382 | else |
mbed_official | 52:a51c77007319 | 383 | { |
mbed_official | 52:a51c77007319 | 384 | /* Disable the selected ADC interrupts */ |
mbed_official | 52:a51c77007319 | 385 | ADCx->CR1 &= (~(uint32_t)itmask); |
mbed_official | 52:a51c77007319 | 386 | } |
mbed_official | 52:a51c77007319 | 387 | } |
mbed_official | 52:a51c77007319 | 388 | |
mbed_official | 52:a51c77007319 | 389 | /** |
mbed_official | 52:a51c77007319 | 390 | * @brief Resets the selected ADC calibration registers. |
mbed_official | 52:a51c77007319 | 391 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 392 | * @retval None |
mbed_official | 52:a51c77007319 | 393 | */ |
mbed_official | 52:a51c77007319 | 394 | void ADC_ResetCalibration(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 395 | { |
mbed_official | 52:a51c77007319 | 396 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 397 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 398 | /* Resets the selected ADC calibration registers */ |
mbed_official | 52:a51c77007319 | 399 | ADCx->CR2 |= CR2_RSTCAL_Set; |
mbed_official | 52:a51c77007319 | 400 | } |
mbed_official | 52:a51c77007319 | 401 | |
mbed_official | 52:a51c77007319 | 402 | /** |
mbed_official | 52:a51c77007319 | 403 | * @brief Gets the selected ADC reset calibration registers status. |
mbed_official | 52:a51c77007319 | 404 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 405 | * @retval The new state of ADC reset calibration registers (SET or RESET). |
mbed_official | 52:a51c77007319 | 406 | */ |
mbed_official | 52:a51c77007319 | 407 | FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 408 | { |
mbed_official | 52:a51c77007319 | 409 | FlagStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 410 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 411 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 412 | /* Check the status of RSTCAL bit */ |
mbed_official | 52:a51c77007319 | 413 | if ((ADCx->CR2 & CR2_RSTCAL_Set) != (uint32_t)RESET) |
mbed_official | 52:a51c77007319 | 414 | { |
mbed_official | 52:a51c77007319 | 415 | /* RSTCAL bit is set */ |
mbed_official | 52:a51c77007319 | 416 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 417 | } |
mbed_official | 52:a51c77007319 | 418 | else |
mbed_official | 52:a51c77007319 | 419 | { |
mbed_official | 52:a51c77007319 | 420 | /* RSTCAL bit is reset */ |
mbed_official | 52:a51c77007319 | 421 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 422 | } |
mbed_official | 52:a51c77007319 | 423 | /* Return the RSTCAL bit status */ |
mbed_official | 52:a51c77007319 | 424 | return bitstatus; |
mbed_official | 52:a51c77007319 | 425 | } |
mbed_official | 52:a51c77007319 | 426 | |
mbed_official | 52:a51c77007319 | 427 | /** |
mbed_official | 52:a51c77007319 | 428 | * @brief Starts the selected ADC calibration process. |
mbed_official | 52:a51c77007319 | 429 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 430 | * @retval None |
mbed_official | 52:a51c77007319 | 431 | */ |
mbed_official | 52:a51c77007319 | 432 | void ADC_StartCalibration(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 433 | { |
mbed_official | 52:a51c77007319 | 434 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 435 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 436 | /* Enable the selected ADC calibration process */ |
mbed_official | 52:a51c77007319 | 437 | ADCx->CR2 |= CR2_CAL_Set; |
mbed_official | 52:a51c77007319 | 438 | } |
mbed_official | 52:a51c77007319 | 439 | |
mbed_official | 52:a51c77007319 | 440 | /** |
mbed_official | 52:a51c77007319 | 441 | * @brief Gets the selected ADC calibration status. |
mbed_official | 52:a51c77007319 | 442 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 443 | * @retval The new state of ADC calibration (SET or RESET). |
mbed_official | 52:a51c77007319 | 444 | */ |
mbed_official | 52:a51c77007319 | 445 | FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 446 | { |
mbed_official | 52:a51c77007319 | 447 | FlagStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 448 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 449 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 450 | /* Check the status of CAL bit */ |
mbed_official | 52:a51c77007319 | 451 | if ((ADCx->CR2 & CR2_CAL_Set) != (uint32_t)RESET) |
mbed_official | 52:a51c77007319 | 452 | { |
mbed_official | 52:a51c77007319 | 453 | /* CAL bit is set: calibration on going */ |
mbed_official | 52:a51c77007319 | 454 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 455 | } |
mbed_official | 52:a51c77007319 | 456 | else |
mbed_official | 52:a51c77007319 | 457 | { |
mbed_official | 52:a51c77007319 | 458 | /* CAL bit is reset: end of calibration */ |
mbed_official | 52:a51c77007319 | 459 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 460 | } |
mbed_official | 52:a51c77007319 | 461 | /* Return the CAL bit status */ |
mbed_official | 52:a51c77007319 | 462 | return bitstatus; |
mbed_official | 52:a51c77007319 | 463 | } |
mbed_official | 52:a51c77007319 | 464 | |
mbed_official | 52:a51c77007319 | 465 | /** |
mbed_official | 52:a51c77007319 | 466 | * @brief Enables or disables the selected ADC software start conversion . |
mbed_official | 52:a51c77007319 | 467 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 468 | * @param NewState: new state of the selected ADC software start conversion. |
mbed_official | 52:a51c77007319 | 469 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 470 | * @retval None |
mbed_official | 52:a51c77007319 | 471 | */ |
mbed_official | 52:a51c77007319 | 472 | void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 473 | { |
mbed_official | 52:a51c77007319 | 474 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 475 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 476 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 477 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 478 | { |
mbed_official | 52:a51c77007319 | 479 | /* Enable the selected ADC conversion on external event and start the selected |
mbed_official | 52:a51c77007319 | 480 | ADC conversion */ |
mbed_official | 52:a51c77007319 | 481 | ADCx->CR2 |= CR2_EXTTRIG_SWSTART_Set; |
mbed_official | 52:a51c77007319 | 482 | } |
mbed_official | 52:a51c77007319 | 483 | else |
mbed_official | 52:a51c77007319 | 484 | { |
mbed_official | 52:a51c77007319 | 485 | /* Disable the selected ADC conversion on external event and stop the selected |
mbed_official | 52:a51c77007319 | 486 | ADC conversion */ |
mbed_official | 52:a51c77007319 | 487 | ADCx->CR2 &= CR2_EXTTRIG_SWSTART_Reset; |
mbed_official | 52:a51c77007319 | 488 | } |
mbed_official | 52:a51c77007319 | 489 | } |
mbed_official | 52:a51c77007319 | 490 | |
mbed_official | 52:a51c77007319 | 491 | /** |
mbed_official | 52:a51c77007319 | 492 | * @brief Gets the selected ADC Software start conversion Status. |
mbed_official | 52:a51c77007319 | 493 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 494 | * @retval The new state of ADC software start conversion (SET or RESET). |
mbed_official | 52:a51c77007319 | 495 | */ |
mbed_official | 52:a51c77007319 | 496 | FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 497 | { |
mbed_official | 52:a51c77007319 | 498 | FlagStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 499 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 500 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 501 | /* Check the status of SWSTART bit */ |
mbed_official | 52:a51c77007319 | 502 | if ((ADCx->CR2 & CR2_SWSTART_Set) != (uint32_t)RESET) |
mbed_official | 52:a51c77007319 | 503 | { |
mbed_official | 52:a51c77007319 | 504 | /* SWSTART bit is set */ |
mbed_official | 52:a51c77007319 | 505 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 506 | } |
mbed_official | 52:a51c77007319 | 507 | else |
mbed_official | 52:a51c77007319 | 508 | { |
mbed_official | 52:a51c77007319 | 509 | /* SWSTART bit is reset */ |
mbed_official | 52:a51c77007319 | 510 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 511 | } |
mbed_official | 52:a51c77007319 | 512 | /* Return the SWSTART bit status */ |
mbed_official | 52:a51c77007319 | 513 | return bitstatus; |
mbed_official | 52:a51c77007319 | 514 | } |
mbed_official | 52:a51c77007319 | 515 | |
mbed_official | 52:a51c77007319 | 516 | /** |
mbed_official | 52:a51c77007319 | 517 | * @brief Configures the discontinuous mode for the selected ADC regular |
mbed_official | 52:a51c77007319 | 518 | * group channel. |
mbed_official | 52:a51c77007319 | 519 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 520 | * @param Number: specifies the discontinuous mode regular channel |
mbed_official | 52:a51c77007319 | 521 | * count value. This number must be between 1 and 8. |
mbed_official | 52:a51c77007319 | 522 | * @retval None |
mbed_official | 52:a51c77007319 | 523 | */ |
mbed_official | 52:a51c77007319 | 524 | void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number) |
mbed_official | 52:a51c77007319 | 525 | { |
mbed_official | 52:a51c77007319 | 526 | uint32_t tmpreg1 = 0; |
mbed_official | 52:a51c77007319 | 527 | uint32_t tmpreg2 = 0; |
mbed_official | 52:a51c77007319 | 528 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 529 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 530 | assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number)); |
mbed_official | 52:a51c77007319 | 531 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 532 | tmpreg1 = ADCx->CR1; |
mbed_official | 52:a51c77007319 | 533 | /* Clear the old discontinuous mode channel count */ |
mbed_official | 52:a51c77007319 | 534 | tmpreg1 &= CR1_DISCNUM_Reset; |
mbed_official | 52:a51c77007319 | 535 | /* Set the discontinuous mode channel count */ |
mbed_official | 52:a51c77007319 | 536 | tmpreg2 = Number - 1; |
mbed_official | 52:a51c77007319 | 537 | tmpreg1 |= tmpreg2 << 13; |
mbed_official | 52:a51c77007319 | 538 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 539 | ADCx->CR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 540 | } |
mbed_official | 52:a51c77007319 | 541 | |
mbed_official | 52:a51c77007319 | 542 | /** |
mbed_official | 52:a51c77007319 | 543 | * @brief Enables or disables the discontinuous mode on regular group |
mbed_official | 52:a51c77007319 | 544 | * channel for the specified ADC |
mbed_official | 52:a51c77007319 | 545 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 546 | * @param NewState: new state of the selected ADC discontinuous mode |
mbed_official | 52:a51c77007319 | 547 | * on regular group channel. |
mbed_official | 52:a51c77007319 | 548 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 549 | * @retval None |
mbed_official | 52:a51c77007319 | 550 | */ |
mbed_official | 52:a51c77007319 | 551 | void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 552 | { |
mbed_official | 52:a51c77007319 | 553 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 554 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 555 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 556 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 557 | { |
mbed_official | 52:a51c77007319 | 558 | /* Enable the selected ADC regular discontinuous mode */ |
mbed_official | 52:a51c77007319 | 559 | ADCx->CR1 |= CR1_DISCEN_Set; |
mbed_official | 52:a51c77007319 | 560 | } |
mbed_official | 52:a51c77007319 | 561 | else |
mbed_official | 52:a51c77007319 | 562 | { |
mbed_official | 52:a51c77007319 | 563 | /* Disable the selected ADC regular discontinuous mode */ |
mbed_official | 52:a51c77007319 | 564 | ADCx->CR1 &= CR1_DISCEN_Reset; |
mbed_official | 52:a51c77007319 | 565 | } |
mbed_official | 52:a51c77007319 | 566 | } |
mbed_official | 52:a51c77007319 | 567 | |
mbed_official | 52:a51c77007319 | 568 | /** |
mbed_official | 52:a51c77007319 | 569 | * @brief Configures for the selected ADC regular channel its corresponding |
mbed_official | 52:a51c77007319 | 570 | * rank in the sequencer and its sample time. |
mbed_official | 52:a51c77007319 | 571 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 572 | * @param ADC_Channel: the ADC channel to configure. |
mbed_official | 52:a51c77007319 | 573 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 574 | * @arg ADC_Channel_0: ADC Channel0 selected |
mbed_official | 52:a51c77007319 | 575 | * @arg ADC_Channel_1: ADC Channel1 selected |
mbed_official | 52:a51c77007319 | 576 | * @arg ADC_Channel_2: ADC Channel2 selected |
mbed_official | 52:a51c77007319 | 577 | * @arg ADC_Channel_3: ADC Channel3 selected |
mbed_official | 52:a51c77007319 | 578 | * @arg ADC_Channel_4: ADC Channel4 selected |
mbed_official | 52:a51c77007319 | 579 | * @arg ADC_Channel_5: ADC Channel5 selected |
mbed_official | 52:a51c77007319 | 580 | * @arg ADC_Channel_6: ADC Channel6 selected |
mbed_official | 52:a51c77007319 | 581 | * @arg ADC_Channel_7: ADC Channel7 selected |
mbed_official | 52:a51c77007319 | 582 | * @arg ADC_Channel_8: ADC Channel8 selected |
mbed_official | 52:a51c77007319 | 583 | * @arg ADC_Channel_9: ADC Channel9 selected |
mbed_official | 52:a51c77007319 | 584 | * @arg ADC_Channel_10: ADC Channel10 selected |
mbed_official | 52:a51c77007319 | 585 | * @arg ADC_Channel_11: ADC Channel11 selected |
mbed_official | 52:a51c77007319 | 586 | * @arg ADC_Channel_12: ADC Channel12 selected |
mbed_official | 52:a51c77007319 | 587 | * @arg ADC_Channel_13: ADC Channel13 selected |
mbed_official | 52:a51c77007319 | 588 | * @arg ADC_Channel_14: ADC Channel14 selected |
mbed_official | 52:a51c77007319 | 589 | * @arg ADC_Channel_15: ADC Channel15 selected |
mbed_official | 52:a51c77007319 | 590 | * @arg ADC_Channel_16: ADC Channel16 selected |
mbed_official | 52:a51c77007319 | 591 | * @arg ADC_Channel_17: ADC Channel17 selected |
mbed_official | 52:a51c77007319 | 592 | * @param Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16. |
mbed_official | 52:a51c77007319 | 593 | * @param ADC_SampleTime: The sample time value to be set for the selected channel. |
mbed_official | 52:a51c77007319 | 594 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 595 | * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles |
mbed_official | 52:a51c77007319 | 596 | * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles |
mbed_official | 52:a51c77007319 | 597 | * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles |
mbed_official | 52:a51c77007319 | 598 | * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles |
mbed_official | 52:a51c77007319 | 599 | * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles |
mbed_official | 52:a51c77007319 | 600 | * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles |
mbed_official | 52:a51c77007319 | 601 | * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles |
mbed_official | 52:a51c77007319 | 602 | * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles |
mbed_official | 52:a51c77007319 | 603 | * @retval None |
mbed_official | 52:a51c77007319 | 604 | */ |
mbed_official | 52:a51c77007319 | 605 | void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime) |
mbed_official | 52:a51c77007319 | 606 | { |
mbed_official | 52:a51c77007319 | 607 | uint32_t tmpreg1 = 0, tmpreg2 = 0; |
mbed_official | 52:a51c77007319 | 608 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 609 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 610 | assert_param(IS_ADC_CHANNEL(ADC_Channel)); |
mbed_official | 52:a51c77007319 | 611 | assert_param(IS_ADC_REGULAR_RANK(Rank)); |
mbed_official | 52:a51c77007319 | 612 | assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime)); |
mbed_official | 52:a51c77007319 | 613 | /* if ADC_Channel_10 ... ADC_Channel_17 is selected */ |
mbed_official | 52:a51c77007319 | 614 | if (ADC_Channel > ADC_Channel_9) |
mbed_official | 52:a51c77007319 | 615 | { |
mbed_official | 52:a51c77007319 | 616 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 617 | tmpreg1 = ADCx->SMPR1; |
mbed_official | 52:a51c77007319 | 618 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 619 | tmpreg2 = SMPR1_SMP_Set << (3 * (ADC_Channel - 10)); |
mbed_official | 52:a51c77007319 | 620 | /* Clear the old channel sample time */ |
mbed_official | 52:a51c77007319 | 621 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 622 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 623 | tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10)); |
mbed_official | 52:a51c77007319 | 624 | /* Set the new channel sample time */ |
mbed_official | 52:a51c77007319 | 625 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 626 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 627 | ADCx->SMPR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 628 | } |
mbed_official | 52:a51c77007319 | 629 | else /* ADC_Channel include in ADC_Channel_[0..9] */ |
mbed_official | 52:a51c77007319 | 630 | { |
mbed_official | 52:a51c77007319 | 631 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 632 | tmpreg1 = ADCx->SMPR2; |
mbed_official | 52:a51c77007319 | 633 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 634 | tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel); |
mbed_official | 52:a51c77007319 | 635 | /* Clear the old channel sample time */ |
mbed_official | 52:a51c77007319 | 636 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 637 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 638 | tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel); |
mbed_official | 52:a51c77007319 | 639 | /* Set the new channel sample time */ |
mbed_official | 52:a51c77007319 | 640 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 641 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 642 | ADCx->SMPR2 = tmpreg1; |
mbed_official | 52:a51c77007319 | 643 | } |
mbed_official | 52:a51c77007319 | 644 | /* For Rank 1 to 6 */ |
mbed_official | 52:a51c77007319 | 645 | if (Rank < 7) |
mbed_official | 52:a51c77007319 | 646 | { |
mbed_official | 52:a51c77007319 | 647 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 648 | tmpreg1 = ADCx->SQR3; |
mbed_official | 52:a51c77007319 | 649 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 650 | tmpreg2 = SQR3_SQ_Set << (5 * (Rank - 1)); |
mbed_official | 52:a51c77007319 | 651 | /* Clear the old SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 652 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 653 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 654 | tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 1)); |
mbed_official | 52:a51c77007319 | 655 | /* Set the SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 656 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 657 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 658 | ADCx->SQR3 = tmpreg1; |
mbed_official | 52:a51c77007319 | 659 | } |
mbed_official | 52:a51c77007319 | 660 | /* For Rank 7 to 12 */ |
mbed_official | 52:a51c77007319 | 661 | else if (Rank < 13) |
mbed_official | 52:a51c77007319 | 662 | { |
mbed_official | 52:a51c77007319 | 663 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 664 | tmpreg1 = ADCx->SQR2; |
mbed_official | 52:a51c77007319 | 665 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 666 | tmpreg2 = SQR2_SQ_Set << (5 * (Rank - 7)); |
mbed_official | 52:a51c77007319 | 667 | /* Clear the old SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 668 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 669 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 670 | tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 7)); |
mbed_official | 52:a51c77007319 | 671 | /* Set the SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 672 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 673 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 674 | ADCx->SQR2 = tmpreg1; |
mbed_official | 52:a51c77007319 | 675 | } |
mbed_official | 52:a51c77007319 | 676 | /* For Rank 13 to 16 */ |
mbed_official | 52:a51c77007319 | 677 | else |
mbed_official | 52:a51c77007319 | 678 | { |
mbed_official | 52:a51c77007319 | 679 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 680 | tmpreg1 = ADCx->SQR1; |
mbed_official | 52:a51c77007319 | 681 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 682 | tmpreg2 = SQR1_SQ_Set << (5 * (Rank - 13)); |
mbed_official | 52:a51c77007319 | 683 | /* Clear the old SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 684 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 685 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 686 | tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 13)); |
mbed_official | 52:a51c77007319 | 687 | /* Set the SQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 688 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 689 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 690 | ADCx->SQR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 691 | } |
mbed_official | 52:a51c77007319 | 692 | } |
mbed_official | 52:a51c77007319 | 693 | |
mbed_official | 52:a51c77007319 | 694 | /** |
mbed_official | 52:a51c77007319 | 695 | * @brief Enables or disables the ADCx conversion through external trigger. |
mbed_official | 52:a51c77007319 | 696 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 697 | * @param NewState: new state of the selected ADC external trigger start of conversion. |
mbed_official | 52:a51c77007319 | 698 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 699 | * @retval None |
mbed_official | 52:a51c77007319 | 700 | */ |
mbed_official | 52:a51c77007319 | 701 | void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 702 | { |
mbed_official | 52:a51c77007319 | 703 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 704 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 705 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 706 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 707 | { |
mbed_official | 52:a51c77007319 | 708 | /* Enable the selected ADC conversion on external event */ |
mbed_official | 52:a51c77007319 | 709 | ADCx->CR2 |= CR2_EXTTRIG_Set; |
mbed_official | 52:a51c77007319 | 710 | } |
mbed_official | 52:a51c77007319 | 711 | else |
mbed_official | 52:a51c77007319 | 712 | { |
mbed_official | 52:a51c77007319 | 713 | /* Disable the selected ADC conversion on external event */ |
mbed_official | 52:a51c77007319 | 714 | ADCx->CR2 &= CR2_EXTTRIG_Reset; |
mbed_official | 52:a51c77007319 | 715 | } |
mbed_official | 52:a51c77007319 | 716 | } |
mbed_official | 52:a51c77007319 | 717 | |
mbed_official | 52:a51c77007319 | 718 | /** |
mbed_official | 52:a51c77007319 | 719 | * @brief Returns the last ADCx conversion result data for regular channel. |
mbed_official | 52:a51c77007319 | 720 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 721 | * @retval The Data conversion value. |
mbed_official | 52:a51c77007319 | 722 | */ |
mbed_official | 52:a51c77007319 | 723 | uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 724 | { |
mbed_official | 52:a51c77007319 | 725 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 726 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 727 | /* Return the selected ADC conversion value */ |
mbed_official | 52:a51c77007319 | 728 | return (uint16_t) ADCx->DR; |
mbed_official | 52:a51c77007319 | 729 | } |
mbed_official | 52:a51c77007319 | 730 | |
mbed_official | 52:a51c77007319 | 731 | /** |
mbed_official | 52:a51c77007319 | 732 | * @brief Returns the last ADC1 and ADC2 conversion result data in dual mode. |
mbed_official | 52:a51c77007319 | 733 | * @retval The Data conversion value. |
mbed_official | 52:a51c77007319 | 734 | */ |
mbed_official | 52:a51c77007319 | 735 | uint32_t ADC_GetDualModeConversionValue(void) |
mbed_official | 52:a51c77007319 | 736 | { |
mbed_official | 52:a51c77007319 | 737 | /* Return the dual mode conversion value */ |
mbed_official | 52:a51c77007319 | 738 | return (*(__IO uint32_t *) DR_ADDRESS); |
mbed_official | 52:a51c77007319 | 739 | } |
mbed_official | 52:a51c77007319 | 740 | |
mbed_official | 52:a51c77007319 | 741 | /** |
mbed_official | 52:a51c77007319 | 742 | * @brief Enables or disables the selected ADC automatic injected group |
mbed_official | 52:a51c77007319 | 743 | * conversion after regular one. |
mbed_official | 52:a51c77007319 | 744 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 745 | * @param NewState: new state of the selected ADC auto injected conversion |
mbed_official | 52:a51c77007319 | 746 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 747 | * @retval None |
mbed_official | 52:a51c77007319 | 748 | */ |
mbed_official | 52:a51c77007319 | 749 | void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 750 | { |
mbed_official | 52:a51c77007319 | 751 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 752 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 753 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 754 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 755 | { |
mbed_official | 52:a51c77007319 | 756 | /* Enable the selected ADC automatic injected group conversion */ |
mbed_official | 52:a51c77007319 | 757 | ADCx->CR1 |= CR1_JAUTO_Set; |
mbed_official | 52:a51c77007319 | 758 | } |
mbed_official | 52:a51c77007319 | 759 | else |
mbed_official | 52:a51c77007319 | 760 | { |
mbed_official | 52:a51c77007319 | 761 | /* Disable the selected ADC automatic injected group conversion */ |
mbed_official | 52:a51c77007319 | 762 | ADCx->CR1 &= CR1_JAUTO_Reset; |
mbed_official | 52:a51c77007319 | 763 | } |
mbed_official | 52:a51c77007319 | 764 | } |
mbed_official | 52:a51c77007319 | 765 | |
mbed_official | 52:a51c77007319 | 766 | /** |
mbed_official | 52:a51c77007319 | 767 | * @brief Enables or disables the discontinuous mode for injected group |
mbed_official | 52:a51c77007319 | 768 | * channel for the specified ADC |
mbed_official | 52:a51c77007319 | 769 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 770 | * @param NewState: new state of the selected ADC discontinuous mode |
mbed_official | 52:a51c77007319 | 771 | * on injected group channel. |
mbed_official | 52:a51c77007319 | 772 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 773 | * @retval None |
mbed_official | 52:a51c77007319 | 774 | */ |
mbed_official | 52:a51c77007319 | 775 | void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 776 | { |
mbed_official | 52:a51c77007319 | 777 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 778 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 779 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 780 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 781 | { |
mbed_official | 52:a51c77007319 | 782 | /* Enable the selected ADC injected discontinuous mode */ |
mbed_official | 52:a51c77007319 | 783 | ADCx->CR1 |= CR1_JDISCEN_Set; |
mbed_official | 52:a51c77007319 | 784 | } |
mbed_official | 52:a51c77007319 | 785 | else |
mbed_official | 52:a51c77007319 | 786 | { |
mbed_official | 52:a51c77007319 | 787 | /* Disable the selected ADC injected discontinuous mode */ |
mbed_official | 52:a51c77007319 | 788 | ADCx->CR1 &= CR1_JDISCEN_Reset; |
mbed_official | 52:a51c77007319 | 789 | } |
mbed_official | 52:a51c77007319 | 790 | } |
mbed_official | 52:a51c77007319 | 791 | |
mbed_official | 52:a51c77007319 | 792 | /** |
mbed_official | 52:a51c77007319 | 793 | * @brief Configures the ADCx external trigger for injected channels conversion. |
mbed_official | 52:a51c77007319 | 794 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 795 | * @param ADC_ExternalTrigInjecConv: specifies the ADC trigger to start injected conversion. |
mbed_official | 52:a51c77007319 | 796 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 797 | * @arg ADC_ExternalTrigInjecConv_T1_TRGO: Timer1 TRGO event selected (for ADC1, ADC2 and ADC3) |
mbed_official | 52:a51c77007319 | 798 | * @arg ADC_ExternalTrigInjecConv_T1_CC4: Timer1 capture compare4 selected (for ADC1, ADC2 and ADC3) |
mbed_official | 52:a51c77007319 | 799 | * @arg ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event selected (for ADC1 and ADC2) |
mbed_official | 52:a51c77007319 | 800 | * @arg ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture compare1 selected (for ADC1 and ADC2) |
mbed_official | 52:a51c77007319 | 801 | * @arg ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture compare4 selected (for ADC1 and ADC2) |
mbed_official | 52:a51c77007319 | 802 | * @arg ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event selected (for ADC1 and ADC2) |
mbed_official | 52:a51c77007319 | 803 | * @arg ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4: External interrupt line 15 or Timer8 |
mbed_official | 52:a51c77007319 | 804 | * capture compare4 event selected (for ADC1 and ADC2) |
mbed_official | 52:a51c77007319 | 805 | * @arg ADC_ExternalTrigInjecConv_T4_CC3: Timer4 capture compare3 selected (for ADC3 only) |
mbed_official | 52:a51c77007319 | 806 | * @arg ADC_ExternalTrigInjecConv_T8_CC2: Timer8 capture compare2 selected (for ADC3 only) |
mbed_official | 52:a51c77007319 | 807 | * @arg ADC_ExternalTrigInjecConv_T8_CC4: Timer8 capture compare4 selected (for ADC3 only) |
mbed_official | 52:a51c77007319 | 808 | * @arg ADC_ExternalTrigInjecConv_T5_TRGO: Timer5 TRGO event selected (for ADC3 only) |
mbed_official | 52:a51c77007319 | 809 | * @arg ADC_ExternalTrigInjecConv_T5_CC4: Timer5 capture compare4 selected (for ADC3 only) |
mbed_official | 52:a51c77007319 | 810 | * @arg ADC_ExternalTrigInjecConv_None: Injected conversion started by software and not |
mbed_official | 52:a51c77007319 | 811 | * by external trigger (for ADC1, ADC2 and ADC3) |
mbed_official | 52:a51c77007319 | 812 | * @retval None |
mbed_official | 52:a51c77007319 | 813 | */ |
mbed_official | 52:a51c77007319 | 814 | void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv) |
mbed_official | 52:a51c77007319 | 815 | { |
mbed_official | 52:a51c77007319 | 816 | uint32_t tmpreg = 0; |
mbed_official | 52:a51c77007319 | 817 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 818 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 819 | assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv)); |
mbed_official | 52:a51c77007319 | 820 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 821 | tmpreg = ADCx->CR2; |
mbed_official | 52:a51c77007319 | 822 | /* Clear the old external event selection for injected group */ |
mbed_official | 52:a51c77007319 | 823 | tmpreg &= CR2_JEXTSEL_Reset; |
mbed_official | 52:a51c77007319 | 824 | /* Set the external event selection for injected group */ |
mbed_official | 52:a51c77007319 | 825 | tmpreg |= ADC_ExternalTrigInjecConv; |
mbed_official | 52:a51c77007319 | 826 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 827 | ADCx->CR2 = tmpreg; |
mbed_official | 52:a51c77007319 | 828 | } |
mbed_official | 52:a51c77007319 | 829 | |
mbed_official | 52:a51c77007319 | 830 | /** |
mbed_official | 52:a51c77007319 | 831 | * @brief Enables or disables the ADCx injected channels conversion through |
mbed_official | 52:a51c77007319 | 832 | * external trigger |
mbed_official | 52:a51c77007319 | 833 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 834 | * @param NewState: new state of the selected ADC external trigger start of |
mbed_official | 52:a51c77007319 | 835 | * injected conversion. |
mbed_official | 52:a51c77007319 | 836 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 837 | * @retval None |
mbed_official | 52:a51c77007319 | 838 | */ |
mbed_official | 52:a51c77007319 | 839 | void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 840 | { |
mbed_official | 52:a51c77007319 | 841 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 842 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 843 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 844 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 845 | { |
mbed_official | 52:a51c77007319 | 846 | /* Enable the selected ADC external event selection for injected group */ |
mbed_official | 52:a51c77007319 | 847 | ADCx->CR2 |= CR2_JEXTTRIG_Set; |
mbed_official | 52:a51c77007319 | 848 | } |
mbed_official | 52:a51c77007319 | 849 | else |
mbed_official | 52:a51c77007319 | 850 | { |
mbed_official | 52:a51c77007319 | 851 | /* Disable the selected ADC external event selection for injected group */ |
mbed_official | 52:a51c77007319 | 852 | ADCx->CR2 &= CR2_JEXTTRIG_Reset; |
mbed_official | 52:a51c77007319 | 853 | } |
mbed_official | 52:a51c77007319 | 854 | } |
mbed_official | 52:a51c77007319 | 855 | |
mbed_official | 52:a51c77007319 | 856 | /** |
mbed_official | 52:a51c77007319 | 857 | * @brief Enables or disables the selected ADC start of the injected |
mbed_official | 52:a51c77007319 | 858 | * channels conversion. |
mbed_official | 52:a51c77007319 | 859 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 860 | * @param NewState: new state of the selected ADC software start injected conversion. |
mbed_official | 52:a51c77007319 | 861 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 862 | * @retval None |
mbed_official | 52:a51c77007319 | 863 | */ |
mbed_official | 52:a51c77007319 | 864 | void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 865 | { |
mbed_official | 52:a51c77007319 | 866 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 867 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 868 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 869 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 870 | { |
mbed_official | 52:a51c77007319 | 871 | /* Enable the selected ADC conversion for injected group on external event and start the selected |
mbed_official | 52:a51c77007319 | 872 | ADC injected conversion */ |
mbed_official | 52:a51c77007319 | 873 | ADCx->CR2 |= CR2_JEXTTRIG_JSWSTART_Set; |
mbed_official | 52:a51c77007319 | 874 | } |
mbed_official | 52:a51c77007319 | 875 | else |
mbed_official | 52:a51c77007319 | 876 | { |
mbed_official | 52:a51c77007319 | 877 | /* Disable the selected ADC conversion on external event for injected group and stop the selected |
mbed_official | 52:a51c77007319 | 878 | ADC injected conversion */ |
mbed_official | 52:a51c77007319 | 879 | ADCx->CR2 &= CR2_JEXTTRIG_JSWSTART_Reset; |
mbed_official | 52:a51c77007319 | 880 | } |
mbed_official | 52:a51c77007319 | 881 | } |
mbed_official | 52:a51c77007319 | 882 | |
mbed_official | 52:a51c77007319 | 883 | /** |
mbed_official | 52:a51c77007319 | 884 | * @brief Gets the selected ADC Software start injected conversion Status. |
mbed_official | 52:a51c77007319 | 885 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 886 | * @retval The new state of ADC software start injected conversion (SET or RESET). |
mbed_official | 52:a51c77007319 | 887 | */ |
mbed_official | 52:a51c77007319 | 888 | FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx) |
mbed_official | 52:a51c77007319 | 889 | { |
mbed_official | 52:a51c77007319 | 890 | FlagStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 891 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 892 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 893 | /* Check the status of JSWSTART bit */ |
mbed_official | 52:a51c77007319 | 894 | if ((ADCx->CR2 & CR2_JSWSTART_Set) != (uint32_t)RESET) |
mbed_official | 52:a51c77007319 | 895 | { |
mbed_official | 52:a51c77007319 | 896 | /* JSWSTART bit is set */ |
mbed_official | 52:a51c77007319 | 897 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 898 | } |
mbed_official | 52:a51c77007319 | 899 | else |
mbed_official | 52:a51c77007319 | 900 | { |
mbed_official | 52:a51c77007319 | 901 | /* JSWSTART bit is reset */ |
mbed_official | 52:a51c77007319 | 902 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 903 | } |
mbed_official | 52:a51c77007319 | 904 | /* Return the JSWSTART bit status */ |
mbed_official | 52:a51c77007319 | 905 | return bitstatus; |
mbed_official | 52:a51c77007319 | 906 | } |
mbed_official | 52:a51c77007319 | 907 | |
mbed_official | 52:a51c77007319 | 908 | /** |
mbed_official | 52:a51c77007319 | 909 | * @brief Configures for the selected ADC injected channel its corresponding |
mbed_official | 52:a51c77007319 | 910 | * rank in the sequencer and its sample time. |
mbed_official | 52:a51c77007319 | 911 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 912 | * @param ADC_Channel: the ADC channel to configure. |
mbed_official | 52:a51c77007319 | 913 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 914 | * @arg ADC_Channel_0: ADC Channel0 selected |
mbed_official | 52:a51c77007319 | 915 | * @arg ADC_Channel_1: ADC Channel1 selected |
mbed_official | 52:a51c77007319 | 916 | * @arg ADC_Channel_2: ADC Channel2 selected |
mbed_official | 52:a51c77007319 | 917 | * @arg ADC_Channel_3: ADC Channel3 selected |
mbed_official | 52:a51c77007319 | 918 | * @arg ADC_Channel_4: ADC Channel4 selected |
mbed_official | 52:a51c77007319 | 919 | * @arg ADC_Channel_5: ADC Channel5 selected |
mbed_official | 52:a51c77007319 | 920 | * @arg ADC_Channel_6: ADC Channel6 selected |
mbed_official | 52:a51c77007319 | 921 | * @arg ADC_Channel_7: ADC Channel7 selected |
mbed_official | 52:a51c77007319 | 922 | * @arg ADC_Channel_8: ADC Channel8 selected |
mbed_official | 52:a51c77007319 | 923 | * @arg ADC_Channel_9: ADC Channel9 selected |
mbed_official | 52:a51c77007319 | 924 | * @arg ADC_Channel_10: ADC Channel10 selected |
mbed_official | 52:a51c77007319 | 925 | * @arg ADC_Channel_11: ADC Channel11 selected |
mbed_official | 52:a51c77007319 | 926 | * @arg ADC_Channel_12: ADC Channel12 selected |
mbed_official | 52:a51c77007319 | 927 | * @arg ADC_Channel_13: ADC Channel13 selected |
mbed_official | 52:a51c77007319 | 928 | * @arg ADC_Channel_14: ADC Channel14 selected |
mbed_official | 52:a51c77007319 | 929 | * @arg ADC_Channel_15: ADC Channel15 selected |
mbed_official | 52:a51c77007319 | 930 | * @arg ADC_Channel_16: ADC Channel16 selected |
mbed_official | 52:a51c77007319 | 931 | * @arg ADC_Channel_17: ADC Channel17 selected |
mbed_official | 52:a51c77007319 | 932 | * @param Rank: The rank in the injected group sequencer. This parameter must be between 1 and 4. |
mbed_official | 52:a51c77007319 | 933 | * @param ADC_SampleTime: The sample time value to be set for the selected channel. |
mbed_official | 52:a51c77007319 | 934 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 935 | * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles |
mbed_official | 52:a51c77007319 | 936 | * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles |
mbed_official | 52:a51c77007319 | 937 | * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles |
mbed_official | 52:a51c77007319 | 938 | * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles |
mbed_official | 52:a51c77007319 | 939 | * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles |
mbed_official | 52:a51c77007319 | 940 | * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles |
mbed_official | 52:a51c77007319 | 941 | * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles |
mbed_official | 52:a51c77007319 | 942 | * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles |
mbed_official | 52:a51c77007319 | 943 | * @retval None |
mbed_official | 52:a51c77007319 | 944 | */ |
mbed_official | 52:a51c77007319 | 945 | void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime) |
mbed_official | 52:a51c77007319 | 946 | { |
mbed_official | 52:a51c77007319 | 947 | uint32_t tmpreg1 = 0, tmpreg2 = 0, tmpreg3 = 0; |
mbed_official | 52:a51c77007319 | 948 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 949 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 950 | assert_param(IS_ADC_CHANNEL(ADC_Channel)); |
mbed_official | 52:a51c77007319 | 951 | assert_param(IS_ADC_INJECTED_RANK(Rank)); |
mbed_official | 52:a51c77007319 | 952 | assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime)); |
mbed_official | 52:a51c77007319 | 953 | /* if ADC_Channel_10 ... ADC_Channel_17 is selected */ |
mbed_official | 52:a51c77007319 | 954 | if (ADC_Channel > ADC_Channel_9) |
mbed_official | 52:a51c77007319 | 955 | { |
mbed_official | 52:a51c77007319 | 956 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 957 | tmpreg1 = ADCx->SMPR1; |
mbed_official | 52:a51c77007319 | 958 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 959 | tmpreg2 = SMPR1_SMP_Set << (3*(ADC_Channel - 10)); |
mbed_official | 52:a51c77007319 | 960 | /* Clear the old channel sample time */ |
mbed_official | 52:a51c77007319 | 961 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 962 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 963 | tmpreg2 = (uint32_t)ADC_SampleTime << (3*(ADC_Channel - 10)); |
mbed_official | 52:a51c77007319 | 964 | /* Set the new channel sample time */ |
mbed_official | 52:a51c77007319 | 965 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 966 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 967 | ADCx->SMPR1 = tmpreg1; |
mbed_official | 52:a51c77007319 | 968 | } |
mbed_official | 52:a51c77007319 | 969 | else /* ADC_Channel include in ADC_Channel_[0..9] */ |
mbed_official | 52:a51c77007319 | 970 | { |
mbed_official | 52:a51c77007319 | 971 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 972 | tmpreg1 = ADCx->SMPR2; |
mbed_official | 52:a51c77007319 | 973 | /* Calculate the mask to clear */ |
mbed_official | 52:a51c77007319 | 974 | tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel); |
mbed_official | 52:a51c77007319 | 975 | /* Clear the old channel sample time */ |
mbed_official | 52:a51c77007319 | 976 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 977 | /* Calculate the mask to set */ |
mbed_official | 52:a51c77007319 | 978 | tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel); |
mbed_official | 52:a51c77007319 | 979 | /* Set the new channel sample time */ |
mbed_official | 52:a51c77007319 | 980 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 981 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 982 | ADCx->SMPR2 = tmpreg1; |
mbed_official | 52:a51c77007319 | 983 | } |
mbed_official | 52:a51c77007319 | 984 | /* Rank configuration */ |
mbed_official | 52:a51c77007319 | 985 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 986 | tmpreg1 = ADCx->JSQR; |
mbed_official | 52:a51c77007319 | 987 | /* Get JL value: Number = JL+1 */ |
mbed_official | 52:a51c77007319 | 988 | tmpreg3 = (tmpreg1 & JSQR_JL_Set)>> 20; |
mbed_official | 52:a51c77007319 | 989 | /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */ |
mbed_official | 52:a51c77007319 | 990 | tmpreg2 = JSQR_JSQ_Set << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))); |
mbed_official | 52:a51c77007319 | 991 | /* Clear the old JSQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 992 | tmpreg1 &= ~tmpreg2; |
mbed_official | 52:a51c77007319 | 993 | /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */ |
mbed_official | 52:a51c77007319 | 994 | tmpreg2 = (uint32_t)ADC_Channel << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))); |
mbed_official | 52:a51c77007319 | 995 | /* Set the JSQx bits for the selected rank */ |
mbed_official | 52:a51c77007319 | 996 | tmpreg1 |= tmpreg2; |
mbed_official | 52:a51c77007319 | 997 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 998 | ADCx->JSQR = tmpreg1; |
mbed_official | 52:a51c77007319 | 999 | } |
mbed_official | 52:a51c77007319 | 1000 | |
mbed_official | 52:a51c77007319 | 1001 | /** |
mbed_official | 52:a51c77007319 | 1002 | * @brief Configures the sequencer length for injected channels |
mbed_official | 52:a51c77007319 | 1003 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1004 | * @param Length: The sequencer length. |
mbed_official | 52:a51c77007319 | 1005 | * This parameter must be a number between 1 to 4. |
mbed_official | 52:a51c77007319 | 1006 | * @retval None |
mbed_official | 52:a51c77007319 | 1007 | */ |
mbed_official | 52:a51c77007319 | 1008 | void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length) |
mbed_official | 52:a51c77007319 | 1009 | { |
mbed_official | 52:a51c77007319 | 1010 | uint32_t tmpreg1 = 0; |
mbed_official | 52:a51c77007319 | 1011 | uint32_t tmpreg2 = 0; |
mbed_official | 52:a51c77007319 | 1012 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1013 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1014 | assert_param(IS_ADC_INJECTED_LENGTH(Length)); |
mbed_official | 52:a51c77007319 | 1015 | |
mbed_official | 52:a51c77007319 | 1016 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 1017 | tmpreg1 = ADCx->JSQR; |
mbed_official | 52:a51c77007319 | 1018 | /* Clear the old injected sequnence lenght JL bits */ |
mbed_official | 52:a51c77007319 | 1019 | tmpreg1 &= JSQR_JL_Reset; |
mbed_official | 52:a51c77007319 | 1020 | /* Set the injected sequnence lenght JL bits */ |
mbed_official | 52:a51c77007319 | 1021 | tmpreg2 = Length - 1; |
mbed_official | 52:a51c77007319 | 1022 | tmpreg1 |= tmpreg2 << 20; |
mbed_official | 52:a51c77007319 | 1023 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 1024 | ADCx->JSQR = tmpreg1; |
mbed_official | 52:a51c77007319 | 1025 | } |
mbed_official | 52:a51c77007319 | 1026 | |
mbed_official | 52:a51c77007319 | 1027 | /** |
mbed_official | 52:a51c77007319 | 1028 | * @brief Set the injected channels conversion value offset |
mbed_official | 52:a51c77007319 | 1029 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1030 | * @param ADC_InjectedChannel: the ADC injected channel to set its offset. |
mbed_official | 52:a51c77007319 | 1031 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1032 | * @arg ADC_InjectedChannel_1: Injected Channel1 selected |
mbed_official | 52:a51c77007319 | 1033 | * @arg ADC_InjectedChannel_2: Injected Channel2 selected |
mbed_official | 52:a51c77007319 | 1034 | * @arg ADC_InjectedChannel_3: Injected Channel3 selected |
mbed_official | 52:a51c77007319 | 1035 | * @arg ADC_InjectedChannel_4: Injected Channel4 selected |
mbed_official | 52:a51c77007319 | 1036 | * @param Offset: the offset value for the selected ADC injected channel |
mbed_official | 52:a51c77007319 | 1037 | * This parameter must be a 12bit value. |
mbed_official | 52:a51c77007319 | 1038 | * @retval None |
mbed_official | 52:a51c77007319 | 1039 | */ |
mbed_official | 52:a51c77007319 | 1040 | void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset) |
mbed_official | 52:a51c77007319 | 1041 | { |
mbed_official | 52:a51c77007319 | 1042 | __IO uint32_t tmp = 0; |
mbed_official | 52:a51c77007319 | 1043 | |
mbed_official | 52:a51c77007319 | 1044 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1045 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1046 | assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel)); |
mbed_official | 52:a51c77007319 | 1047 | assert_param(IS_ADC_OFFSET(Offset)); |
mbed_official | 52:a51c77007319 | 1048 | |
mbed_official | 52:a51c77007319 | 1049 | tmp = (uint32_t)ADCx; |
mbed_official | 52:a51c77007319 | 1050 | tmp += ADC_InjectedChannel; |
mbed_official | 52:a51c77007319 | 1051 | |
mbed_official | 52:a51c77007319 | 1052 | /* Set the selected injected channel data offset */ |
mbed_official | 52:a51c77007319 | 1053 | *(__IO uint32_t *) tmp = (uint32_t)Offset; |
mbed_official | 52:a51c77007319 | 1054 | } |
mbed_official | 52:a51c77007319 | 1055 | |
mbed_official | 52:a51c77007319 | 1056 | /** |
mbed_official | 52:a51c77007319 | 1057 | * @brief Returns the ADC injected channel conversion result |
mbed_official | 52:a51c77007319 | 1058 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1059 | * @param ADC_InjectedChannel: the converted ADC injected channel. |
mbed_official | 52:a51c77007319 | 1060 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1061 | * @arg ADC_InjectedChannel_1: Injected Channel1 selected |
mbed_official | 52:a51c77007319 | 1062 | * @arg ADC_InjectedChannel_2: Injected Channel2 selected |
mbed_official | 52:a51c77007319 | 1063 | * @arg ADC_InjectedChannel_3: Injected Channel3 selected |
mbed_official | 52:a51c77007319 | 1064 | * @arg ADC_InjectedChannel_4: Injected Channel4 selected |
mbed_official | 52:a51c77007319 | 1065 | * @retval The Data conversion value. |
mbed_official | 52:a51c77007319 | 1066 | */ |
mbed_official | 52:a51c77007319 | 1067 | uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel) |
mbed_official | 52:a51c77007319 | 1068 | { |
mbed_official | 52:a51c77007319 | 1069 | __IO uint32_t tmp = 0; |
mbed_official | 52:a51c77007319 | 1070 | |
mbed_official | 52:a51c77007319 | 1071 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1072 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1073 | assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel)); |
mbed_official | 52:a51c77007319 | 1074 | |
mbed_official | 52:a51c77007319 | 1075 | tmp = (uint32_t)ADCx; |
mbed_official | 52:a51c77007319 | 1076 | tmp += ADC_InjectedChannel + JDR_Offset; |
mbed_official | 52:a51c77007319 | 1077 | |
mbed_official | 52:a51c77007319 | 1078 | /* Returns the selected injected channel conversion data value */ |
mbed_official | 52:a51c77007319 | 1079 | return (uint16_t) (*(__IO uint32_t*) tmp); |
mbed_official | 52:a51c77007319 | 1080 | } |
mbed_official | 52:a51c77007319 | 1081 | |
mbed_official | 52:a51c77007319 | 1082 | /** |
mbed_official | 52:a51c77007319 | 1083 | * @brief Enables or disables the analog watchdog on single/all regular |
mbed_official | 52:a51c77007319 | 1084 | * or injected channels |
mbed_official | 52:a51c77007319 | 1085 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1086 | * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration. |
mbed_official | 52:a51c77007319 | 1087 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1088 | * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel |
mbed_official | 52:a51c77007319 | 1089 | * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel |
mbed_official | 52:a51c77007319 | 1090 | * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel |
mbed_official | 52:a51c77007319 | 1091 | * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel |
mbed_official | 52:a51c77007319 | 1092 | * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel |
mbed_official | 52:a51c77007319 | 1093 | * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels |
mbed_official | 52:a51c77007319 | 1094 | * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog |
mbed_official | 52:a51c77007319 | 1095 | * @retval None |
mbed_official | 52:a51c77007319 | 1096 | */ |
mbed_official | 52:a51c77007319 | 1097 | void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog) |
mbed_official | 52:a51c77007319 | 1098 | { |
mbed_official | 52:a51c77007319 | 1099 | uint32_t tmpreg = 0; |
mbed_official | 52:a51c77007319 | 1100 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1101 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1102 | assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog)); |
mbed_official | 52:a51c77007319 | 1103 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 1104 | tmpreg = ADCx->CR1; |
mbed_official | 52:a51c77007319 | 1105 | /* Clear AWDEN, AWDENJ and AWDSGL bits */ |
mbed_official | 52:a51c77007319 | 1106 | tmpreg &= CR1_AWDMode_Reset; |
mbed_official | 52:a51c77007319 | 1107 | /* Set the analog watchdog enable mode */ |
mbed_official | 52:a51c77007319 | 1108 | tmpreg |= ADC_AnalogWatchdog; |
mbed_official | 52:a51c77007319 | 1109 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 1110 | ADCx->CR1 = tmpreg; |
mbed_official | 52:a51c77007319 | 1111 | } |
mbed_official | 52:a51c77007319 | 1112 | |
mbed_official | 52:a51c77007319 | 1113 | /** |
mbed_official | 52:a51c77007319 | 1114 | * @brief Configures the high and low thresholds of the analog watchdog. |
mbed_official | 52:a51c77007319 | 1115 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1116 | * @param HighThreshold: the ADC analog watchdog High threshold value. |
mbed_official | 52:a51c77007319 | 1117 | * This parameter must be a 12bit value. |
mbed_official | 52:a51c77007319 | 1118 | * @param LowThreshold: the ADC analog watchdog Low threshold value. |
mbed_official | 52:a51c77007319 | 1119 | * This parameter must be a 12bit value. |
mbed_official | 52:a51c77007319 | 1120 | * @retval None |
mbed_official | 52:a51c77007319 | 1121 | */ |
mbed_official | 52:a51c77007319 | 1122 | void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, |
mbed_official | 52:a51c77007319 | 1123 | uint16_t LowThreshold) |
mbed_official | 52:a51c77007319 | 1124 | { |
mbed_official | 52:a51c77007319 | 1125 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1126 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1127 | assert_param(IS_ADC_THRESHOLD(HighThreshold)); |
mbed_official | 52:a51c77007319 | 1128 | assert_param(IS_ADC_THRESHOLD(LowThreshold)); |
mbed_official | 52:a51c77007319 | 1129 | /* Set the ADCx high threshold */ |
mbed_official | 52:a51c77007319 | 1130 | ADCx->HTR = HighThreshold; |
mbed_official | 52:a51c77007319 | 1131 | /* Set the ADCx low threshold */ |
mbed_official | 52:a51c77007319 | 1132 | ADCx->LTR = LowThreshold; |
mbed_official | 52:a51c77007319 | 1133 | } |
mbed_official | 52:a51c77007319 | 1134 | |
mbed_official | 52:a51c77007319 | 1135 | /** |
mbed_official | 52:a51c77007319 | 1136 | * @brief Configures the analog watchdog guarded single channel |
mbed_official | 52:a51c77007319 | 1137 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1138 | * @param ADC_Channel: the ADC channel to configure for the analog watchdog. |
mbed_official | 52:a51c77007319 | 1139 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1140 | * @arg ADC_Channel_0: ADC Channel0 selected |
mbed_official | 52:a51c77007319 | 1141 | * @arg ADC_Channel_1: ADC Channel1 selected |
mbed_official | 52:a51c77007319 | 1142 | * @arg ADC_Channel_2: ADC Channel2 selected |
mbed_official | 52:a51c77007319 | 1143 | * @arg ADC_Channel_3: ADC Channel3 selected |
mbed_official | 52:a51c77007319 | 1144 | * @arg ADC_Channel_4: ADC Channel4 selected |
mbed_official | 52:a51c77007319 | 1145 | * @arg ADC_Channel_5: ADC Channel5 selected |
mbed_official | 52:a51c77007319 | 1146 | * @arg ADC_Channel_6: ADC Channel6 selected |
mbed_official | 52:a51c77007319 | 1147 | * @arg ADC_Channel_7: ADC Channel7 selected |
mbed_official | 52:a51c77007319 | 1148 | * @arg ADC_Channel_8: ADC Channel8 selected |
mbed_official | 52:a51c77007319 | 1149 | * @arg ADC_Channel_9: ADC Channel9 selected |
mbed_official | 52:a51c77007319 | 1150 | * @arg ADC_Channel_10: ADC Channel10 selected |
mbed_official | 52:a51c77007319 | 1151 | * @arg ADC_Channel_11: ADC Channel11 selected |
mbed_official | 52:a51c77007319 | 1152 | * @arg ADC_Channel_12: ADC Channel12 selected |
mbed_official | 52:a51c77007319 | 1153 | * @arg ADC_Channel_13: ADC Channel13 selected |
mbed_official | 52:a51c77007319 | 1154 | * @arg ADC_Channel_14: ADC Channel14 selected |
mbed_official | 52:a51c77007319 | 1155 | * @arg ADC_Channel_15: ADC Channel15 selected |
mbed_official | 52:a51c77007319 | 1156 | * @arg ADC_Channel_16: ADC Channel16 selected |
mbed_official | 52:a51c77007319 | 1157 | * @arg ADC_Channel_17: ADC Channel17 selected |
mbed_official | 52:a51c77007319 | 1158 | * @retval None |
mbed_official | 52:a51c77007319 | 1159 | */ |
mbed_official | 52:a51c77007319 | 1160 | void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel) |
mbed_official | 52:a51c77007319 | 1161 | { |
mbed_official | 52:a51c77007319 | 1162 | uint32_t tmpreg = 0; |
mbed_official | 52:a51c77007319 | 1163 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1164 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1165 | assert_param(IS_ADC_CHANNEL(ADC_Channel)); |
mbed_official | 52:a51c77007319 | 1166 | /* Get the old register value */ |
mbed_official | 52:a51c77007319 | 1167 | tmpreg = ADCx->CR1; |
mbed_official | 52:a51c77007319 | 1168 | /* Clear the Analog watchdog channel select bits */ |
mbed_official | 52:a51c77007319 | 1169 | tmpreg &= CR1_AWDCH_Reset; |
mbed_official | 52:a51c77007319 | 1170 | /* Set the Analog watchdog channel */ |
mbed_official | 52:a51c77007319 | 1171 | tmpreg |= ADC_Channel; |
mbed_official | 52:a51c77007319 | 1172 | /* Store the new register value */ |
mbed_official | 52:a51c77007319 | 1173 | ADCx->CR1 = tmpreg; |
mbed_official | 52:a51c77007319 | 1174 | } |
mbed_official | 52:a51c77007319 | 1175 | |
mbed_official | 52:a51c77007319 | 1176 | /** |
mbed_official | 52:a51c77007319 | 1177 | * @brief Enables or disables the temperature sensor and Vrefint channel. |
mbed_official | 52:a51c77007319 | 1178 | * @param NewState: new state of the temperature sensor. |
mbed_official | 52:a51c77007319 | 1179 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 52:a51c77007319 | 1180 | * @retval None |
mbed_official | 52:a51c77007319 | 1181 | */ |
mbed_official | 52:a51c77007319 | 1182 | void ADC_TempSensorVrefintCmd(FunctionalState NewState) |
mbed_official | 52:a51c77007319 | 1183 | { |
mbed_official | 52:a51c77007319 | 1184 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1185 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 52:a51c77007319 | 1186 | if (NewState != DISABLE) |
mbed_official | 52:a51c77007319 | 1187 | { |
mbed_official | 52:a51c77007319 | 1188 | /* Enable the temperature sensor and Vrefint channel*/ |
mbed_official | 52:a51c77007319 | 1189 | ADC1->CR2 |= CR2_TSVREFE_Set; |
mbed_official | 52:a51c77007319 | 1190 | } |
mbed_official | 52:a51c77007319 | 1191 | else |
mbed_official | 52:a51c77007319 | 1192 | { |
mbed_official | 52:a51c77007319 | 1193 | /* Disable the temperature sensor and Vrefint channel*/ |
mbed_official | 52:a51c77007319 | 1194 | ADC1->CR2 &= CR2_TSVREFE_Reset; |
mbed_official | 52:a51c77007319 | 1195 | } |
mbed_official | 52:a51c77007319 | 1196 | } |
mbed_official | 52:a51c77007319 | 1197 | |
mbed_official | 52:a51c77007319 | 1198 | /** |
mbed_official | 52:a51c77007319 | 1199 | * @brief Checks whether the specified ADC flag is set or not. |
mbed_official | 52:a51c77007319 | 1200 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1201 | * @param ADC_FLAG: specifies the flag to check. |
mbed_official | 52:a51c77007319 | 1202 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1203 | * @arg ADC_FLAG_AWD: Analog watchdog flag |
mbed_official | 52:a51c77007319 | 1204 | * @arg ADC_FLAG_EOC: End of conversion flag |
mbed_official | 52:a51c77007319 | 1205 | * @arg ADC_FLAG_JEOC: End of injected group conversion flag |
mbed_official | 52:a51c77007319 | 1206 | * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag |
mbed_official | 52:a51c77007319 | 1207 | * @arg ADC_FLAG_STRT: Start of regular group conversion flag |
mbed_official | 52:a51c77007319 | 1208 | * @retval The new state of ADC_FLAG (SET or RESET). |
mbed_official | 52:a51c77007319 | 1209 | */ |
mbed_official | 52:a51c77007319 | 1210 | FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG) |
mbed_official | 52:a51c77007319 | 1211 | { |
mbed_official | 52:a51c77007319 | 1212 | FlagStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 1213 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1214 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1215 | assert_param(IS_ADC_GET_FLAG(ADC_FLAG)); |
mbed_official | 52:a51c77007319 | 1216 | /* Check the status of the specified ADC flag */ |
mbed_official | 52:a51c77007319 | 1217 | if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET) |
mbed_official | 52:a51c77007319 | 1218 | { |
mbed_official | 52:a51c77007319 | 1219 | /* ADC_FLAG is set */ |
mbed_official | 52:a51c77007319 | 1220 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 1221 | } |
mbed_official | 52:a51c77007319 | 1222 | else |
mbed_official | 52:a51c77007319 | 1223 | { |
mbed_official | 52:a51c77007319 | 1224 | /* ADC_FLAG is reset */ |
mbed_official | 52:a51c77007319 | 1225 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 1226 | } |
mbed_official | 52:a51c77007319 | 1227 | /* Return the ADC_FLAG status */ |
mbed_official | 52:a51c77007319 | 1228 | return bitstatus; |
mbed_official | 52:a51c77007319 | 1229 | } |
mbed_official | 52:a51c77007319 | 1230 | |
mbed_official | 52:a51c77007319 | 1231 | /** |
mbed_official | 52:a51c77007319 | 1232 | * @brief Clears the ADCx's pending flags. |
mbed_official | 52:a51c77007319 | 1233 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1234 | * @param ADC_FLAG: specifies the flag to clear. |
mbed_official | 52:a51c77007319 | 1235 | * This parameter can be any combination of the following values: |
mbed_official | 52:a51c77007319 | 1236 | * @arg ADC_FLAG_AWD: Analog watchdog flag |
mbed_official | 52:a51c77007319 | 1237 | * @arg ADC_FLAG_EOC: End of conversion flag |
mbed_official | 52:a51c77007319 | 1238 | * @arg ADC_FLAG_JEOC: End of injected group conversion flag |
mbed_official | 52:a51c77007319 | 1239 | * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag |
mbed_official | 52:a51c77007319 | 1240 | * @arg ADC_FLAG_STRT: Start of regular group conversion flag |
mbed_official | 52:a51c77007319 | 1241 | * @retval None |
mbed_official | 52:a51c77007319 | 1242 | */ |
mbed_official | 52:a51c77007319 | 1243 | void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG) |
mbed_official | 52:a51c77007319 | 1244 | { |
mbed_official | 52:a51c77007319 | 1245 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1246 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1247 | assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG)); |
mbed_official | 52:a51c77007319 | 1248 | /* Clear the selected ADC flags */ |
mbed_official | 52:a51c77007319 | 1249 | ADCx->SR = ~(uint32_t)ADC_FLAG; |
mbed_official | 52:a51c77007319 | 1250 | } |
mbed_official | 52:a51c77007319 | 1251 | |
mbed_official | 52:a51c77007319 | 1252 | /** |
mbed_official | 52:a51c77007319 | 1253 | * @brief Checks whether the specified ADC interrupt has occurred or not. |
mbed_official | 52:a51c77007319 | 1254 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1255 | * @param ADC_IT: specifies the ADC interrupt source to check. |
mbed_official | 52:a51c77007319 | 1256 | * This parameter can be one of the following values: |
mbed_official | 52:a51c77007319 | 1257 | * @arg ADC_IT_EOC: End of conversion interrupt mask |
mbed_official | 52:a51c77007319 | 1258 | * @arg ADC_IT_AWD: Analog watchdog interrupt mask |
mbed_official | 52:a51c77007319 | 1259 | * @arg ADC_IT_JEOC: End of injected conversion interrupt mask |
mbed_official | 52:a51c77007319 | 1260 | * @retval The new state of ADC_IT (SET or RESET). |
mbed_official | 52:a51c77007319 | 1261 | */ |
mbed_official | 52:a51c77007319 | 1262 | ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT) |
mbed_official | 52:a51c77007319 | 1263 | { |
mbed_official | 52:a51c77007319 | 1264 | ITStatus bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 1265 | uint32_t itmask = 0, enablestatus = 0; |
mbed_official | 52:a51c77007319 | 1266 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1267 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1268 | assert_param(IS_ADC_GET_IT(ADC_IT)); |
mbed_official | 52:a51c77007319 | 1269 | /* Get the ADC IT index */ |
mbed_official | 52:a51c77007319 | 1270 | itmask = ADC_IT >> 8; |
mbed_official | 52:a51c77007319 | 1271 | /* Get the ADC_IT enable bit status */ |
mbed_official | 52:a51c77007319 | 1272 | enablestatus = (ADCx->CR1 & (uint8_t)ADC_IT) ; |
mbed_official | 52:a51c77007319 | 1273 | /* Check the status of the specified ADC interrupt */ |
mbed_official | 52:a51c77007319 | 1274 | if (((ADCx->SR & itmask) != (uint32_t)RESET) && enablestatus) |
mbed_official | 52:a51c77007319 | 1275 | { |
mbed_official | 52:a51c77007319 | 1276 | /* ADC_IT is set */ |
mbed_official | 52:a51c77007319 | 1277 | bitstatus = SET; |
mbed_official | 52:a51c77007319 | 1278 | } |
mbed_official | 52:a51c77007319 | 1279 | else |
mbed_official | 52:a51c77007319 | 1280 | { |
mbed_official | 52:a51c77007319 | 1281 | /* ADC_IT is reset */ |
mbed_official | 52:a51c77007319 | 1282 | bitstatus = RESET; |
mbed_official | 52:a51c77007319 | 1283 | } |
mbed_official | 52:a51c77007319 | 1284 | /* Return the ADC_IT status */ |
mbed_official | 52:a51c77007319 | 1285 | return bitstatus; |
mbed_official | 52:a51c77007319 | 1286 | } |
mbed_official | 52:a51c77007319 | 1287 | |
mbed_official | 52:a51c77007319 | 1288 | /** |
mbed_official | 52:a51c77007319 | 1289 | * @brief Clears the ADCx's interrupt pending bits. |
mbed_official | 52:a51c77007319 | 1290 | * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral. |
mbed_official | 52:a51c77007319 | 1291 | * @param ADC_IT: specifies the ADC interrupt pending bit to clear. |
mbed_official | 52:a51c77007319 | 1292 | * This parameter can be any combination of the following values: |
mbed_official | 52:a51c77007319 | 1293 | * @arg ADC_IT_EOC: End of conversion interrupt mask |
mbed_official | 52:a51c77007319 | 1294 | * @arg ADC_IT_AWD: Analog watchdog interrupt mask |
mbed_official | 52:a51c77007319 | 1295 | * @arg ADC_IT_JEOC: End of injected conversion interrupt mask |
mbed_official | 52:a51c77007319 | 1296 | * @retval None |
mbed_official | 52:a51c77007319 | 1297 | */ |
mbed_official | 52:a51c77007319 | 1298 | void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT) |
mbed_official | 52:a51c77007319 | 1299 | { |
mbed_official | 52:a51c77007319 | 1300 | uint8_t itmask = 0; |
mbed_official | 52:a51c77007319 | 1301 | /* Check the parameters */ |
mbed_official | 52:a51c77007319 | 1302 | assert_param(IS_ADC_ALL_PERIPH(ADCx)); |
mbed_official | 52:a51c77007319 | 1303 | assert_param(IS_ADC_IT(ADC_IT)); |
mbed_official | 52:a51c77007319 | 1304 | /* Get the ADC IT index */ |
mbed_official | 52:a51c77007319 | 1305 | itmask = (uint8_t)(ADC_IT >> 8); |
mbed_official | 52:a51c77007319 | 1306 | /* Clear the selected ADC interrupt pending bits */ |
mbed_official | 52:a51c77007319 | 1307 | ADCx->SR = ~(uint32_t)itmask; |
mbed_official | 52:a51c77007319 | 1308 | } |
mbed_official | 52:a51c77007319 | 1309 | |
mbed_official | 52:a51c77007319 | 1310 | /** |
mbed_official | 52:a51c77007319 | 1311 | * @} |
mbed_official | 52:a51c77007319 | 1312 | */ |
mbed_official | 52:a51c77007319 | 1313 | |
mbed_official | 52:a51c77007319 | 1314 | /** |
mbed_official | 52:a51c77007319 | 1315 | * @} |
mbed_official | 52:a51c77007319 | 1316 | */ |
mbed_official | 52:a51c77007319 | 1317 | |
mbed_official | 52:a51c77007319 | 1318 | /** |
mbed_official | 52:a51c77007319 | 1319 | * @} |
mbed_official | 52:a51c77007319 | 1320 | */ |
mbed_official | 52:a51c77007319 | 1321 | |
mbed_official | 84:f54042cbc282 | 1322 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |