HAL_adc.h 13.3 KB
Newer Older
Z
ZhuGangfei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
/**
******************************************************************************
* @file    HAL_adc.h
* @author  AE Team
* @version V1.0.0
* @date    28/7/2017
* @brief   This file contains all the functions prototypes for the ADC firmware 
*          library.
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2017 MindMotion</center></h2>
*/ 

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HAL_ADC_H
#define __HAL_ADC_H

/* Includes ------------------------------------------------------------------*/
#include "HAL_device.h"

/** @addtogroup StdPeriph_Driver
* @{
*/

/** @addtogroup ADC
* @{
*/

/** @defgroup ADC_Exported_Types
* @{
*/

/** 
* @brief  ADC Init structure definition  
*/

/*
typedef struct
{
uint32_t ADC_Mode;
FunctionalState ADC_ScanConvMode; 
FunctionalState ADC_ContinuousConvMode;
uint32_t ADC_ExternalTrigConv;
uint32_t ADC_DataAlign;
uint8_t ADC_NbrOfChannel;
}ADC_InitTypeDef;
*/
typedef struct
{
  uint32_t ADC_Resolution;  
  uint32_t ADC_PRESCARE;
  uint32_t ADC_Mode;
  FunctionalState ADC_ContinuousConvMode;
  uint32_t ADC_ExternalTrigConv;     
  uint32_t ADC_DataAlign;
}ADC_InitTypeDef;
/**
* @}
*/

/** @defgroup ADC_Exported_Constants
* @{
*/

#define IS_ADC_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \
((*(uint32_t*)&(PERIPH)) == ADC2_BASE))

#define IS_ADC_DMA_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \
((*(uint32_t*)&(PERIPH)) == ADC2_BASE))

/** @defgroup ADC_Resolution
* @{
*/ 
#define ADC_Resolution_12b                         ((uint32_t)0x00000000)
#define ADC_Resolution_11b                         ((uint32_t)0x00000080)
#define ADC_Resolution_10b                         ((uint32_t)0x00000100)
#define ADC_Resolution_9b                          ((uint32_t)0x00000180)
#define ADC_Resolution_8b                          ((uint32_t)0x00000200)
/** 
* @brief  for ADC1, ADC2
*/

#define ADC_PCLK2_PRESCARE_2                       ((uint32_t)0x00000000)              
#define ADC_PCLK2_PRESCARE_4                       ((uint32_t)0x00000008)              
#define ADC_PCLK2_PRESCARE_6                       ((uint32_t)0x00000010)              
#define ADC_PCLK2_PRESCARE_8                       ((uint32_t)0x00000018)              
#define ADC_PCLK2_PRESCARE_10                      ((uint32_t)0x00000020)              
#define ADC_PCLK2_PRESCARE_12                      ((uint32_t)0x00000028)              
#define ADC_PCLK2_PRESCARE_14                      ((uint32_t)0x00000030)              
#define ADC_PCLK2_PRESCARE_16                      ((uint32_t)0x00000038)              
#define ADC_PCLK2_PRESCARE_32                      ((uint32_t)0x00000040)              
#define ADC_PCLK2_PRESCARE_64                      ((uint32_t)0x00000048)              
#define ADC_PCLK2_PRESCARE_128                     ((uint32_t)0x00000050)              
#define ADC_PCLK2_PRESCARE_256                     ((uint32_t)0x00000058)              
#define ADC_PCLK2_PRESCARE_512                     ((uint32_t)0x00000060)              
#define ADC_PCLK2_PRESCARE_1024                    ((uint32_t)0x00000068)              
#define ADC_PCLK2_PRESCARE_2048                    ((uint32_t)0x00000070)              
#define ADC_PCLK2_PRESCARE_4096                    ((uint32_t)0x00000078)              


/** @defgroup ADC_dual_mode 
* @{
*/

#define ADC_Mode_Single                   	((uint32_t)0x00000000)
#define ADC_Mode_Single_Period              ((uint32_t)0x00000200)
#define ADC_Mode_Continuous_Scan            ((uint32_t)0x00000400)


#define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Single) || \
((MODE) == ADC_Mode_Single_Period) || \
  ((MODE) == ADC_Mode_Continuous_Scan))
/**
* @}
*/



