mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 21:35:44 +03:00
Merge pull request #3898 from jflyper/bfdev-configurable-adc
Configurable ADC
This commit is contained in:
commit
037313f995
13 changed files with 231 additions and 154 deletions
|
@ -33,10 +33,6 @@
|
|||
|
||||
#include "common/utils.h"
|
||||
|
||||
#ifndef ADC_INSTANCE
|
||||
#define ADC_INSTANCE ADC1
|
||||
#endif
|
||||
|
||||
const adcDevice_t adcHardware[] = {
|
||||
{ .ADCx = ADC1, .rccADC = RCC_AHB(ADC12), .DMAy_Channelx = DMA1_Channel1 },
|
||||
#ifdef ADC24_DMA_REMAP
|
||||
|
@ -48,61 +44,47 @@ const adcDevice_t adcHardware[] = {
|
|||
};
|
||||
|
||||
const adcTagMap_t adcTagMap[] = {
|
||||
{ DEFIO_TAG_E__PA0, ADC_Channel_1 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA1, ADC_Channel_2 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA2, ADC_Channel_3 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA3, ADC_Channel_4 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA4, ADC_Channel_1 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA5, ADC_Channel_2 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA6, ADC_Channel_3 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA7, ADC_Channel_4 }, // ADC2
|
||||
{ DEFIO_TAG_E__PB0, ADC_Channel_12 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB1, ADC_Channel_1 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB2, ADC_Channel_12 }, // ADC2
|
||||
{ DEFIO_TAG_E__PB12, ADC_Channel_3 }, // ADC4
|
||||
{ DEFIO_TAG_E__PB13, ADC_Channel_5 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB14, ADC_Channel_4 }, // ADC4
|
||||
{ DEFIO_TAG_E__PB15, ADC_Channel_5 }, // ADC4
|
||||
{ DEFIO_TAG_E__PC0, ADC_Channel_6 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC1, ADC_Channel_7 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC2, ADC_Channel_8 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC3, ADC_Channel_9 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC4, ADC_Channel_5 }, // ADC2
|
||||
{ DEFIO_TAG_E__PC5, ADC_Channel_11 }, // ADC2
|
||||
{ DEFIO_TAG_E__PD8, ADC_Channel_12 }, // ADC4
|
||||
{ DEFIO_TAG_E__PD9, ADC_Channel_13 }, // ADC4
|
||||
{ DEFIO_TAG_E__PD10, ADC_Channel_7 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD11, ADC_Channel_8 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD12, ADC_Channel_9 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD13, ADC_Channel_10 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD14, ADC_Channel_11 }, // ADC34
|
||||
{ DEFIO_TAG_E__PE7, ADC_Channel_13 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE8, ADC_Channel_6 }, // ADC34
|
||||
{ DEFIO_TAG_E__PE9, ADC_Channel_2 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE10, ADC_Channel_14 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE11, ADC_Channel_15 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE12, ADC_Channel_16 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE13, ADC_Channel_3 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE14, ADC_Channel_1 }, // ADC4
|
||||
{ DEFIO_TAG_E__PE15, ADC_Channel_2 }, // ADC4
|
||||
{ DEFIO_TAG_E__PF2, ADC_Channel_10 }, // ADC12
|
||||
{ DEFIO_TAG_E__PF4, ADC_Channel_5 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA0, ADC_DEVICES_1, ADC_Channel_1 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA1, ADC_DEVICES_1, ADC_Channel_2 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA2, ADC_DEVICES_1, ADC_Channel_3 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA3, ADC_DEVICES_1, ADC_Channel_4 }, // ADC1
|
||||
{ DEFIO_TAG_E__PA4, ADC_DEVICES_2, ADC_Channel_1 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA5, ADC_DEVICES_2, ADC_Channel_2 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA6, ADC_DEVICES_2, ADC_Channel_3 }, // ADC2
|
||||
{ DEFIO_TAG_E__PA7, ADC_DEVICES_4, ADC_Channel_4 }, // ADC2
|
||||
{ DEFIO_TAG_E__PB0, ADC_DEVICES_3, ADC_Channel_12 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB1, ADC_DEVICES_3, ADC_Channel_1 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB2, ADC_DEVICES_2, ADC_Channel_12 }, // ADC2
|
||||
{ DEFIO_TAG_E__PB12, ADC_DEVICES_4, ADC_Channel_3 }, // ADC4
|
||||
{ DEFIO_TAG_E__PB13, ADC_DEVICES_3, ADC_Channel_5 }, // ADC3
|
||||
{ DEFIO_TAG_E__PB14, ADC_DEVICES_4, ADC_Channel_4 }, // ADC4
|
||||
{ DEFIO_TAG_E__PB15, ADC_DEVICES_4, ADC_Channel_5 }, // ADC4
|
||||
{ DEFIO_TAG_E__PC0, ADC_DEVICES_12, ADC_Channel_6 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC1, ADC_DEVICES_12, ADC_Channel_7 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC2, ADC_DEVICES_12, ADC_Channel_8 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC3, ADC_DEVICES_12, ADC_Channel_9 }, // ADC12
|
||||
{ DEFIO_TAG_E__PC4, ADC_DEVICES_2, ADC_Channel_5 }, // ADC2
|
||||
{ DEFIO_TAG_E__PC5, ADC_DEVICES_2, ADC_Channel_11 }, // ADC2
|
||||
{ DEFIO_TAG_E__PD8, ADC_DEVICES_4, ADC_Channel_12 }, // ADC4
|
||||
{ DEFIO_TAG_E__PD9, ADC_DEVICES_4, ADC_Channel_13 }, // ADC4
|
||||
{ DEFIO_TAG_E__PD10, ADC_DEVICES_34, ADC_Channel_7 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD11, ADC_DEVICES_34, ADC_Channel_8 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD12, ADC_DEVICES_34, ADC_Channel_9 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD13, ADC_DEVICES_34, ADC_Channel_10 }, // ADC34
|
||||
{ DEFIO_TAG_E__PD14, ADC_DEVICES_34, ADC_Channel_11 }, // ADC34
|
||||
{ DEFIO_TAG_E__PE7, ADC_DEVICES_3, ADC_Channel_13 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE8, ADC_DEVICES_34, ADC_Channel_6 }, // ADC34
|
||||
{ DEFIO_TAG_E__PE9, ADC_DEVICES_3, ADC_Channel_2 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE10, ADC_DEVICES_3, ADC_Channel_14 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE11, ADC_DEVICES_3, ADC_Channel_15 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE12, ADC_DEVICES_3, ADC_Channel_16 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE13, ADC_DEVICES_3, ADC_Channel_3 }, // ADC3
|
||||
{ DEFIO_TAG_E__PE14, ADC_DEVICES_4, ADC_Channel_1 }, // ADC4
|
||||
{ DEFIO_TAG_E__PE15, ADC_DEVICES_4, ADC_Channel_2 }, // ADC4
|
||||
{ DEFIO_TAG_E__PF2, ADC_DEVICES_12, ADC_Channel_10 }, // ADC12
|
||||
{ DEFIO_TAG_E__PF4, ADC_DEVICES_1, ADC_Channel_5 }, // ADC1
|
||||
};
|
||||
|
||||
ADCDevice adcDeviceByInstance(ADC_TypeDef *instance)
|
||||
{
|
||||
if (instance == ADC1)
|
||||
return ADCDEV_1;
|
||||
|
||||
if (instance == ADC2)
|
||||
return ADCDEV_2;
|
||||
|
||||
if (instance == ADC3)
|
||||
return ADCDEV_3;
|
||||
|
||||
return ADCINVALID;
|
||||
}
|
||||
|
||||
void adcInit(const adcConfig_t *config)
|
||||
{
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
|
@ -139,8 +121,9 @@ void adcInit(const adcConfig_t *config)
|
|||
|
||||
bool adcActive = false;
|
||||
for (int i = 0; i < ADC_CHANNEL_COUNT; i++) {
|
||||
if (!adcOperatingConfig[i].tag)
|
||||
if (!adcVerifyPin(adcOperatingConfig[i].tag, device)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
adcActive = true;
|
||||
IOInit(IOGetByTag(adcOperatingConfig[i].tag), OWNER_ADC_BATT + i, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue