diff options
Diffstat (limited to 'keyboards/jones/v03/matrix.c')
| -rw-r--r-- | keyboards/jones/v03/matrix.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/keyboards/jones/v03/matrix.c b/keyboards/jones/v03/matrix.c new file mode 100644 index 000000000..9f3e76f93 --- /dev/null +++ b/keyboards/jones/v03/matrix.c | |||
| @@ -0,0 +1,99 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012-2020 Jun Wako, Jack Humbert, Yiancar, Takeshi Nishio | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <stdint.h> | ||
| 18 | #include <stdbool.h> | ||
| 19 | #include "matrix.h" | ||
| 20 | #include "quantum.h" | ||
| 21 | |||
| 22 | #define ROW_SHIFTER ((uint16_t)1) | ||
| 23 | |||
| 24 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 25 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 26 | |||
| 27 | static void select_row(uint8_t row) { | ||
| 28 | setPinOutput(row_pins[row]); | ||
| 29 | writePinLow(row_pins[row]); | ||
| 30 | } | ||
| 31 | |||
| 32 | static void unselect_row(uint8_t row) { | ||
| 33 | setPinInputHigh(row_pins[row]); | ||
| 34 | } | ||
| 35 | |||
| 36 | static void unselect_rows(void) { | ||
| 37 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | ||
| 38 | setPinInputHigh(row_pins[x]); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | static void init_pins(void) { | ||
| 43 | unselect_rows(); | ||
| 44 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 45 | setPinInputHigh(col_pins[x]); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | ||
| 50 | // Store last value of row prior to reading | ||
| 51 | matrix_row_t last_row_value = current_matrix[current_row]; | ||
| 52 | |||
| 53 | // Clear data in matrix row | ||
| 54 | current_matrix[current_row] = 0; | ||
| 55 | |||
| 56 | // Select row and wait for row selecton to stabilize | ||
| 57 | select_row(current_row); | ||
| 58 | matrix_io_delay(); | ||
| 59 | |||
| 60 | // For each col... | ||
| 61 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | ||
| 62 | |||
| 63 | // skip reading when index equals (= pin itself) | ||
| 64 | if (col_index != current_row) { | ||
| 65 | // Check col pin pin_state | ||
| 66 | if (readPin(col_pins[col_index]) == 0) { | ||
| 67 | // Pin LO, set col bit | ||
| 68 | current_matrix[current_row] |= (ROW_SHIFTER << col_index); | ||
| 69 | } else { | ||
| 70 | // Pin HI, clear col bit | ||
| 71 | current_matrix[current_row] &= ~(ROW_SHIFTER << col_index); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | // Unselect row | ||
| 77 | unselect_row(current_row); | ||
| 78 | |||
| 79 | return (last_row_value != current_matrix[current_row]); | ||
| 80 | } | ||
| 81 | |||
| 82 | void matrix_init_custom(void) { | ||
| 83 | // initialize key pins | ||
| 84 | init_pins(); | ||
| 85 | |||
| 86 | matrix_init_quantum(); | ||
| 87 | } | ||
| 88 | |||
| 89 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 90 | bool changed = false; | ||
| 91 | |||
| 92 | // Set row, read cols | ||
| 93 | for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { | ||
| 94 | changed |= read_cols_on_row(current_matrix, current_row); | ||
| 95 | } | ||
| 96 | |||
| 97 | matrix_scan_quantum(); | ||
| 98 | return changed; | ||
| 99 | } | ||
