On 14:31 Tue 07 Apr     , Daniel Gorsulowski wrote:
> This patch bases on patch of Ulf Samuelsson
> ([PATCH 1/1] ARM: Add command to control coloured led from the console,
> Wed Jan 7 21:09:55 CET 2009)
> It allows any board implementing the user LED API
> to control the LEDs from the console.
> 
> led [ 1 | 2 | 3 | 4 | 5 | all ]  [ on | off ]
> 
> Adding configuration item CONFIG_CMD_LED enables the command.
> The items CONFIG_LED1...5 configure the associated gpio-pins.
> 
> Signed-off-by: Daniel Gorsulowski <[email protected]>
> ---
>  common/Makefile               |    1 +
>  common/cmd_led.c              |  105 
> +++++++++++++++++++++++++++++++++++++++++
>  cpu/arm926ejs/at91/Makefile   |    1 +
>  cpu/arm926ejs/at91/user_led.c |  102 +++++++++++++++++++++++++++++++++++++++
>  include/user_led.h            |   60 +++++++++++++++++++++++
>  5 files changed, 269 insertions(+), 0 deletions(-)
>  create mode 100644 common/cmd_led.c
>  create mode 100644 cpu/arm926ejs/at91/user_led.c
>  create mode 100644 include/user_led.h
> 
> diff --git a/common/Makefile b/common/Makefile
> index b9f4ca7..e0f571c 100644
> --- a/common/Makefile
> +++ b/common/Makefile
> @@ -103,6 +103,7 @@ COBJS-$(CONFIG_CMD_IMMAP) += cmd_immap.o
>  COBJS-$(CONFIG_CMD_IRQ) += cmd_irq.o
>  COBJS-$(CONFIG_CMD_ITEST) += cmd_itest.o
>  COBJS-$(CONFIG_CMD_JFFS2) += cmd_jffs2.o
> +COBJS-$(CONFIG_CMD_LED) += cmd_led.o
>  COBJS-$(CONFIG_CMD_LICENSE) += cmd_license.o
>  COBJS-y += cmd_load.o
>  COBJS-$(CONFIG_LOGBUFFER) += cmd_log.o
> diff --git a/common/cmd_led.c b/common/cmd_led.c
> new file mode 100644
> index 0000000..248f3a9
> --- /dev/null
> +++ b/common/cmd_led.c
> @@ -0,0 +1,105 @@
> +/*
> + * (C) Copyright 2008
> + * Ulf Samuelsson <ulf.samuelsson at atmel.com>
> + *
> + * 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
> + */
> +
> +/*
> + * This file provides a shell like 'test' function to return
> + * true/false from an integer or string compare of two memory
> + * locations or a location and a scalar/literal.
> + * A few parts were lifted from bash 'test' command
> + */
> +
> +#include <common.h>
> +#include <config.h>
> +#include <command.h>
> +#include <user_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], "4") == 0) {
> +             led = (1 << 3);
> +     } else if (strcmp(argv[1], "5") == 0) {
> +             led = (1 << 4);
> +     } else if (strcmp(argv[1], "all") == 0) {
> +             led = 31;
> +     } else {
> +             printf ("Usage:\n%s\n", cmdtp->usage);
> +             return 1;
> +     }
> +
> +     if (strcmp(argv[2], "off") == 0) {
> +#ifdef CONFIG_LED1
> +             if(led & 1) user_LED1_off();
please no uppercase in the function name
abd please use the collor API or extend it
and do not add 100 of functions
please a parameter

btw please move this to lib_arm/


> +#endif
> +#ifdef CONFIG_LED2
> +             if(led & 2) user_LED2_off();
> +#endif
> +#ifdef CONFIG_LED3
> +             if(led & 4) user_LED3_off();
> +#endif
> +#ifdef CONFIG_LED4
> +             if(led & 8) user_LED4_off();
> +#endif
> +#ifdef CONFIG_LED5
> +             if(led & 16) user_LED5_off();
> +#endif
> +     } else if (strcmp(argv[2], "on") == 0) {
> +#ifdef CONFIG_LED1
> +             if(led & 1) user_LED1_on();
> +#endif
> +#ifdef CONFIG_LED2
> +             if(led & 2) user_LED2_on();
> +#endif
> +#ifdef CONFIG_LED3
> +             if(led & 4) user_LED3_on();
> +#endif
> +#ifdef CONFIG_LED4
> +             if(led & 8) user_LED4_on();
> +#endif
> +#ifdef CONFIG_LED5
> +             if(led & 16) user_LED5_on();
> +#endif
> +     } else {
> +             printf ("Usage:\n%s\n", cmdtp->usage);
> +             return 1;
> +     }
> +     return 0;
> +}
> +
> +U_BOOT_CMD(
> +     led, 3, 1, do_led,
> +     "[1|2|3|4|5|all] [on|off]",
> +     "[1|2|3|4|5|all] [on|off] sets/clears led 1,2,3,4,5"
> +);
> diff --git a/cpu/arm926ejs/at91/Makefile b/cpu/arm926ejs/at91/Makefile
> index 34e7461..f404cf1 100644
> --- a/cpu/arm926ejs/at91/Makefile
> +++ b/cpu/arm926ejs/at91/Makefile
> @@ -55,6 +55,7 @@ COBJS-y                             += at91sam9rl_serial.o
>  COBJS-$(CONFIG_HAS_DATAFLASH)        += at91sam9rl_spi.o
>  endif
>  COBJS-$(CONFIG_AT91_LED)     += led.o
> +COBJS-$(CONFIG_USER_LED)     += user_led.o
>  COBJS-y      += timer.o
>  SOBJS        = lowlevel_init.o
>  
> diff --git a/cpu/arm926ejs/at91/user_led.c b/cpu/arm926ejs/at91/user_led.c
> new file mode 100644
> index 0000000..a5dc197
> --- /dev/null
> +++ b/cpu/arm926ejs/at91/user_led.c
> @@ -0,0 +1,102 @@
> +/*
> + * (C) Copyright 2007-2008
> + * Stelian Pop <[email protected]>
> + * Lead Tech Design <www.leadtechdesign.com>
> + *
> + * 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 <asm/arch/at91sam9263.h>
only 9263?
please use asm/arch/hardware.h

> +#include <asm/arch/at91_pmc.h>
> +#include <asm/arch/gpio.h>
> +#include <asm/arch/io.h>
> +
> +void user_LED_init(void)
> +{
> +     /* Enable clock */
> +     at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_PIOB |
> +                                   1 << AT91SAM9263_ID_PIOCDE);
> +
> +     at91_set_gpio_output(CONFIG_LED1, 1);
> +     at91_set_gpio_output(CONFIG_LED2, 1);
> +
> +     at91_set_gpio_value(CONFIG_LED1, 1);
> +     at91_set_gpio_value(CONFIG_LED2, 1);
> +}
> +
> +#ifdef CONFIG_LED1
> +void user_LED1_on(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED1, 0);
> +}
> +
> +void user_LED1_off(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED1, 1);
> +}
> +#endif
> +
> +#ifdef CONFIG_LED2
> +void user_LED2_on(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED2, 0);
> +}
> +
> +void user_LED2_off(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED2, 1);
> +}
> +#endif
> +
> +#ifdef CONFIG_LED3
> +void user_LED3_on(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED3, 0);
> +}
> +
> +void user_LED3_off(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED3, 1);
> +}
> +#endif
> +
> +#ifdef CONFIG_LED4
> +void user_LED4_on(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED4, 0);
> +}
> +
> +void user_LED4_off(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED4, 1);
> +}
> +#endif
> +
> +#ifdef CONFIG_LED5
> +void user_LED5_on(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED5, 0);
> +}
> +
> +void user_LED5_off(void)
> +{
> +     at91_set_gpio_value(CONFIG_LED5, 1);
> +}
> +#endif
> diff --git a/include/user_led.h b/include/user_led.h
please move to include/asm-arm/ as it's arm specific
> new file mode 100644
> index 0000000..e0b808f
> --- /dev/null
> +++ b/include/user_led.h
> @@ -0,0 +1,60 @@
> +/*
> + * (C) Copyright 2008
> + * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
                                                [email protected]

Best Regards,
J
_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to