Moved VFD buttons to separate module

This commit is contained in:
Gregor Riepl 2021-04-21 23:22:11 +02:00
parent ec2e7ae044
commit c5b29bdee2
4 changed files with 34 additions and 23 deletions

View file

@ -1,7 +1,7 @@
PRG = display PRG = display
PROJ_ROOT = ../.. PROJ_ROOT = ../..
AVRCANLIB_PATH = $(PROJ_ROOT)/avr-can-lib AVRCANLIB_PATH = $(PROJ_ROOT)/avr-can-lib
OBJ = main.o display.o \ OBJ = main.o display.o button.o \
$(AVRCANLIB_PATH)/src/at90can_buffer.o \ $(AVRCANLIB_PATH)/src/at90can_buffer.o \
$(AVRCANLIB_PATH)/src/at90can.o \ $(AVRCANLIB_PATH)/src/at90can.o \
$(AVRCANLIB_PATH)/src/at90can_disable_dyn_filter.o \ $(AVRCANLIB_PATH)/src/at90can_disable_dyn_filter.o \

25
display/firmware/button.c Normal file
View file

@ -0,0 +1,25 @@
#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;
}

View file

@ -0,0 +1,5 @@
#include <stdint.h>
void button_init();
uint8_t button_get();

View file

@ -6,11 +6,11 @@
#include <can.h> #include <can.h>
#include <messages.h> #include <messages.h>
#include "display.h" #include "display.h"
#include "button.h"
static bool report_change = false; static bool report_change = false;
static void init(); static void init();
static uint8_t get_buttons();
static void send_status(); static void send_status();
static void loop(); static void loop();
@ -40,11 +40,7 @@ static void loop();
static void init() { static void init() {
// initialize buttons // initialize buttons
// PB2, PB3, PB4, PB5, PB6, PC0, PC1, PC4: input, no pullup (button0..7) button_init();
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));
// initialize VFD // initialize VFD
display_init(); display_init();
@ -79,23 +75,8 @@ static void init() {
sei(); sei();
} }
static uint8_t get_buttons() {
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;
}
static void send_status() { static void send_status() {
uint8_t status = get_buttons(); uint8_t status = button_get();
if (can_check_free_buffer()) { if (can_check_free_buffer()) {
can_t msg = { can_t msg = {