summaryrefslogtreecommitdiff
path: root/keyboards/mechlovin/infinity87/rev2/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/mechlovin/infinity87/rev2/matrix.c')
-rw-r--r--keyboards/mechlovin/infinity87/rev2/matrix.c344
1 files changed, 145 insertions, 199 deletions
diff --git a/keyboards/mechlovin/infinity87/rev2/matrix.c b/keyboards/mechlovin/infinity87/rev2/matrix.c
index 6f417765aa..b1b0d20654 100644
--- a/keyboards/mechlovin/infinity87/rev2/matrix.c
+++ b/keyboards/mechlovin/infinity87/rev2/matrix.c
@@ -60,61 +60,12 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
return (last_row_value != current_matrix[current_row]);
}
-#elif (DIODE_DIRECTION == COL2ROW)
-
-static void select_row(uint8_t row) {
- setPinOutput(row_pins[row]);
- writePinLow(row_pins[row]);
-}
-
-static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
-
-static void unselect_rows(void) {
- for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
- setPinInputHigh(row_pins[x]);
- }
-}
-
-static void init_pins(void) {
- unselect_rows();
- for (uint8_t x = 0; x < MATRIX_COLS; x++) {
- setPinInputHigh(col_pins[x]);
- }
-}
-
-static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
- // Store last value of row prior to reading
- matrix_row_t last_row_value = current_matrix[current_row];
-
- // Clear data in matrix row
- current_matrix[current_row] = 0;
-
- // Select row and wait for row selecton to stabilize
- select_row(current_row);
- wait_us(30);
-
- // For each col...
- for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
-
- // Select the col pin to read (active low)
- uint8_t pin_state = readPin(col_pins[col_index]);
-
- // Populate the matrix row with the state of the col pin
- current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
- }
-
- // Unselect row
- unselect_row(current_row);
-
- return (last_row_value != current_matrix[current_row]);
-}
-
#elif (DIODE_DIRECTION == ROW2COL)
/* Cols 0 - 16
- * These columns use two 74HC138 3 to 8 bit demultiplexer. D6, D7 is the enable pin, must be set high (1) to use it.
+ * These columns use two 74HC138 3 to 8 bit demultiplexer. B0, F1 is the enable pin, must be set high (1) to use it.
*
- * col / pin: PA0 PA1 PA2 PD6 PD7 PC4
+ * col / pin: PB5 PB7 PF0 PB0 PF1 PE6
* 0: 0 ── 0 ── 0 1 ── 0 0
* ────────────────────────────────────────────
* 1: 0 ── 0 ── 1 1 ── 0 0
@@ -153,103 +104,103 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
static void select_col(uint8_t col) {
switch (col) {
case 0:
- writePinLow(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinHigh(D6);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinHigh(B0);
break;
case 1:
- writePinLow(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinHigh(D6);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinHigh(B0);
break;
case 2:
- writePinLow(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinHigh(D6);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinHigh(B0);
break;
case 3:
- writePinLow(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinHigh(D6);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinHigh(B0);
break;
case 4:
- writePinHigh(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinHigh(D6);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinHigh(B0);
break;
case 5:
- writePinHigh(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinHigh(D6);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinHigh(B0);
break;
case 6:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinHigh(D6);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinHigh(B0);
break;
case 7:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinHigh(D6);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinHigh(B0);
break;
case 8:
- writePinLow(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinHigh(D7);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinHigh(F1);
break;
case 9:
- writePinLow(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinHigh(D7);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinHigh(F1);
break;
case 10:
- writePinLow(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinHigh(D7);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinHigh(F1);
break;
case 11:
- writePinLow(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinHigh(D7);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinHigh(F1);
break;
case 12:
- writePinHigh(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinHigh(D7);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinHigh(F1);
break;
case 13:
- writePinHigh(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinHigh(D7);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinHigh(F1);
break;
case 14:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinHigh(D7);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinHigh(F1);
break;
case 15:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinHigh(D7);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinHigh(F1);
break;
case 16:
- writePinLow(C4);
+ writePinLow(E6);
break;
}
}
@@ -257,117 +208,117 @@ static void select_col(uint8_t col) {
static void unselect_col(uint8_t col) {
switch (col) {
case 0:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinLow(D6);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinLow(B0);
break;
case 1:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinLow(D6);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinLow(B0);
break;
case 2:
- writePinHigh(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinLow(D6);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinLow(B0);
break;
case 3:
- writePinHigh(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinLow(D6);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinLow(B0);
break;
case 4:
- writePinLow(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinLow(D6);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinLow(B0);
break;
case 5:
- writePinLow(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinLow(D6);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinLow(B0);
break;
case 6:
- writePinLow(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinLow(D6);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinLow(B0);
break;
case 7:
- writePinLow(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinLow(D6);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinLow(B0);
break;
case 8:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinLow(D7);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinLow(F1);
break;
case 9:
- writePinHigh(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinLow(D7);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinLow(F1);
break;
case 10:
- writePinHigh(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinLow(D7);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinLow(F1);
break;
case 11:
- writePinHigh(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinLow(D7);
+ writePinHigh(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinLow(F1);
break;
case 12:
- writePinLow(A0);
- writePinHigh(A1);
- writePinHigh(A2);
- writePinLow(D7);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
+ writePinLow(F1);
break;
case 13:
- writePinLow(A0);
- writePinHigh(A1);
- writePinLow(A2);
- writePinLow(D7);
+ writePinLow(B5);
+ writePinHigh(B7);
+ writePinLow(F0);
+ writePinLow(F1);
break;
case 14:
- writePinLow(A0);
- writePinLow(A1);
- writePinLow(A2);
- writePinLow(D7);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinLow(F0);
+ writePinLow(F1);
break;
case 15:
- writePinLow(A0);
- writePinLow(A1);
- writePinHigh(A2);
- writePinLow(D7);
+ writePinLow(B5);
+ writePinLow(B7);
+ writePinHigh(F0);
+ writePinLow(F1);
break;
case 16:
- writePinHigh(C4);
+ writePinHigh(E6);
break;
}
}
static void unselect_cols(void) {
//Native
- writePinHigh(C4);
+ writePinHigh(E6);
//Demultiplexer
- writePinLow(D6);
- writePinLow(D7);
- writePinHigh(A0);
- writePinHigh(A1);
- writePinHigh(A2);
+ writePinLow(B0);
+ writePinLow(F1);
+ writePinHigh(B5);
+ writePinHigh(B7);
+ writePinHigh(F0);
}
static void init_pins(void) {
@@ -375,12 +326,12 @@ static void init_pins(void) {
for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
setPinInputHigh(row_pins[x]);
}
- setPinOutput(A0);
- setPinOutput(A1);
- setPinOutput(A2);
- setPinOutput(D6);
- setPinOutput(D7);
- setPinOutput(C4);
+ setPinOutput(B5);
+ setPinOutput(B7);
+ setPinOutput(F0);
+ setPinOutput(B0);
+ setPinOutput(F1);
+ setPinOutput(E6);
}
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) {
@@ -426,12 +377,7 @@ void matrix_init_custom(void) {
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
bool changed = false;
-#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW)
- // Set row, read cols
- for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
- changed |= read_cols_on_row(current_matrix, current_row);
- }
-#elif (DIODE_DIRECTION == ROW2COL)
+#if defined(DIRECT_PINS) || (DIODE_DIRECTION == ROW2COL)
// Set col, read rows
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
changed |= read_rows_on_col(current_matrix, current_col);