/*
 * key.c
 *
 *  Created on: 4 апр. 2016 г.
 *      Author: mvinogradov
 */
#include <avr/io.h>
#include <avr_helper.h>
#include "buttons.h"

void key_init(void)
{
DDR(KEY_PORT) &= ~KEY_ANY;
PORT(KEY_PORT) |= KEY_ANY;
DDR(KEY_FORWARD_PORT) &= ~KEY_FORWARD;
PORT(KEY_FORWARD_PORT) |= KEY_FORWARD;

DDR(INT_PORT)|= _BV(INT_PIN); // INT0 port configure as output not pullup
PORT(INT_PORT) &= ~_BV(INT_PIN);
}

uint8_t get_key(void){
   return (~PIN(KEY_PORT) & KEY_ANY) | ((PIN(KEY_FORWARD_PORT) & KEY_FORWARD) ? 0 : _BV(6));
    //return ~PIN(KEY_PORT) & KEY_ANY;
    //return PIN(KEY_FORWARD_PORT) & KEY_FORWARD ? 0 : _BV(6);
}
