From 817d9211d5f3c608dc231e1d3232d22294f9c782 Mon Sep 17 00:00:00 2001 From: laforge Date: Thu, 21 Sep 2006 12:03:18 +0000 Subject: some code cleanup git-svn-id: https://svn.openpcd.org:2342/trunk@214 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/src/os/led.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'firmware/src/os') diff --git a/firmware/src/os/led.c b/firmware/src/os/led.c index 96ffecc..2a57558 100644 --- a/firmware/src/os/led.c +++ b/firmware/src/os/led.c @@ -26,6 +26,11 @@ #include #include +static const int ledport[] = { + [1] = OPENPCD_PIO_LED1, + [2] = OPENPCD_PIO_LED2, +}; + static int led2port(int led) { if (led == 1) @@ -38,11 +43,12 @@ static int led2port(int led) void led_switch(int led, int on) { - int port = led2port(led); - - if (port == -1) + int port; + + if (led < 1 || led > 2) return; + port = ledport[led]; if (on) AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, port); else @@ -51,19 +57,21 @@ void led_switch(int led, int on) int led_get(int led) { - int port = led2port(led); + int port; - if (port == -1) + if (led < 1 || led > 2) return -1; + port = ledport[led]; + return !(AT91F_PIO_GetOutputDataStatus(AT91C_BASE_PIOA) & port); } int led_toggle(int led) { int on = led_get(led); - if (on == -1) - return -1; + if (on < 0) + return on; if (on) led_switch(led, 0); -- cgit v1.2.3