mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
169:e3b6fe271b81
Parent:
168:9672193075cf
Child:
171:89b338f31ef1
--- a/targets/TARGET_STM/TARGET_STM32L0/analogin_api.c	Thu Jul 06 15:42:05 2017 +0100
+++ b/targets/TARGET_STM/TARGET_STM32L0/analogin_api.c	Wed Jul 19 17:31:21 2017 +0100
@@ -42,21 +42,31 @@
 
 void analogin_init(analogin_t *obj, PinName pin)
 {
-    // Get the peripheral name from the pin and assign it to the object
-    obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
+    uint32_t function = (uint32_t)NC;
+    obj->adc = (ADCName)NC;
+
+    // ADC Internal Channels "pins"  (Temperature, Vref, Vbat, ...)
+    //   are described in PinNames.h and PeripheralPins.c
+    //   Pin value must be >= 0xF0
+    if (pin < 0xF0) {
+        // 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 pin function and assign the used channel 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;