/** @defgroup ADC_extrenal_trigger_sources_for_regular_channels_conversion 
* @{
*/

/** 
* @brief  for ADC1  
*/

#define ADC_ExternalTrigConv_T1_CC1         	((uint32_t)0x00000000)
#define ADC_ExternalTrigConv_T1_CC2   			  ((uint32_t)0x00000010)
#define ADC_ExternalTrigConv_T1_CC3     		  ((uint32_t)0x00000020)
#define ADC_ExternalTrigConv_T2_CC2  			  ((uint32_t)0x00000030)
#define ADC_ExternalTrigConv_T3_TRGO      		((uint32_t)0x00000040)
#define ADC_ExternalTrigConv_T4_CC4      		((uint32_t)0x00000050)
#define ADC_ExternalTrigConv_T3_CC1      		((uint32_t)0x00000060)
#define ADC_ExternalTrigConv_EXTI_11     	  ((uint32_t)0x00000070)

/** 
* @brief  for ADC2
*/

#define ADC_ExternalTrigConv_T1_TRGO          ((uint32_t)0x00000000)
#define ADC_ExternalTrigConv_T1_CC4           ((uint32_t)0x00000010)
#define ADC_ExternalTrigConv_T2_TRGO          ((uint32_t)0x00000020)
#define ADC_ExternalTrigConv_T2_CC1           ((uint32_t)0x00000030)
#define ADC_ExternalTrigConv_T3_CC4           ((uint32_t)0x00000040)
#define ADC_ExternalTrigConv_T4_TRGO          ((uint32_t)0x00000050)
#define ADC_ExternalTrigConv_T3_CC1           ((uint32_t)0x00000060)
#define ADC_ExternalTrigConv_EXTI_15          ((uint32_t)0x00000070)



#define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
  ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
    ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
      ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
        ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
          ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
            ((REGTRIG) == ADC_ExternalTrigConv_EXTI_11) || \
              ((REGTRIG) == ADC_ExternalTrigConv_T1_TRGO) || \
                ((REGTRIG) == ADC_ExternalTrigConv_T1_CC4) || \
                  ((REGTRIG) == ADC_ExternalTrigConv_T2_TRGO) || \
                    ((REGTRIG) == ADC_ExternalTrigConv_T2_CC1) || \
                      ((REGTRIG) == ADC_ExternalTrigConv_T3_CC4) || \
                        ((REGTRIG) == ADC_ExternalTrigConv_T4_TRGO) || \
                          ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
                            ((REGTRIG) == ADC_ExternalTrigConv_EXTI_15))
/**
* @}
*/

/** @defgroup ADC_data_align 
* @{
*/

#define ADC_DataAlign_Right                        ((uint32_t)0x00000000)
#define ADC_DataAlign_Left                         ((uint32_t)0x00000800)
#define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
((ALIGN) == ADC_DataAlign_Left))
/**
* @}
*/

/** @defgroup ADC_channels 
* @{
*/

#define ADC_Channel_0                               ((uint8_t)0x00)
#define ADC_Channel_1                               ((uint8_t)0x01)
#define ADC_Channel_2                               ((uint8_t)0x02)
#define ADC_Channel_3                               ((uint8_t)0x03)
#define ADC_Channel_4                               ((uint8_t)0x04)
#define ADC_Channel_5                               ((uint8_t)0x05)
#define ADC_Channel_6                               ((uint8_t)0x06)
#define ADC_Channel_7                               ((uint8_t)0x07)
#define ADC_Channel_8                               ((uint8_t)0x08)
#define ADC_Channel_All															((uint8_t)0x0f)


#define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \
((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \
  ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \
    ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \
      ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_All))
/**
* @}
*/

#define  ADC_SMPR_SMP                      ((uint32_t)0x00000007)        /*!< SMP[2:0] bits (Sampling time selection) */
#define  ADC_SMPR_SMP_0                    ((uint32_t)0x00000001)        /*!< Bit 0 */
#define  ADC_SMPR_SMP_1                    ((uint32_t)0x00000002)        /*!< Bit 1 */
#define  ADC_SMPR_SMP_2                    ((uint32_t)0x00000004)        /*!< Bit 2 */
/** @defgroup ADC_sampling_times 
* @{
*/ 

