@@ -40,6 +40,9 @@ ADC_HandleTypeDef AdcHandle;
40
40
41
41
void analogin_init (analogin_t * obj , PinName pin )
42
42
{
43
+ uint32_t function = (uint32_t )NC ;
44
+ obj -> adc = (ADCName )NC ;
45
+
43
46
#if defined(ADC1 )
44
47
static int adc1_inited = 0 ;
45
48
#endif
@@ -49,20 +52,27 @@ void analogin_init(analogin_t *obj, PinName pin)
49
52
#if defined(ADC3 )
50
53
static int adc3_inited = 0 ;
51
54
#endif
52
- // Get the peripheral name from the pin and assign it to the object
53
- obj -> adc = (ADCName )pinmap_peripheral (pin , PinMap_ADC );
55
+ // ADC Internal Channels "pins" (Temperature, Vref, Vbat, ...)
56
+ // are described in PinNames.h and PeripheralPins.c
57
+ // Pin value must be between 0xF0 and 0xFF
58
+ if ((pin < 0xF0 ) || (pin >= 0x100 )) {
59
+ // Normal channels
60
+ // Get the peripheral name from the pin and assign it to the object
61
+ obj -> adc = (ADCName )pinmap_peripheral (pin , PinMap_ADC );
62
+ // Get the functions (adc channel) from the pin and assign it to the object
63
+ function = pinmap_function (pin , PinMap_ADC );
64
+ // Configure GPIO
65
+ pinmap_pinout (pin , PinMap_ADC );
66
+ } else {
67
+ // Internal channels
68
+ obj -> adc = (ADCName )pinmap_peripheral (pin , PinMap_ADC_Internal );
69
+ function = pinmap_function (pin , PinMap_ADC_Internal );
70
+ // No GPIO configuration for internal channels
71
+ }
54
72
MBED_ASSERT (obj -> adc != (ADCName )NC );
55
-
56
- // Get the functions (adc channel) from the pin and assign it to the object
57
- uint32_t function = pinmap_function (pin , PinMap_ADC );
58
73
MBED_ASSERT (function != (uint32_t )NC );
59
- obj -> channel = STM_PIN_CHANNEL (function );
60
74
61
- // Configure GPIO excepted for internal channels (Temperature, Vref, Vbat, ...)
62
- // ADC Internal Channels "pins" are described in PinNames.h and must have a value >= 0xF0
63
- if (pin < 0xF0 ) {
64
- pinmap_pinout (pin , PinMap_ADC );
65
- }
75
+ obj -> channel = STM_PIN_CHANNEL (function );
66
76
67
77
// Save pin number for the read function
68
78
obj -> pin = pin ;
0 commit comments