2 #include <avr/interrupt.h>
7 static uint16_t button_start[N_BUTTONS];
8 static unsigned char button_pressed[N_BUTTONS];
10 static unsigned char sleep_after_release;
14 DDRB &= ~(_BV(PB6) | _BV(PB0));
15 PORTB |= _BV(PB6) | _BV(PB0);
17 sleep_after_release = 0;
21 static void inline long_press(unsigned char n)
23 sleep_after_release = 1;
27 static void do_sleep()
30 // MCUCR |= _BV(ISC00); // any edge generates IRQ
33 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
38 GIMSK |= _BV(INT0); // enable INT0
44 GIMSK &= ~_BV(INT0); // disable INT0
48 static void inline short_press(unsigned char n)
53 void timer_check_buttons()
55 unsigned char pinb = PINB;
57 unsigned char port_states[N_BUTTONS] = {
61 for (i = 0; i < N_BUTTONS; i++) {
62 if (!port_states[i]) { // is pressed
63 if (button_pressed[i] == 0) {
64 // begin of button press
65 button_pressed[i] = 1;
66 button_start[i] = jiffies;
71 } else if (button_pressed[i] == 1) {
72 // been already pressed
73 uint16_t duration = jiffies - button_start[i];
76 button_pressed[i] = 2;
80 } else { // is not pressed
81 if (button_pressed[i]) { // just depressed
82 uint16_t duration = jiffies - button_start[i];
88 button_pressed[i] = 0;
89 if (duration > 6 && duration < 30)
91 if (sleep_after_release)