hbc: interrupt stubs
[lra-as-sensor] / hbc.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <avr/io.h>
4 #include <avr/wdt.h>
5 #include <avr/sleep.h>
6 #include <avr/power.h>
7 #include <avr/interrupt.h>
8 #include <util/delay.h>
9 #include "haptic.h"
10
11 /* idle mode will wake up board and will
12  * return PC after latest sleep_mode() call */
13 EMPTY_INTERRUPT(SIG_COMPARATOR);
14
15 /* for debugging purposes */
16 ISR(BADISR_vect) 
17 {
18 }
19
20 static void switch_idle(void)
21 {
22         sei();
23         set_sleep_mode(SLEEP_MODE_IDLE);
24         sleep_mode();
25 }
26
27 static void init_board(void)
28 {
29         power_adc_disable();
30         wdt_disable();
31         /* enable interal reference for 
32          * comparator 
33          * When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). */
34 }
35
36 int main(void)
37 {
38         
39         init_board();   
40
41         while(1) {
42
43                 /* set LRA as sensor and switch to idle mode
44                  * check back-EMF of LRA: if treshold is surpassed
45                  * comparator intterupt is triggered */
46                 set_lra_as_sensor();
47                 switch_idle(); 
48
49                 /* board wakes up, set LRA as actuator and
50                  * plays haptic effect */
51                 set_lra_as_actuator();
52                 play_haptic();
53
54         }
55
56 }