Add quiet parameter to cmd_gpio for use when part of a script
Enable repeat... especially useful when used with input and toggle
Add "outstate" command that will return and print the state of an output

Signed-off-by: Joe Hershberger <joe.hershber...@ni.com>
Cc: Joe Hershberger <joe.hershber...@gmail.com>
Cc: Mike Frysinger <vap...@gentoo.org>
---
 common/cmd_gpio.c |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c
index 9cc790a..0acb93e 100644
--- a/common/cmd_gpio.c
+++ b/common/cmd_gpio.c
@@ -20,6 +20,7 @@ enum gpio_cmd {
        GPIO_SET,
        GPIO_CLEAR,
        GPIO_TOGGLE,
+       GPIO_OUTSTATE,
 };
 
 static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -27,7 +28,7 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[])
        int gpio;
        enum gpio_cmd sub_cmd;
        ulong value;
-       const char *str_cmd, *str_gpio;
+       const char *str_cmd, *str_gpio, *str_quiet = "0";
 
 #ifdef gpio_status
        if (argc == 2 && !strcmp(argv[1], "status")) {
@@ -36,18 +37,22 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
        }
 #endif
 
-       if (argc != 3)
+       if (argc != 3 && argc != 4)
  show_usage:
                return cmd_usage(cmdtp);
+
        str_cmd = argv[1];
        str_gpio = argv[2];
+       if (argc == 4)
+               str_quiet = argv[3];
 
        /* parse the behavior */
        switch (*str_cmd) {
-               case 'i': sub_cmd = GPIO_INPUT;  break;
-               case 's': sub_cmd = GPIO_SET;    break;
-               case 'c': sub_cmd = GPIO_CLEAR;  break;
-               case 't': sub_cmd = GPIO_TOGGLE; break;
+               case 'i': sub_cmd = GPIO_INPUT;    break;
+               case 's': sub_cmd = GPIO_SET;      break;
+               case 'c': sub_cmd = GPIO_CLEAR;    break;
+               case 't': sub_cmd = GPIO_TOGGLE;   break;
+               case 'o': sub_cmd = GPIO_OUTSTATE; break;
                default:  goto show_usage;
        }
 
@@ -68,22 +73,26 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
                value = gpio_get_value(gpio);
        } else {
                switch (sub_cmd) {
-                       case GPIO_SET:    value = 1; break;
-                       case GPIO_CLEAR:  value = 0; break;
-                       case GPIO_TOGGLE: value = !gpio_get_value(gpio); break;
+                       case GPIO_SET:      value = 1; break;
+                       case GPIO_CLEAR:    value = 0; break;
+                       case GPIO_TOGGLE:   value = !gpio_get_value(gpio); 
break;
+                       case GPIO_OUTSTATE: value = gpio_get_value(gpio); break;
                        default:          goto show_usage;
                }
                gpio_direction_output(gpio, value);
        }
-       printf("gpio: pin %s (gpio %i) value is %lu\n",
-               str_gpio, gpio, value);
+
+       if (*str_quiet == '0')
+               printf("gpio: pin %s (gpio %i) value is %lu\n",
+                       str_gpio, gpio, value);
 
        gpio_free(gpio);
 
        return value;
 }
 
-U_BOOT_CMD(gpio, 3, 0, do_gpio,
-       "input/set/clear/toggle gpio pins",
-       "<input|set|clear|toggle> <pin>\n"
-       "    - input/set/clear/toggle the specified pin");
+U_BOOT_CMD(gpio, 4, 1, do_gpio,
+       "input/set/clear/toggle/outstate gpio pins",
+       "<input|set|clear|toggle|outstate> <pin> [quiet]\n"
+       "    - input/set/clear/toggle/outstate the specified pin\n"
+       "    - quiet: if 1, do not print");
-- 
1.6.0.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to