2013-09-05 22:13:51 +02:00
|
|
|
#include <pentabug/matrix.h>
|
|
|
|
|
|
|
|
#include <pentabug/timer.h>
|
|
|
|
#include <pentabug/hal.h>
|
|
|
|
|
2013-09-08 08:50:40 +02:00
|
|
|
static uint8_t pixels[9] = {0};
|
2013-09-05 22:13:51 +02:00
|
|
|
static uint8_t index;
|
2013-09-08 08:50:40 +02:00
|
|
|
static uint8_t cycle;
|
2013-09-05 22:13:51 +02:00
|
|
|
|
|
|
|
void matrix_init(void) {
|
|
|
|
DDRD |= (1 << 5) | (1 << 6) | (1 << 7);
|
|
|
|
DDRC |= (1 << 4) | (1 << 5);
|
|
|
|
DDRB |= 1 << 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void move_line(uint8_t line) {
|
2013-09-07 12:08:57 +02:00
|
|
|
PORTD |= 0xe0;
|
|
|
|
PORTD &= ~(1 << (line + 5));
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|
2013-09-08 08:50:40 +02:00
|
|
|
static void write_line(uint8_t data[], uint8_t timing) {
|
2013-09-07 12:08:57 +02:00
|
|
|
PORTC &= ~((1 << 5) | (1 << 4));
|
|
|
|
PORTB &= ~(1 << 2);
|
2013-09-05 22:13:51 +02:00
|
|
|
|
2013-09-08 08:50:40 +02:00
|
|
|
if(data[0] > timing) {
|
2013-09-07 12:08:57 +02:00
|
|
|
PORTC |= 1 << 5;
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|
2013-09-08 08:50:40 +02:00
|
|
|
if(data[1] > timing) {
|
2013-09-07 12:08:57 +02:00
|
|
|
PORTC |= 1 << 4;
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|
2013-09-08 08:50:40 +02:00
|
|
|
if(data[2] > timing) {
|
2013-09-07 12:08:57 +02:00
|
|
|
PORTB |= 1 << 2;
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void matrix_int(void) {
|
|
|
|
++index;
|
|
|
|
|
|
|
|
if(index >= 3) {
|
2013-09-08 08:50:40 +02:00
|
|
|
++cycle;
|
2013-09-05 22:13:51 +02:00
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
move_line(index);
|
2013-09-08 08:50:40 +02:00
|
|
|
write_line(pixels + (index * 3), cycle & 3);
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void matrix_start(void) {
|
|
|
|
matrix_init();
|
2013-09-08 08:50:40 +02:00
|
|
|
start_timer(PRESCALE_64, 32, matrix_int);
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void matrix_stop(void) {
|
|
|
|
stop_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void matrix_show(void) {
|
2013-09-08 08:50:40 +02:00
|
|
|
for(uint8_t n = 0; n < 4; ++n) {
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
for(i = 0; i < 3; ++i) {
|
|
|
|
move_line(i);
|
|
|
|
write_line(pixels + (i * 3), n);
|
|
|
|
wait_ms(1);
|
|
|
|
}
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void matrix_set(uint8_t x, uint8_t y, uint8_t active) {
|
2013-09-08 08:50:40 +02:00
|
|
|
pixels[x*3+y] = active ? 4 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void matrix_brightness(uint8_t x, uint8_t y, uint8_t brightness) {
|
|
|
|
pixels[x*3+y] = brightness;
|
2013-09-05 22:13:51 +02:00
|
|
|
}
|
|
|
|
|