mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Dec 02 11:30:05 2013 +0000
Revision:
52:a51c77007319
Child:
70:c1fbde68b492
Synchronized with git revision 49df530ae72ce97ccc773d1f2c13b38e868e6abd

Full URL: https://github.com/mbedmicro/mbed/commit/49df530ae72ce97ccc773d1f2c13b38e868e6abd/

Add STMicroelectronics NUCLEO_F103RB target

Who changed what in which revision?

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