From 3a537d8ef98c348f29170836ff61ddb4302d2692 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 30 May 2014 15:15:29 +0100 Subject: [PATCH] Align F1 and F3 ADC code. --- src/drivers/adc_common.c | 3 +++ src/drivers/adc_stm32f10x.c | 20 +++++++++++++++----- src/drivers/adc_stm32f30x.c | 16 +++++++++++----- src/platform.h | 13 ++++++++----- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/drivers/adc_common.c b/src/drivers/adc_common.c index 0d380b011..5467170c8 100755 --- a/src/drivers/adc_common.c +++ b/src/drivers/adc_common.c @@ -25,6 +25,9 @@ uint16_t adcGetChannel(uint8_t channel) if (adcConfig[2].enabled) { debug[2] = adcValues[adcConfig[2].dmaIndex]; } + if (adcConfig[3].enabled) { + debug[3] = adcValues[adcConfig[3].dmaIndex]; + } #endif return adcValues[adcConfig[channel].dmaIndex]; } diff --git a/src/drivers/adc_stm32f10x.c b/src/drivers/adc_stm32f10x.c index 2be4a5496..bca0f54ab 100644 --- a/src/drivers/adc_stm32f10x.c +++ b/src/drivers/adc_stm32f10x.c @@ -31,6 +31,12 @@ void adcInit(drv_adc_config_t *init) uint8_t configuredAdcChannels = 0; memset(&adcConfig, 0, sizeof(adcConfig)); + // configure always-present battery index (ADC4) + adcConfig[ADC_BATTERY].adcChannel = ADC_Channel_4; + adcConfig[ADC_BATTERY].dmaIndex = configuredAdcChannels++; + adcConfig[ADC_BATTERY].enabled = true; + adcConfig[ADC_BATTERY].sampleTime = ADC_SampleTime_239Cycles5; + if (init->enableRSSI) { adcConfig[ADC_RSSI].adcChannel = ADC_Channel_1; adcConfig[ADC_RSSI].dmaIndex = configuredAdcChannels++; @@ -38,12 +44,14 @@ void adcInit(drv_adc_config_t *init) adcConfig[ADC_RSSI].sampleTime = ADC_SampleTime_239Cycles5; } - // configure always-present battery index (ADC4) - adcConfig[ADC_BATTERY].adcChannel = ADC_Channel_4; - adcConfig[ADC_BATTERY].dmaIndex = configuredAdcChannels++; - adcConfig[ADC_BATTERY].enabled = true; - adcConfig[ADC_BATTERY].sampleTime = ADC_SampleTime_239Cycles5; +#ifdef OLIMEXINO + adcConfig[ADC_EXTERNAL1].adcChannel = ADC_Channel_5; + adcConfig[ADC_EXTERNAL1].dmaIndex = configuredAdcChannels++; + adcConfig[ADC_EXTERNAL1].enabled = true; + adcConfig[ADC_EXTERNAL1].sampleTime = ADC_SampleTime_239Cycles5; +#endif +#ifdef NAZE // optional ADC5 input on rev.5 hardware if (hse_value == 12000000) { adcConfig[ADC_EXTERNAL1].adcChannel = ADC_Channel_5; @@ -51,6 +59,7 @@ void adcInit(drv_adc_config_t *init) adcConfig[ADC_EXTERNAL1].enabled = true; adcConfig[ADC_EXTERNAL1].sampleTime = ADC_SampleTime_239Cycles5; } +#endif if (init->enableCurrentMeter) { adcConfig[ADC_CURRENT].adcChannel = ADC_Channel_9; @@ -59,6 +68,7 @@ void adcInit(drv_adc_config_t *init) adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_239Cycles5; } + // ADC driver assumes all the GPIO was already placed in 'AIN' mode DMA_DeInit(DMA1_Channel1); dma.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR; diff --git a/src/drivers/adc_stm32f30x.c b/src/drivers/adc_stm32f30x.c index 322a943b5..e9e647320 100644 --- a/src/drivers/adc_stm32f30x.c +++ b/src/drivers/adc_stm32f30x.c @@ -31,11 +31,11 @@ void adcInit(drv_adc_config_t *init) adcChannelCount++; if (init->enableCurrentMeter) { - adcConfig[ADC_CURRENT].adcChannel = ADC_Channel_7; - adcConfig[ADC_CURRENT].dmaIndex = adcChannelCount; - adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_601Cycles5; - adcConfig[ADC_CURRENT].enabled = true; - adcChannelCount++; + adcConfig[ADC_CURRENT].adcChannel = ADC_Channel_7; + adcConfig[ADC_CURRENT].dmaIndex = adcChannelCount; + adcConfig[ADC_CURRENT].sampleTime = ADC_SampleTime_601Cycles5; + adcConfig[ADC_CURRENT].enabled = true; + adcChannelCount++; } if (init->enableRSSI) { @@ -46,6 +46,12 @@ void adcInit(drv_adc_config_t *init) adcChannelCount++; } + adcConfig[ADC_EXTERNAL1].adcChannel = ADC_Channel_9; + adcConfig[ADC_EXTERNAL1].dmaIndex = adcChannelCount; + adcConfig[ADC_EXTERNAL1].sampleTime = ADC_SampleTime_601Cycles5; + adcConfig[ADC_EXTERNAL1].enabled = true; + adcChannelCount++; + DMA_DeInit(DMA1_Channel1); DMA_StructInit(&DMA_InitStructure); diff --git a/src/platform.h b/src/platform.h index 98d4482a7..d17a12b74 100644 --- a/src/platform.h +++ b/src/platform.h @@ -65,16 +65,19 @@ #ifdef OLIMEXINO // OLIMEXINO -#ifdef OLIMEXINO_UNCUT_LED2_E_JUMPER -// LED2 is using one of the pwm pins (PWM2), so we must not use PWM2. @See pwmInit() +//#define OLIMEXINO_UNCUT_LED1_E_JUMPER +//#define OLIMEXINO_UNCUT_LED2_E_JUMPER + +#ifdef OLIMEXINO_UNCUT_LED1_E_JUMPER #define LED0_GPIO GPIOA -#define LED0_PIN Pin_1 // D3, PA1/USART2_RTS/ADC1/TIM2_CH3 - "LED2" on silkscreen, Yellow +#define LED0_PIN Pin_5 // D13, PA5/SPI1_SCK/ADC5 - "LED1" on silkscreen, Green #define LED0 #endif -#ifdef OLIMEXINO_UNCUT_LED1_E_JUMPER +#ifdef OLIMEXINO_UNCUT_LED2_E_JUMPER +// "LED2" is using one of the PWM pins (CH2/PWM2), so we must not use PWM2 unless the jumper is cut. @See pwmInit() #define LED1_GPIO GPIOA -#define LED1_PIN Pin_5 // D13, PA5/SPI1_SCK/ADC5 - "LED1" on silkscreen, Green +#define LED1_PIN Pin_1 // D3, PA1/USART2_RTS/ADC1/TIM2_CH3 - "LED2" on silkscreen, Yellow #define LED1 #endif