display: changed pin mapping to fixed pcb, fixed fuse bits

This commit is contained in:
Gregor Riepl 2022-01-10 01:52:34 +01:00
parent 93e28f79a6
commit 20cf35bbd1
4 changed files with 60 additions and 78 deletions

View file

@ -25,9 +25,9 @@ DEFS = -DF_CPU=16000000UL -DHAS_CAN_CONFIG_H
INCLUDES = -I. -I$(PROJ_ROOT) -I$(AVRCANLIB_PATH)
LIBS =
LFUSE = 0xdf
HFUSE = 0xd9
EFUSE = 0xfe
LFUSE = 0xfe
HFUSE = 0xdf
EFUSE = 0xff
EXTRA_CLEAN_FILES =

View file

@ -1,25 +1,34 @@
#include <avr/io.h>
#include "button.h"
// BUTTON0 PD0
// BUTTON1 PD1
// BUTTON2 PD5
// BUTTON3 PD6
// BUTTON4 PD7
// BUTTON5 PC0
// BUTTON6 PC4 (VFDRESET)
// BUTTON7 PC1
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));
// PD0, PD1, PD5, PD6, PD7, PC0, PC1: input, no pullup (button0..6,7)
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));
}
uint8_t button_get() {
uint8_t pinb = PINB;
uint8_t pinc = PINC;
uint8_t pind = PIND;
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 (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);
if (pinc & _BV(PC0)) buttons |= _BV(5);
if (pinc & _BV(PC1)) buttons |= _BV(6);
if (pinc & _BV(PC4)) buttons |= _BV(7);
//if (pinc & _BV(PC4)) buttons |= _BV(6);
if (pinc & _BV(PC1)) buttons |= _BV(7);
return buttons;
}

View file