#define ADC_SampleTime_1_5Cycles                     ((uint32_t)0x00000000)
#define ADC_SampleTime_7_5Cycles                     ((uint32_t)0x00000001)
#define ADC_SampleTime_13_5Cycles                    ((uint32_t)0x00000002)
#define ADC_SampleTime_28_5Cycles                    ((uint32_t)0x00000003)
#define ADC_SampleTime_41_5Cycles                    ((uint32_t)0x00000004)
#define ADC_SampleTime_55_5Cycles                    ((uint32_t)0x00000005)
#define ADC_SampleTime_71_5Cycles                    ((uint32_t)0x00000006)
#define ADC_SampleTime_239_5Cycles                   ((uint32_t)0x00000007)

/** @defgroup ADC_injected_channel_selection 
* @{
*/

#define ADC_InjectedChannel_0                       ((uint8_t)0x18)
#define ADC_InjectedChannel_1                       ((uint8_t)0x1C)
#define ADC_InjectedChannel_2                       ((uint8_t)0x20)
#define ADC_InjectedChannel_3                       ((uint8_t)0x24)
#define ADC_InjectedChannel_4                       ((uint8_t)0x28)
#define ADC_InjectedChannel_5                       ((uint8_t)0x2C)
#define ADC_InjectedChannel_6                       ((uint8_t)0x30)
#define ADC_InjectedChannel_7                       ((uint8_t)0x34)
#define ADC_InjectedChannel_8                       ((uint8_t)0x38)
#define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \
((CHANNEL) == ADC_InjectedChannel_2) || \
  ((CHANNEL) == ADC_InjectedChannel_3) || \
    ((CHANNEL) == ADC_InjectedChannel_4) || \
      ((CHANNEL) == ADC_InjectedChannel_5) || \
        ((CHANNEL) == ADC_InjectedChannel_6) || \
          ((CHANNEL) == ADC_InjectedChannel_7) || \
            ((CHANNEL) == ADC_InjectedChannel_8))
/**
* @}
*/

/** @defgroup ADC_analog_watchdog_selection 
* @{
*/

#define ADC_AnalogWatchdog_SingleRegEnable         ((uint32_t)0x00000002)
#define ADC_AnalogWatchdog_None                    ((uint32_t)0x00000000)

#define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
((WATCHDOG) == ADC_AnalogWatchdog_None))
/**
* @}
*/

/** @defgroup ADC_interrupts_definition 
* @{
*/

#define ADC_IT_EOC                                 ((uint16_t)0x0001)
#define ADC_IT_AWD                                 ((uint16_t)0x0002)

#define IS_ADC_IT(IT) ((((IT) & (uint16_t)0xFFFC) == 0x00) && ((IT) != 0x00))

#define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD)) 

/**
* @}
*/

/** @defgroup ADC_flags_definition 
* @{
*/

#define ADC_FLAG_AWD                               ((uint8_t)0x02) //ADWIF Ƚϱ־λ
#define ADC_FLAG_EOC                               ((uint8_t)0x01) //ADIF  ת־λ
#define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xF0) == 0x00) && ((FLAG) != 0x00))
#define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC))

/**
* @}
*/

/** @defgroup ADC_thresholds 
* @{
*/

#define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)

/**
* @}
*/

/** @defgroup ADC_injected_offset 
* @{
*/

#define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF)

/**
* @}
*/

/** @defgroup ADC_injected_length 
* @{
*/

#define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))

/**
* @}
*/

/** @defgroup ADC_injected_rank 
* @{
*/

#define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))

/**
* @}
*/ 


/** @defgroup ADC_regular_length 
* @{
*/

#define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
/**
* @}
*/

/** @defgroup ADC_regular_rank 
* @{
*/

#define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))

/**
* @}
*/

/** @defgroup ADC_regular_discontinuous_mode_number 
* @{
*/

#define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))

/**
* @}
*/

/**
* @}
*/

/** @defgroup ADC_Exported_Macros
* @{
*/

/**
* @}
*/

/** @defgroup ADC_Exported_Functions
* @{
*/

void ADC_DeInit(ADC_TypeDef* ADCx);
void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);

void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog);
void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
void ADC_TempSensorVrefintCmd(FunctionalState NewState);
FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);

#endif /*__HAL_ADC_H */

/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/