26 lines
797 B
C
26 lines
797 B
C
|
#include <avr/io.h>
|
||
|
#include "button.h"
|
||
|
|
||
|
void button_init() {
|
||
|
// PB2, PB3, PB4, PB5, PB6, PC0, PC1, PC4: input, no pullup (button0..7)
|
||
|
PORTB &= ~(_BV(PB2) | _BV(PB3) | _BV(PB4) | _BV(PB5) | _BV(PB6));
|
||
|
DDRB &= ~(_BV(PB2) | _BV(PB3) | _BV(PB4) | _BV(PB5) | _BV(PB6));
|
||
|
PORTC &= ~(_BV(PC0) | _BV(PC1) | _BV(PC4));
|
||
|
DDRC &= ~(_BV(PC0) | _BV(PC1) | _BV(PC4));
|
||
|
}
|
||
|
|
||
|
uint8_t button_get() {
|
||
|
uint8_t pinb = PINB;
|
||
|
uint8_t pinc = PINC;
|
||
|
uint8_t buttons = 0;
|
||
|
if (pinb & _BV(PB2)) buttons |= _BV(0);
|
||
|
if (pinb & _BV(PB3)) buttons |= _BV(1);
|
||
|
if (pinb & _BV(PB4)) buttons |= _BV(2);
|
||
|
if (pinb & _BV(PB5)) buttons |= _BV(3);
|
||
|
if (pinb & _BV(PB6)) buttons |= _BV(4);
|
||
|
if (pinc & _BV(PC0)) buttons |= _BV(5);
|
||
|
if (pinc & _BV(PC1)) buttons |= _BV(6);
|
||
|
if (pinc & _BV(PC4)) buttons |= _BV(7);
|
||
|
return buttons;
|
||
|
}
|