From 9572baa71b85f8db93f363740e633486eaf974b8 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 6 Feb 2011 14:10:07 -0500 Subject: [PATCH] fix mc13224v led driver to only touch gpio used for leds. --- cpu/mc1322x/board/redbee-econotag.h | 8 +++- cpu/mc1322x/leds-arch.c | 43 ++++++++----------- .../redbee-econotag/contiki-mc1322x-main.c | 21 ++++----- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/cpu/mc1322x/board/redbee-econotag.h b/cpu/mc1322x/board/redbee-econotag.h index 515428af2..14b40dec2 100644 --- a/cpu/mc1322x/board/redbee-econotag.h +++ b/cpu/mc1322x/board/redbee-econotag.h @@ -36,9 +36,15 @@ #ifndef BOARD_REDBEE_ECONOTAG_H #define BOARD_REDBEE_ECONOTAG_H +#define GPIO_LED_RED GPIO_44 +#define GPIO_LED_GREEN GPIO_45 +#define GPIO_LED_BLUE GPIO_43 /* don't have a blue LED so we use IO43 */ + +/* old defs. don't use these */ +/* remove these someday */ #define LED_RED 44 #define LED_GREEN 45 -#define LED_BLUE 44 /* don't have a blue LED so we reuse red */ +#define LED_BLUE 43 /* don't have a blue LED so we use IO43 */ /* XTAL TUNE parameters */ /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ diff --git a/cpu/mc1322x/leds-arch.c b/cpu/mc1322x/leds-arch.c index 92cc33211..7c416809c 100644 --- a/cpu/mc1322x/leds-arch.c +++ b/cpu/mc1322x/leds-arch.c @@ -38,43 +38,36 @@ #include "mc1322x.h" #include "board.h" -#define LED_ARCH_RED (1ULL << LED_RED) -#define LED_ARCH_GREEN (1ULL << LED_GREEN) -#define LED_ARCH_BLUE (1ULL << LED_BLUE) +#define LED_ARCH_RED GPIO_LED_RED +#define LED_ARCH_GREEN GPIO_LED_GREEN +#define LED_ARCH_BLUE GPIO_LED_BLUE -#define LED_ARCH_YELLOW (LED_ARCH_RED | LED_ARCH_GREEN ) -#define LED_ARCH_PURPLE (LED_ARCH_RED | LED_ARCH_BLUE) -#define LED_ARCH_CYAN ( LED_ARCH_GREEN | LED_ARCH_BLUE) -#define LED_ARCH_WHITE (LED_ARCH_RED | LED_ARCH_GREEN | LED_ARCH_BLUE) - -/*FIXME: this is broken --- don't set all of the GPIO direction */ void leds_arch_init(void) { - gpio_pad_dir(LED_ARCH_WHITE); + /* set gpio func_sel to gpio (3) */ + GPIO->FUNC_SEL.LED_ARCH_RED = 3; + GPIO->FUNC_SEL.LED_ARCH_GREEN = 3; + GPIO->FUNC_SEL.LED_ARCH_BLUE = 3; + + /* set led gpios to output */ + GPIO->PAD_DIR.LED_ARCH_RED = 1; + GPIO->PAD_DIR.LED_ARCH_GREEN = 1; + GPIO->PAD_DIR.LED_ARCH_BLUE = 1; } unsigned char leds_arch_get(void) { - uint64_t led = (((uint64_t)*GPIO_DATA1) << 32) | *GPIO_DATA0; - return ((led & LED_ARCH_RED) ? 0 : LEDS_RED) - | ((led & LED_ARCH_GREEN) ? 0 : LEDS_GREEN) - | ((led & LED_ARCH_BLUE) ? 0 : LEDS_BLUE) - | ((led & LED_ARCH_YELLOW) ? 0 : LEDS_YELLOW); + return ((GPIO->DATA.LED_ARCH_RED) ? 0 : LEDS_RED) + | ((GPIO->DATA.LED_ARCH_GREEN) ? 0 : LEDS_GREEN) + | ((GPIO->DATA.LED_ARCH_BLUE) ? 0 : LEDS_BLUE); } -/*FIXME: this is broken --- it hits the entire GPIO data register and breaks the button sensor */ void leds_arch_set(unsigned char leds) { - uint64_t led; - - led = (led & ~(LED_ARCH_RED|LED_ARCH_GREEN|LED_ARCH_YELLOW|LED_ARCH_BLUE)) - | ((leds & LEDS_RED) ? LED_ARCH_RED : 0) - | ((leds & LEDS_GREEN) ? LED_ARCH_GREEN : 0) - | ((leds & LEDS_BLUE) ? LED_ARCH_BLUE : 0) - | ((leds & LEDS_YELLOW) ? LED_ARCH_YELLOW : 0); - - gpio_data(led); + if(leds & LEDS_RED) { GPIO->DATA.LED_ARCH_RED = 1; } else { gpio_reset(LED_ARCH_RED); } + if(leds & LEDS_GREEN) { gpio_set(LED_ARCH_GREEN); } else { gpio_reset(LED_ARCH_GREEN); } + if(leds & LEDS_BLUE) { gpio_set(LED_ARCH_BLUE); } else { gpio_reset(LED_ARCH_BLUE); } } diff --git a/platform/redbee-econotag/contiki-mc1322x-main.c b/platform/redbee-econotag/contiki-mc1322x-main.c index 743cb7f2d..7d822d4bb 100644 --- a/platform/redbee-econotag/contiki-mc1322x-main.c +++ b/platform/redbee-econotag/contiki-mc1322x-main.c @@ -145,7 +145,7 @@ static void set_gateway(void) { if(!is_gateway) { -// leds_on(LEDS_RED); + leds_on(LEDS_RED); printf("%d.%d: making myself the IP network gateway.\n\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n", @@ -175,14 +175,6 @@ SENSORS(&button_sensor); void init_lowlevel(void) { - /* led direction init */ - set_bit(*GPIO_PAD_DIR0,8); - set_bit(*GPIO_PAD_DIR0,9); - set_bit(*GPIO_PAD_DIR0,10); - set_bit(*GPIO_PAD_DIR0,23); - set_bit(*GPIO_PAD_DIR0,24); - set_bit(*GPIO_PAD_DIR0,25); - /* button init */ /* set up kbi */ enable_irq_kbi(4); @@ -205,10 +197,6 @@ init_lowlevel(void) set_channel(RF_CHANNEL - 11); /* channel 11 */ set_power(0x12); /* 0x12 is the highest, not documented */ - /* control TX_ON with the radio */ - *GPIO_FUNC_SEL2 = (0x01 << ((44-16*2)*2)); - gpio_pad_dir_set( 1ULL << 44 ); - enable_irq(CRM); #if USE_32KHZ_XTAL @@ -345,6 +333,13 @@ main(void) /* Clock */ clock_init(); + /* LED driver */ + leds_init(); + + /* control TX_ON with the radio */ + GPIO->FUNC_SEL.GPIO_44 = 2; + GPIO->PAD_DIR.GPIO_44 = 1; + /* Process subsystem */ process_init(); process_start(&etimer_process, NULL);