src/switch.c
author Tero Marttila <terom@paivola.fi>
Wed, 08 Oct 2014 23:20:19 +0300
changeset 10 d485c5b3ab4d
parent 8 61eba9d55764
permissions -rw-r--r--
spi: mixture of old spi_update and new spi_readwrite interfaces, using spi mode3 for adxl345
#include "stdlib.h"
//#include "switch.h"

#include <avr/io.h>
#include <avr/interrupt.h>

byte switch_mask;
byte switch_status;
byte switch_state;

ISR(PCINT0_vect)
{
    switch_status = 1;
    switch_state = PINB;
}

ISR(PCINT1_vect)
{
    switch_status = 1;
    switch_state = PINC;
}

ISR(PCINT2_vect)
{
    switch_status = 1;
    switch_state = PIND;
}

byte switch_read (byte *sp)
{
    if (!switch_status)
        return 0;

    switch_status = 0;

    *sp = ~switch_state & switch_mask;

    return 1;
}