# HG changeset patch # User ethanzonca@CL-SEC241-08.cedarville.edu # Date 2012-12-04 12:09:39 # Node ID 6314aa4c914330aeec9b99db7f32b411b7b90c00 # Parent e97303daddff3dedab498da1b48a305961f5e021 Updated LED library to support multiple ports. Currently has operation issues likely due to 100% SRAM usage. diff --git a/master/master/lib/led.c b/master/master/lib/led.c --- a/master/master/lib/led.c +++ b/master/master/lib/led.c @@ -13,31 +13,31 @@ #include "../config.h" #include #include -#include "led.h" +#include "led.h" + void led_setup() { - // Configure ports/pins for LEDs - DDRA = 0xff; - //PORTA = 0x00; -} - -void led_on(uint8_t led) -{ - // Turn the specified LED on - PORTA |= (1< + +enum leds { + LED_ACT0 = 0, + LED_ACT1, + LED_ACT2, + LED_ACT3, + + LED_POWER, + LED_STATUS, + LED_ERROR, + LED_SIDEBOARD, + LED_ACTIVITY, + LED_CYCLE +}; + +typedef struct {uint8_t* direction; uint8_t* port; uint8_t pin;} led_t; + +// Match order of leds enum +static led_t ledList[] = { + {&DDRA, &PORTA, PA4}, // ACT0 + {&DDRA, &PORTA, PA5}, // ACT1 + {&DDRA, &PORTA, PA6}, // ACT2 + {&DDRA, &PORTA, PA7}, // ACT3 + +//pcb: +// {&DDRB, &PORTB, PB4}, // POWER +// {&DDRB, &PORTB, PB3}, // STATUS +// {&DDRB, &PORTB, PB2}, // ERROR + +//breadboard: + {&DDRA, &PORTA, PA2}, // POWER + {&DDRA, &PORTA, PA0}, // STATUS + {&DDRA, &PORTA, PA1}, // ERROR + + {&DDRD, &PORTD, PD6}, // SIDEBOARD + {&DDRD, &PORTD, PD5}, // ACTIVITY + {&DDRD, &PORTD, PD4}, // CYCLE +}; + +#define NUM_LEDS 10 void led_setup(); void led_on(uint8_t led); void led_off(uint8_t led); -void led_toggle(uint8_t led); void led_errorcode(uint8_t code); #endif /* LED_H_ */ diff --git a/master/master/master.c b/master/master/master.c --- a/master/master/master.c +++ b/master/master/master.c @@ -61,7 +61,7 @@ int main(void) //serial0_sendString("---------------------------------\r\n\r\n"); //serial0_sendString("\f\r\n\r\Hello.\r\n\r\n"); - led_on(POWER); + led_on(LED_POWER); // Buffer for string operations char logbuf[16]; @@ -81,10 +81,10 @@ int main(void) // Periodic: Logging if(time_millis() - lastLog > LOGGER_RATE) { - led_on(STAT); + led_on(LED_STATUS); snprintf(logbuf, 16, "%lu,%d,\r\n", time_millis(), sensordata_get(HUMIDITY)); logger_log(logbuf); - led_off(STAT); + led_off(LED_STATUS); lastLog = time_millis(); }