]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_pin.c
Change license to MIT
[pes-rpp/rpp-test-sw.git] / rpp-test-sw / commands / cmd_pin.c
index 71ee438206c6fe2ae75754ec51ff1024b7120895..6816d50928662041a5805e1a82955357dde1ccd4 100644 (file)
@@ -6,10 +6,26 @@
  * Authors:
  *     - Michal Horn
  *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
  * File : cmd_pin.c
  *
@@ -27,7 +43,7 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "drv/digital_io_def.h"
+#include "drv/gio_tab.h"
 #include "cmdproc_utils.h"
 
 /**
@@ -43,17 +59,21 @@ int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        uint32_t i;
 
        rpp_sci_printf("List of all defined pins. Those names can be used by pinval command.\r\n");
-       uint32_t pin_cnt = rpp_gio_get_pin_cnt();
-       const char* pin_names[128];
-       rpp_gio_get_pin_names(pin_names, pin_cnt);
-       for (i = 0; i < pin_cnt; i++) {
-               if (strcmp(pin_names[i], DIO_PIN_NAME_UNUSED) == 0) continue;
-               rpp_sci_printf(pin_names[i]);
-               rpp_sci_printf("\r\n");
-       }
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               rpp_sci_printf("%s\r\n", gio_table[i].pin_name);
        return 1;
 }
 
+static enum pin_name pin_from_name(const char *pin_name)
+{
+       uint32_t i;
+
+       for (i = 0; i < ARRAY_SIZE(gio_table); i++)
+               if (strcmp(pin_name, gio_table[i].pin_name) == 0)
+                       return (enum pin_name)i;
+       return _PIN_INVALID;
+}
+
 /**
  * @brief      Set or get pin value
  *
@@ -73,6 +93,9 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (sscanf(p, "%31s ", pinName) != 1)
                return -CMDERR_BADPAR;
 
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
 
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
@@ -80,13 +103,13 @@ int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                        return -CMDERR_BADPAR;
                if (val != 0 && val != 1)
                        return -CMDERR_BADPAR;
-               if (rpp_gio_set_val(pinName, val) == FAILURE) {
+               if (rpp_gio_set(pin, val) == FAILURE) {
                        return -CMDERR_BADPAR;;
                }
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
        }
        else {  // No more parameters = get values
-               int32_t pin_value = rpp_gio_get_val(pinName);
+               int pin_value = rpp_gio_get(pin);
                if (pin_value == FAILURE) {
                        return -CMDERR_BADPAR;
                }
@@ -114,32 +137,29 @@ int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        if (sscanf(p, "%31s ", pinName) != 1)
                return -CMDERR_BADPAR;
 
+       enum pin_name pin = pin_from_name(pinName);
+       if (pin == _PIN_INVALID)
+               return -CMDERR_BADPAR;
+
        if (param[2] != NULL) {     // More parameters = set values
                p = param[2];
                if (sscanf(p, "%u %1s", &val, &spareParams) != 1)
                        return -CMDERR_BADPAR;
-               if (val == 0) {
-                       if (rpp_gio_set_input(pinName) == FAILURE) {
-                               return -CMDERR_BADPAR;
-                       }
-               }
-               else if (val == 1) {
-                       if (rpp_gio_set_output(pinName, 0) == FAILURE) {
-                               return -CMDERR_BADPAR;
-                       }
-               }
-               else {
-                       return -CMDERR_BADPAR;
-               }
+               uint32_t pin_dsc = gio_table[pin].pin_dsc;
+
+               pin_dsc &= ~GIO_PIN_CONF_DIR_MASK;
+               pin_dsc |= val ? GIO_PIN_CONF_DIR_OUT : GIO_PIN_CONF_DIR_IN;
+
+               gio_setup(pin_dsc);
 
                return cmd_opchar_replong(cmd_io, param, val, 0, 0);
        }
        else {  // No more parameters = get values
-               int32_t pin_dir = rpp_gio_is_dir_output(pinName);
-               if (pin_dir == FAILURE) {
-                       return -CMDERR_BADPAR;
-               }
-               rpp_sci_printf("pindir%s=%d\n", pinName, pin_dir);
+               int32_t pin_dir = 0/* rpp_gio_is_dir_output(pinName) */;
+/*             if (pin_dir == FAILURE) { */
+/*                     return -CMDERR_BADPAR; */
+/*             } */
+               rpp_sci_printf("pindir%s=%d FIXME not implemented\n", pinName, pin_dir);
                return 0;
        }
 }