diff options
| author | Drashna Jaelre <drashna@live.com> | 2021-07-03 00:20:11 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-03 00:20:11 -0700 |
| commit | 3ab805fc67e95dfb23188bf63c7f5fbb2edcf038 (patch) | |
| tree | 82bea03e93dd8b8046b637693d0e73aa4f28eec2 /quantum/split_common | |
| parent | 8da8aabbe5796232c0f17f849badd455d42b0277 (diff) | |
| download | qmk_firmware-3ab805fc67e95dfb23188bf63c7f5fbb2edcf038.tar.gz qmk_firmware-3ab805fc67e95dfb23188bf63c7f5fbb2edcf038.zip | |
Add support for NO_PIN to all matrix types (#12238)
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'quantum/split_common')
| -rw-r--r-- | quantum/split_common/matrix.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 56d91b07f..d8e078e9b 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
| @@ -67,6 +67,14 @@ static inline void setPinInputHigh_atomic(pin_t pin) { | |||
| 67 | ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } | 67 | ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | static inline uint8_t readMatrixPin(pin_t pin) { | ||
| 71 | if (pin != NO_PIN) { | ||
| 72 | return readPin(pin); | ||
| 73 | } else { | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 70 | // matrix code | 78 | // matrix code |
| 71 | 79 | ||
| 72 | #ifdef DIRECT_PINS | 80 | #ifdef DIRECT_PINS |
| @@ -101,20 +109,34 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 101 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) | 109 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) |
| 102 | # if (DIODE_DIRECTION == COL2ROW) | 110 | # if (DIODE_DIRECTION == COL2ROW) |
| 103 | 111 | ||
| 104 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } | 112 | static bool select_row(uint8_t row) { |
| 113 | pin_t pin = row_pins[row]; | ||
| 114 | if (pin != NO_PIN) { | ||
| 115 | setPinOutput_writeLow(pin); | ||
| 116 | return true; | ||
| 117 | } | ||
| 118 | return false; | ||
| 119 | } | ||
| 105 | 120 | ||
| 106 | static void unselect_row(uint8_t row) { setPinInputHigh_atomic(row_pins[row]); } | 121 | static void unselect_row(uint8_t row) { |
| 122 | pin_t pin = row_pins[row]; | ||
| 123 | if (pin != NO_PIN) { | ||
| 124 | setPinInputHigh_atomic(pin); | ||
| 125 | } | ||
| 126 | } | ||
| 107 | 127 | ||
| 108 | static void unselect_rows(void) { | 128 | static void unselect_rows(void) { |
| 109 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { | 129 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { |
| 110 | setPinInputHigh_atomic(row_pins[x]); | 130 | unselect_row(x); |
| 111 | } | 131 | } |
| 112 | } | 132 | } |
| 113 | 133 | ||
| 114 | __attribute__((weak)) void matrix_init_pins(void) { | 134 | __attribute__((weak)) void matrix_init_pins(void) { |
| 115 | unselect_rows(); | 135 | unselect_rows(); |
| 116 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 136 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
| 117 | setPinInputHigh_atomic(col_pins[x]); | 137 | if (col_pins[x] != NO_PIN) { |
| 138 | setPinInputHigh_atomic(col_pins[x]); | ||
| 139 | } | ||
| 118 | } | 140 | } |
| 119 | } | 141 | } |
| 120 | 142 | ||
| @@ -122,14 +144,14 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 122 | // Start with a clear matrix row | 144 | // Start with a clear matrix row |
| 123 | matrix_row_t current_row_value = 0; | 145 | matrix_row_t current_row_value = 0; |
| 124 | 146 | ||
| 125 | // Select row | 147 | if (!select_row(current_row)) { // Select row |
| 126 | select_row(current_row); | 148 | return; // skip NO_PIN row |
| 149 | } | ||
| 127 | matrix_output_select_delay(); | 150 | matrix_output_select_delay(); |
| 128 | 151 | ||
| 129 | // For each col... | 152 | // For each col... |
| 130 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 153 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
| 131 | // Select the col pin to read (active low) | 154 | uint8_t pin_state = readMatrixPin(col_pins[col_index]); |
| 132 | uint8_t pin_state = readPin(col_pins[col_index]); | ||
| 133 | 155 | ||
| 134 | // Populate the matrix row with the state of the col pin | 156 | // Populate the matrix row with the state of the col pin |
| 135 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 157 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
| @@ -145,32 +167,48 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 145 | 167 | ||
| 146 | # elif (DIODE_DIRECTION == ROW2COL) | 168 | # elif (DIODE_DIRECTION == ROW2COL) |
| 147 | 169 | ||
| 148 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } | 170 | static bool select_col(uint8_t col) { |
| 171 | pin_t pin = col_pins[col]; | ||
| 172 | if (pin != NO_PIN) { | ||
| 173 | setPinOutput_writeLow(pin); | ||
| 174 | return true; | ||
| 175 | } | ||
| 176 | return false; | ||
| 177 | } | ||
| 149 | 178 | ||
| 150 | static void unselect_col(uint8_t col) { setPinInputHigh_atomic(col_pins[col]); } | 179 | static void unselect_col(uint8_t col) { |
| 180 | pin_t pin = col_pins[col]; | ||
| 181 | if (pin != NO_PIN) { | ||
| 182 | setPinInputHigh_atomic(pin); | ||
| 183 | } | ||
| 184 | } | ||
| 151 | 185 | ||
| 152 | static void unselect_cols(void) { | 186 | static void unselect_cols(void) { |
| 153 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 187 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
| 154 | setPinInputHigh_atomic(col_pins[x]); | 188 | unselect_col(x); |
| 155 | } | 189 | } |
| 156 | } | 190 | } |
| 157 | 191 | ||
| 158 | __attribute__((weak)) void matrix_init_pins(void) { | 192 | __attribute__((weak)) void matrix_init_pins(void) { |
| 159 | unselect_cols(); | 193 | unselect_cols(); |
| 160 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { | 194 | for (uint8_t x = 0; x < ROWS_PER_HAND; x++) { |
| 161 | setPinInputHigh_atomic(row_pins[x]); | 195 | if (row_pins[x] != NO_PIN) { |
| 196 | setPinInputHigh_atomic(row_pins[x]); | ||
| 197 | } | ||
| 162 | } | 198 | } |
| 163 | } | 199 | } |
| 164 | 200 | ||
| 165 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 201 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { |
| 166 | // Select col | 202 | // Select col |
| 167 | select_col(current_col); | 203 | if (!select_col(current_col)) { // select col |
| 204 | return; // skip NO_PIN col | ||
| 205 | } | ||
| 168 | matrix_output_select_delay(); | 206 | matrix_output_select_delay(); |
| 169 | 207 | ||
| 170 | // For each row... | 208 | // For each row... |
| 171 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { | 209 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { |
| 172 | // Check row pin state | 210 | // Check row pin state |
| 173 | if (readPin(row_pins[row_index]) == 0) { | 211 | if (readMatrixPin(row_pins[row_index]) == 0) { |
| 174 | // Pin LO, set col bit | 212 | // Pin LO, set col bit |
| 175 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | 213 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); |
| 176 | } else { | 214 | } else { |
