mirror of https://github.com/ARMmbed/mbed-os.git
STM32F2 Internal ADC channels rework
Internal ADC pin are now out of PinMap_ADC arraypull/4209/head
parent
c23fea7de0
commit
74c2273f42
|
@ -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_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_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
|
{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_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_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
|
{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
|
||||||
|
|
|
@ -40,6 +40,9 @@ ADC_HandleTypeDef AdcHandle;
|
||||||
|
|
||||||
void analogin_init(analogin_t *obj, PinName pin)
|
void analogin_init(analogin_t *obj, PinName pin)
|
||||||
{
|
{
|
||||||
|
uint32_t function = (uint32_t)NC;
|
||||||
|
obj->adc = (ADCName)NC;
|
||||||
|
|
||||||
#if defined(ADC1)
|
#if defined(ADC1)
|
||||||
static int adc1_inited = 0;
|
static int adc1_inited = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,20 +52,27 @@ void analogin_init(analogin_t *obj, PinName pin)
|
||||||
#if defined(ADC3)
|
#if defined(ADC3)
|
||||||
static int adc3_inited = 0;
|
static int adc3_inited = 0;
|
||||||
#endif
|
#endif
|
||||||
|
// 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
|
// Get the peripheral name from the pin and assign it to the object
|
||||||
obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
|
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
|
// Get the functions (adc channel) from the pin and assign it to the object
|
||||||
uint32_t function = pinmap_function(pin, PinMap_ADC);
|
function = pinmap_function(pin, PinMap_ADC);
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
// Configure GPIO
|
||||||
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);
|
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
|
// Save pin number for the read function
|
||||||
obj->pin = pin;
|
obj->pin = pin;
|
||||||
|
|
Loading…
Reference in New Issue