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/matrix.c | |
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/matrix.c')
-rw-r--r-- | quantum/matrix.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 71ef27089..566d9ff34 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
@@ -53,6 +53,14 @@ static inline void setPinInputHigh_atomic(pin_t pin) { | |||
53 | ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } | 53 | ATOMIC_BLOCK_FORCEON { setPinInputHigh(pin); } |
54 | } | 54 | } |
55 | 55 | ||
56 | static inline uint8_t readMatrixPin(pin_t pin) { | ||
57 | if (pin != NO_PIN) { | ||
58 | return readPin(pin); | ||
59 | } else { | ||
60 | return 1; | ||
61 | } | ||
62 | } | ||
63 | |||
56 | // matrix code | 64 | // matrix code |
57 | 65 | ||
58 | #ifdef DIRECT_PINS | 66 | #ifdef DIRECT_PINS |
@@ -87,20 +95,34 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
87 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) | 95 | # if defined(MATRIX_ROW_PINS) && defined(MATRIX_COL_PINS) |
88 | # if (DIODE_DIRECTION == COL2ROW) | 96 | # if (DIODE_DIRECTION == COL2ROW) |
89 | 97 | ||
90 | static void select_row(uint8_t row) { setPinOutput_writeLow(row_pins[row]); } | 98 | static bool select_row(uint8_t row) { |
99 | pin_t pin = row_pins[row]; | ||
100 | if (pin != NO_PIN) { | ||
101 | setPinOutput_writeLow(pin); | ||
102 | return true; | ||
103 | } | ||
104 | return false; | ||
105 | } | ||
91 | 106 | ||
92 | static void unselect_row(uint8_t row) { setPinInputHigh_atomic(row_pins[row]); } | 107 | static void unselect_row(uint8_t row) { |
108 | pin_t pin = row_pins[row]; | ||
109 | if (pin != NO_PIN) { | ||
110 | setPinInputHigh_atomic(pin); | ||
111 | } | ||
112 | } | ||
93 | 113 | ||
94 | static void unselect_rows(void) { | 114 | static void unselect_rows(void) { |
95 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | 115 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { |
96 | setPinInputHigh_atomic(row_pins[x]); | 116 | unselect_row(x); |
97 | } | 117 | } |
98 | } | 118 | } |
99 | 119 | ||
100 | __attribute__((weak)) void matrix_init_pins(void) { | 120 | __attribute__((weak)) void matrix_init_pins(void) { |
101 | unselect_rows(); | 121 | unselect_rows(); |
102 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 122 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
103 | setPinInputHigh_atomic(col_pins[x]); | 123 | if (col_pins[x] != NO_PIN) { |
124 | setPinInputHigh_atomic(col_pins[x]); | ||
125 | } | ||
104 | } | 126 | } |
105 | } | 127 | } |
106 | 128 | ||
@@ -108,14 +130,14 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
108 | // Start with a clear matrix row | 130 | // Start with a clear matrix row |
109 | matrix_row_t current_row_value = 0; | 131 | matrix_row_t current_row_value = 0; |
110 | 132 | ||
111 | // Select row | 133 | if (!select_row(current_row)) { // Select row |
112 | select_row(current_row); | 134 | return; // skip NO_PIN row |
135 | } | ||
113 | matrix_output_select_delay(); | 136 | matrix_output_select_delay(); |
114 | 137 | ||
115 | // For each col... | 138 | // For each col... |
116 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 139 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
117 | // Select the col pin to read (active low) | 140 | uint8_t pin_state = readMatrixPin(col_pins[col_index]); |
118 | uint8_t pin_state = readPin(col_pins[col_index]); | ||
119 | 141 | ||
120 | // Populate the matrix row with the state of the col pin | 142 | // Populate the matrix row with the state of the col pin |
121 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 143 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
@@ -131,32 +153,48 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
131 | 153 | ||
132 | # elif (DIODE_DIRECTION == ROW2COL) | 154 | # elif (DIODE_DIRECTION == ROW2COL) |
133 | 155 | ||
134 | static void select_col(uint8_t col) { setPinOutput_writeLow(col_pins[col]); } | 156 | static bool select_col(uint8_t col) { |
157 | pin_t pin = col_pins[col]; | ||
158 | if (pin != NO_PIN) { | ||
159 | setPinOutput_writeLow(pin); | ||
160 | return true; | ||
161 | } | ||
162 | return false; | ||
163 | } | ||
135 | 164 | ||
136 | static void unselect_col(uint8_t col) { setPinInputHigh_atomic(col_pins[col]); } | 165 | static void unselect_col(uint8_t col) { |
166 | pin_t pin = col_pins[col]; | ||
167 | if (pin != NO_PIN) { | ||
168 | setPinInputHigh_atomic(pin); | ||
169 | } | ||
170 | } | ||
137 | 171 | ||
138 | static void unselect_cols(void) { | 172 | static void unselect_cols(void) { |
139 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | 173 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { |
140 | setPinInputHigh_atomic(col_pins[x]); | 174 | unselect_col(x); |
141 | } | 175 | } |
142 | } | 176 | } |
143 | 177 | ||
144 | __attribute__((weak)) void matrix_init_pins(void) { | 178 | __attribute__((weak)) void matrix_init_pins(void) { |
145 | unselect_cols(); | 179 | unselect_cols(); |
146 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { | 180 | for (uint8_t x = 0; x < MATRIX_ROWS; x++) { |
147 | setPinInputHigh_atomic(row_pins[x]); | 181 | if (row_pins[x] != NO_PIN) { |
182 | setPinInputHigh_atomic(row_pins[x]); | ||
183 | } | ||
148 | } | 184 | } |
149 | } | 185 | } |
150 | 186 | ||
151 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 187 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { |
152 | // Select col | 188 | // Select col |
153 | select_col(current_col); | 189 | if (!select_col(current_col)) { // select col |
190 | return; // skip NO_PIN col | ||
191 | } | ||
154 | matrix_output_select_delay(); | 192 | matrix_output_select_delay(); |
155 | 193 | ||
156 | // For each row... | 194 | // For each row... |
157 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { | 195 | for (uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { |
158 | // Check row pin state | 196 | // Check row pin state |
159 | if (readPin(row_pins[row_index]) == 0) { | 197 | if (readMatrixPin(row_pins[row_index]) == 0) { |
160 | // Pin LO, set col bit | 198 | // Pin LO, set col bit |
161 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | 199 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); |
162 | } else { | 200 | } else { |