aboutsummaryrefslogtreecommitdiff
path: root/keyboards/al1/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/al1/matrix.c')
-rw-r--r--keyboards/al1/matrix.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/keyboards/al1/matrix.c b/keyboards/al1/matrix.c
new file mode 100644
index 000000000..1407cbc08
--- /dev/null
+++ b/keyboards/al1/matrix.c
@@ -0,0 +1,92 @@
1#include "matrix.h"
2
3#include "gpio.h"
4
5static uint8_t read_rows(void) {
6 return (readPin(C7) ? 0 : 1) |
7 (readPin(B1) ? 0 : 2) |
8 (readPin(B2) ? 0 : 4) |
9 (readPin(C6) ? 0 : 8) |
10 (readPin(B4) ? 0 : 16) |
11 (readPin(B5) ? 0 : 32);
12}
13
14static void select_col(uint8_t col) {
15 writePinLow(D3);
16
17 writePin(D4, (col & 1));
18 writePin(D5, (col & 2));
19 writePin(D6, (col & 4));
20 writePin(D7, (col & 8));
21}
22
23static void unselect_cols(void) {
24 writePinHigh(D3);
25}
26
27void matrix_init_custom(void) {
28 /* 74HC154 col pin configuration
29 * pin: D3 D7 D6 D5 D4
30 * row: off 0 x x x x
31 * 0 1 0 0 0 0
32 * 1 1 0 0 0 1
33 * 2 1 0 0 1 0
34 * 3 1 0 0 1 1
35 * 4 1 0 1 0 0
36 * 5 1 0 1 0 1
37 * 6 1 0 1 1 0
38 * 7 1 0 1 1 1
39 * 8 1 1 0 0 0
40 * 9 1 1 0 0 1
41 * 10 1 1 0 1 0
42 * 11 1 1 0 1 1
43 * 12 1 1 1 0 0
44 * 13 1 1 1 0 1
45 * 14 1 1 1 1 0
46 * 15 1 1 1 1 1
47 */
48 setPinOutput(D3);
49 writePinHigh(D3);
50
51 setPinOutput(D4);
52 setPinOutput(D5);
53 setPinOutput(D6);
54 setPinOutput(D7);
55
56
57 /* Row pin configuration
58 *
59 * row: 0 1 2 3 4 5
60 * pin: C7 B1 B2 C6 B4 B5
61 *
62 */
63 setPinInputHigh(C7);
64 setPinInputHigh(B1);
65 setPinInputHigh(B2);
66 setPinInputHigh(C6);
67 setPinInputHigh(B4);
68 setPinInputHigh(B5);
69}
70
71bool matrix_scan_custom(matrix_row_t current_matrix[]) {
72 bool changed = false;
73
74 for (uint8_t col = 0; col < MATRIX_COLS; col++) {
75 select_col(col);
76 matrix_io_delay();
77 uint8_t rows = read_rows();
78
79 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
80 bool prev_bit = current_matrix[row] & ((matrix_row_t)1 << col);
81 bool curr_bit = rows & (1 << row);
82
83 if (prev_bit != curr_bit) {
84 current_matrix[row] ^= ((matrix_row_t)1 << col);
85 changed = true;
86 }
87 }
88 unselect_cols();
89 }
90
91 return changed;
92}