1 /** 2 ****************************************************************************** 3 * @file HAL_adc.h 4 * @author AE Team 5 * @version V1.0.0 6 * @date 28/7/2017 7 * @brief This file contains all the functions prototypes for the ADC firmware 8 * library. 9 ****************************************************************************** 10 * @copy 11 * 12 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 * TIME. AS A RESULT, MindMotion SHALL NOT BE HELD LIABLE FOR ANY 15 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 * 19 * <h2><center>© COPYRIGHT 2017 MindMotion</center></h2> 20 */ 21 22 /* Define to prevent recursive inclusion -------------------------------------*/ 23 #ifndef __HAL_ADC_H 24 #define __HAL_ADC_H 25 26 /* Includes ------------------------------------------------------------------*/ 27 #include "HAL_device.h" 28 29 /** @addtogroup StdPeriph_Driver 30 * @{ 31 */ 32 33 /** @addtogroup ADC 34 * @{ 35 */ 36 37 /** @defgroup ADC_Exported_Types 38 * @{ 39 */ 40 41 /** 42 * @brief ADC Init structure definition 43 */ 44 45 /* 46 typedef struct 47 { 48 uint32_t ADC_Mode; 49 FunctionalState ADC_ScanConvMode; 50 FunctionalState ADC_ContinuousConvMode; 51 uint32_t ADC_ExternalTrigConv; 52 uint32_t ADC_DataAlign; 53 uint8_t ADC_NbrOfChannel; 54 }ADC_InitTypeDef; 55 */ 56 typedef struct 57 { 58 uint32_t ADC_Resolution; 59 uint32_t ADC_PRESCARE; 60 uint32_t ADC_Mode; 61 FunctionalState ADC_ContinuousConvMode; 62 uint32_t ADC_ExternalTrigConv; 63 uint32_t ADC_DataAlign; 64 }ADC_InitTypeDef; 65 /** 66 * @} 67 */ 68 69 /** @defgroup ADC_Exported_Constants 70 * @{ 71 */ 72 73 #define IS_ADC_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \ 74 ((*(uint32_t*)&(PERIPH)) == ADC2_BASE)) 75 76 #define IS_ADC_DMA_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == ADC1_BASE) || \ 77 ((*(uint32_t*)&(PERIPH)) == ADC2_BASE)) 78 79 /** @defgroup ADC_Resolution 80 * @{ 81 */ 82 #define ADC_Resolution_12b ((uint32_t)0x00000000) 83 #define ADC_Resolution_11b ((uint32_t)0x00000080) 84 #define ADC_Resolution_10b ((uint32_t)0x00000100) 85 #define ADC_Resolution_9b ((uint32_t)0x00000180) 86 #define ADC_Resolution_8b ((uint32_t)0x00000200) 87 /** 88 * @brief for ADC1, ADC2 89 */ 90 91 #define ADC_PCLK2_PRESCARE_2 ((uint32_t)0x00000000) 92 #define ADC_PCLK2_PRESCARE_4 ((uint32_t)0x00000008) 93 #define ADC_PCLK2_PRESCARE_6 ((uint32_t)0x00000010) 94 #define ADC_PCLK2_PRESCARE_8 ((uint32_t)0x00000018) 95 #define ADC_PCLK2_PRESCARE_10 ((uint32_t)0x00000020) 96 #define ADC_PCLK2_PRESCARE_12 ((uint32_t)0x00000028) 97 #define ADC_PCLK2_PRESCARE_14 ((uint32_t)0x00000030) 98 #define ADC_PCLK2_PRESCARE_16 ((uint32_t)0x00000038) 99 #define ADC_PCLK2_PRESCARE_32 ((uint32_t)0x00000040) 100 #define ADC_PCLK2_PRESCARE_64 ((uint32_t)0x00000048) 101 #define ADC_PCLK2_PRESCARE_128 ((uint32_t)0x00000050) 102 #define ADC_PCLK2_PRESCARE_256 ((uint32_t)0x00000058) 103 #define ADC_PCLK2_PRESCARE_512 ((uint32_t)0x00000060) 104 #define ADC_PCLK2_PRESCARE_1024 ((uint32_t)0x00000068) 105 #define ADC_PCLK2_PRESCARE_2048 ((uint32_t)0x00000070) 106 #define ADC_PCLK2_PRESCARE_4096 ((uint32_t)0x00000078) 107 108 109 /** @defgroup ADC_dual_mode 110 * @{ 111 */ 112 113 #define ADC_Mode_Single ((uint32_t)0x00000000) 114 #define ADC_Mode_Single_Period ((uint32_t)0x00000200) 115 #define ADC_Mode_Continuous_Scan ((uint32_t)0x00000400) 116 117 118 #define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Single) || \ 119 ((MODE) == ADC_Mode_Single_Period) || \ 120 ((MODE) == ADC_Mode_Continuous_Scan)) 121 /** 122 * @} 123 */ 124 125 126 127 /** @defgroup ADC_extrenal_trigger_sources_for_regular_channels_conversion 128 * @{ 129 */ 130 131 /** 132 * @brief for ADC1 133 */ 134 135 #define ADC_ExternalTrigConv_T1_CC1 ((uint32_t)0x00000000) 136 #define ADC_ExternalTrigConv_T1_CC2 ((uint32_t)0x00000010) 137 #define ADC_ExternalTrigConv_T1_CC3 ((uint32_t)0x00000020) 138 #define ADC_ExternalTrigConv_T2_CC2 ((uint32_t)0x00000030) 139 #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)0x00000040) 140 #define ADC_ExternalTrigConv_T4_CC4 ((uint32_t)0x00000050) 141 #define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x00000060) 142 #define ADC_ExternalTrigConv_EXTI_11 ((uint32_t)0x00000070) 143 144 /** 145 * @brief for ADC2 146 */ 147 148 #define ADC_ExternalTrigConv_T1_TRGO ((uint32_t)0x00000000) 149 #define ADC_ExternalTrigConv_T1_CC4 ((uint32_t)0x00000010) 150 #define ADC_ExternalTrigConv_T2_TRGO ((uint32_t)0x00000020) 151 #define ADC_ExternalTrigConv_T2_CC1 ((uint32_t)0x00000030) 152 #define ADC_ExternalTrigConv_T3_CC4 ((uint32_t)0x00000040) 153 #define ADC_ExternalTrigConv_T4_TRGO ((uint32_t)0x00000050) 154 #define ADC_ExternalTrigConv_T3_CC1 ((uint32_t)0x00000060) 155 #define ADC_ExternalTrigConv_EXTI_15 ((uint32_t)0x00000070) 156 157 158 159 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \ 160 ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \ 161 ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \ 162 ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \ 163 ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \ 164 ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \ 165 ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \ 166 ((REGTRIG) == ADC_ExternalTrigConv_EXTI_11) || \ 167 ((REGTRIG) == ADC_ExternalTrigConv_T1_TRGO) || \ 168 ((REGTRIG) == ADC_ExternalTrigConv_T1_CC4) || \ 169 ((REGTRIG) == ADC_ExternalTrigConv_T2_TRGO) || \ 170 ((REGTRIG) == ADC_ExternalTrigConv_T2_CC1) || \ 171 ((REGTRIG) == ADC_ExternalTrigConv_T3_CC4) || \ 172 ((REGTRIG) == ADC_ExternalTrigConv_T4_TRGO) || \ 173 ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \ 174 ((REGTRIG) == ADC_ExternalTrigConv_EXTI_15)) 175 /** 176 * @} 177 */ 178 179 /** @defgroup ADC_data_align 180 * @{ 181 */ 182 183 #define ADC_DataAlign_Right ((uint32_t)0x00000000) 184 #define ADC_DataAlign_Left ((uint32_t)0x00000800) 185 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \ 186 ((ALIGN) == ADC_DataAlign_Left)) 187 /** 188 * @} 189 */ 190 191 /** @defgroup ADC_channels 192 * @{ 193 */ 194 195 #define ADC_Channel_0 ((uint8_t)0x00) 196 #define ADC_Channel_1 ((uint8_t)0x01) 197 #define ADC_Channel_2 ((uint8_t)0x02) 198 #define ADC_Channel_3 ((uint8_t)0x03) 199 #define ADC_Channel_4 ((uint8_t)0x04) 200 #define ADC_Channel_5 ((uint8_t)0x05) 201 #define ADC_Channel_6 ((uint8_t)0x06) 202 #define ADC_Channel_7 ((uint8_t)0x07) 203 #define ADC_Channel_8 ((uint8_t)0x08) 204 #define ADC_Channel_All ((uint8_t)0x0f) 205 206 207 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \ 208 ((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \ 209 ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \ 210 ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \ 211 ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_All)) 212 /** 213 * @} 214 */ 215 216 #define ADC_SMPR_SMP ((uint32_t)0x00000007) /*!< SMP[2:0] bits (Sampling time selection) */ 217 #define ADC_SMPR_SMP_0 ((uint32_t)0x00000001) /*!< Bit 0 */ 218 #define ADC_SMPR_SMP_1 ((uint32_t)0x00000002) /*!< Bit 1 */ 219 #define ADC_SMPR_SMP_2 ((uint32_t)0x00000004) /*!< Bit 2 */ 220 /** @defgroup ADC_sampling_times 221 * @{ 222 */ 223 224 #define ADC_SampleTime_1_5Cycles ((uint32_t)0x00000000) 225 #define ADC_SampleTime_7_5Cycles ((uint32_t)0x00000001) 226 #define ADC_SampleTime_13_5Cycles ((uint32_t)0x00000002) 227 #define ADC_SampleTime_28_5Cycles ((uint32_t)0x00000003) 228 #define ADC_SampleTime_41_5Cycles ((uint32_t)0x00000004) 229 #define ADC_SampleTime_55_5Cycles ((uint32_t)0x00000005) 230 #define ADC_SampleTime_71_5Cycles ((uint32_t)0x00000006) 231 #define ADC_SampleTime_239_5Cycles ((uint32_t)0x00000007) 232 233 /** @defgroup ADC_injected_channel_selection 234 * @{ 235 */ 236 237 #define ADC_InjectedChannel_0 ((uint8_t)0x18) 238 #define ADC_InjectedChannel_1 ((uint8_t)0x1C) 239 #define ADC_InjectedChannel_2 ((uint8_t)0x20) 240 #define ADC_InjectedChannel_3 ((uint8_t)0x24) 241 #define ADC_InjectedChannel_4 ((uint8_t)0x28) 242 #define ADC_InjectedChannel_5 ((uint8_t)0x2C) 243 #define ADC_InjectedChannel_6 ((uint8_t)0x30) 244 #define ADC_InjectedChannel_7 ((uint8_t)0x34) 245 #define ADC_InjectedChannel_8 ((uint8_t)0x38) 246 #define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \ 247 ((CHANNEL) == ADC_InjectedChannel_2) || \ 248 ((CHANNEL) == ADC_InjectedChannel_3) || \ 249 ((CHANNEL) == ADC_InjectedChannel_4) || \ 250 ((CHANNEL) == ADC_InjectedChannel_5) || \ 251 ((CHANNEL) == ADC_InjectedChannel_6) || \ 252 ((CHANNEL) == ADC_InjectedChannel_7) || \ 253 ((CHANNEL) == ADC_InjectedChannel_8)) 254 /** 255 * @} 256 */ 257 258 /** @defgroup ADC_analog_watchdog_selection 259 * @{ 260 */ 261 262 #define ADC_AnalogWatchdog_SingleRegEnable ((uint32_t)0x00000002) 263 #define ADC_AnalogWatchdog_None ((uint32_t)0x00000000) 264 265 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \ 266 ((WATCHDOG) == ADC_AnalogWatchdog_None)) 267 /** 268 * @} 269 */ 270 271 /** @defgroup ADC_interrupts_definition 272 * @{ 273 */ 274 275 #define ADC_IT_EOC ((uint16_t)0x0001) 276 #define ADC_IT_AWD ((uint16_t)0x0002) 277 278 #define IS_ADC_IT(IT) ((((IT) & (uint16_t)0xFFFC) == 0x00) && ((IT) != 0x00)) 279 280 #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD)) 281 282 /** 283 * @} 284 */ 285 286 /** @defgroup ADC_flags_definition 287 * @{ 288 */ 289 290 #define ADC_FLAG_AWD ((uint8_t)0x02) //ADWIF �Ƚϱ�־λ 291 #define ADC_FLAG_EOC ((uint8_t)0x01) //ADIF ת��������־λ 292 #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xF0) == 0x00) && ((FLAG) != 0x00)) 293 #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC)) 294 295 /** 296 * @} 297 */ 298 299 /** @defgroup ADC_thresholds 300 * @{ 301 */ 302 303 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF) 304 305 /** 306 * @} 307 */ 308 309 /** @defgroup ADC_injected_offset 310 * @{ 311 */ 312 313 #define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF) 314 315 /** 316 * @} 317 */ 318 319 /** @defgroup ADC_injected_length 320 * @{ 321 */ 322 323 #define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4)) 324 325 /** 326 * @} 327 */ 328 329 /** @defgroup ADC_injected_rank 330 * @{ 331 */ 332 333 #define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4)) 334 335 /** 336 * @} 337 */ 338 339 340 /** @defgroup ADC_regular_length 341 * @{ 342 */ 343 344 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10)) 345 /** 346 * @} 347 */ 348 349 /** @defgroup ADC_regular_rank 350 * @{ 351 */ 352 353 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10)) 354 355 /** 356 * @} 357 */ 358 359 /** @defgroup ADC_regular_discontinuous_mode_number 360 * @{ 361 */ 362 363 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8)) 364 365 /** 366 * @} 367 */ 368 369 /** 370 * @} 371 */ 372 373 /** @defgroup ADC_Exported_Macros 374 * @{ 375 */ 376 377 /** 378 * @} 379 */ 380 381 /** @defgroup ADC_Exported_Functions 382 * @{ 383 */ 384 385 void ADC_DeInit(ADC_TypeDef* ADCx); 386 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct); 387 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct); 388 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState); 389 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState); 390 void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState); 391 void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState); 392 FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx); 393 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime); 394 void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState); 395 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx); 396 397 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog); 398 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold); 399 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel); 400 void ADC_TempSensorVrefintCmd(FunctionalState NewState); 401 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG); 402 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG); 403 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT); 404 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT); 405 406 #endif /*__HAL_ADC_H */ 407 408 /** 409 * @} 410 */ 411 412 /** 413 * @} 414 */ 415 416 /** 417 * @} 418 */ 419 420 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/ 421