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 | |
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>
-rw-r--r-- | quantum/matrix.c | 66 | ||||
-rw-r--r-- | quantum/split_common/matrix.c | 66 |
2 files changed, 104 insertions, 28 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 { |
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 { |