2009-06-19 21:09:08 +00:00
|
|
|
#include"../autoconf.h"
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
#include "borg_hw.h"
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
/* pinout of the ribbon cable connected to the panel
|
|
|
|
* (the numbering is actually upside down)
|
2009-06-19 21:09:08 +00:00
|
|
|
*
|
|
|
|
* 1-3 GND
|
2011-08-17 01:16:25 +00:00
|
|
|
* 4 +5V for logic
|
2009-06-19 21:09:08 +00:00
|
|
|
* 5-8 +12V
|
|
|
|
* 9-10 GND
|
|
|
|
* 11 CP3
|
|
|
|
* 12 CP2
|
|
|
|
* 13 CP1
|
|
|
|
* 14 /show
|
|
|
|
* 15 CP4
|
|
|
|
* 16 /EO3
|
|
|
|
* 17-18 GND
|
|
|
|
* 19-26 D0-D7
|
|
|
|
*
|
2011-08-17 01:16:25 +00:00
|
|
|
* and now the right way round:
|
2009-06-19 21:09:08 +00:00
|
|
|
* 1 D7
|
|
|
|
* 2 D6
|
|
|
|
* 3 D5
|
|
|
|
* 4 D4
|
|
|
|
* 5 D3
|
|
|
|
* 6 D2
|
|
|
|
* 7 D1
|
|
|
|
* 8 D0
|
|
|
|
* 9 GND
|
|
|
|
* 10 GND
|
|
|
|
* 11 /EO3
|
|
|
|
* 12 CP4
|
|
|
|
* 13 /show
|
|
|
|
* 14 CP1
|
|
|
|
* 15 CP2
|
|
|
|
* 16 CP3
|
|
|
|
* 17 GND
|
|
|
|
* 18 GND
|
|
|
|
* 19 +12V
|
|
|
|
* 20 +12V
|
|
|
|
* 21 +12V
|
|
|
|
* 22 +12V
|
|
|
|
* 23 +5V
|
|
|
|
* 24 GND
|
|
|
|
* 25 GND
|
|
|
|
* 26 GND
|
|
|
|
*
|
2011-08-17 01:16:25 +00:00
|
|
|
* Four 40374 latches are used. No. 1, 2 and 4 drive from the data bus to the
|
|
|
|
* panel, no. 3 drives from the button outputs to the data bus. The EOs of
|
|
|
|
* 1, 2 and 4 are hardwired to GND.
|
2009-06-19 21:09:08 +00:00
|
|
|
*
|
2011-08-17 01:16:25 +00:00
|
|
|
* The LEDs are aligned to a 12*16 matrix. The values for the LED columns are
|
|
|
|
* passed to the latches via CP1 und CP2 (16 columns total). The index of the
|
|
|
|
* row is passed during the deletion of "/show".
|
2009-06-19 21:09:08 +00:00
|
|
|
*
|
2011-08-17 01:16:25 +00:00
|
|
|
* The buttons are aligned to an 8*8 matrix. The rows get separately set to
|
|
|
|
* "high" via latch 4. The columns can then be read via latch 3.
|
2009-06-19 21:09:08 +00:00
|
|
|
*/
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// data port for the panel
|
2009-06-19 21:09:08 +00:00
|
|
|
#define COLPORT PORTC
|
|
|
|
#define COLDDR DDRC
|
|
|
|
#define COLPIN PINC
|
|
|
|
|
|
|
|
#define CTRLPORT PORTD
|
|
|
|
#define CTRLDDR DDRD
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// pins on CTRLPORT
|
2009-06-19 21:09:08 +00:00
|
|
|
#define PIN_EO3 PD7
|
|
|
|
#define PIN_CP4 PD2
|
|
|
|
#define PIN_SHOW PD3
|
|
|
|
#define PIN_CP1 PD4
|
|
|
|
#define PIN_CP2 PD5
|
|
|
|
#define PIN_CP3 PD6
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
// buffer which holds the currently shown frame
|
2009-06-19 21:09:08 +00:00
|
|
|
unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES];
|
|
|
|
|
|
|
|
volatile uint8_t keys[8];
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
2009-06-19 21:09:08 +00:00
|
|
|
inline void busywait() {
|
|
|
|
//unsigned char i;
|
2011-08-17 01:16:25 +00:00
|
|
|
//for(i=0; i < 20; i++){
|
2009-06-19 21:09:08 +00:00
|
|
|
// asm volatile("nop");
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// display a row
|
2009-06-19 21:09:08 +00:00
|
|
|
inline void rowshow(unsigned char row, unsigned char plane){
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT |= (1 << PIN_SHOW); //blank
|
|
|
|
|
|
|
|
COLPORT = pixmap[plane][row][0];
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT |= (1 << PIN_CP1);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_CP1);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
COLPORT = pixmap[plane][row][1];
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT |= (1 << PIN_CP2);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_CP2);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
COLPORT = row;
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_SHOW);
|
2009-06-19 21:09:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
2009-06-19 21:09:08 +00:00
|
|
|
inline void checkkeys(uint8_t row){
|
|
|
|
static uint8_t mask;
|
2011-08-17 01:16:25 +00:00
|
|
|
if (row == 0) {
|
2009-06-19 21:09:08 +00:00
|
|
|
mask = 1;
|
2011-08-17 01:16:25 +00:00
|
|
|
} else {
|
2009-06-19 21:09:08 +00:00
|
|
|
//read keyboard cols into latch
|
|
|
|
COLDDR = 0;
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_EO3);
|
|
|
|
CTRLPORT |= (1 << PIN_CP3);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_CP3);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
keys[row - 1] = COLPIN;
|
|
|
|
CTRLPORT |= (1 << PIN_EO3);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
|
|
|
COLDDR = 0xFF;
|
|
|
|
}
|
2011-08-17 01:16:25 +00:00
|
|
|
|
|
|
|
COLPORT = mask;
|
2009-06-19 21:09:08 +00:00
|
|
|
mask <<= 1;
|
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT |= (1 << PIN_CP4);
|
2009-06-19 21:09:08 +00:00
|
|
|
busywait();
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT &= ~(1 << PIN_CP4);
|
2009-06-19 21:09:08 +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_COMP_vect)
|
2009-06-19 21:09:08 +00:00
|
|
|
{
|
|
|
|
static unsigned char plane = 0;
|
|
|
|
static unsigned char row = 0;
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// reset watchdog
|
2009-06-19 21:09:08 +00:00
|
|
|
wdt_reset();
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// output current row according to current plane
|
2009-06-19 21:09:08 +00:00
|
|
|
rowshow(row, plane);
|
|
|
|
|
|
|
|
if( (plane == 2) && (row<9) ) checkkeys(row);
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// increment both row and plane
|
2009-06-19 21:09:08 +00:00
|
|
|
if(++row == NUM_ROWS){
|
|
|
|
row = 0;
|
|
|
|
if(++plane==NUMPLANE) plane=0;
|
|
|
|
switch(plane){
|
|
|
|
case 0:
|
|
|
|
OCR0 = 5;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
OCR0 = 12;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
OCR0 = 20;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void timer0_off(){
|
|
|
|
cli();
|
|
|
|
|
|
|
|
TCCR0 = 0x00;
|
|
|
|
sei();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// initialize timer which triggers the interrupt
|
2009-06-19 21:09:08 +00:00
|
|
|
void timer0_on(){
|
2011-08-17 01:16:25 +00:00
|
|
|
/* 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 = 0x0C; // CTC Mode, clk/64
|
|
|
|
TCNT0 = 0; // reset timer
|
|
|
|
OCR0 = 20; // compare with this value
|
|
|
|
TIMSK = 0x02; // compare match Interrupt on
|
2009-06-19 21:09:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
|
2009-06-19 21:09:08 +00:00
|
|
|
void borg_hw_init(){
|
|
|
|
//Pins am Zeilenport auf Ausgang
|
2011-08-17 01:16:25 +00:00
|
|
|
CTRLPORT |= (1 << PIN_EO3) | (1 << PIN_SHOW);
|
|
|
|
CTRLDDR |= (1 << PIN_EO3) | (1 << PIN_CP4) | (1 << PIN_SHOW)
|
|
|
|
| (1 << PIN_CP1) | (1 << PIN_CP2) | (1 << PIN_CP3);
|
|
|
|
|
|
|
|
// switch off all columns for now
|
|
|
|
// switch column ports to output mode
|
|
|
|
COLDDR = 0xFF;
|
2009-06-19 21:09:08 +00:00
|
|
|
COLPORT = 0x00;
|
2011-08-17 01:16:25 +00:00
|
|
|
|
2009-06-19 21:09:08 +00:00
|
|
|
timer0_on();
|
|
|
|
|
2011-08-17 01:16:25 +00:00
|
|
|
// activate watchdog timer
|
2009-06-19 21:09:08 +00:00
|
|
|
wdt_reset();
|
2011-08-17 01:16:25 +00:00
|
|
|
wdt_enable(0x00); // 17ms watchdog
|
2009-06-19 21:09:08 +00:00
|
|
|
}
|