mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
Merge remote-tracking branch 'origin/amorale/OP-1828_optional_analog_inputs' into next
This commit is contained in:
commit
061ef1e377
@ -38,6 +38,7 @@ typedef void (*ADCCallback)(float *data);
|
||||
|
||||
/* Public Functions */
|
||||
void PIOS_ADC_Config(uint32_t oversampling);
|
||||
void PIOS_ADC_PinSetup(uint32_t pin);
|
||||
int32_t PIOS_ADC_PinGet(uint32_t pin);
|
||||
float PIOS_ADC_PinGetVolt(uint32_t pin);
|
||||
int16_t *PIOS_ADC_GetRawBuffer(void);
|
||||
|
@ -99,10 +99,11 @@ static void init_dma(void);
|
||||
static void init_adc(void);
|
||||
#endif
|
||||
|
||||
struct dma_config {
|
||||
struct pios_adc_pin_config {
|
||||
GPIO_TypeDef *port;
|
||||
uint32_t pin;
|
||||
uint32_t channel;
|
||||
bool initialize;
|
||||
};
|
||||
|
||||
struct adc_accumulator {
|
||||
@ -111,7 +112,7 @@ struct adc_accumulator {
|
||||
};
|
||||
|
||||
#if defined(PIOS_INCLUDE_ADC)
|
||||
static const struct dma_config config[] = PIOS_DMA_PIN_CONFIG;
|
||||
static const struct pios_adc_pin_config config[] = PIOS_DMA_PIN_CONFIG;
|
||||
#define PIOS_ADC_NUM_PINS (sizeof(config) / sizeof(config[0]))
|
||||
|
||||
static struct adc_accumulator accumulator[PIOS_ADC_NUM_PINS];
|
||||
@ -123,18 +124,11 @@ static uint16_t adc_raw_buffer[2][PIOS_ADC_MAX_SAMPLES][PIOS_ADC_NUM_PINS];
|
||||
#if defined(PIOS_INCLUDE_ADC)
|
||||
static void init_pins(void)
|
||||
{
|
||||
/* Setup analog pins */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
for (uint32_t i = 0; i < PIOS_ADC_NUM_PINS; ++i) {
|
||||
if (config[i].port == NULL) {
|
||||
if (!config[i].initialize) {
|
||||
continue;
|
||||
}
|
||||
GPIO_InitStructure.GPIO_Pin = config[i].pin;
|
||||
GPIO_Init(config[i].port, &GPIO_InitStructure);
|
||||
PIOS_ADC_PinSetup(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,6 +448,19 @@ void PIOS_ADC_DMA_Handler(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void PIOS_ADC_PinSetup(uint32_t pin)
|
||||
{
|
||||
if (config[pin].port != NULL && pin < PIOS_ADC_NUM_PINS) {
|
||||
/* Setup analog pin */
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
GPIO_StructInit(&GPIO_InitStructure);
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
|
||||
GPIO_InitStructure.GPIO_Pin = config[pin].pin;
|
||||
GPIO_Init(config[pin].port, &GPIO_InitStructure);
|
||||
}
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_ADC */
|
||||
|
||||
/**
|
||||
|
@ -908,6 +908,17 @@ void PIOS_Board_Init(void)
|
||||
#include <pios_ws2811.h>
|
||||
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg);
|
||||
#endif // PIOS_INCLUDE_WS2811
|
||||
#ifdef PIOS_INCLUDE_ADC
|
||||
{
|
||||
uint8_t adc_config[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||
HwSettingsADCRoutingArrayGet(adc_config);
|
||||
for (uint32_t i = 0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||
if (adc_config[i] != HWSETTINGS_ADCROUTING_DISABLED) {
|
||||
PIOS_ADC_PinSetup(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PIOS_INCLUDE_ADC
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -264,10 +264,10 @@ extern uint32_t pios_packet_handler;
|
||||
// -------------------------
|
||||
#define PIOS_DMA_PIN_CONFIG \
|
||||
{ \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11 }, \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12 }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11, false }, \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12, false }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint, false }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor, false }, /* Temperature sensor */ \
|
||||
}
|
||||
|
||||
/* we have to do all this to satisfy the PIOS_ADC_MAX_SAMPLES define in pios_adc.h */
|
||||
|
@ -449,6 +449,17 @@ void PIOS_Board_Init(void)
|
||||
// PIOS_TIM_InitClock(&pios_tim4_cfg);
|
||||
PIOS_Video_Init(&pios_video_cfg);
|
||||
#endif
|
||||
#ifdef PIOS_INCLUDE_ADC
|
||||
{
|
||||
uint8_t adc_config[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||
HwSettingsADCRoutingArrayGet(adc_config);
|
||||
for (uint32_t i = 0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||
if (adc_config[i] != HWSETTINGS_ADCROUTING_DISABLED) {
|
||||
PIOS_ADC_PinSetup(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PIOS_INCLUDE_ADC
|
||||
}
|
||||
|
||||
uint16_t supv_timer = 0;
|
||||
|
@ -208,13 +208,13 @@ extern uint32_t pios_com_telem_usb_id;
|
||||
|
||||
#define PIOS_DMA_PIN_CONFIG \
|
||||
{ \
|
||||
{ GPIOC, GPIO_Pin_0, ADC_Channel_10 }, \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11 }, \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12 }, \
|
||||
{ NULL, 0, ADC_Channel_TempSensor }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_3, ADC_Channel_13 }, \
|
||||
{ GPIOA, GPIO_Pin_7, ADC_Channel_7 }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint } /* Voltage reference */ \
|
||||
{ GPIOC, GPIO_Pin_0, ADC_Channel_10, true }, \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11, true }, \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12, true }, \
|
||||
{ NULL, 0, ADC_Channel_TempSensor, true }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_3, ADC_Channel_13, true }, \
|
||||
{ GPIOA, GPIO_Pin_7, ADC_Channel_7, true }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint, true } /* Voltage reference */ \
|
||||
}
|
||||
|
||||
/* we have to do all this to satisfy the PIOS_ADC_MAX_SAMPLES define in pios_adc.h */
|
||||
|
@ -943,8 +943,18 @@ void PIOS_Board_Init(void)
|
||||
if (ws2811_pin_settings != HWSETTINGS_WS2811LED_OUT_DISABLED && ws2811_pin_settings < NELEMENTS(pios_ws2811_pin_cfg)) {
|
||||
PIOS_WS2811_Init(&pios_ws2811_cfg, &pios_ws2811_pin_cfg[ws2811_pin_settings]);
|
||||
}
|
||||
|
||||
#endif // PIOS_INCLUDE_WS2811
|
||||
#ifdef PIOS_INCLUDE_ADC
|
||||
{
|
||||
uint8_t adc_config[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||
HwSettingsADCRoutingArrayGet(adc_config);
|
||||
for (uint32_t i = 0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||
if (adc_config[i] != HWSETTINGS_ADCROUTING_DISABLED) {
|
||||
PIOS_ADC_PinSetup(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PIOS_INCLUDE_ADC
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -283,21 +283,25 @@ extern uint32_t pios_packet_handler;
|
||||
// -------------------------
|
||||
#define PIOS_DMA_PIN_CONFIG \
|
||||
{ \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11 }, \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12 }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11, false }, /* batt/sonar pin 3 */ \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12, false }, /* batt/sonar pin 4 */ \
|
||||
{ GPIOA, GPIO_Pin_3, ADC_Channel_3, false }, /* Servo pin 3 */ \
|
||||
{ GPIOA, GPIO_Pin_2, ADC_Channel_2, false }, /* Servo pin 4 */ \
|
||||
{ GPIOA, GPIO_Pin_1, ADC_Channel_1, false }, /* Servo pin 5 */ \
|
||||
{ GPIOA, GPIO_Pin_0, ADC_Channel_9, false }, /* Servo pin 6 */ \
|
||||
{ NULL, 0, ADC_Channel_Vrefint, false }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor, false }, /* Temperature sensor */ \
|
||||
}
|
||||
|
||||
/* we have to do all this to satisfy the PIOS_ADC_MAX_SAMPLES define in pios_adc.h */
|
||||
/* which is annoying because this then determines the rate at which we generate buffer turnover events */
|
||||
/* the objective here is to get enough buffer space to support 100Hz averaging rate */
|
||||
#define PIOS_ADC_NUM_CHANNELS 4
|
||||
#define PIOS_ADC_NUM_CHANNELS 8
|
||||
#define PIOS_ADC_MAX_OVERSAMPLING 2
|
||||
#define PIOS_ADC_USE_ADC2 0
|
||||
|
||||
#define PIOS_ADC_USE_TEMP_SENSOR
|
||||
#define PIOS_ADC_TEMPERATURE_PIN 3
|
||||
#define PIOS_ADC_TEMPERATURE_PIN 7
|
||||
|
||||
// -------------------------
|
||||
// USB
|
||||
|
@ -925,6 +925,17 @@ void PIOS_Board_Init(void)
|
||||
default:
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#ifdef PIOS_INCLUDE_ADC
|
||||
{
|
||||
uint8_t adc_config[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||
HwSettingsADCRoutingArrayGet(adc_config);
|
||||
for (uint32_t i = 0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||
if (adc_config[i] != HWSETTINGS_ADCROUTING_DISABLED) {
|
||||
PIOS_ADC_PinSetup(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // PIOS_INCLUDE_ADC
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,11 +242,11 @@ extern uint32_t pios_com_hkosd_id;
|
||||
// -------------------------
|
||||
#define PIOS_DMA_PIN_CONFIG \
|
||||
{ \
|
||||
{ GPIOC, GPIO_Pin_0, ADC_Channel_10 }, \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11 }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12 } \
|
||||
{ GPIOC, GPIO_Pin_0, ADC_Channel_10, true }, \
|
||||
{ GPIOC, GPIO_Pin_1, ADC_Channel_11, true }, \
|
||||
{ NULL, 0, ADC_Channel_Vrefint, true }, /* Voltage reference */ \
|
||||
{ NULL, 0, ADC_Channel_TempSensor, true }, /* Temperature sensor */ \
|
||||
{ GPIOC, GPIO_Pin_2, ADC_Channel_12, true } \
|
||||
}
|
||||
|
||||
/* we have to do all this to satisfy the PIOS_ADC_MAX_SAMPLES define in pios_adc.h */
|
||||
|
@ -23,7 +23,7 @@
|
||||
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,DebugConsole,Disabled" defaultvalue="Disabled"/>
|
||||
|
||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,GPS,Fault,Altitude,Airspeed,TxPID,Battery,Overo,MagBaro,OsdHk" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||
<field name="ADCRouting" units="" type="enum" elementnames="adc0,adc1,adc2,adc3" options="Disabled,BatteryVoltage,BatteryCurrent,AnalogAirspeed,Generic" defaultvalue="Disabled"/>
|
||||
<field name="ADCRouting" units="" type="enum" elementnames="adc0,adc1,adc2,adc3,adc4,adc5,adc6,adc7" options="Disabled,BatteryVoltage,BatteryCurrent,AnalogAirspeed,Generic" defaultvalue="Disabled"/>
|
||||
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||
<field name="WS2811LED_Out" units="" type="enum" elements="1" options="ServoOut1,ServoOut2,ServoOut3,ServoOut4,ServoOut5,ServoOut6,FlexiIOPin3,FlexiIOPin4,Disabled" defaultvalue="Disabled" />
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user