fix mc13224v led driver to only touch gpio used for leds.

This commit is contained in:
Mariano Alvira 2011-02-06 14:10:07 -05:00
parent dbe6407a22
commit 9572baa71b
3 changed files with 33 additions and 39 deletions

View file

@ -36,9 +36,15 @@
#ifndef BOARD_REDBEE_ECONOTAG_H #ifndef BOARD_REDBEE_ECONOTAG_H
#define 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_RED 44
#define LED_GREEN 45 #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 */ /* XTAL TUNE parameters */
/* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */ /* see http://devl.org/pipermail/mc1322x/2009-December/000162.html */

View file

@ -38,43 +38,36 @@
#include "mc1322x.h" #include "mc1322x.h"
#include "board.h" #include "board.h"
#define LED_ARCH_RED (1ULL << LED_RED) #define LED_ARCH_RED GPIO_LED_RED
#define LED_ARCH_GREEN (1ULL << LED_GREEN) #define LED_ARCH_GREEN GPIO_LED_GREEN
#define LED_ARCH_BLUE (1ULL << LED_BLUE) #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) 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) unsigned char leds_arch_get(void)
{ {
uint64_t led = (((uint64_t)*GPIO_DATA1) << 32) | *GPIO_DATA0;
return ((led & LED_ARCH_RED) ? 0 : LEDS_RED) return ((GPIO->DATA.LED_ARCH_RED) ? 0 : LEDS_RED)
| ((led & LED_ARCH_GREEN) ? 0 : LEDS_GREEN) | ((GPIO->DATA.LED_ARCH_GREEN) ? 0 : LEDS_GREEN)
| ((led & LED_ARCH_BLUE) ? 0 : LEDS_BLUE) | ((GPIO->DATA.LED_ARCH_BLUE) ? 0 : LEDS_BLUE);
| ((led & LED_ARCH_YELLOW) ? 0 : LEDS_YELLOW);
} }
/*FIXME: this is broken --- it hits the entire GPIO data register and breaks the button sensor */
void leds_arch_set(unsigned char leds) void leds_arch_set(unsigned char leds)
{ {
uint64_t 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); }
led = (led & ~(LED_ARCH_RED|LED_ARCH_GREEN|LED_ARCH_YELLOW|LED_ARCH_BLUE)) if(leds & LEDS_BLUE) { gpio_set(LED_ARCH_BLUE); } else { gpio_reset(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);
} }

View file

@ -145,7 +145,7 @@ static void
set_gateway(void) set_gateway(void)
{ {
if(!is_gateway) { if(!is_gateway) {
// leds_on(LEDS_RED); leds_on(LEDS_RED);
printf("%d.%d: making myself the IP network gateway.\n\n", printf("%d.%d: making myself the IP network gateway.\n\n",
rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]);
printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n", printf("IPv4 address of the gateway: %d.%d.%d.%d\n\n",
@ -175,14 +175,6 @@ SENSORS(&button_sensor);
void void
init_lowlevel(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 */ /* button init */
/* set up kbi */ /* set up kbi */
enable_irq_kbi(4); enable_irq_kbi(4);
@ -205,10 +197,6 @@ init_lowlevel(void)
set_channel(RF_CHANNEL - 11); /* channel 11 */ set_channel(RF_CHANNEL - 11); /* channel 11 */
set_power(0x12); /* 0x12 is the highest, not documented */ 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); enable_irq(CRM);
#if USE_32KHZ_XTAL #if USE_32KHZ_XTAL
@ -345,6 +333,13 @@ main(void)
/* Clock */ /* Clock */
clock_init(); 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 subsystem */
process_init(); process_init();
process_start(&etimer_process, NULL); process_start(&etimer_process, NULL);