aboutsummaryrefslogtreecommitdiff
path: root/keyboards/mechlovin/infinity87/rev2/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/mechlovin/infinity87/rev2/matrix.c')
-rw-r--r--keyboards/mechlovin/infinity87/rev2/matrix.c344
1 files changed, 145 insertions, 199 deletions
diff --git a/keyboards/mechlovin/infinity87/rev2/matrix.c b/keyboards/mechlovin/infinity87/rev2/matrix.c
index 6f417765a..b1b0d2065 100644
--- a/keyboards/mechlovin/infinity87/rev2/matrix.c
+++ b/keyboards/mechlovin/infinity87/rev2/matrix.c
@@ -60,61 +60,12 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
60 return (last_row_value != current_matrix[current_row]); 60 return (last_row_value != current_matrix[current_row]);
61} 61}
62 62
63#elif (DIODE_DIRECTION == COL2ROW)
64
65static void select_row(uint8_t row) {
66 setPinOutput(row_pins[row]);
67 writePinLow(row_pins[row]);
68}
69
70static void unselect_row(uint8_t row) { setPinInputHigh(row_pins[row]); }
71
72static void unselect_rows(void) {
73 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
74 setPinInputHigh(row_pins[x]);
75 }
76}
77
78static void init_pins(void) {
79 unselect_rows();
80 for (uint8_t x = 0; x < MATRIX_COLS; x++) {
81 setPinInputHigh(col_pins[x]);
82 }
83}
84
85static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
86 // Store last value of row prior to reading
87 matrix_row_t last_row_value = current_matrix[current_row];
88
89 // Clear data in matrix row
90 current_matrix[current_row] = 0;
91
92 // Select row and wait for row selecton to stabilize
93 select_row(current_row);
94 wait_us(30);
95
96 // For each col...
97 for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
98
99 // Select the col pin to read (active low)
100 uint8_t pin_state = readPin(col_pins[col_index]);
101
102 // Populate the matrix row with the state of the col pin
103 current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
104 }
105
106 // Unselect row
107 unselect_row(current_row);
108
109 return (last_row_value != current_matrix[current_row]);
110}
111
112#elif (DIODE_DIRECTION == ROW2COL) 63#elif (DIODE_DIRECTION == ROW2COL)
113 64
114/* Cols 0 - 16 65/* Cols 0 - 16
115 * These columns use two 74HC138 3 to 8 bit demultiplexer. D6, D7 is the enable pin, must be set high (1) to use it. 66 * These columns use two 74HC138 3 to 8 bit demultiplexer. B0, F1 is the enable pin, must be set high (1) to use it.
116 * 67 *
117 * col / pin: PA0 PA1 PA2 PD6 PD7 PC4 68 * col / pin: PB5 PB7 PF0 PB0 PF1 PE6
118 * 0: 0 ── 0 ── 0 1 ── 0 0 69 * 0: 0 ── 0 ── 0 1 ── 0 0
119 * ──────────────────────────────────────────── 70 * ────────────────────────────────────────────
120 * 1: 0 ── 0 ── 1 1 ── 0 0 71 * 1: 0 ── 0 ── 1 1 ── 0 0
@@ -153,103 +104,103 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
153static void select_col(uint8_t col) { 104static void select_col(uint8_t col) {
154 switch (col) { 105 switch (col) {
155 case 0: 106 case 0:
156 writePinLow(A0); 107 writePinLow(B5);
157 writePinLow(A1); 108 writePinLow(B7);
158 writePinLow(A2); 109 writePinLow(F0);
159 writePinHigh(D6); 110 writePinHigh(B0);
160 break; 111 break;
161 case 1: 112 case 1:
162 writePinLow(A0); 113 writePinLow(B5);
163 writePinLow(A1); 114 writePinLow(B7);
164 writePinHigh(A2); 115 writePinHigh(F0);
165 writePinHigh(D6); 116 writePinHigh(B0);
166 break; 117 break;
167 case 2: 118 case 2:
168 writePinLow(A0); 119 writePinLow(B5);
169 writePinHigh(A1); 120 writePinHigh(B7);
170 writePinLow(A2); 121 writePinLow(F0);
171 writePinHigh(D6); 122 writePinHigh(B0);
172 break; 123 break;
173 case 3: 124 case 3:
174 writePinLow(A0); 125 writePinLow(B5);
175 writePinHigh(A1); 126 writePinHigh(B7);
176 writePinHigh(A2); 127 writePinHigh(F0);
177 writePinHigh(D6); 128 writePinHigh(B0);
178 break; 129 break;
179 case 4: 130 case 4:
180 writePinHigh(A0); 131 writePinHigh(B5);
181 writePinLow(A1); 132 writePinLow(B7);
182 writePinLow(A2); 133 writePinLow(F0);
183 writePinHigh(D6); 134 writePinHigh(B0);
184 break; 135 break;
185 case 5: 136 case 5:
186 writePinHigh(A0); 137 writePinHigh(B5);
187 writePinLow(A1); 138 writePinLow(B7);
188 writePinHigh(A2); 139 writePinHigh(F0);
189 writePinHigh(D6); 140 writePinHigh(B0);
190 break; 141 break;
191 case 6: 142 case 6:
192 writePinHigh(A0); 143 writePinHigh(B5);
193 writePinHigh(A1); 144 writePinHigh(B7);
194 writePinLow(A2); 145 writePinLow(F0);
195 writePinHigh(D6); 146 writePinHigh(B0);
196 break; 147 break;
197 case 7: 148 case 7:
198 writePinHigh(A0); 149 writePinHigh(B5);
199 writePinHigh(A1); 150 writePinHigh(B7);
200 writePinHigh(A2); 151 writePinHigh(F0);
201 writePinHigh(D6); 152 writePinHigh(B0);
202 break; 153 break;
203 case 8: 154 case 8:
204 writePinLow(A0); 155 writePinLow(B5);
205 writePinLow(A1); 156 writePinLow(B7);
206 writePinLow(A2); 157 writePinLow(F0);
207 writePinHigh(D7); 158 writePinHigh(F1);
208 break; 159 break;
209 case 9: 160 case 9:
210 writePinLow(A0); 161 writePinLow(B5);
211 writePinLow(A1); 162 writePinLow(B7);
212 writePinHigh(A2); 163 writePinHigh(F0);
213 writePinHigh(D7); 164 writePinHigh(F1);
214 break; 165 break;
215 case 10: 166 case 10:
216 writePinLow(A0); 167 writePinLow(B5);
217 writePinHigh(A1); 168 writePinHigh(B7);
218 writePinLow(A2); 169 writePinLow(F0);
219 writePinHigh(D7); 170 writePinHigh(F1);
220 break; 171 break;
221 case 11: 172 case 11:
222 writePinLow(A0); 173 writePinLow(B5);
223 writePinHigh(A1); 174 writePinHigh(B7);
224 writePinHigh(A2); 175 writePinHigh(F0);
225 writePinHigh(D7); 176 writePinHigh(F1);
226 break; 177 break;
227 case 12: 178 case 12:
228 writePinHigh(A0); 179 writePinHigh(B5);
229 writePinLow(A1); 180 writePinLow(B7);
230 writePinLow(A2); 181 writePinLow(F0);
231 writePinHigh(D7); 182 writePinHigh(F1);
232 break; 183 break;
233 case 13: 184 case 13:
234 writePinHigh(A0); 185 writePinHigh(B5);
235 writePinLow(A1); 186 writePinLow(B7);
236 writePinHigh(A2); 187 writePinHigh(F0);
237 writePinHigh(D7); 188 writePinHigh(F1);
238 break; 189 break;
239 case 14: 190 case 14:
240 writePinHigh(A0); 191 writePinHigh(B5);
241 writePinHigh(A1); 192 writePinHigh(B7);
242 writePinHigh(A2); 193 writePinHigh(F0);
243 writePinHigh(D7); 194 writePinHigh(F1);
244 break; 195 break;
245 case 15: 196 case 15:
246 writePinHigh(A0); 197 writePinHigh(B5);
247 writePinHigh(A1); 198 writePinHigh(B7);
248 writePinLow(A2); 199 writePinLow(F0);
249 writePinHigh(D7); 200 writePinHigh(F1);
250 break; 201 break;
251 case 16: 202 case 16:
252 writePinLow(C4); 203 writePinLow(E6);
253 break; 204 break;
254 } 205 }
255} 206}
@@ -257,117 +208,117 @@ static void select_col(uint8_t col) {
257static void unselect_col(uint8_t col) { 208static void unselect_col(uint8_t col) {
258 switch (col) { 209 switch (col) {
259 case 0: 210 case 0:
260 writePinHigh(A0); 211 writePinHigh(B5);
261 writePinHigh(A1); 212 writePinHigh(B7);
262 writePinHigh(A2); 213 writePinHigh(F0);
263 writePinLow(D6); 214 writePinLow(B0);
264 break; 215 break;
265 case 1: 216 case 1:
266 writePinHigh(A0); 217 writePinHigh(B5);
267 writePinHigh(A1); 218 writePinHigh(B7);
268 writePinLow(A2); 219 writePinLow(F0);
269 writePinLow(D6); 220 writePinLow(B0);
270 break; 221 break;
271 case 2: 222 case 2:
272 writePinHigh(A0); 223 writePinHigh(B5);
273 writePinLow(A1); 224 writePinLow(B7);
274 writePinHigh(A2); 225 writePinHigh(F0);
275 writePinLow(D6); 226 writePinLow(B0);
276 break; 227 break;
277 case 3: 228 case 3:
278 writePinHigh(A0); 229 writePinHigh(B5);
279 writePinLow(A1); 230 writePinLow(B7);
280 writePinLow(A2); 231 writePinLow(F0);
281 writePinLow(D6); 232 writePinLow(B0);
282 break; 233 break;
283 case 4: 234 case 4:
284 writePinLow(A0); 235 writePinLow(B5);
285 writePinHigh(A1); 236 writePinHigh(B7);
286 writePinHigh(A2); 237 writePinHigh(F0);
287 writePinLow(D6); 238 writePinLow(B0);
288 break; 239 break;
289 case 5: 240 case 5:
290 writePinLow(A0); 241 writePinLow(B5);
291 writePinHigh(A1); 242 writePinHigh(B7);
292 writePinLow(A2); 243 writePinLow(F0);
293 writePinLow(D6); 244 writePinLow(B0);
294 break; 245 break;
295 case 6: 246 case 6:
296 writePinLow(A0); 247 writePinLow(B5);
297 writePinLow(A1); 248 writePinLow(B7);
298 writePinHigh(A2); 249 writePinHigh(F0);
299 writePinLow(D6); 250 writePinLow(B0);
300 break; 251 break;
301 case 7: 252 case 7:
302 writePinLow(A0); 253 writePinLow(B5);
303 writePinLow(A1); 254 writePinLow(B7);
304 writePinLow(A2); 255 writePinLow(F0);
305 writePinLow(D6); 256 writePinLow(B0);
306 break; 257 break;
307 case 8: 258 case 8:
308 writePinHigh(A0); 259 writePinHigh(B5);
309 writePinHigh(A1); 260 writePinHigh(B7);
310 writePinHigh(A2); 261 writePinHigh(F0);
311 writePinLow(D7); 262 writePinLow(F1);
312 break; 263 break;
313 case 9: 264 case 9:
314 writePinHigh(A0); 265 writePinHigh(B5);
315 writePinHigh(A1); 266 writePinHigh(B7);
316 writePinLow(A2); 267 writePinLow(F0);
317 writePinLow(D7); 268 writePinLow(F1);
318 break; 269 break;
319 case 10: 270 case 10:
320 writePinHigh(A0); 271 writePinHigh(B5);
321 writePinLow(A1); 272 writePinLow(B7);
322 writePinHigh(A2); 273 writePinHigh(F0);
323 writePinLow(D7); 274 writePinLow(F1);
324 break; 275 break;
325 case 11: 276 case 11:
326 writePinHigh(A0); 277 writePinHigh(B5);
327 writePinLow(A1); 278 writePinLow(B7);
328 writePinLow(A2); 279 writePinLow(F0);
329 writePinLow(D7); 280 writePinLow(F1);
330 break; 281 break;
331 case 12: 282 case 12:
332 writePinLow(A0); 283 writePinLow(B5);
333 writePinHigh(A1); 284 writePinHigh(B7);
334 writePinHigh(A2); 285 writePinHigh(F0);
335 writePinLow(D7); 286 writePinLow(F1);
336 break; 287 break;
337 case 13: 288 case 13:
338 writePinLow(A0); 289 writePinLow(B5);
339 writePinHigh(A1); 290 writePinHigh(B7);
340 writePinLow(A2); 291 writePinLow(F0);
341 writePinLow(D7); 292 writePinLow(F1);
342 break; 293 break;
343 case 14: 294 case 14:
344 writePinLow(A0); 295 writePinLow(B5);
345 writePinLow(A1); 296 writePinLow(B7);
346 writePinLow(A2); 297 writePinLow(F0);
347 writePinLow(D7); 298 writePinLow(F1);
348 break; 299 break;
349 case 15: 300 case 15:
350 writePinLow(A0); 301 writePinLow(B5);
351 writePinLow(A1); 302 writePinLow(B7);
352 writePinHigh(A2); 303 writePinHigh(F0);
353 writePinLow(D7); 304 writePinLow(F1);
354 break; 305 break;
355 case 16: 306 case 16:
356 writePinHigh(C4); 307 writePinHigh(E6);
357 break; 308 break;
358 } 309 }
359} 310}
360 311
361static void unselect_cols(void) { 312static void unselect_cols(void) {
362 //Native 313 //Native
363 writePinHigh(C4); 314 writePinHigh(E6);
364 315
365 //Demultiplexer 316 //Demultiplexer
366 writePinLow(D6); 317 writePinLow(B0);
367 writePinLow(D7); 318 writePinLow(F1);
368 writePinHigh(A0); 319 writePinHigh(B5);
369 writePinHigh(A1); 320 writePinHigh(B7);
370 writePinHigh(A2); 321 writePinHigh(F0);
371} 322}
372 323
373static void init_pins(void) { 324static void init_pins(void) {
@@ -375,12 +326,12 @@ static void init_pins(void) {
375 for (uint8_t x = 0; x < MATRIX_ROWS; x++) { 326 for (uint8_t x = 0; x < MATRIX_ROWS; x++) {
376 setPinInputHigh(row_pins[x]); 327 setPinInputHigh(row_pins[x]);
377 } 328 }
378 setPinOutput(A0); 329 setPinOutput(B5);
379 setPinOutput(A1); 330 setPinOutput(B7);
380 setPinOutput(A2); 331 setPinOutput(F0);
381 setPinOutput(D6); 332 setPinOutput(B0);
382 setPinOutput(D7); 333 setPinOutput(F1);
383 setPinOutput(C4); 334 setPinOutput(E6);
384} 335}
385 336
386static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { 337static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) {
@@ -426,12 +377,7 @@ void matrix_init_custom(void) {
426bool matrix_scan_custom(matrix_row_t current_matrix[]) { 377bool matrix_scan_custom(matrix_row_t current_matrix[]) {
427 bool changed = false; 378 bool changed = false;
428 379
429#if defined(DIRECT_PINS) || (DIODE_DIRECTION == COL2ROW) 380#if defined(DIRECT_PINS) || (DIODE_DIRECTION == ROW2COL)
430 // Set row, read cols
431 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
432 changed |= read_cols_on_row(current_matrix, current_row);
433 }
434#elif (DIODE_DIRECTION == ROW2COL)
435 // Set col, read rows 381 // Set col, read rows
436 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { 382 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
437 changed |= read_rows_on_col(current_matrix, current_col); 383 changed |= read_rows_on_col(current_matrix, current_col);