d0169bdc4389b9fad16cd68ea2b1908c95e70ae9
[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 volatile int xvar = 1;
12
13 /* idle mode will wake up board and will
14  * return PC after latest sleep_mode() call */
15 EMPTY_INTERRUPT(SIG_COMPARATOR);
16
17 ISR(TIM0_OVF_vect)
18 {
19         xvar++;
20 }
21
22 /* for debugging purposes */
23 ISR(BADISR_vect) 
24 {
25 }
26
27
28 static void switch_idle(void)
29 {
30         sei();
31         set_sleep_mode(SLEEP_MODE_IDLE);
32         sleep_mode();
33 }
34
35 static void init_board(void)
36 {
37         power_adc_disable();
38         wdt_disable();
39         /* enable interal reference for 
40          * comparator 
41          * When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). */
42 }
43
44 int main(void)
45 {
46         
47         init_board();
48
49         xvar = 1;
50         cli();
51         TCCR0A = 0x00;
52         TCCR0B = (1 << CS00) | (1 << CS02);
53         TCNT0 = 0;
54         TIMSK |= (1 << TOIE0);
55         sei();
56
57         while(1) {
58
59                 /* set LRA as sensor and switch to idle mode
60                  * check back-EMF of LRA: if treshold is surpassed
61                  * comparator intterupt is triggered */
62 //              set_lra_as_sensor();
63 //              switch_idle(); 
64 //
65 //              /* board wakes up, set LRA as actuator and
66 //               * plays haptic effect */
67 //              set_lra_as_actuator();
68 //              play_haptic();
69
70         }
71
72 }