@ -2,6 +2,19 @@
#include <util/delay.h>
#include "display.h"
// VFDDB0 PB0
// VFDDB1 PB1
// VFDDB2 PB2
// VFDDB3 PB3
// VFDDB4 PB4
// VFDDB5 PB5
// VFDDB6 PB6
// VFDDB7 PB7
// VFDRS PC5
// VFDRW PC6
// VFDE PC7
// VFDRST (PC4)
// maximum wait time until busy should be deasserted
// bail out if it takes longer than that
// unit: 10us (roughly)
@ -10,13 +23,12 @@
void display_init() {
// PC5, PC6, PC7: output (VFD RS, RW, E), RS=0, RW=1, E=1
// PB0, PB1, PB7, PD0, PD1, PD5, PD6, PD7: output (VFD DB) - can be switched to input (pullup not needed)
PORTB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB7));
DDRB |= _BV(PB0) | _BV(PB1) | _BV(PB7);
// PC4: output, active low (VFD RESET), unused in display v2
// PB0..7: output (VFD DB) - can be switched to input (pullup not needed)
PORTB = 0x00;
DDRB = 0xff;
PORTC |= _BV(PC6) | _BV(PC7);
DDRC |= _BV(PC5) | _BV(PC6) | _BV(PC7);
PORTD &= ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
DDRD |= _BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7);
display_wait_ready();
_delay_ms(100);
@ -49,40 +61,26 @@ static void display_set_e(bool on) {
}
}
static void display_set_reset(bool on) {
if (on) {
PORTC |= _BV(PC4);
} else {
PORTC &= ~_BV(PC4);
}
}
static void display_set_data(uint8_t data) {
uint8_t datab = PORTB & ~(_BV(PB0) | _BV(PB1) | _BV(PB7));
uint8_t datad = PORTD & ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
datab |= (data & _BV(2)) ? _BV(PB0) : 0;
datab |= (data & _BV(3)) ? _BV(PB1) : 0;
datab |= (data & _BV(4)) ? _BV(PB7) : 0;
datad |= (data & _BV(0)) ? _BV(PD0) : 0;
datad |= (data & _BV(1)) ? _BV(PD1) : 0;
datad |= (data & _BV(5)) ? _BV(PD5) : 0;
datad |= (data & _BV(6)) ? _BV(PD6) : 0;
datad |= (data & _BV(7)) ? _BV(PD7) : 0;
PORTB = datab;
PORTD = datad;
PORTB = data;
}
static uint8_t display_get_data() {
uint8_t datab = PINB;
uint8_t datad = PIND;
uint8_t data = 0;
data |= (datad & _BV(PD0)) ? _BV(0) : 0;
data |= (datad & _BV(PD1)) ? _BV(1) : 0;
data |= (datad & _BV(PD5)) ? _BV(5) : 0;
data |= (datad & _BV(PD6)) ? _BV(6) : 0;
data |= (datad & _BV(PD7)) ? _BV(7) : 0;
data |= (datab & _BV(PB0)) ? _BV(2) : 0;
data |= (datab & _BV(PB1)) ? _BV(3) : 0;
data |= (datab & _BV(PB7)) ? _BV(4) : 0;
uint8_t data = PINB;
return data;
}
uint8_t display_read_ir() {
// switch PD to input
DDRB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB7));
DDRD &= ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
DDRB = 0x00;
// E=0 (enable/clock) RS=0 (IR) RW=1 (read)
PORTC = (PORTC & ~(_BV(PC5) | _BV(PC7))) | _BV(PC6);
_delay_us(0.23);
@ -90,33 +88,20 @@ uint8_t display_read_ir() {
PORTC |= _BV(PC7);
_delay_us(0.16);
// read inputs
uint8_t datab = PINB;
uint8_t datad = PIND;
uint8_t data = PINB;
_delay_us(0.23 - 0.16);
// E=0 (enable/clock)
PORTC &= ~_BV(PC7);
_delay_us(0.01);
// reset to idle / output
PORTC = _BV(PC6) | _BV(PC7);
DDRB |= _BV(PB0) | _BV(PB1) | _BV(PB7);
DDRD |= _BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7);
// reassemble data
uint8_t data = 0;
data |= (datad & _BV(PD0)) ? _BV(0) : 0;
data |= (datad & _BV(PD1)) ? _BV(1) : 0;
data |= (datad & _BV(PD5)) ? _BV(5) : 0;
data |= (datad & _BV(PD6)) ? _BV(6) : 0;
data |= (datad & _BV(PD7)) ? _BV(7) : 0;
data |= (datab & _BV(PB0)) ? _BV(2) : 0;
data |= (datab & _BV(PB1)) ? _BV(3) : 0;
data |= (datab & _BV(PB7)) ? _BV(4) : 0;
DDRB = 0xff;
return data;
}
uint8_t display_read_dr() {
// switch PD to input
DDRB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB7));
DDRD &= ~(_BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7));
DDRB = 0x00;
// E=0 (enable/clock) RS=1 (IR) RW=1 (read)
PORTC = (PORTC & ~_BV(PC7)) | (_BV(PC5) | _BV(PC6));
_delay_us(0.23);
@ -124,26 +109,14 @@ uint8_t display_read_dr() {
PORTC |= _BV(PC7);
_delay_us(0.16);
// read inputs
uint8_t datab = PINB;
uint8_t datad = PIND;
uint8_t data = PINB;
_delay_us(0.23 - 0.16);
// E=0 (enable/clock)
PORTC &= ~_BV(PC7);
_delay_us(0.01);
// reset to idle / output
PORTC = _BV(PC6) | _BV(PC7);
DDRB |= _BV(PB0) | _BV(PB1) | _BV(PB7);
DDRD |= _BV(PD0) | _BV(PD1) | _BV(PD5) | _BV(PD6) | _BV(PD7);
// reassemble data
uint8_t data = 0;
data |= (datad & _BV(PD0)) ? _BV(0) : 0;
data |= (datad & _BV(PD1)) ? _BV(1) : 0;
data |= (datad & _BV(PD5)) ? _BV(5) : 0;
data |= (datad & _BV(PD6)) ? _BV(6) : 0;
data |= (datad & _BV(PD7)) ? _BV(7) : 0;
data |= (datab & _BV(PB0)) ? _BV(2) : 0;
data |= (datab & _BV(PB1)) ? _BV(3) : 0;
data |= (datab & _BV(PB7)) ? _BV(4) : 0;
DDRB = 0xff;
return data;
}

View file

@ -236,7 +236,7 @@ static void test2() {
int main() {
init();
while (1) {
loop();
//test();
//loop();
test();
}
}