Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Hobbyking_Cheetah_Compact Hobbyking_Cheetah_Compact_DRV8323_14bit Hobbyking_Cheetah_Compact_DRV8323_V51_201907 HKC_MiniCheetah ... more
Fork of mbed-dev by
Diff: targets/TARGET_STM/TARGET_STM32F0/analogin_api.c
- Revision:
- 172:7d866c31b3c5
- Parent:
- 171:89b338f31ef1
diff -r 89b338f31ef1 -r 7d866c31b3c5 targets/TARGET_STM/TARGET_STM32F0/analogin_api.c
--- a/targets/TARGET_STM/TARGET_STM32F0/analogin_api.c Wed Aug 16 18:27:13 2017 +0100
+++ b/targets/TARGET_STM/TARGET_STM32F0/analogin_api.c Thu Aug 31 17:27:04 2017 +0100
@@ -39,21 +39,30 @@
int adc_inited = 0;
void analogin_init(analogin_t *obj, PinName pin) {
- // Get the peripheral name from the pin and assign it to the object
- obj->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC);
+ uint32_t function = (uint32_t)NC;
+
+ // 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->handle.Instance = (ADC_TypeDef *) 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->handle.Instance = (ADC_TypeDef *) pinmap_peripheral(pin, PinMap_ADC_Internal);
+ function = pinmap_function(pin, PinMap_ADC_Internal);
+ // No GPIO configuration for internal channels
+ }
MBED_ASSERT(obj->handle.Instance != (ADC_TypeDef *)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;
