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 static void inline long_press(unsigned char n)
26 static void inline short_press(unsigned char n)
31 void timer_check_buttons()
33 unsigned char pinb = PINB;
35 unsigned char port_states[N_BUTTONS] = {
39 for (i = 0; i < N_BUTTONS; i++) {
40 if (!port_states[i]) { // is pressed
41 if (button_pressed[i] == 0) {
42 // begin of button press
43 button_pressed[i] = 1;
44 button_start[i] = jiffies;
49 } else if (button_pressed[i] == 1) {
50 // been already pressed
51 uint16_t duration = jiffies - button_start[i];
54 button_pressed[i] = 2;
58 } else { // is not pressed
59 if (button_pressed[i]) { // just depressed
60 uint16_t duration = jiffies - button_start[i];
66 button_pressed[i] = 0;
67 if (duration > 6 && duration < 30)
77 unsigned char tmpval = PINB & _BV(PB6);
79 gpio_set(GPIO_LED2, tmpval);