mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Files at this revision

API Documentation at this revision

Comitter:
jcassette
Date:
Mon Mar 14 14:20:17 2016 +0000
Parent:
78:fcc37a1ad8f5
Commit message:
FRDM-K64F AnalogIn: add support for ADC channels with no mapped pins

Changed in this revision

api/AnalogIn.h Show annotated file Show diff for this revision Revisions of this file
hal/analogin_api.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c Show annotated file Show diff for this revision Revisions of this file
diff -r fcc37a1ad8f5 -r 9f34958201cc api/AnalogIn.h
--- a/api/AnalogIn.h	Tue Mar 01 07:15:10 2016 +0000
+++ b/api/AnalogIn.h	Mon Mar 14 14:20:17 2016 +0000
@@ -50,10 +50,17 @@
     /** Create an AnalogIn, connected to the specified pin
      *
      * @param pin AnalogIn pin to connect to
-     * @param name (optional) A string to identify the object
      */
     AnalogIn(PinName pin) {
-        analogin_init(&_adc, pin);
+        analogin_init_pin(&_adc, pin);
+    }
+    
+    /** Create an AnalogIn, connected to the specified ADC channel
+     *
+     * @param name ADC channel to connect to
+     */
+    AnalogIn(ADCName name) {
+        analogin_init_name(&_adc, name);
     }
 
     /** Read the input voltage, represented as a float in the range [0.0, 1.0]
diff -r fcc37a1ad8f5 -r 9f34958201cc hal/analogin_api.h
--- a/hal/analogin_api.h	Tue Mar 01 07:15:10 2016 +0000
+++ b/hal/analogin_api.h	Mon Mar 14 14:20:17 2016 +0000
@@ -26,7 +26,8 @@
 
 typedef struct analogin_s analogin_t;
 
-void     analogin_init    (analogin_t *obj, PinName pin);
+void     analogin_init_pin(analogin_t *obj, PinName pin);
+void     analogin_init_name(analogin_t *obj, ADCName name);
 float    analogin_read    (analogin_t *obj);
 uint16_t analogin_read_u16(analogin_t *obj);
 
diff -r fcc37a1ad8f5 -r 9f34958201cc targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c
--- a/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c	Tue Mar 01 07:15:10 2016 +0000
+++ b/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/analogin_api.c	Mon Mar 14 14:20:17 2016 +0000
@@ -28,8 +28,7 @@
 
 #define MAX_FADC 6000000
 
-void analogin_init(analogin_t *obj, PinName pin) {
-    obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
+static void analogin_init(analogin_t *obj) {
     MBED_ASSERT(obj->adc != (ADCName)NC);
 
     uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT;
@@ -59,15 +58,24 @@
     ADC_HAL_SetHwAverageMode(adc_addrs[instance], kAdcHwAverageCountOf4);
     ADC_HAL_SetChnMuxMode(adc_addrs[instance],
         obj->adc & (1 << ADC_B_CHANNEL_SHIFT) ? kAdcChnMuxOfB : kAdcChnMuxOfA);
+}
 
+void analogin_init_pin(analogin_t *obj, PinName pin) {
+    obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
+    analogin_init(obj);
     pinmap_pinout(pin, PinMap_ADC);
 }
 
+void analogin_init_name(analogin_t *obj, ADCName name) {
+    obj->adc = name;
+    analogin_init(obj);
+}
+
 uint16_t analogin_read_u16(analogin_t *obj) {
     uint32_t instance = obj->adc >> ADC_INSTANCE_SHIFT;
     uint32_t adc_addrs[] = ADC_BASE_ADDRS;
     /* sw trigger (SC1A) */
-    ADC_HAL_ConfigChn(adc_addrs[instance], 0, false, false, obj->adc & 0xF);
+    ADC_HAL_ConfigChn(adc_addrs[instance], 0, false, false, obj->adc & 0x1F);
     while (!ADC_HAL_GetChnConvCompletedCmd(adc_addrs[instance], 0));
     return ADC_HAL_GetChnConvValueRAW(adc_addrs[instance], 0);
 }