STM32F3DISCOVERY/CHEBUZZF3 - Move ADC pin definitions to target.h files

This commit is contained in:
Dominic Clifton 2015-02-04 19:12:13 +00:00
parent 8aee0b25e2
commit 430ccd2338
5 changed files with 59 additions and 11 deletions

View File

@ -25,6 +25,8 @@
#include "adc.h" #include "adc.h"
//#define DEBUG_ADC_CHANNELS
#ifdef USE_ADC #ifdef USE_ADC
adc_config_t adcConfig[ADC_CHANNEL_COUNT]; adc_config_t adcConfig[ADC_CHANNEL_COUNT];
volatile uint16_t adcValues[ADC_CHANNEL_COUNT]; volatile uint16_t adcValues[ADC_CHANNEL_COUNT];
@ -33,7 +35,7 @@ extern int16_t debug[4];
uint16_t adcGetChannel(uint8_t channel) uint16_t adcGetChannel(uint8_t channel)
{ {
#if DEBUG_ADC_CHANNELS #ifdef DEBUG_ADC_CHANNELS
if (adcConfig[0].enabled) { if (adcConfig[0].enabled) {
debug[0] = adcValues[adcConfig[0].dmaIndex]; debug[0] = adcValues[adcConfig[0].dmaIndex];
} }

View File

@ -64,7 +64,7 @@ void adcInit(drv_adc_config_t *init)
GPIO_StructInit(&GPIO_InitStructure); GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
#ifdef VBAT_ADC_GPIO_PIN #ifdef VBAT_ADC_GPIO
GPIO_InitStructure.GPIO_Pin = VBAT_ADC_GPIO_PIN; GPIO_InitStructure.GPIO_Pin = VBAT_ADC_GPIO_PIN;
GPIO_Init(VBAT_ADC_GPIO, &GPIO_InitStructure); GPIO_Init(VBAT_ADC_GPIO, &GPIO_InitStructure);
adcConfig[ADC_BATTERY].adcChannel = VBAT_ADC_CHANNEL; adcConfig[ADC_BATTERY].adcChannel = VBAT_ADC_CHANNEL;

View File

@ -44,42 +44,56 @@ void adcInit(drv_adc_config_t *init)
memset(&adcConfig, 0, sizeof(adcConfig)); memset(&adcConfig, 0, sizeof(adcConfig));
GPIO_StructInit(&GPIO_InitStructure); GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
adcConfig[ADC_BATTERY].adcChannel = ADC_Channel_6; #ifdef VBAT_ADC_GPIO
GPIO_InitStructure.GPIO_Pin = VBAT_ADC_GPIO_PIN;
GPIO_Init(VBAT_ADC_GPIO, &GPIO_InitStructure);
adcConfig[ADC_BATTERY].adcChannel = VBAT_ADC_CHANNEL;
adcConfig[ADC_BATTERY].dmaIndex = adcChannelCount; adcConfig[ADC_BATTERY].dmaIndex = adcChannelCount;
adcConfig[ADC_BATTERY].sampleTime = ADC_SampleTime_601Cycles5; adcConfig[ADC_BATTERY].sampleTime = ADC_SampleTime_601Cycles5;
adcConfig[ADC_BATTERY].enabled = true; adcConfig[ADC_BATTERY].enabled = true;
adcChannelCount++; adcChannelCount++;
#endif
#ifdef CURRENT_METER_ADC_GPIO
if (init->enableCurrentMeter) { if (init->enableCurrentMeter) {
GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_1; GPIO_InitStructure.GPIO_Pin = CURRENT_METER_ADC_GPIO_PIN;
GPIO_Init(CURRENT_METER_ADC_GPIO, &GPIO_InitStructure);
adcConfig[ADC_CURRENT].adcChannel = ADC_Channel_7; adcConfig[ADC_CURRENT].adcChannel = CURRENT_METER_ADC_CHANNEL;
adcConfig[ADC_CURRENT].dmaIndex = adcChannelCount; adcConfig[ADC_CURRENT].dmaIndex = adcChannelCount;
adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_601Cycles5; adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_601Cycles5;
adcConfig[ADC_CURRENT].enabled = true; adcConfig[ADC_CURRENT].enabled = true;
adcChannelCount++; adcChannelCount++;
} }
#endif
#ifdef RSSI_ADC_GPIO
if (init->enableRSSI) { if (init->enableRSSI) {
GPIO_InitStructure.GPIO_Pin |= GPIO_Pin_2; GPIO_InitStructure.GPIO_Pin = RSSI_ADC_GPIO_PIN;
GPIO_Init(RSSI_ADC_GPIO, &GPIO_InitStructure);
adcConfig[ADC_RSSI].adcChannel = ADC_Channel_8; adcConfig[ADC_RSSI].adcChannel = RSSI_ADC_CHANNEL;
adcConfig[ADC_RSSI].dmaIndex = adcChannelCount; adcConfig[ADC_RSSI].dmaIndex = adcChannelCount;
adcConfig[ADC_RSSI].sampleTime = ADC_SampleTime_601Cycles5; adcConfig[ADC_RSSI].sampleTime = ADC_SampleTime_601Cycles5;
adcConfig[ADC_RSSI].enabled = true; adcConfig[ADC_RSSI].enabled = true;
adcChannelCount++; adcChannelCount++;
} }
#endif
adcConfig[ADC_EXTERNAL1].adcChannel = ADC_Channel_9; #ifdef EXTERNAL1_ADC_GPIO
GPIO_InitStructure.GPIO_Pin = EXTERNAL1_ADC_GPIO_PIN;
GPIO_Init(EXTERNAL1_ADC_GPIO, &GPIO_InitStructure);
adcConfig[ADC_EXTERNAL1].adcChannel = EXTERNAL1_ADC_CHANNEL;
adcConfig[ADC_EXTERNAL1].dmaIndex = adcChannelCount; adcConfig[ADC_EXTERNAL1].dmaIndex = adcChannelCount;
adcConfig[ADC_EXTERNAL1].sampleTime = ADC_SampleTime_601Cycles5; adcConfig[ADC_EXTERNAL1].sampleTime = ADC_SampleTime_601Cycles5;
adcConfig[ADC_EXTERNAL1].enabled = true; adcConfig[ADC_EXTERNAL1].enabled = true;
adcChannelCount++; adcChannelCount++;
#endif
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256); // 72 MHz divided by 256 = 281.25 kHz RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256); // 72 MHz divided by 256 = 281.25 kHz
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_ADC12, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_ADC12, ENABLE);
@ -103,7 +117,6 @@ void adcInit(drv_adc_config_t *init)
DMA_Cmd(DMA1_Channel1, ENABLE); DMA_Cmd(DMA1_Channel1, ENABLE);
GPIO_Init(GPIOC, &GPIO_InitStructure);
// calibrate // calibrate

