mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #4153 from jeromecoutant/PR_AF2_LEVEL0
STM32F2: Internal ADC channels reworkpull/3872/merge
commit
1c77628149
|
@ -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
|
||||
|
@ -107,7 +111,7 @@ const PinMap PinMap_I2C_SDA[] = {
|
|||
// {PB_7, I2C_1 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)}, // LED2
|
||||
{PB_9, I2C_1 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
|
||||
{PB_11, I2C_2 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
|
||||
{PC_9, I2C_3 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
|
||||
// {PC_9, I2C_3 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)}, // no I2C_3 SCL available
|
||||
{PF_0, I2C_2 , STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
|
||||
{NC, NC, 0}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue