summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-09-27 21:31:54 +0200
committerNicolas Schodet2011-09-27 21:31:54 +0200
commit02200f6e08a34b693257c4a628a7cf9d12cb6b35 (patch)
treeab684f5b3abf476b6835f41032221093d4981692
parentc4cb248eead0c403442cc018f2ebe3123fb2d395 (diff)
src/common: small led_display optimizations
-rw-r--r--src/common/button.c6
-rw-r--r--src/common/button.h8
-rw-r--r--src/common/led.c6
3 files changed, 9 insertions, 11 deletions
diff --git a/src/common/button.c b/src/common/button.c
index 51941d2..adcda43 100644
--- a/src/common/button.c
+++ b/src/common/button.c
@@ -64,12 +64,6 @@ button_wait (void)
}
}
-uint8_t
-button_pressed (void)
-{
- return !IO_GET (BUTTON_IO);
-}
-
SIGNAL (PCINT0_vect)
{
/* Nothing to do, only wake up. */
diff --git a/src/common/button.h b/src/common/button.h
index 1145a69..f7c1238 100644
--- a/src/common/button.h
+++ b/src/common/button.h
@@ -23,6 +23,7 @@
* Web: http://ni.fr.eu.org/
* Email: <nico at ni.fr.eu.org>
* }}} */
+#include "io.h"
/** Button port. */
#define BUTTON_IO B, 1
@@ -36,7 +37,10 @@ void
button_wait (void);
/** Return true if button is currently pressed. */
-uint8_t
-button_pressed (void);
+static inline uint8_t
+button_pressed (void)
+{
+ return !IO_GET (BUTTON_IO);
+}
#endif /* button_h */
diff --git a/src/common/led.c b/src/common/led.c
index fb41f06..a8a31d7 100644
--- a/src/common/led.c
+++ b/src/common/led.c
@@ -83,15 +83,15 @@ led_display (uint16_t leds, uint16_t duration)
{
uint8_t portb, ddrb;
uint8_t l;
- uint16_t i;
+ uint16_t i, mask;
portb = PORTB & ~LED_MASK;
ddrb = DDRB & ~LED_MASK;
for (i = 0; i < duration; i++)
{
- for (l = 0; l < UTILS_COUNT (led_tab); l++)
+ for (l = 0, mask = 1; l < UTILS_COUNT (led_tab); l++, mask <<= 1)
{
/* Turn on if selected. */
- if (leds & (1u << l))
+ if (leds & mask)
{
PORTB = portb | led_tab[l].port;
DDRB = ddrb | led_tab[l].ddr;