|
|
@ -27,6 +27,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h"
|
|
|
|
#include "kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h"
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
#include <avr/wdt.h>
|
|
|
|
|
|
|
|
#include "kaleidoscope/hardware/avr/pins_and_ports.h"
|
|
|
|
#include "kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h"
|
|
|
|
#include "kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define I2C_ADDR 0b0100000
|
|
|
|
#define I2C_ADDR 0b0100000
|
|
|
@ -85,78 +86,42 @@ out:
|
|
|
|
return status;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
|
|
ErgoDoxScanner::initCols() {
|
|
|
|
|
|
|
|
DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
|
|
|
|
|
|
|
|
PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
ErgoDoxScanner::begin() {
|
|
|
|
ErgoDoxScanner::begin() {
|
|
|
|
expander_error_ = initExpander();
|
|
|
|
expander_error_ = initExpander();
|
|
|
|
|
|
|
|
|
|
|
|
unselectRows();
|
|
|
|
// Init columns
|
|
|
|
initCols();
|
|
|
|
DDRF &= ~(1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
|
|
|
|
|
|
|
|
PORTF |= (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 1 | 1 << 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init rows
|
|
|
|
|
|
|
|
DDRB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
PORTB |= (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
DDRD |= (1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
PORTD |= (1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
DDRC |= (1 << 6);
|
|
|
|
|
|
|
|
PORTC |= (1 << 6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __attribute__((optimize(3)))
|
|
|
|
void __attribute__((optimize(3))) ErgoDoxScanner::selectExtenderRow(int row) {
|
|
|
|
ErgoDoxScanner::selectRow(int row) {
|
|
|
|
if (!expander_error_) {
|
|
|
|
if (row < 7) {
|
|
|
|
expander_error_ = i2c_start(I2C_ADDR_WRITE);
|
|
|
|
if (!expander_error_) {
|
|
|
|
if (expander_error_)
|
|
|
|
expander_error_ = i2c_start(I2C_ADDR_WRITE);
|
|
|
|
goto out;
|
|
|
|
if (expander_error_)
|
|
|
|
expander_error_ = i2c_write(GPIOA);
|
|
|
|
goto out;
|
|
|
|
if (expander_error_)
|
|
|
|
expander_error_ = i2c_write(GPIOA);
|
|
|
|
goto out;
|
|
|
|
if (expander_error_)
|
|
|
|
expander_error_ = i2c_write(0xFF & ~(1 << row));
|
|
|
|
goto out;
|
|
|
|
if (expander_error_)
|
|
|
|
expander_error_ = i2c_write(0xFF & ~(1 << row));
|
|
|
|
goto out;
|
|
|
|
if (expander_error_)
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
out:
|
|
|
|
i2c_stop();
|
|
|
|
i2c_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
switch (row) {
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
|
|
|
DDRB |= (1 << 0);
|
|
|
|
|
|
|
|
PORTB &= ~(1 << 0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
|
|
|
|
DDRB |= (1 << 1);
|
|
|
|
|
|
|
|
PORTB &= ~(1 << 1);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
|
|
|
|
DDRB |= (1 << 2);
|
|
|
|
|
|
|
|
PORTB &= ~(1 << 2);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 10:
|
|
|
|
|
|
|
|
DDRB |= (1 << 3);
|
|
|
|
|
|
|
|
PORTB &= ~(1 << 3);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11:
|
|
|
|
|
|
|
|
DDRD |= (1 << 2);
|
|
|
|
|
|
|
|
PORTD &= ~(1 << 3);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12:
|
|
|
|
|
|
|
|
DDRD |= (1 << 3);
|
|
|
|
|
|
|
|
PORTD &= ~(1 << 3);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 13:
|
|
|
|
|
|
|
|
DDRC |= (1 << 6);
|
|
|
|
|
|
|
|
PORTC &= ~(1 << 6);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __attribute__((optimize(3)))
|
|
|
|
void __attribute__((optimize(3))) ErgoDoxScanner::toggleATMegaRow(int row) {
|
|
|
|
ErgoDoxScanner::unselectRows() {
|
|
|
|
static uint8_t row_pins[] = { PIN_B0, PIN_B1, PIN_B2, PIN_B3, PIN_D2, PIN_D3, PIN_C6 };
|
|
|
|
DDRB &= ~(1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
|
|
|
|
OUTPUT_TOGGLE(row_pins[row]);
|
|
|
|
PORTB &= ~(1 << 0 | 1 << 1 | 1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
DDRD &= ~(1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
PORTD &= ~(1 << 2 | 1 << 3);
|
|
|
|
|
|
|
|
DDRC &= ~(1 << 6);
|
|
|
|
|
|
|
|
PORTC &= ~(1 << 6);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t __attribute__((optimize(3)))
|
|
|
|
uint8_t __attribute__((optimize(3)))
|
|
|
|