2 #include <avr/interrupt.h>
4 #include <util/delay.h>
8 static uint16_t button_start[N_BUTTONS];
9 static unsigned char button_pressed[N_BUTTONS];
10 static unsigned char just_waked_up;
16 DDRA &= ~(_BV(PA3) | _BV(PA4));
17 PORTA |= _BV(PA3) | _BV(PA4);
19 for (i=0; i < N_BUTTONS; i++) {
21 button_pressed[i] = 0;
29 static void do_sleep()
35 gpio_before_poweroff(); // Set the status LED on again
37 while((PINA & _BV(PA3)) == 0)
38 ; // wait for button release
42 susp_gpio(); // disable the status LED
47 static void inline long_press(unsigned char n)
53 static void inline short_press(unsigned char n)
59 void timer_check_buttons()
61 unsigned char pin = PINA;
63 unsigned char port_states[N_BUTTONS] = {
68 for (i = 0; i < N_BUTTONS; i++) {
69 if (!port_states[i]) { // is pressed
70 if (i == 0 && just_waked_up)
72 if (button_pressed[i] == 0) {
73 // begin of button press
74 button_pressed[i] = 1;
75 button_start[i] = jiffies;
80 } else if (button_pressed[i] == 1) {
81 // been already pressed
82 uint16_t duration = jiffies - button_start[i];
85 button_pressed[i] = 2;
89 } else { // is not pressed
92 if (button_pressed[i]) { // just depressed
93 uint16_t duration = jiffies - button_start[i];
99 button_pressed[i] = 0;
100 if (duration > 6 && duration < 30)