diff options
| author | Jay Greco <jayv.greco@gmail.com> | 2021-12-27 02:03:40 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-27 21:03:40 +1100 |
| commit | ac31863021791c8bbaa98a83afe90ec6505f4897 (patch) | |
| tree | ea01199de3ac472defb20e1b5f5a8b5b8aaf483b /quantum/matrix_common.c | |
| parent | 4519af69a971d4fdc005c70a9d38be67a0680815 (diff) | |
Custom matrix lite support for split keyboards (#14674)
* Custom matrix lite support for split keyboards
* WIP: matrix -> matrix_common refactor
* Move matrix_post_scan() to matrix_common.c
Diffstat (limited to 'quantum/matrix_common.c')
| -rw-r--r-- | quantum/matrix_common.c | 75 |
1 files changed, 70 insertions, 5 deletions
diff --git a/quantum/matrix_common.c b/quantum/matrix_common.c index fe1d5b1edd..79f77421e1 100644 --- a/quantum/matrix_common.c +++ b/quantum/matrix_common.c | |||
| @@ -4,6 +4,14 @@ | |||
| 4 | #include "wait.h" | 4 | #include "wait.h" |
| 5 | #include "print.h" | 5 | #include "print.h" |
| 6 | #include "debug.h" | 6 | #include "debug.h" |
| 7 | #ifdef SPLIT_KEYBOARD | ||
| 8 | # include "split_common/split_util.h" | ||
| 9 | # include "split_common/transactions.h" | ||
| 10 | |||
| 11 | # define ROWS_PER_HAND (MATRIX_ROWS / 2) | ||
| 12 | #else | ||
| 13 | # define ROWS_PER_HAND (MATRIX_ROWS) | ||
| 14 | #endif | ||
| 7 | 15 | ||
| 8 | #ifndef MATRIX_IO_DELAY | 16 | #ifndef MATRIX_IO_DELAY |
| 9 | # define MATRIX_IO_DELAY 30 | 17 | # define MATRIX_IO_DELAY 30 |
| @@ -13,6 +21,11 @@ | |||
| 13 | matrix_row_t raw_matrix[MATRIX_ROWS]; | 21 | matrix_row_t raw_matrix[MATRIX_ROWS]; |
| 14 | matrix_row_t matrix[MATRIX_ROWS]; | 22 | matrix_row_t matrix[MATRIX_ROWS]; |
| 15 | 23 | ||
| 24 | #ifdef SPLIT_KEYBOARD | ||
| 25 | // row offsets for each hand | ||
| 26 | uint8_t thisHand, thatHand; | ||
| 27 | #endif | ||
| 28 | |||
| 16 | #ifdef MATRIX_MASKED | 29 | #ifdef MATRIX_MASKED |
| 17 | extern const matrix_row_t matrix_mask[]; | 30 | extern const matrix_row_t matrix_mask[]; |
| 18 | #endif | 31 | #endif |
| @@ -78,18 +91,61 @@ uint8_t matrix_key_count(void) { | |||
| 78 | return count; | 91 | return count; |
| 79 | } | 92 | } |
| 80 | 93 | ||
| 94 | #ifdef SPLIT_KEYBOARD | ||
| 95 | bool matrix_post_scan(void) { | ||
| 96 | bool changed = false; | ||
| 97 | if (is_keyboard_master()) { | ||
| 98 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; | ||
| 99 | if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { | ||
| 100 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 101 | if (matrix[thatHand + i] != slave_matrix[i]) { | ||
| 102 | matrix[thatHand + i] = slave_matrix[i]; | ||
| 103 | changed = true; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } else { | ||
| 107 | // reset other half if disconnected | ||
| 108 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 109 | matrix[thatHand + i] = 0; | ||
| 110 | slave_matrix[i] = 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | changed = true; | ||
| 114 | } | ||
| 115 | |||
| 116 | matrix_scan_quantum(); | ||
| 117 | } else { | ||
| 118 | transport_slave(matrix + thatHand, matrix + thisHand); | ||
| 119 | |||
| 120 | matrix_slave_scan_kb(); | ||
| 121 | } | ||
| 122 | |||
| 123 | return changed; | ||
| 124 | } | ||
| 125 | #endif | ||
| 126 | |||
| 81 | /* `matrix_io_delay ()` exists for backwards compatibility. From now on, use matrix_output_unselect_delay(). */ | 127 | /* `matrix_io_delay ()` exists for backwards compatibility. From now on, use matrix_output_unselect_delay(). */ |
| 82 | __attribute__((weak)) void matrix_io_delay(void) { wait_us(MATRIX_IO_DELAY); } | 128 | __attribute__((weak)) void matrix_io_delay(void) { wait_us(MATRIX_IO_DELAY); } |
| 83 | |||
| 84 | __attribute__((weak)) void matrix_output_select_delay(void) { waitInputPinDelay(); } | 129 | __attribute__((weak)) void matrix_output_select_delay(void) { waitInputPinDelay(); } |
| 85 | __attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { matrix_io_delay(); } | 130 | __attribute__((weak)) void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { matrix_io_delay(); } |
| 86 | 131 | ||
| 87 | // CUSTOM MATRIX 'LITE' | 132 | // CUSTOM MATRIX 'LITE' |
| 88 | __attribute__((weak)) void matrix_init_custom(void) {} | 133 | __attribute__((weak)) void matrix_init_custom(void) {} |
| 89 | |||
| 90 | __attribute__((weak)) bool matrix_scan_custom(matrix_row_t current_matrix[]) { return true; } | 134 | __attribute__((weak)) bool matrix_scan_custom(matrix_row_t current_matrix[]) { return true; } |
| 91 | 135 | ||
| 136 | #ifdef SPLIT_KEYBOARD | ||
| 137 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } | ||
| 138 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | ||
| 139 | #endif | ||
| 140 | |||
| 92 | __attribute__((weak)) void matrix_init(void) { | 141 | __attribute__((weak)) void matrix_init(void) { |
| 142 | #ifdef SPLIT_KEYBOARD | ||
| 143 | split_pre_init(); | ||
| 144 | |||
| 145 | thisHand = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 146 | thatHand = ROWS_PER_HAND - thisHand; | ||
| 147 | #endif | ||
| 148 | |||
| 93 | matrix_init_custom(); | 149 | matrix_init_custom(); |
| 94 | 150 | ||
| 95 | // initialize matrix state: all keys off | 151 | // initialize matrix state: all keys off |
| @@ -98,17 +154,26 @@ __attribute__((weak)) void matrix_init(void) { | |||
| 98 | matrix[i] = 0; | 154 | matrix[i] = 0; |
| 99 | } | 155 | } |
| 100 | 156 | ||
| 101 | debounce_init(MATRIX_ROWS); | 157 | debounce_init(ROWS_PER_HAND); |
| 102 | 158 | ||
| 103 | matrix_init_quantum(); | 159 | matrix_init_quantum(); |
| 160 | |||
| 161 | #ifdef SPLIT_KEYBOARD | ||
| 162 | split_post_init(); | ||
| 163 | #endif | ||
| 104 | } | 164 | } |
| 105 | 165 | ||
| 106 | __attribute__((weak)) uint8_t matrix_scan(void) { | 166 | __attribute__((weak)) uint8_t matrix_scan(void) { |
| 107 | bool changed = matrix_scan_custom(raw_matrix); | 167 | bool changed = matrix_scan_custom(raw_matrix); |
| 108 | 168 | ||
| 109 | debounce(raw_matrix, matrix, MATRIX_ROWS, changed); | 169 | #ifdef SPLIT_KEYBOARD |
| 110 | 170 | debounce(raw_matrix, matrix + thisHand, ROWS_PER_HAND, changed); | |
| 171 | changed = (changed || matrix_post_scan()); | ||
| 172 | #else | ||
| 173 | debounce(raw_matrix, matrix, ROWS_PER_HAND, changed); | ||
| 111 | matrix_scan_quantum(); | 174 | matrix_scan_quantum(); |
| 175 | #endif | ||
| 176 | |||
| 112 | return changed; | 177 | return changed; |
| 113 | } | 178 | } |
| 114 | 179 | ||
