hbc: only use comp0a
[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_COMPA_vect)
18 {       
19         xvar++;
20 }
21
22 static void switch_idle(void)
23 {
24         sei();
25         set_sleep_mode(SLEEP_MODE_IDLE);
26         sleep_mode();
27 }
28
29 static void init_board(void)
30 {
31         power_adc_disable();
32         wdt_disable();
33         /* enable interal reference for 
34          * comparator 
35          * When the bandgap reference is connected to the Analog Comparator (by setting the ACBG bit in ACSR). */
36 }
37
38 int main(void)
39 {
40         init_board();
41         xvar = 1;       
42         cli();
43         DDRB |= (1 << DDB0); /* set PB0 as output */
44         TCCR0A = TCCR0B = 0;
45         TCCR0A |= (1 << WGM01) | (1 << WGM00) | (1 << COM0A1);
46         TCCR0B |= (1 << CS02) | (1 << CS00); /* clk/1024 prescaler */
47         OCR0A = 0x7F; /* 50% duty cycle */
48         TCNT0 = 0;
49         TIMSK = (1 << OCIE0A); /* enable interrupts for overflow and compare */
50         sei();
51
52         while(1) {
53                 _delay_ms(100);
54                 /* set LRA as sensor and switch to idle mode
55                  * check back-EMF of LRA: if treshold is surpassed
56                  * comparator intterupt is triggered */
57 //              set_lra_as_sensor();
58 //              switch_idle(); 
59 //
60 //              /* board wakes up, set LRA as actuator and
61 //               * plays haptic effect */
62 //              set_lra_as_actuator();
63 //              play_haptic();
64
65         }
66
67 }