All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/1] at91: Add command to control up to 3 GPIO LEDs from the console
Date: Thu, 7 May 2009 08:31:59 +0200	[thread overview]
Message-ID: <200905070832.01278.sr@denx.de> (raw)
In-Reply-To: <1241619669338-git-send-email-Daniel.Gorsulowski@esd.eu>

Hi Daniel,

On Wednesday 06 May 2009, Daniel Gorsulowski wrote:
> This patch allows any at91 board, implementing the GPIO LED API,
> to control the LEDs from the console.
>
> led [ 1 | 2 | 3 | all ]  [ on | off ]

Why limit this to a max of 3 LED's? If this is a generic command (which I like 
btw) then we should support a user/board defined number of LED's. In your case 
it's 3, but the infrastructure should support any number.

More comments below.

<snip>

> diff --git a/common/cmd_led.c b/common/cmd_led.c
> new file mode 100644
> index 0000000..f914d2d
> --- /dev/null
> +++ b/common/cmd_led.c
> @@ -0,0 +1,86 @@
> +/*
> + * (C) Copyright 2008
> + * Ulf Samuelsson <ulf.samuelsson@atmel.com>
> + *
> + * (C) Copyright 2009
> + * Daniel Gorsulowski <daniel.gorsulowski@esd.eu>
> + * esd electronic system design gmbh <www.esd.eu>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <config.h>
> +#include <command.h>
> +#include <asm/arch/led.h>
> +
> +int do_led(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
> +{
> +	int led;
> +
> +	/* Validate arguments */
> +	if ((argc != 3)) {
> +		printf("Usage:\n%s\n", cmdtp->usage);
> +		return 1;
> +	}
> +	if (strcmp(argv[1], "1") == 0) {
> +		led = (1 << 0);
> +	} else if (strcmp(argv[1], "2") == 0) {
> +		led = (1 << 1);
> +	} else if (strcmp(argv[1], "3") == 0) {
> +		led = (1 << 2);
> +	} else if (strcmp(argv[1], "all") == 0) {
> +		led = 31;
> +	} else {
> +		printf ("Usage:\n%s\n", cmdtp->usage);
> +		return 1;
> +	}

Here we have the problem with max of 3 again. Why not just scan the 2nd 
parameter as an int and use it as parameter for the following function calls 
(see below)?

> +
> +	if (strcmp(argv[2], "off") == 0) {
> +#ifdef CONFIG_USER1_LED
> +		if(led & 1) user1_led_off();
> +#endif
> +#ifdef CONFIG_USER2_LED
> +		if(led & 2) user2_led_off();
> +#endif
> +#ifdef CONFIG_USER3_LED
> +		if(led & 4) user3_led_off();
> +#endif
> +	} else if (strcmp(argv[2], "on") == 0) {
> +#ifdef CONFIG_USER1_LED
> +		if(led & 1) user1_led_on();
> +#endif
> +#ifdef CONFIG_USER2_LED
> +		if(led & 2) user2_led_on();
> +#endif
> +#ifdef CONFIG_USER3_LED
> +		if(led & 4) user3_led_on();
> +#endif

I suggest to use something like this here:

	led_nr = simple_strtoul(argv[1], NULL, 10);
	if (led_nr > CONFIG_LED_MAX) {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}

	if (strcmp(argv[2], "off") == 0) {
		on = 1;
	} else if (strcmp(argv[2], "on") == 0) {
		on = 0;
	} else {
		printf ("Usage:\n%s\n", cmdtp->usage);
		return 1;
	}

	user_led(led_nr, on);

No ugly #ifdef's in this case. What do you think?

Best regards,
Stefan

  parent reply	other threads:[~2009-05-07  6:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-06 14:21 [U-Boot] [PATCH 1/1] at91: Add command to control up to 3 GPIO LEDs from the console Daniel Gorsulowski
2009-05-06 20:37 ` Wolfgang Denk
2009-05-06 20:40   ` Mike Frysinger
2009-05-07  6:01   ` Daniel Gorsulowski
2009-05-07  7:32     ` Wolfgang Denk
2009-05-08  5:37       ` Daniel Gorsulowski
2009-05-07  6:31 ` Stefan Roese [this message]
2009-05-08  5:28   ` Daniel Gorsulowski
2009-05-08  6:21     ` Stefan Roese
2009-05-14  8:49       ` Daniel Gorsulowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200905070832.01278.sr@denx.de \
    --to=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.