aboutsummaryrefslogtreecommitdiff
path: root/keyboards/whitefox/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/whitefox/matrix.c')
-rw-r--r--keyboards/whitefox/matrix.c135
1 files changed, 0 insertions, 135 deletions
diff --git a/keyboards/whitefox/matrix.c b/keyboards/whitefox/matrix.c
deleted file mode 100644
index c6f2c8d62..000000000
--- a/keyboards/whitefox/matrix.c
+++ /dev/null
@@ -1,135 +0,0 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include <string.h>
4#include "hal.h"
5#include "timer.h"
6#include "wait.h"
7#include "print.h"
8#include "matrix.h"
9
10
11/*
12 * Matt3o's WhiteFox
13 * Column pins are input with internal pull-down. Row pins are output and strobe with high.
14 * Key is high or 1 when it turns on.
15 *
16 * col: { PTD0, PTD1, PTD4, PTD5, PTD6, PTD7, PTC1, PTC2 }
17 * row: { PTB2, PTB3, PTB18, PTB19, PTC0, PTC8, PTC9, PTC10, PTC11 }
18 */
19/* matrix state(1:on, 0:off) */
20static matrix_row_t matrix[MATRIX_ROWS];
21static matrix_row_t matrix_debouncing[MATRIX_ROWS];
22static bool debouncing = false;
23static uint16_t debouncing_time = 0;
24
25
26void matrix_init(void)
27{
28//debug_matrix = true;
29 /* Column(sense) */
30 palSetPadMode(GPIOD, 0, PAL_MODE_INPUT_PULLDOWN);
31 palSetPadMode(GPIOD, 1, PAL_MODE_INPUT_PULLDOWN);
32 palSetPadMode(GPIOD, 4, PAL_MODE_INPUT_PULLDOWN);
33 palSetPadMode(GPIOD, 5, PAL_MODE_INPUT_PULLDOWN);
34 palSetPadMode(GPIOD, 6, PAL_MODE_INPUT_PULLDOWN);
35 palSetPadMode(GPIOD, 7, PAL_MODE_INPUT_PULLDOWN);
36 palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_PULLDOWN);
37 palSetPadMode(GPIOC, 2, PAL_MODE_INPUT_PULLDOWN);
38
39 /* Row(strobe) */
40 palSetPadMode(GPIOB, 2, PAL_MODE_OUTPUT_PUSHPULL);
41 palSetPadMode(GPIOB, 3, PAL_MODE_OUTPUT_PUSHPULL);
42 palSetPadMode(GPIOB, 18, PAL_MODE_OUTPUT_PUSHPULL);
43 palSetPadMode(GPIOB, 19, PAL_MODE_OUTPUT_PUSHPULL);
44 palSetPadMode(GPIOC, 0, PAL_MODE_OUTPUT_PUSHPULL);
45 palSetPadMode(GPIOC, 8, PAL_MODE_OUTPUT_PUSHPULL);
46 palSetPadMode(GPIOC, 9, PAL_MODE_OUTPUT_PUSHPULL);
47 palSetPadMode(GPIOC, 10, PAL_MODE_OUTPUT_PUSHPULL);
48 palSetPadMode(GPIOC, 11, PAL_MODE_OUTPUT_PUSHPULL);
49
50 memset(matrix, 0, MATRIX_ROWS * sizeof(matrix_row_t));
51 memset(matrix_debouncing, 0, MATRIX_ROWS * sizeof(matrix_row_t));
52
53 matrix_init_quantum();
54}
55
56uint8_t matrix_scan(void)
57{
58 for (int row = 0; row < MATRIX_ROWS; row++) {
59 matrix_row_t data = 0;
60
61 // strobe row
62 switch (row) {
63 case 0: palSetPad(GPIOB, 2); break;
64 case 1: palSetPad(GPIOB, 3); break;
65 case 2: palSetPad(GPIOB, 18); break;
66 case 3: palSetPad(GPIOB, 19); break;
67 case 4: palSetPad(GPIOC, 0); break;
68 case 5: palSetPad(GPIOC, 8); break;
69 case 6: palSetPad(GPIOC, 9); break;
70 case 7: palSetPad(GPIOC, 10); break;
71 case 8: palSetPad(GPIOC, 11); break;
72 }
73
74 wait_us(20); // need wait to settle pin state
75
76 // read col data: { PTD0, PTD1, PTD4, PTD5, PTD6, PTD7, PTC1, PTC2 }
77 data = ((palReadPort(GPIOC) & 0x06UL) << 5) |
78 ((palReadPort(GPIOD) & 0xF0UL) >> 2) |
79 (palReadPort(GPIOD) & 0x03UL);
80
81 // un-strobe row
82 switch (row) {
83 case 0: palClearPad(GPIOB, 2); break;
84 case 1: palClearPad(GPIOB, 3); break;
85 case 2: palClearPad(GPIOB, 18); break;
86 case 3: palClearPad(GPIOB, 19); break;
87 case 4: palClearPad(GPIOC, 0); break;
88 case 5: palClearPad(GPIOC, 8); break;
89 case 6: palClearPad(GPIOC, 9); break;
90 case 7: palClearPad(GPIOC, 10); break;
91 case 8: palClearPad(GPIOC, 11); break;
92 }
93
94 if (matrix_debouncing[row] != data) {
95 matrix_debouncing[row] = data;
96 debouncing = true;
97 debouncing_time = timer_read();
98 }
99 }
100
101 if (debouncing && timer_elapsed(debouncing_time) > DEBOUNCE) {
102 for (int row = 0; row < MATRIX_ROWS; row++) {
103 matrix[row] = matrix_debouncing[row];
104 }
105 debouncing = false;
106 }
107 matrix_scan_quantum();
108 return 1;
109}
110
111bool matrix_is_on(uint8_t row, uint8_t col)
112{
113 return (matrix[row] & (1<<col));
114}
115
116matrix_row_t matrix_get_row(uint8_t row)
117{
118 return matrix[row];
119}
120
121void matrix_print(void)
122{
123 xprintf("\nr/c 01234567\n");
124 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
125 xprintf("%X0: ", row);
126 matrix_row_t data = matrix_get_row(row);
127 for (int col = 0; col < MATRIX_COLS; col++) {
128 if (data & (1<<col))
129 xprintf("1");
130 else
131 xprintf("0");
132 }
133 xprintf("\n");
134 }
135}