Merge pull request #454 from keyboardio/hardware/atreus/scanning-optimization

Atreus: Minor refactoring around row selection during scan
pull/458/head
Jesse Vincent 6 years ago committed by GitHub
commit 0ced80854a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -46,14 +46,15 @@ uint16_t Atreus::masks_[ROWS];
uint8_t Atreus::debounce_matrix_[ROWS][COLS]; uint8_t Atreus::debounce_matrix_[ROWS][COLS];
uint8_t Atreus::debounce = 3; uint8_t Atreus::debounce = 3;
constexpr uint8_t Atreus::row_pins[4];
void Atreus::setup(void) { void Atreus::setup(void) {
wdt_disable(); wdt_disable();
delay(100); delay(100);
for (uint8_t i = 0; i < ROWS; i++) { // Initialize rows
unselectRow(i); DDRD |= _BV(0) | _BV(1) | _BV(3) | _BV(2);
keyState_[i] = previousKeyState_[i] = 0; PORTD |= _BV(0) | _BV(1) | _BV(3) | _BV(2);
}
// Initialize columns // Initialize columns
DDRB &= ~(_BV(5) | _BV(4) | _BV(6) | _BV(7)); DDRB &= ~(_BV(5) | _BV(4) | _BV(6) | _BV(7));
@ -82,50 +83,8 @@ void Atreus::setup(void) {
TIMSK1 = _BV(TOIE1); TIMSK1 = _BV(TOIE1);
} }
void Atreus::selectRow(uint8_t row) { void Atreus::toggleRow(uint8_t row) {
switch (row) { PORTD ^= _BV(row_pins[row]);
case 0:
DDRD |= (_BV(0));
PORTD &= ~(_BV(0));
break;
case 1:
DDRD |= (_BV(1));
PORTD &= ~(_BV(1));
break;
case 2:
DDRD |= (_BV(3));
PORTD &= ~(_BV(3));
break;
case 3:
DDRD |= (_BV(2));
PORTD &= ~(_BV(2));
break;
default:
break;
}
}
void Atreus::unselectRow(uint8_t row) {
switch (row) {
case 0:
DDRD &= ~(_BV(0));
PORTD |= (_BV(0));
break;
case 1:
DDRD &= ~(_BV(1));
PORTD |= (_BV(1));
break;
case 2:
DDRD &= ~(_BV(3));
PORTD |= (_BV(3));
break;
case 3:
DDRD &= ~(_BV(2));
PORTD |= (_BV(2));
break;
default:
break;
}
} }
uint16_t Atreus::readCols() { uint16_t Atreus::readCols() {
@ -149,9 +108,9 @@ void Atreus::readMatrixRow(uint8_t current_row) {
mask = debounceMaskForRow(current_row); mask = debounceMaskForRow(current_row);
selectRow(current_row); toggleRow(current_row);
cols = (readCols() & mask) | (keyState_[current_row] & ~mask); cols = (readCols() & mask) | (keyState_[current_row] & ~mask);
unselectRow(current_row); toggleRow(current_row);
debounceRow(cols ^ keyState_[current_row], current_row); debounceRow(cols ^ keyState_[current_row], current_row);
keyState_[current_row] = cols; keyState_[current_row] = cols;
} }

@ -127,14 +127,15 @@ class Atreus {
static uint8_t debounce; static uint8_t debounce;
private: private:
static constexpr uint8_t row_pins[4] = {0, 1, 3, 2};
static uint16_t previousKeyState_[matrix_rows]; static uint16_t previousKeyState_[matrix_rows];
static uint16_t keyState_[matrix_rows]; static uint16_t keyState_[matrix_rows];
static uint16_t masks_[matrix_rows]; static uint16_t masks_[matrix_rows];
static void readMatrixRow(uint8_t row); static void readMatrixRow(uint8_t row);
static uint16_t readCols(); static uint16_t readCols();
static void selectRow(uint8_t row); static void toggleRow(uint8_t row);
static void unselectRow(uint8_t row);
static uint8_t debounce_matrix_[matrix_rows][matrix_columns]; static uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint16_t debounceMaskForRow(uint8_t row); static uint16_t debounceMaskForRow(uint8_t row);

Loading…
Cancel
Save