hbc: interrupt stubs
[lra-as-sensor] / hbc.c
diff --git a/hbc.c b/hbc.c
index 157d617..c5749cc 100644 (file)
--- a/hbc.c
+++ b/hbc.c
@@ -1,21 +1,56 @@
+#include <stdio.h>
+#include <stdlib.h>
 #include <avr/io.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+#include <avr/power.h>
 #include <avr/interrupt.h>
+#include <util/delay.h>
+#include "haptic.h"
 
-#include <stdio.h>
-#include <stdlib.h>
+/* idle mode will wake up board and will
+ * return PC after latest sleep_mode() call */
+EMPTY_INTERRUPT(SIG_COMPARATOR);
 
-#include <util/delay.h>
+/* for debugging purposes */
+ISR(BADISR_vect) 
+{
+}
 
-int main(void) {
-       
+static void switch_idle(void)
+{
+       sei();
+       set_sleep_mode(SLEEP_MODE_IDLE);
+       sleep_mode();
+}
+
+static void init_board(void)
+{
+       power_adc_disable();
+       wdt_disable();
+       /* enable interal reference for 
+        * comparator 
+        * When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). */
+}
+
+int main(void)
+{
        
-       DDRB |= (1 << DDB3);
-       PORTB = (1 << PB3);
+       init_board();   
 
        while(1) {
-               
-       }
 
-       return 0;
+               /* set LRA as sensor and switch to idle mode
+                * check back-EMF of LRA: if treshold is surpassed
+                * comparator intterupt is triggered */
+               set_lra_as_sensor();
+               switch_idle(); 
+
+               /* board wakes up, set LRA as actuator and
+                * plays haptic effect */
+               set_lra_as_actuator();
+               play_haptic();
+
+       }
 
 }