#include #include #include "bughal.h" #include "util.h" //for timer /* Hardware abstraction layer for Pentabug hardware */ /* * initialize LEDs on C0-C3 */ static uint8_t oldinput; // button readings from last poll cycle static uint8_t curinput; // button readings from current poll cycle //each switch has its own state machine static uint8_t btnstates[BTN_BUTTONS]; //array for current button states static uint8_t btncounters[BTN_BUTTONS]; //individual counter for button state machine static timer_t btntimers[BTN_BUTTONS]; //individiual timer for for button state machine void init_leds(void){ //enable LED channels as output DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3); // both LEDs off PORTC &= ~((1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3)); //TCCR2A = (1 << WGM21); //TCCR2B = (1 << CS20)|(1 << CS21); //OCR2A = 255; /* TOP */ // TCNT2 = 0; // /*enable interrupt*/ // TIMSK2 |= (1< BTN_T_LONGFACT){ //500ms held btnstates[i] = BTNST_LDN; } } else { //button was released btnstates[i] = BTNST_SUP; //signal shortclick } break; case BTNST_LDN: //is longpressed and still held down if (!(curinput & (1< going to shortpress btncounters[i]++; btnstates[i] = BTNST_SDN; //starting over from short pressed } else { btnstates[i] = BTNST_SUP; //nope, it was bouncing, back to old state } break; case BTNST_LUPDBNC: //Button was pressed again after beeing short pressed(or is bouncing) if ((curinput & (1< going to shortpress btncounters[i]++; btnstates[i] = BTNST_SDN; //starting over from short pressed } else { btnstates[i] = BTNST_LUP; //nope, it was bouncing, back to old state } break; default: //curently catches nothing // do nothing yet ; } //end switch timer_set(&btntimers[i], BTN_T_DEBOUNCE); } void button_poll(){ curinput = ~(PIND & 0b00000011); for(uint8_t i=0; i