1
0
Fork 0

[Keyboard] Interlace matrix scan for performance on Moonlander (#13625)

This commit is contained in:
Hugues Morisset 2021-08-13 20:52:27 +02:00 committed by GitHub
parent 20589fb050
commit d5eb673426
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -129,54 +129,7 @@ void matrix_init(void) {
uint8_t matrix_scan(void) { uint8_t matrix_scan(void) {
bool changed = false; bool changed = false;
matrix_row_t data = 0; // Try to re-init right side
// actual matrix
for (uint8_t row = 0; row < ROWS_PER_HAND; row++) {
// strobe row
switch (row) {
case 0: writePinHigh(B10); break;
case 1: writePinHigh(B11); break;
case 2: writePinHigh(B12); break;
case 3: writePinHigh(B13); break;
case 4: writePinHigh(B14); break;
case 5: writePinHigh(B15); break;
}
// need wait to settle pin state
matrix_io_delay();
// read col data
data = (
(readPin(A0) << 0 ) |
(readPin(A1) << 1 ) |
(readPin(A2) << 2 ) |
(readPin(A3) << 3 ) |
(readPin(A6) << 4 ) |
(readPin(A7) << 5 ) |
(readPin(B0) << 6 )
);
// unstrobe row
switch (row) {
case 0: writePinLow(B10); break;
case 1: writePinLow(B11); break;
case 2: writePinLow(B12); break;
case 3: writePinLow(B13); break;
case 4: writePinLow(B14); break;
case 5: writePinLow(B15); break;
}
if (matrix_debouncing[row] != data) {
matrix_debouncing[row] = data;
debouncing = true;
debouncing_time = timer_read();
changed = true;
}
}
for (uint8_t row = 0; row <= ROWS_PER_HAND; row++) {
// right side
if (!mcp23018_initd) { if (!mcp23018_initd) {
if (++mcp23018_reset_loop == 0) { if (++mcp23018_reset_loop == 0) {
// if (++mcp23018_reset_loop >= 1300) { // if (++mcp23018_reset_loop >= 1300) {
@ -195,11 +148,26 @@ uint8_t matrix_scan(void) {
} }
} }
matrix_row_t data = 0;
// actual matrix
for (uint8_t row = 0; row <= ROWS_PER_HAND; row++) {
// strobe row
switch (row) {
case 0: writePinHigh(B10); break;
case 1: writePinHigh(B11); break;
case 2: writePinHigh(B12); break;
case 3: writePinHigh(B13); break;
case 4: writePinHigh(B14); break;
case 5: writePinHigh(B15); break;
case 6: break; // Left hand has 6 rows
}
// right side
if (mcp23018_initd) {
// #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs // #define MCP23_ROW_PINS { GPB5, GBP4, GBP3, GBP2, GBP1, GBP0 } outputs
// #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs // #define MCP23_COL_PINS { GPA0, GBA1, GBA2, GBA3, GBA4, GBA5, GBA6 } inputs
// select row // select row
mcp23018_tx[0] = 0x12; // GPIOA mcp23018_tx[0] = 0x12; // GPIOA
mcp23018_tx[1] = (0b01111111 & ~(1 << (row))) | ((uint8_t)!mcp23018_leds[2] << 7); // activate row mcp23018_tx[1] = (0b01111111 & ~(1 << (row))) | ((uint8_t)!mcp23018_leds[2] << 7); // activate row
mcp23018_tx[2] = ((uint8_t)!mcp23018_leds[1] << 6) | ((uint8_t)!mcp23018_leds[0] << 7); // activate row mcp23018_tx[2] = ((uint8_t)!mcp23018_leds[1] << 6) | ((uint8_t)!mcp23018_leds[0] << 7); // activate row
@ -228,6 +196,44 @@ uint8_t matrix_scan(void) {
} }
} }
// left side
if (row < ROWS_PER_HAND) {
// i2c comm incur enough wait time
if (!mcp23018_initd) {
// need wait to settle pin state
matrix_io_delay();
}
// read col data
data = (
(readPin(A0) << 0 ) |
(readPin(A1) << 1 ) |
(readPin(A2) << 2 ) |
(readPin(A3) << 3 ) |
(readPin(A6) << 4 ) |
(readPin(A7) << 5 ) |
(readPin(B0) << 6 )
);
// unstrobe row
switch (row) {
case 0: writePinLow(B10); break;
case 1: writePinLow(B11); break;
case 2: writePinLow(B12); break;
case 3: writePinLow(B13); break;
case 4: writePinLow(B14); break;
case 5: writePinLow(B15); break;
case 6: break;
}
if (matrix_debouncing[row] != data) {
matrix_debouncing[row] = data;
debouncing = true;
debouncing_time = timer_read();
changed = true;
}
}
}
// Debounce both hands
if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) { if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
for (int row = 0; row < ROWS_PER_HAND; row++) { for (int row = 0; row < ROWS_PER_HAND; row++) {
matrix[row] = matrix_debouncing[row]; matrix[row] = matrix_debouncing[row];