2010-01-13 03:01:07 +00:00
|
|
|
#include "../config.h"
|
|
|
|
#include "../makros.h"
|
|
|
|
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
#include "borg_hw.h"
|
|
|
|
|
|
|
|
#define PIN_DATA PB4
|
|
|
|
#define PIN_CLK PB3
|
|
|
|
#define PIN_STR PB2
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// buffer which holds the currently shown frame
|
2010-01-13 03:01:07 +00:00
|
|
|
unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES];
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// switch to next row
|
|
|
|
static void nextrow(uint8_t row) {
|
|
|
|
// clear states of the preceding row
|
2010-01-13 03:01:07 +00:00
|
|
|
PORTC &= 0xF0;
|
|
|
|
PORTD &= 0x0F;
|
|
|
|
PORTB &= 0xFC;
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// short delay loop, to ensure proper deactivation of the drivers
|
2010-01-13 03:01:07 +00:00
|
|
|
unsigned char i;
|
2011-08-17 01:16:25 +00:00
|
|
|
for (i = 0; i < 10; i++) {
|
2010-01-13 03:01:07 +00:00
|
|
|
asm volatile("nop");
|
|
|
|
}
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
if (row == 0) {
|
|
|
|
// row 0: initialize first shift register
|
|
|
|
PORTB &= ~(1 << PIN_DATA); // row is active low
|
|
|
|
PORTB |= (1 << PIN_CLK);
|
|
|
|
PORTB &= ~(1 << PIN_CLK);
|
|
|
|
PORTB |= (1 << PIN_DATA);
|
|
|
|
} else {
|
|
|
|
// remaining rows: just shift forward
|
|
|
|
PORTB |= (1 << PIN_CLK);
|
|
|
|
PORTB &= ~(1 << PIN_CLK);
|
2010-01-13 03:01:07 +00:00
|
|
|
}
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// another delay loop, to ensure that the drivers are ready
|
|
|
|
for (i = 0; i < 20; i++) {
|
2010-01-13 03:01:07 +00:00
|
|
|
asm volatile("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// display a row
|
|
|
|
static void rowshow(unsigned char row, unsigned char plane) {
|
|
|
|
// depending on the currently drawn plane, display the row for a specific
|
|
|
|
// amount of time
|
|
|
|
static unsigned char const tcnt0_table[] = {244, 236, 206};
|
|
|
|
TCNT0 = tcnt0_table[plane];
|
2010-01-13 03:01:07 +00:00
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// output data of the current row to the column drivers
|
2010-01-13 03:01:07 +00:00
|
|
|
uint8_t tmp, tmp1;
|
2011-08-17 01:16:25 +00:00
|
|
|
tmp = pixmap[plane][row][0];
|
2010-01-13 03:01:07 +00:00
|
|
|
tmp1 = pixmap[plane][row][1];
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
PORTC = (PORTC & 0xF0) | (tmp & 0x0F);
|
|
|
|
PORTD = (PORTD & 0x0F) | (tmp & 0xF0);
|
|
|
|
PORTB = (PORTB & 0xFC) | (tmp1 & 0x03);
|
2010-01-13 03:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// depending on the plane this interrupt gets triggered at 50 kHz, 31.25 kHz or
|
|
|
|
// 12.5 kHz
|
2012-03-23 01:27:59 +00:00
|
|
|
ISR(TIMER0_OVF0_vect) {
|
2010-01-13 03:01:07 +00:00
|
|
|
static unsigned char plane = 0;
|
|
|
|
static unsigned char row = 0;
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// reset watchdog
|
2010-01-13 03:01:07 +00:00
|
|
|
wdt_reset();
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// increment both row and plane
|
|
|
|
if (++plane == NUMPLANE) {
|
|
|
|
plane = 0;
|
|
|
|
if (++row == NUM_ROWS) {
|
2010-01-13 03:01:07 +00:00
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
nextrow(row);
|
|
|
|
}
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// output current row according to current plane
|
2010-01-13 03:01:07 +00:00
|
|
|
rowshow(row, plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
void timer0_off() {
|
2010-01-13 03:01:07 +00:00
|
|
|
cli();
|
2011-08-17 01:16:25 +00:00
|
|
|
/*
|
|
|
|
COLPORT1 = 0;
|
|
|
|
COLPORT2 = 0;
|
|
|
|
ROWPORT = 0;
|
|
|
|
*/
|
2010-01-13 03:01:07 +00:00
|
|
|
TCCR0 = 0x00;
|
|
|
|
sei();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// initialize timer which triggers the interrupt
|
|
|
|
static void timer0_on() {
|
|
|
|
/* TCCR0: FOC0 WGM00 COM01 COM00 WGM01 CS02 CS01 CS00
|
|
|
|
CS02 CS01 CS00
|
|
|
|
0 0 0 stop
|
|
|
|
0 0 1 clk
|
|
|
|
0 1 0 clk/8
|
|
|
|
0 1 1 clk/64
|
|
|
|
1 0 0 clk/256
|
|
|
|
1 0 1 clk/1024
|
|
|
|
*/
|
|
|
|
TCCR0 = 0x03; // clk/64
|
|
|
|
TCNT0 = 0xFF - 20; // reset timer
|
|
|
|
TIMSK |= (1 << TOIE0); // compare match Interrupt on
|
2010-01-13 03:01:07 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
void borg_hw_init() {
|
|
|
|
// set required pins to output mode
|
|
|
|
DDRC = 0x0F; // PC0-3 - Row 0-3
|
|
|
|
DDRD = 0xF4; // PD4-7 - Row 4-7 PD2 - ground for joy
|
|
|
|
DDRB = 0x1F; // PB0-1 - Row 8-9 PB2-3 - STR, CLK, d
|
|
|
|
|
|
|
|
// turn off all columns for now, clk off, d and str on
|
|
|
|
// PC4-5, PD013 pullup on
|
|
|
|
PORTC = 0x30;
|
|
|
|
PORTD = 0x0B;
|
|
|
|
PORTB = 0x14;
|
|
|
|
|
2010-01-13 03:01:07 +00:00
|
|
|
timer0_on();
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// activate watchdog timer
|
2010-01-13 03:01:07 +00:00
|
|
|
wdt_reset();
|
2011-08-17 01:16:25 +00:00
|
|
|
wdt_enable(0x00); // 17ms watchdog
|
2010-01-13 03:01:07 +00:00
|
|
|
}
|