2 #include <avr/interrupt.h>
6 static uint16_t button_start[N_BUTTONS];
7 static unsigned char button_pressed[N_BUTTONS];
11 // MCUCR |= _BV(ISC00); // any edge generates IRQ
12 // GIMSK |= _BV(INT0); // enable INT0
13 DDRB &= ~(_BV(PB6) | _BV(PB0));
14 PORTB |= _BV(PB6) | _BV(PB0);
19 extern unsigned char led1_counter;
21 void timer_check_buttons()
23 unsigned char pinb = PINB;
25 unsigned char port_states[N_BUTTONS] = {
29 for (i = 0; i < N_BUTTONS; i++) {
30 if (!port_states[i]) { // is pressed
31 if (button_pressed[i]) { // been already pressed
32 // TODO long button press
34 uint16_t duration = jiffies - button_start[i];
35 if (duration > 10 && duration < 40) {
36 gpio_set(GPIO_LED2, 1);
39 } else { // begin of button press
40 button_pressed[i] = 1;
41 button_start[i] = jiffies;
45 } else { // is not pressed
46 if (button_pressed[i]) { // just depressed
47 uint16_t duration = jiffies - button_start[i];
51 // led_set_number_pattern(N_PWMLEDS, 1 + (duration >> 3));
52 button_pressed[i] = 0;
56 break; // FIXME - delete this when btn1 is ready
63 unsigned char tmpval = PINB & _BV(PB6);
65 gpio_set(GPIO_LED2, tmpval);