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 at atmel.com> > + * > + * (C) Copyright 2009 > + * Daniel Gorsulowski <daniel.gorsulow...@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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot