From eac46a9194a211b97e4fb5a77ed8320f17dd7a8c Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Mon, 21 May 2012 09:59:01 -0700 Subject: More debug command cleanup to save space (saves another 1.5KB) BUG=none TEST=(run the commands) Change-Id: Id3ca58528fa68a4cec606edf2b98b9af38ac228f Signed-off-by: Randall Spangler --- common/gpio_commands.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) (limited to 'common/gpio_commands.c') diff --git a/common/gpio_commands.c b/common/gpio_commands.c index 1f32cc2e5e..ca8487533d 100644 --- a/common/gpio_commands.c +++ b/common/gpio_commands.c @@ -11,6 +11,9 @@ #include "util.h" +static uint8_t last_val[(GPIO_COUNT + 7) / 8]; + + /* Find a GPIO signal by name. Returns the signal index, or GPIO_COUNT if * no match. */ static enum gpio_signal find_signal_by_name(const char *name) @@ -30,8 +33,6 @@ static enum gpio_signal find_signal_by_name(const char *name) } -static uint8_t last_val[(GPIO_COUNT + 7) / 8]; - /* If v is different from the last value for index i, updates the last value * and returns 1; else returns 0. */ static int last_val_changed(int i, int v) @@ -47,6 +48,7 @@ static int last_val_changed(int i, int v) } } + static int command_gpio_get(int argc, char **argv) { const struct gpio_info *g = gpio_list; @@ -55,10 +57,8 @@ static int command_gpio_get(int argc, char **argv) /* If a signal is specified, print only that one */ if (argc == 2) { i = find_signal_by_name(argv[1]); - if (i == GPIO_COUNT) { - ccputs("Unknown signal name.\n"); - return EC_ERROR_UNKNOWN; - } + if (i == GPIO_COUNT) + return EC_ERROR_INVAL; g = gpio_list + i; v = gpio_get_level(i); changed = last_val_changed(i, v); @@ -68,7 +68,6 @@ static int command_gpio_get(int argc, char **argv) } /* Otherwise print them all */ - ccputs("Current GPIO levels:\n"); for (i = 0; i < GPIO_COUNT; i++, g++) { if (!g->mask) continue; /* Skip unsupported signals */ @@ -92,32 +91,23 @@ static int command_gpio_set(int argc, char **argv) char *e; int v, i; - if (argc < 3) { - ccputs("Usage: gpioset <0|1>\n"); - return EC_ERROR_UNKNOWN; - } + if (argc < 3) + return EC_ERROR_INVAL; i = find_signal_by_name(argv[1]); - if (i == GPIO_COUNT) { - ccputs("Unknown signal name.\n"); - return EC_ERROR_UNKNOWN; - } + if (i == GPIO_COUNT) + return EC_ERROR_INVAL; g = gpio_list + i; - if (!g->mask) { - ccputs("Signal is not implemented.\n"); - return EC_ERROR_UNKNOWN; - } - if (!(g->flags & GPIO_OUTPUT)) { - ccputs("Signal is not an output.\n"); - return EC_ERROR_UNKNOWN; - } + if (!g->mask) + return EC_ERROR_INVAL; + + if (!(g->flags & GPIO_OUTPUT)) + return EC_ERROR_INVAL; v = strtoi(argv[2], &e, 0); - if (*e) { - ccputs("Invalid signal value.\n"); - return EC_ERROR_UNKNOWN; - } + if (*e) + return EC_ERROR_INVAL; return gpio_set_level(i, v); } -- cgit v1.2.1