HAL_ChibiOS: enable analog input on IOMCU

This commit is contained in:
Andrew Tridgell 2018-10-29 10:24:01 +11:00
parent b45b8ff703
commit af4340d1d1
7 changed files with 39 additions and 10 deletions

View File

@ -19,7 +19,7 @@
#include "hal.h"
#include <AP_Common/Semaphore.h>
#if HAL_USE_ADC == TRUE
#if HAL_USE_ADC == TRUE && !defined(HAL_DISABLE_ADC_DRIVER)
#include "AnalogIn.h"

View File

@ -24,7 +24,7 @@
// number of samples on each channel to gather on each DMA callback
#define ADC_DMA_BUF_DEPTH 8
#if HAL_USE_ADC == TRUE
#if HAL_USE_ADC == TRUE && !defined(HAL_DISABLE_ADC_DRIVER)
class ChibiOS::AnalogSource : public AP_HAL::AnalogSource {
public:

View File

@ -59,7 +59,7 @@ static ChibiOS::SPIDeviceManager spiDeviceManager;
static Empty::SPIDeviceManager spiDeviceManager;
#endif
#if HAL_USE_ADC == TRUE
#if HAL_USE_ADC == TRUE && !defined(HAL_DISABLE_ADC_DRIVER)
static ChibiOS::AnalogIn analogIn;
#else
static Empty::AnalogIn analogIn;

View File

@ -268,7 +268,7 @@ void Scheduler::_run_timers()
_failsafe();
}
#if HAL_USE_ADC == TRUE
#if HAL_USE_ADC == TRUE && !defined(HAL_DISABLE_ADC_DRIVER)
// process analog input
((AnalogIn *)hal.analogin)->_timer_tick();
#endif

View File

@ -53,6 +53,15 @@ PB13 SAFETY_LED OUTPUT HIGH
PA8 INPUT PULLUP # RC Input PPM
# analog inputs
PA4 VSERVO ADC1
PA5 VRSSI ADC1
define HAL_ADC_VSERVO_CHAN ADC_CHANNEL_IN4
define HAL_ADC_VRSSI_CHAN ADC_CHANNEL_IN5
define HAL_USE_ADC TRUE
define STM32_ADC_USE_ADC1 TRUE
define HAL_DISABLE_ADC_DRIVER TRUE
#Manually define ICU settings
define HAL_USE_ICU TRUE
define STM32_ICU_USE_TIM1 TRUE
@ -88,7 +97,6 @@ define HAL_NO_RCIN_THREAD
#defined to turn off undef warnings
define __FPU_PRESENT 0
define HAL_USE_ADC FALSE
define HAL_USE_RTC FALSE
define HAL_NO_FLASH_SUPPORT TRUE
define HAL_NO_UARTDRIVER TRUE

View File

@ -31,4 +31,25 @@ mcu = {
# size of main memory
'RAM_SIZE_KB' : 8,
}
}
ADC1_map = {
# format is PIN : ADC1_CHAN
"PA0" : 0,
"PA1" : 1,
"PA2" : 2,
"PA3" : 3,
"PA4" : 4,
"PA5" : 5,
"PA6" : 6,
"PA7" : 7,
"PB0" : 8,
"PB1" : 9,
"PC0" : 10,
"PC1" : 11,
"PC2" : 12,
"PC3" : 13,
"PC4" : 14,
"PC5" : 15,
}

View File

@ -52,9 +52,9 @@ static uint16_t adc_sample_channel(uint32_t channel)
/* capture one sample */
ADC1->SQR3 = channel;
ADC1->CR2 |= ADC_CR2_ADON;
ADC1->CR2 |= ADC_CR2_ADON;
/* wait for the conversion to complete */
/* wait for the conversion to complete */
uint32_t counter = 16;
while (!(ADC1->SR & ADC_SR_EOC)) {
@ -62,8 +62,8 @@ static uint16_t adc_sample_channel(uint32_t channel)
// ensure EOC is clear
ADC1->SR = 0;
return 0xffff;
}
}
}
}
// return sample (this also clears EOC flag)
return ADC1->DR;