2021-04-21 23:22:11 +02:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include "button.h"
|
|
|
|
|
2022-01-10 01:52:34 +01:00
|
|
|
// BUTTON0 PD0
|
|
|
|
// BUTTON1 PD1
|
|
|
|
// BUTTON2 PD5
|
|
|
|
// BUTTON3 PD6
|
|
|
|
// BUTTON4 PD7
|
|
|
|
// BUTTON5 PC0
|
|
|
|
// BUTTON6 PC4 (VFDRESET)
|
|
|
|
// BUTTON7 PC1
|
|
|
|
|
2021-04-21 23:22:11 +02:00
|
|
|
void button_init() {
|
2022-01-11 01:23:23 +01:00
|
|
|
// PD0, PD1, PD5, PD6, PD7, PC0, PC1: input, no pullup (button0..5,7)
|
2022-01-10 01:52:34 +01:00
|
|
|
PORTD &= ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
|
|
|
|
DDRD &= ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
|
|
|
|
PORTC &= ~(_BV(PC0) | _BV(PC1));
|
|
|
|
DDRC &= ~(_BV(PC0) | _BV(PC1));
|
2021-04-21 23:22:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t button_get() {
|
|
|
|
uint8_t pinc = PINC;
|
2022-01-10 01:52:34 +01:00
|
|
|
uint8_t pind = PIND;
|
2021-04-21 23:22:11 +02:00
|
|
|
uint8_t buttons = 0;
|
2022-01-10 01:52:34 +01:00
|
|
|
if (pind & _BV(PD0)) buttons |= _BV(0);
|
|
|
|
if (pind & _BV(PD1)) buttons |= _BV(1);
|
|
|
|
if (pind & _BV(PD5)) buttons |= _BV(2);
|
|
|
|
if (pind & _BV(PD6)) buttons |= _BV(3);
|
|
|
|
if (pind & _BV(PD7)) buttons |= _BV(4);
|
2021-04-21 23:22:11 +02:00
|
|
|
if (pinc & _BV(PC0)) buttons |= _BV(5);
|
2022-01-10 01:52:34 +01:00
|
|
|
//if (pinc & _BV(PC4)) buttons |= _BV(6);
|
|
|
|
if (pinc & _BV(PC1)) buttons |= _BV(7);
|
2021-04-21 23:22:11 +02:00
|
|
|
return buttons;
|
|
|
|
}
|