92 lines
2.2 KiB
C
92 lines
2.2 KiB
C
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
|
|
#include "franzis_pp.h"
|
|
#include "framebuffer.h"
|
|
|
|
void __attribute__ ((naked)) __attribute__ ((section (".init6"))) franzis_pingpong_init() {
|
|
ROW0_DDR |= (1 << ROW0_PIN);
|
|
ROW1_DDR |= (1 << ROW1_PIN);
|
|
ROW2_DDR |= (1 << ROW2_PIN);
|
|
ROW3_DDR |= (1 << ROW3_PIN);
|
|
ROW4_DDR |= (1 << ROW4_PIN);
|
|
ROW5_DDR |= (1 << ROW5_PIN);
|
|
ROW6_DDR |= (1 << ROW6_PIN);
|
|
ROW7_DDR |= (1 << ROW7_PIN);
|
|
ROW8_DDR |= (1 << ROW8_PIN);
|
|
ROW9_DDR |= (1 << ROW9_PIN);
|
|
|
|
COLS_DDR |= (1 << COLS_STR);
|
|
COLS_DDR |= (1 << COLS_DATA);
|
|
COLS_DDR |= (1 << COLS_CLK);
|
|
|
|
ROW2_PORT |= (1 << ROW2_PIN);
|
|
|
|
COLS_PORT |= (1 << COLS_CLK);
|
|
|
|
TCCR2 = (1 << CS22);
|
|
TIMSK = (1 << TOIE2);
|
|
|
|
sei();
|
|
}
|
|
|
|
void franzis_pingpong_push(uint16_t data) {
|
|
COLS_PORT |= (1 << COLS_STR);
|
|
|
|
uint8_t i;
|
|
for (i = 0; i<=11; i++) {
|
|
COLS_PORT &= ~(1 << COLS_CLK);
|
|
if (data & 1) {
|
|
COLS_PORT &= ~(1 << COLS_DATA);
|
|
} else {
|
|
COLS_PORT |= (1 << COLS_DATA);
|
|
}
|
|
COLS_PORT |= (1 << COLS_CLK);
|
|
data = data >> 1;
|
|
}
|
|
|
|
COLS_PORT &= ~(1 << COLS_STR);
|
|
}
|
|
|
|
void franzis_pingpong_clear_row() {
|
|
ROW0_PORT &= ~(1 << ROW0_PIN);
|
|
ROW1_PORT &= ~(1 << ROW1_PIN);
|
|
ROW2_PORT &= ~(1 << ROW2_PIN);
|
|
ROW3_PORT &= ~(1 << ROW3_PIN);
|
|
ROW4_PORT &= ~(1 << ROW4_PIN);
|
|
ROW5_PORT &= ~(1 << ROW5_PIN);
|
|
ROW6_PORT &= ~(1 << ROW6_PIN);
|
|
ROW7_PORT &= ~(1 << ROW7_PIN);
|
|
ROW8_PORT &= ~(1 << ROW8_PIN);
|
|
ROW9_PORT &= ~(1 << ROW9_PIN);
|
|
}
|
|
|
|
void franzis_pingpong_select_row(uint8_t row) {
|
|
switch(row) {
|
|
case 0: ROW0_PORT |= (1 << ROW0_PIN); break;
|
|
case 1: ROW1_PORT |= (1 << ROW1_PIN); break;
|
|
case 2: ROW2_PORT |= (1 << ROW2_PIN); break;
|
|
case 3: ROW3_PORT |= (1 << ROW3_PIN); break;
|
|
case 4: ROW4_PORT |= (1 << ROW4_PIN); break;
|
|
case 5: ROW5_PORT |= (1 << ROW5_PIN); break;
|
|
case 6: ROW6_PORT |= (1 << ROW6_PIN); break;
|
|
case 7: ROW7_PORT |= (1 << ROW7_PIN); break;
|
|
case 8: ROW8_PORT |= (1 << ROW8_PIN); break;
|
|
case 9: ROW9_PORT |= (1 << ROW9_PIN); break;
|
|
}
|
|
}
|
|
|
|
uint8_t fb_nextrow = 0;
|
|
|
|
ISR(TIMER2_OVF_vect) {
|
|
franzis_pingpong_clear_row();
|
|
|
|
uint16_t data = ( framebuffer[fb_nextrow][0] ) | ( framebuffer[fb_nextrow][1] << 8);
|
|
franzis_pingpong_push(data);
|
|
|
|
franzis_pingpong_select_row(fb_nextrow);
|
|
|
|
fb_nextrow++;
|
|
fb_nextrow = fb_nextrow % 10;
|
|
}
|