View File

@ -70,6 +70,23 @@
#define USE_ADC #define USE_ADC
#define VBAT_ADC_GPIO GPIOC
#define VBAT_ADC_GPIO_PIN GPIO_Pin_0
#define VBAT_ADC_CHANNEL ADC_Channel_6
#define CURRENT_METER_ADC_GPIO GPIOC
#define CURRENT_METER_ADC_GPIO_PIN GPIO_Pin_1
#define CURRENT_METER_ADC_CHANNEL ADC_Channel_7
#define RSSI_ADC_GPIO GPIOC
#define RSSI_ADC_GPIO_PIN GPIO_Pin_2
#define RSSI_ADC_CHANNEL ADC_Channel_8
#define EXTERNAL1_ADC_GPIO GPIOC
#define EXTERNAL1_ADC_GPIO_PIN GPIO_Pin_3
#define EXTERNAL1_ADC_CHANNEL ADC_Channel_9
#define SENSORS_SET (SENSOR_ACC | SENSOR_BARO | SENSOR_MAG) #define SENSORS_SET (SENSOR_ACC | SENSOR_BARO | SENSOR_MAG)
#define GPS #define GPS

View File

@ -61,6 +61,22 @@
#define USE_ADC #define USE_ADC
#define VBAT_ADC_GPIO GPIOC
#define VBAT_ADC_GPIO_PIN GPIO_Pin_0
#define VBAT_ADC_CHANNEL ADC_Channel_6
#define CURRENT_METER_ADC_GPIO GPIOC
#define CURRENT_METER_ADC_GPIO_PIN GPIO_Pin_1
#define CURRENT_METER_ADC_CHANNEL ADC_Channel_7
#define RSSI_ADC_GPIO GPIOC
#define RSSI_ADC_GPIO_PIN GPIO_Pin_2
#define RSSI_ADC_CHANNEL ADC_Channel_8
#define EXTERNAL1_ADC_GPIO GPIOC
#define EXTERNAL1_ADC_GPIO_PIN GPIO_Pin_3
#define EXTERNAL1_ADC_CHANNEL ADC_Channel_9
#define SENSORS_SET (SENSOR_ACC | SENSOR_MAG) #define SENSORS_SET (SENSOR_ACC | SENSOR_MAG)
#define BLACKBOX #define BLACKBOX