]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_adc.c
adc: Use board-dependent function for LSB-to-Volts conversion
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_adc.c
index e6a621d69b93ccebf7735a337c3aac40a21605ab..1f56f47684d6e07daec20cab9a62b4651f9dc58c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2016 Czech Technical University in Prague
  *
  * Created on: 28.2.2013
  *
 
 #ifndef DOCGEN
 
-#include "hal/hal.h"
 #include "rpp/rpp.h"
 #include <stdio.h>
-
-static double lsb2volts(unsigned lsb)
-{
-       return ((double)lsb + 0.0)*2.5/4095*10;
-}
-
+#include "drv/port.h"
 
 /**
  * @brief Read values from ADC port
@@ -48,17 +42,17 @@ int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *p
        if (param[1] == param[0] + 7) { /* Single pin variant */
                if (sscanf(param[1], "%d", &min) != 1)
                        return -CMDERR_BADPAR;
-               if (min > 15)
+               if (min >= PORT_ADC_CHANNELS)
                        return -CMDERR_NODEV;
                max = min;
        }
        else {              /* All pins */
                min = 0;
-               max = PORT_ADC_CHANNEL_NUM-1;
+               max = PORT_ADC_CHANNELS - 1;
        }
        for (i = min; i <= max; i++) {
                unsigned d = rpp_adc_get(i+1);
-               double v = lsb2volts(d);
+               double v = port_adc_lsb2volts(d);
                rpp_sci_printf("ADC%-2d %4d lsb ~ %5.2f V\n", i, d, v);
        }
        return 0;
@@ -68,14 +62,13 @@ int cmd_do_adc_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
        int i;
 
-       rpp_sci_printf("ADC Inputs Test [0-15]:\r\n");
-       rpp_sci_printf("=======================================================================\r\n");
+       rpp_sci_printf("ADC Inputs Test [0-%d]:\r\n", PORT_ADC_CHANNELS - 1);
 
-       for (i = 0; i < 16; i++)
-               rpp_sci_printf("%5d ", i);
+       for (i = 0; i < PORT_ADC_CHANNELS; i++)
+               rpp_sci_printf("======");
        rpp_sci_printf("\n");
 
-       for (i = 1; i < 13; i++)
+       for (i = 0; i < PORT_ADC_CHANNELS; i++)
                rpp_sci_printf("%5d ", i);
        rpp_sci_printf("\n");
 
@@ -84,12 +77,14 @@ int cmd_do_adc_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        portTickType last_wake_time = xTaskGetTickCount();
 
        while (cmd_io->getc(cmd_io) < 0) {
+        // Update inputs
+        rpp_adc_update();
 
-               for (i = 0; i < 16; i++)
+               for (i = 0; i < PORT_ADC_CHANNELS; i++)
                        rpp_sci_printf("%5d ", rpp_adc_get(i+1));
                rpp_sci_printf("lsb\n");
-               for (i = 0; i < 16; i++)
-                       rpp_sci_printf("%5.2f ", lsb2volts(rpp_adc_get(i+1)));
+               for (i = 0; i < PORT_ADC_CHANNELS; i++)
+                       rpp_sci_printf("%5.2f ", port_adc_lsb2volts(rpp_adc_get(i+1)));
                rpp_sci_printf("V\r\033[A"); /* Cursor up */