Subversion Repositories Projects

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/****************************************************************************
 *   Copyright (C) 2011 by Claas Anders "CaScAdE" Rathje                    *
 *   admiralcascade@gmail.com                                               *
 *   Project-URL: http://www.mylifesucks.de/oss/c-epilepsy/                 *
 *                                                                          *
 *   This program is free software; you can redistribute it and/or modify   *
 *   it under the terms of the GNU General Public License as published by   *
 *   the Free Software Foundation; either version 2 of the License.         *
 *                                                                          *
 *   This program is distributed in the hope that it will be useful,        *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
 *   GNU General Public License for more details.                           *
 *                                                                          *
 *   You should have received a copy of the GNU General Public License      *
 *   along with this program; if not, write to the                          *
 *   Free Software Foundation, Inc.,                                        *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.              *
 ****************************************************************************/


#include "buttons.h"

volatile uint8_t BUTTONS;

void buttons_init() {
    DDRD &= ~((1 << PD4) | (1 << PD5)); // switches are input
    PORTD |= ((1 << PD4) | (1 << PD5)); // pullups for switches

    // unmask pin change interrupts 28 and 29
    PCMSK3 |= ((1 << PCINT28) | (1 << PCINT29));

    // enable PCINT31..24
    PCICR |= (1 << PCIE3);
}

ISR(PCINT3_vect) {
    uint8_t raw = PIND; // for different buttons
    // mode
    if (!(raw & (1 << MODE))) {
        BUTTONS |= (1 << MODE);
    }
    // set
    if (!(raw & (1 << SET))) {
        BUTTONS |= (1 << SET);
    }
}

uint8_t mode_pressed() {
    if (BUTTONS & (1 << MODE)) {
        BUTTONS &= ~(1 << MODE);
        CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM;
        return 1;
    }
    return 0;
}

uint8_t set_pressed() {
    if (BUTTONS & (1 << SET)) {
        BUTTONS &= ~(1 << SET);
        CEPILEPSYFLAGS |= CEPI_DIRTYEEPROM;
        return 1;
    }
    return 0;
}