diff options
Diffstat (limited to 'keyboards/sekigon/grs_70ec/matrix.c')
| -rw-r--r-- | keyboards/sekigon/grs_70ec/matrix.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/keyboards/sekigon/grs_70ec/matrix.c b/keyboards/sekigon/grs_70ec/matrix.c new file mode 100644 index 000000000..7e90d99af --- /dev/null +++ b/keyboards/sekigon/grs_70ec/matrix.c | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* Copyright 2020 sekigon-gonnoc | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "grs_70ec.h" | ||
| 18 | |||
| 19 | #include "ec_switch_matrix.h" | ||
| 20 | #include "matrix.h" | ||
| 21 | #include "debug.h" | ||
| 22 | #include "split_util.h" | ||
| 23 | #include "transport.h" | ||
| 24 | #include "debounce.h" | ||
| 25 | |||
| 26 | #ifndef LOW_THRESHOLD | ||
| 27 | # define LOW_THRESHOLD 200 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef HIGH_THRESHOLD | ||
| 31 | # define HIGH_THRESHOLD 300 | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #define ERROR_DISCONNECT_COUNT 20 | ||
| 35 | |||
| 36 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) | ||
| 37 | |||
| 38 | /* matrix state(1:on, 0:off) */ | ||
| 39 | extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values | ||
| 40 | extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values | ||
| 41 | |||
| 42 | // row offsets for each hand | ||
| 43 | uint8_t thisHand, thatHand; | ||
| 44 | |||
| 45 | // user-defined overridable functions | ||
| 46 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | ||
| 47 | |||
| 48 | void matrix_init_custom(void) { | ||
| 49 | split_pre_init(); | ||
| 50 | |||
| 51 | ecsm_config_t ecsm_config = {.low_threshold = LOW_THRESHOLD, .high_threshold = HIGH_THRESHOLD}; | ||
| 52 | |||
| 53 | ecsm_init(&ecsm_config); | ||
| 54 | |||
| 55 | thisHand = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 56 | thatHand = ROWS_PER_HAND - thisHand; | ||
| 57 | |||
| 58 | split_post_init(); | ||
| 59 | } | ||
| 60 | |||
| 61 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
| 62 | bool updated = ecsm_matrix_scan(current_matrix); | ||
| 63 | |||
| 64 | static int cnt = 0; | ||
| 65 | if (cnt++ == 300) { | ||
| 66 | cnt = 0; | ||
| 67 | ecsm_print_matrix(); | ||
| 68 | print("\n"); | ||
| 69 | } | ||
| 70 | |||
| 71 | return updated; | ||
| 72 | } | ||
| 73 | |||
| 74 | void matrix_post_scan(void) { | ||
| 75 | if (is_keyboard_master()) { | ||
| 76 | static uint8_t error_count; | ||
| 77 | |||
| 78 | if (!transport_master(matrix + thatHand)) { | ||
| 79 | error_count++; | ||
| 80 | |||
| 81 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 82 | // reset other half if disconnected | ||
| 83 | dprintf("Error: disconnect split half\n"); | ||
| 84 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 85 | matrix[thatHand + i] = 0; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | } else { | ||
| 89 | error_count = 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | matrix_scan_quantum(); | ||
| 93 | } else { | ||
| 94 | transport_slave(matrix + thisHand); | ||
| 95 | |||
| 96 | matrix_slave_scan_user(); | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | uint8_t matrix_scan(void) { | ||
| 101 | bool changed = matrix_scan_custom(raw_matrix); | ||
| 102 | |||
| 103 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); | ||
| 104 | |||
| 105 | matrix_post_scan(); | ||
| 106 | return changed; | ||
| 107 | } | ||
