]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/blobdiff - rpp/src/rpp/adc.c
Unify ADC among targets
[pes-rpp/rpp-lib.git] / rpp / src / rpp / adc.c
index 8f0ede023e7c5a8ed43784d1923e6c923131d71d..30e180d7294ee2de45ffffb7096a58fed099789c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Carlos Jenkins <carlos@jenkins.co.cr>
 
 #ifndef FREERTOS_POSIX
 #include "drv/drv.h"
+#include "drv/port.h"
 
-// RPP has 12 ADC channels
-// See s_adcSelect and s_adcFiFoSize in ti_drv_adc.c for hardware configuration.
-#define ADC_CHANNELS 16
-static adcData_t in_cache[ADC_CHANNELS];
+static uint16_t in_cache[PORT_ADC_CHANNELS];
 #endif
 
 static boolean_t initialized = FALSE;
@@ -47,7 +45,7 @@ int8_t rpp_adc_init()
 
 int16_t rpp_adc_get(uint8_t pin)
 {
-       if ((pin < 1) || (pin > 16))
+       if ((pin < 1) || (pin > PORT_ADC_CHANNELS))
                return -1;
 
        int16_t result = 0;
@@ -55,7 +53,7 @@ int16_t rpp_adc_get(uint8_t pin)
 #ifndef FREERTOS_POSIX
        // This conversion uint16_t -> int16_t is safe because we know values
        // are 12bits. Here we are masking those 12bits just in case.
-       result = (int16_t)(in_cache[pin - 1].value & 0xFFF);
+       result = in_cache[pin - 1] & 0xFFF;
 #endif
 
        return result;
@@ -65,8 +63,8 @@ int16_t rpp_adc_get(uint8_t pin)
 int8_t rpp_adc_update()
 {
 #ifndef FREERTOS_POSIX
-       // in_cache is thread safe because it's only write operation is mutexed
-       drv_adc_read_adc((adcData_t *)&in_cache);
+       const struct port_desc *port = &port_desc[PORT_ID_ADC];
+       port->get(port, in_cache, sizeof(in_cache));
 #endif
 
        return SUCCESS;