Forked.
Fork of mbed-dev by
Diff: targets/TARGET_STM/TARGET_STM32F2/analogin_api.c
- Revision:
- 163:74e0ce7f98e8
- Parent:
- 160:d5399cc887bb
- Child:
- 171:89b338f31ef1
diff -r e13f6fdb2ac4 -r 74e0ce7f98e8 targets/TARGET_STM/TARGET_STM32F2/analogin_api.c --- a/targets/TARGET_STM/TARGET_STM32F2/analogin_api.c Wed Apr 12 16:21:43 2017 +0100 +++ b/targets/TARGET_STM/TARGET_STM32F2/analogin_api.c Fri Apr 28 14:04:18 2017 +0100 @@ -40,6 +40,9 @@ 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,21 +52,28 @@ #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); + // 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); - - // 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) { - pinmap_pinout(pin, PinMap_ADC); - } - // Save pin number for the read function obj->pin = pin;