summaryrefslogtreecommitdiff
path: root/src/common/button.c
diff options
context:
space:
mode:
authorNicolas Schodet2011-09-26 19:35:24 +0200
committerNicolas Schodet2011-09-26 19:41:34 +0200
commit83f4265644321022cce13d0e4f5a5f5335a4d7a9 (patch)
tree85cfdaa03745a2ab6b301cc20c1a35e5a9ace998 /src/common/button.c
parent38b4a4d5ca0f30a5e058de2a99436df187a46f52 (diff)
src/binwatch, src/common: add power reduction and sleep when waiting button
Diffstat (limited to 'src/common/button.c')
-rw-r--r--src/common/button.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/common/button.c b/src/common/button.c
index 1924f62..7209eff 100644
--- a/src/common/button.c
+++ b/src/common/button.c
@@ -26,6 +26,7 @@
#include "io.h"
#include "button.h"
#include "led.h"
+#include "power.h"
/** Delay for the button to be considered debounced. */
#define BUTTON_DEBOUNCE_MS 100
@@ -33,6 +34,9 @@
void
button_init (void)
{
+ /* Initialise pin change interrupt. */
+ GIMSK |= _BV (PCIE);
+ PCMSK = IO_BV (BUTTON_IO);
/* Button is shared with leds, no PORT init. */
}
@@ -40,8 +44,12 @@ void
button_wait (void)
{
/* Wait until button is pressed. */
- while (IO_GET (BUTTON_IO))
- ;
+ GIFR = _BV (PCIF); /* Clear previous interrupt. */
+ if (IO_GET (BUTTON_IO))
+ {
+ /* Sleep, the pin change interrupt will wake me up. */
+ power_sleep ();
+ }
/* Remove pull-up to save battery and shut off leds. */
led_no_pull_up ();
/* Wait until button is really released. */
@@ -62,3 +70,8 @@ button_pressed (void)
return !IO_GET (BUTTON_IO);
}
+SIGNAL (PCINT0_vect)
+{
+ /* Nothing to do, only wake up. */
+}
+