diff options
Diffstat (limited to 'keyboards/bpiphany/ghost_squid/matrix.c')
-rw-r--r-- | keyboards/bpiphany/ghost_squid/matrix.c | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/keyboards/bpiphany/ghost_squid/matrix.c b/keyboards/bpiphany/ghost_squid/matrix.c new file mode 100644 index 000000000..b0ad60755 --- /dev/null +++ b/keyboards/bpiphany/ghost_squid/matrix.c | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | Copyright 2014 Ralf Schmitt <[email protected]> | ||
3 | Copyright 2016 Daniel Svensson <[email protected]> | ||
4 | |||
5 | This program is free software: you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation, either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include "matrix.h" | ||
20 | #include "quantum.h" | ||
21 | |||
22 | matrix_row_t read_rows(void) { | ||
23 | return | ||
24 | (PINB & (1 << 1) ? 0 : ((matrix_row_t)1 << 0)) | | ||
25 | (PINC & (1 << 2) ? 0 : ((matrix_row_t)1 << 1)) | | ||
26 | (PINB & (1 << 6) ? 0 : ((matrix_row_t)1 << 2)) | | ||
27 | (PINB & (1 << 4) ? 0 : ((matrix_row_t)1 << 3)) | | ||
28 | (PINB & (1 << 3) ? 0 : ((matrix_row_t)1 << 4)) | | ||
29 | (PINB & (1 << 2) ? 0 : ((matrix_row_t)1 << 5)) | | ||
30 | (PINB & (1 << 0) ? 0 : ((matrix_row_t)1 << 6)) | | ||
31 | (PINB & (1 << 5) ? 0 : ((matrix_row_t)1 << 7)); | ||
32 | } | ||
33 | |||
34 | void select_col(uint8_t col) { | ||
35 | switch (col) { | ||
36 | case 0: PORTD = (PORTD & ~0b01111110) | 0b01100010; break; | ||
37 | case 1: PORTD = (PORTD & ~0b01111110) | 0b01101000; break; | ||
38 | case 2: PORTD = (PORTD & ~0b01111110) | 0b01101100; break; | ||
39 | case 3: PORTD = (PORTD & ~0b01111110) | 0b01110000; break; | ||
40 | case 4: PORTD = (PORTD & ~0b01111110) | 0b01111000; break; | ||
41 | case 5: PORTD = (PORTD & ~0b01111110) | 0b01100000; break; | ||
42 | case 6: PORTD = (PORTD & ~0b01111110) | 0b01110100; break; | ||
43 | case 7: PORTD = (PORTD & ~0b01111110) | 0b01100100; break; | ||
44 | case 8: PORTD = (PORTD & ~0b01111110) | 0b01111100; break; | ||
45 | case 9: PORTD = (PORTD & ~0b01111110) | 0b01101010; break; | ||
46 | case 10: PORTD = (PORTD & ~0b01111110) | 0b00110110; break; | ||
47 | case 11: PORTD = (PORTD & ~0b01111110) | 0b00010110; break; | ||
48 | case 12: PORTD = (PORTD & ~0b01111110) | 0b01001110; break; | ||
49 | case 13: PORTD = (PORTD & ~0b01111110) | 0b00111110; break; | ||
50 | case 14: PORTD = (PORTD & ~0b01111110) | 0b00011110; break; | ||
51 | case 15: PORTD = (PORTD & ~0b01111110) | 0b01000110; break; | ||
52 | case 16: PORTD = (PORTD & ~0b01111110) | 0b00100110; break; | ||
53 | case 17: PORTD = (PORTD & ~0b01111110) | 0b00101110; break; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | void matrix_init_custom(void) { | ||
58 | /* Column output pins */ | ||
59 | setPinOutput(D1); | ||
60 | setPinOutput(D2); | ||
61 | setPinOutput(D3); | ||
62 | setPinOutput(D4); | ||
63 | setPinOutput(D5); | ||
64 | setPinOutput(D6); | ||
65 | |||
66 | /* Row input pins */ | ||
67 | writePinHigh(B0); | ||
68 | writePinHigh(B1); | ||
69 | writePinHigh(B2); | ||
70 | writePinHigh(B3); | ||
71 | writePinHigh(B4); | ||
72 | writePinHigh(B5); | ||
73 | writePinHigh(B6); | ||
74 | writePinHigh(C2); | ||
75 | } | ||
76 | |||
77 | bool matrix_scan_custom(matrix_row_t current_matrix[]) { | ||
78 | bool changed = false; | ||
79 | |||
80 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | ||
81 | select_col(col); | ||
82 | matrix_io_delay(); | ||
83 | matrix_row_t rows = read_rows(); | ||
84 | |||
85 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
86 | bool prev_bit = current_matrix[row] & ((matrix_row_t)1 << col); | ||
87 | bool curr_bit = rows & (1 << row); | ||
88 | |||
89 | if (prev_bit != curr_bit) { | ||
90 | current_matrix[row] ^= (matrix_row_t)1 << col; | ||
91 | changed = true; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | return changed; | ||
97 | } | ||