STM32F2 Internal ADC channels rework

Internal ADC pin are now out of PinMap_ADC array
pull/4153/head
jeromecoutant 2017-04-11 11:16:46 +02:00
parent 7da6960cfe
commit 43ab8812d7
2 changed files with 26 additions and 12 deletions

View File

@ -87,6 +87,10 @@ const PinMap PinMap_ADC[] = {
{PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6
{PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7
{PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8
{NC, NC, 0}
};
const PinMap PinMap_ADC_Internal[] = {
{ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // See in analogin_api.c the correct ADC channel used
{ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, // See in analogin_api.c the correct ADC channel used
{ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // See in analogin_api.c the correct ADC channel used

View File

@ -40,6 +40,9 @@ ADC_HandleTypeDef AdcHandle;
void analogin_init(analogin_t *obj, PinName pin)
{
uint32_t function = (uint32_t)NC;
obj->adc = (ADCName)NC;
#if defined(ADC1)
static int adc1_inited = 0;
#endif
@ -49,20 +52,27 @@ void analogin_init(analogin_t *obj, PinName pin)
#if defined(ADC3)
static int adc3_inited = 0;
#endif
// Get the peripheral name from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
MBED_ASSERT(obj->adc != (ADCName)NC);
// Get the functions (adc channel) from the pin and assign it to the object
uint32_t function = pinmap_function(pin, PinMap_ADC);
MBED_ASSERT(function != (uint32_t)NC);
obj->channel = STM_PIN_CHANNEL(function);
// Configure GPIO excepted for internal channels (Temperature, Vref, Vbat, ...)
// ADC Internal Channels "pins" are described in PinNames.h and must have a value >= 0xF0
if (pin < 0xF0) {
// ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
// are described in PinNames.h and PeripheralPins.c
// Pin value must be between 0xF0 and 0xFF
if ((pin < 0xF0) || (pin >= 0x100)) {
// Normal channels
// Get the peripheral name from the pin and assign it to the object
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
// Get the functions (adc channel) from the pin and assign it to the object
function = pinmap_function(pin, PinMap_ADC);
// Configure GPIO
pinmap_pinout(pin, PinMap_ADC);
} else {
// Internal channels
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC_Internal);
function = pinmap_function(pin, PinMap_ADC_Internal);
// No GPIO configuration for internal channels
}
MBED_ASSERT(obj->adc != (ADCName)NC);
MBED_ASSERT(function != (uint32_t)NC);
obj->channel = STM_PIN_CHANNEL(function);
// Save pin number for the read function
obj->pin = pin;