|
|
@ -1,6 +1,7 @@ |
|
|
|
#include "../config.h" |
|
|
|
#include "../makros.h" |
|
|
|
|
|
|
|
#include <stdbool.h> |
|
|
|
#include <avr/interrupt.h> |
|
|
|
#include <avr/io.h> |
|
|
|
#include <avr/wdt.h> |
|
|
@ -21,23 +22,27 @@ |
|
|
|
# define TIMER0_COMPARE(t) OCR0A = t |
|
|
|
# define TIMER0_INT_ENABLE() TIMSK0 = _BV(OCIE0A) |
|
|
|
# define TIMER0_ISR TIMER0_COMPA_vect |
|
|
|
#else // ATmega8
|
|
|
|
#elif defined(__AVR_ATmega8__) || \ |
|
|
|
defined(__AVR_ATmega8A__) // ATmega8
|
|
|
|
# define TIMER0_OFF() TCCR0 = 0 |
|
|
|
# define TIMER0_MODE_CS256() TCCR0 = _BV(CS02) |
|
|
|
# define TIMER0_RESET() TCNT0 = 0 |
|
|
|
# define TIMER0_COMPARE(t) TCNT0 = (0xff - t) |
|
|
|
# define TIMER0_INT_ENABLE() TIMSK = _BV(TOIE0) |
|
|
|
# define TIMER0_ISR TIMER0_OVF_vect |
|
|
|
#else |
|
|
|
# error MCU not supported by LED Tester. |
|
|
|
#endif |
|
|
|
|
|
|
|
bool g_highpower = false; |
|
|
|
|
|
|
|
/* Output data of the current row to the column drivers:
|
|
|
|
* Column: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 |
|
|
|
* Pin: PD2 PD3 PC5 PC4 PC3 PC2 PC1 PC0 PD7 PD6 PB5 PB4 PB3 PB2 PB1 PB0 |
|
|
|
*/ |
|
|
|
#define DISPLAY_PINS_B (_BV(PB5)|_BV(PB4)|_BV(PB3)|_BV(PB2)|_BV(PB1)|_BV(PB0)) |
|
|
|
#define DISPLAY_PINS_C (_BV(PC5)|_BV(PC4)|_BV(PC3)|_BV(PC2)|_BV(PC1)|_BV(PC0)) |
|
|
|
#define DISPLAY_PINS_D (_BV(PD7)|_BV(PD6)|_BV(PD3)|_BV(PD2)) |
|
|
|
#define DISPLAY_B (_BV(PB5)|_BV(PB4)|_BV(PB3)|_BV(PB2)|_BV(PB1)|_BV(PB0)) |
|
|
|
#define DISPLAY_C (_BV(PC5)|_BV(PC4)|_BV(PC3)|_BV(PC2)|_BV(PC1)|_BV(PC0)) |
|
|
|
#define DISPLAY_D (_BV(PD7)|_BV(PD6)|_BV(PD3)|_BV(PD2)) |
|
|
|
|
|
|
|
#define ROW_DUMMY_PORT PORTB |
|
|
|
#define ROW_DUMMY_DDR DDRB |
|
|
@ -53,9 +58,9 @@ unsigned char pixmap[NUMPLANE][NUM_ROWS][LINEBYTES]; |
|
|
|
// switch to next row
|
|
|
|
static void nextrow(uint8_t row) { |
|
|
|
// switch off all columns for now
|
|
|
|
PORTB &= ~(DISPLAY_PINS_B); |
|
|
|
PORTC &= ~(DISPLAY_PINS_C); |
|
|
|
PORTD &= ~(DISPLAY_PINS_D); |
|
|
|
PORTB &= ~(DISPLAY_B); |
|
|
|
PORTC &= ~(DISPLAY_C); |
|
|
|
PORTD &= ~(DISPLAY_D); |
|
|
|
|
|
|
|
// short delay loop, to ensure proper deactivation of the drivers
|
|
|
|
unsigned char i; |
|
|
@ -69,8 +74,10 @@ static void nextrow(uint8_t row) { |
|
|
|
ROW_LED_PORT |= _BV(ROW_LED_PIN); // unblock LED MOSFET
|
|
|
|
} else { /* fake rows simulated by resistors */ |
|
|
|
// remaining rows: unblock resistor MOSFET, block LED MOSFET
|
|
|
|
ROW_LED_PORT &= ~_BV(ROW_LED_PIN); // block LED MOSFET
|
|
|
|
ROW_DUMMY_PORT |= _BV(ROW_DUMMY_PIN); // block resistor MOSFET
|
|
|
|
ROW_LED_PORT &= ~_BV(ROW_LED_PIN); // block LED MOSFET
|
|
|
|
if (g_highpower) { |
|
|
|
ROW_DUMMY_PORT |= _BV(ROW_DUMMY_PIN); // unblock resistor MOSFET
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// another delay loop, to ensure that the drivers are ready
|
|
|
@ -92,9 +99,9 @@ static void rowshow(unsigned char row, unsigned char plane) { |
|
|
|
|
|
|
|
TIMER0_COMPARE(ocr_table[plane]); |
|
|
|
|
|
|
|
uint8_t port_b = (PORTB & ~DISPLAY_PINS_B) | (0x3f & pixmap[plane][row][0]); |
|
|
|
uint8_t port_c = (PORTC & ~DISPLAY_PINS_C) | (0x3f & pixmap[plane][row][1]); |
|
|
|
uint8_t port_d = (PORTD & ~DISPLAY_PINS_D) | (0xc0 & pixmap[plane][row][0]); |
|
|
|
uint8_t port_b = (PORTB & ~DISPLAY_B) | (DISPLAY_B & pixmap[plane][row][0]); |
|
|
|
uint8_t port_c = (PORTC & ~DISPLAY_C) | (DISPLAY_C & pixmap[plane][row][1]); |
|
|
|
uint8_t port_d = (PORTD & ~DISPLAY_D) | (0xc0 & pixmap[plane][row][0]); |
|
|
|
if (0x40u & pixmap[plane][row][1]) port_d |= _BV(PD3); |
|
|
|
if (0x80u & pixmap[plane][row][1]) port_d |= _BV(PD2); |
|
|
|
|
|
|
@ -130,9 +137,9 @@ ISR(TIMER0_ISR) { |
|
|
|
void timer0_off() { |
|
|
|
cli(); |
|
|
|
// switch off all columns
|
|
|
|
PORTB &= ~(DISPLAY_PINS_B); |
|
|
|
PORTC &= ~(DISPLAY_PINS_C); |
|
|
|
PORTD &= ~(DISPLAY_PINS_D); |
|
|
|
PORTB &= ~(DISPLAY_B); |
|
|
|
PORTC &= ~(DISPLAY_C); |
|
|
|
PORTD &= ~(DISPLAY_D); |
|
|
|
TIMER0_OFF(); |
|
|
|
sei(); |
|
|
|
} |
|
|
@ -149,16 +156,16 @@ static void timer0_on() { |
|
|
|
|
|
|
|
void borg_hw_init() { |
|
|
|
// switch column and row ports to output mode
|
|
|
|
DDRB |= DISPLAY_PINS_B; |
|
|
|
DDRC |= DISPLAY_PINS_C; |
|
|
|
DDRD |= DISPLAY_PINS_D; |
|
|
|
DDRB |= DISPLAY_B; |
|
|
|
DDRC |= DISPLAY_C; |
|
|
|
DDRD |= DISPLAY_D; |
|
|
|
ROW_DUMMY_DDR |= _BV(ROW_DUMMY_PIN); |
|
|
|
ROW_LED_DDR |= _BV(ROW_LED_PIN); |
|
|
|
|
|
|
|
// switch off all columns for now
|
|
|
|
PORTB &= ~(DISPLAY_PINS_B); |
|
|
|
PORTC &= ~(DISPLAY_PINS_C); |
|
|
|
PORTD &= ~(DISPLAY_PINS_D); |
|
|
|
PORTB &= ~(DISPLAY_B); |
|
|
|
PORTC &= ~(DISPLAY_C); |
|
|
|
PORTD &= ~(DISPLAY_D); |
|
|
|
|
|
|
|
// switch off all rows
|
|
|
|
ROW_DUMMY_PORT &= ~_BV(ROW_DUMMY_PIN); |
|
|
|