Skip to contentSkip to conversation

gpio: Expand cmd_gpio functionality and script friendliness

PATCH New Joe Hershberger 3 participants 4 messages Aug 10, 2011 – Aug 11, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: Expand cmd_gpio functionality and script friendliness

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

Cc Joe Hershberger <[email protected]>
Cc Mike Frysinger <[email protected]>
---
 common/cmd_gpio.c |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)
common/cmd_gpio.c +24 -15
index 9cc790a..0acb93e 100644
@@ -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");
Signature · 1 line
1.6.0.2
#1 lore raw

PATCH 1/1 gpio: Expand cmd_gpio functionality and script friendliness

Quoted 3 lines · On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:

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

a similar patch was posted somewhat recently but was declined. please see the archive for more info.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110810/8285a5cf/attachment.pgp

#2 lore raw

PATCH 1/1 gpio: Expand cmd_gpio functionality and script friendliness

Hi Mike,

Quoted 7 lines · Mike Frysinger
Quoted 3 lines · On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:

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

a similar patch was posted somewhat recently but was declined. ?please see the archive for more info.

I attempted to locate what you are referring to, but had no luck. I saw nothing that referenced "cmd_gpio" that was similar. Any clues about what aspects were rejected so I'll have a better idea what to search for? Possibly who rejected it?

Thanks,
-Joe

#3 lore raw

PATCH 1/1 gpio: Expand cmd_gpio functionality and script friendliness

Quoted 6 lines · On Wednesday, August 10, 2011 22:07:28 Joe Hershberger wrote:
Quoted 5 lines · Mike Frysinger
Quoted 3 lines · On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:

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

Quoted 7 lines
Quoted 2 lines

a similar patch was posted somewhat recently but was declined. please see the archive for more info.

I attempted to locate what you are referring to, but had no luck. I saw nothing that referenced "cmd_gpio" that was similar. Any clues about what aspects were rejected so I'll have a better idea what to search for? Possibly who rejected it?

[U-Boot] [RFC] gpio command: return value on write, additional actions -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20110810/329651bb/attachment.pgp