summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-06-17 00:45:31 +0200
committerNicolas Schodet2011-09-26 19:41:34 +0200
commit38b4a4d5ca0f30a5e058de2a99436df187a46f52 (patch)
tree08fed49b2bbac63fea0d40940e15e27182ce6b5d
parentca0e7d4a5b7e0d2ae98580fd2dd17fb82fc43d1d (diff)
src/common: remove pull up when button is pressed
-rw-r--r--src/common/button.c6
-rw-r--r--src/common/button.h3
-rw-r--r--src/common/led.c6
-rw-r--r--src/common/led.h4
4 files changed, 16 insertions, 3 deletions
diff --git a/src/common/button.c b/src/common/button.c
index 8d1a49b..1924f62 100644
--- a/src/common/button.c
+++ b/src/common/button.c
@@ -25,9 +25,7 @@
#include "modules/utils/utils.h"
#include "io.h"
#include "button.h"
-
-/** Button port. */
-#define BUTTON_IO B, 1
+#include "led.h"
/** Delay for the button to be considered debounced. */
#define BUTTON_DEBOUNCE_MS 100
@@ -44,6 +42,8 @@ button_wait (void)
/* Wait until button is pressed. */
while (IO_GET (BUTTON_IO))
;
+ /* Remove pull-up to save battery and shut off leds. */
+ led_no_pull_up ();
/* Wait until button is really released. */
uint8_t debounce_ms = 0;
while (debounce_ms < BUTTON_DEBOUNCE_MS)
diff --git a/src/common/button.h b/src/common/button.h
index d98adf7..1145a69 100644
--- a/src/common/button.h
+++ b/src/common/button.h
@@ -24,6 +24,9 @@
* Email: <nico at ni.fr.eu.org>
* }}} */
+/** Button port. */
+#define BUTTON_IO B, 1
+
/** Initialise button. */
void
button_init (void);
diff --git a/src/common/led.c b/src/common/led.c
index db674c4..19ba5a9 100644
--- a/src/common/led.c
+++ b/src/common/led.c
@@ -93,3 +93,9 @@ led_display (uint16_t leds, uint16_t duration)
}
}
+void
+led_no_pull_up (void)
+{
+ PORTB = (PORTB & ~LED_MASK) | IO_BV (BUTTON_IO);
+}
+
diff --git a/src/common/led.h b/src/common/led.h
index 6f1ce50..848a53a 100644
--- a/src/common/led.h
+++ b/src/common/led.h
@@ -40,4 +40,8 @@ led_init (void);
void
led_display (uint16_t leds, uint16_t duration);
+/** Remove all leds pull-up. */
+void
+led_no_pull_up (void);
+
#endif /* led_h */