WILLY BAYOT / anaDMA

Dependents:   TDEMNucleo

Files at this revision

API Documentation at this revision

Comitter:
willybayot
Date:
Sat Jan 03 15:41:29 2015 +0000
Parent:
2:08779d8f1873
Commit message:
revision 2;

Changed in this revision

AnaloginDMA.h Show annotated file Show diff for this revision Revisions of this file
analoginDMA_api.c Show annotated file Show diff for this revision Revisions of this file
analoginDMA_api.h Show annotated file Show diff for this revision Revisions of this file
--- a/AnaloginDMA.h	Sat Jan 03 14:28:35 2015 +0000
+++ b/AnaloginDMA.h	Sat Jan 03 15:41:29 2015 +0000
@@ -58,13 +58,12 @@
     }
 
  
-    /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
+    /** Read the 'Length' input voltage(s), represented as an array of  unsigned short pData
      *
-     * @returns
-     *   16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
+     * @returns status: 0 = OK, 1 = ERROR, 2=BUSY, 3 = TIMEOUT
      */
-    void read(uint16_t* pData, uint32_t Length) {
-        analoginDMA_read_u16(&_adc, pData, Length);
+    HAL_StatusTypeDef read(uint16_t* pData, uint32_t Length) {
+         return analoginDMA_read_u16(&_adc, pData, Length);
     }
 
 
--- a/analoginDMA_api.c	Sat Jan 03 14:28:35 2015 +0000
+++ b/analoginDMA_api.c	Sat Jan 03 15:41:29 2015 +0000
@@ -79,10 +79,9 @@
     }
 }
 
-static inline uint16_t adc_read(analogin_t *obj,uint16_t* pData, uint32_t Length)
+static inline HAL_StatusTypeDef adc_read(analogin_t *obj,uint16_t* pData, uint32_t Length)
 {
     ADC_ChannelConfTypeDef sConfig;
-
     AdcDMAHandle.Instance = (ADC_TypeDef *)(obj->adc);
 
     // Configure ADC channel
@@ -140,34 +139,26 @@
             sConfig.Channel = ADC_CHANNEL_15;
             break;
         default:
-            return 0;
-    }
+            return HAL_ERROR;
+        }
 
     HAL_ADC_ConfigChannel(&AdcDMAHandle, &sConfig);
 
-   // HAL_ADC_Start(&AdcDMAHandle); // Start conversion
     HAL_ADC_Start_DMA(&AdcDMAHandle, (uint32_t*) pData, Length);
 
     // Wait end of conversion and get value
-    if (HAL_ADC_PollForConversion(&AdcDMAHandle, 10) == HAL_OK) {
-        return (HAL_OK);
-    } else {
-        return 0;
-    }
+    return (HAL_ADC_PollForConversion(&AdcDMAHandle, 1)); 
 }
 
-uint16_t analogin_readdMA_u16(analogin_t *obj,uint16_t* pData, uint32_t Length)
+HAL_StatusTypeDef analogin_readdMA_u16(analogin_t *obj,uint16_t* pData, uint32_t Length)
 {
-    uint16_t value = adc_read(obj,pData, Length);
-    // 12-bit to 16-bit conversion
-    value = ((value << 4) & (uint16_t)0xFFF0) | ((value >> 8) & (uint16_t)0x000F);
-    return value;
+    return adc_read(obj,pData, Length);
+ 
 }
 
-float analoginDMA_read(analogin_t *obj,uint16_t* pData, uint32_t Length)
+HAL_StatusTypeDef analoginDMA_read(analogin_t *obj,uint16_t* pData, uint32_t Length)
 {
-    uint16_t value = adc_read(obj, pData, Length);
-    return (float)value * (1.0f / (float)0xFFF); // 12 bits range
+    return adc_read(obj, pData, Length);
 }
 
 #endif
--- a/analoginDMA_api.h	Sat Jan 03 14:28:35 2015 +0000
+++ b/analoginDMA_api.h	Sat Jan 03 15:41:29 2015 +0000
@@ -27,8 +27,8 @@
 typedef struct analogin_s analogin_t;
 
 void     analoginDMA_init    (analogin_t *obj, PinName pin);
-float    analoginDMA_read    (analogin_t *obj,uint16_t* pData, uint32_t Length);
-uint16_t analoginDMA_read_u16(analogin_t *obj,uint16_t* pData, uint32_t Length);
+HAL_StatusTypeDef analoginDMA_read    (analogin_t *obj,uint16_t* pData, uint32_t Length);
+HAL_StatusTypeDef analoginDMA_read_u16(analogin_t *obj,uint16_t* pData, uint32_t Length);
 
 #ifdef __cplusplus
 }