aboutsummaryrefslogtreecommitdiff
path: root/keyboards/xd84/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/xd84/matrix.c')
-rw-r--r--keyboards/xd84/matrix.c80
1 files changed, 42 insertions, 38 deletions
diff --git a/keyboards/xd84/matrix.c b/keyboards/xd84/matrix.c
index 4cb5544ca..a4ddbee9a 100644
--- a/keyboards/xd84/matrix.c
+++ b/keyboards/xd84/matrix.c
@@ -30,65 +30,69 @@
30//_____Utility funcs___________________________________________________________ 30//_____Utility funcs___________________________________________________________
31 31
32static void init_pins(void) { 32static void init_pins(void) {
33 // init all cols high - IC2 all input 33 // init all cols high - IC2 all input
34 pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT);//same as initial state 34 pca9555_set_config(IC2, PCA9555_PORT0, ALL_INPUT); // same as initial state
35 pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT);//same as initial state 35 pca9555_set_config(IC2, PCA9555_PORT1, ALL_INPUT); // same as initial state
36 36
37 // init all rows - IC1 port0 input 37 // init all rows - IC1 port0 input
38 pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT);//same as initial state 38 pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT); // same as initial state
39 pca9555_set_output(IC1, PCA9555_PORT0, ALL_LOW);
39} 40}
40 41
41static void select_row(uint8_t row) { 42static void select_row(uint8_t row) {
42 // For the XD84 all rows are on the same IC and port 43 // For the XD84 all rows are on the same IC and port
43 // so its safe enough to assume here row == pin 44 // so its safe enough to assume here row == pin
44 uint8_t pin = row; 45 uint8_t pin = row;
45 uint8_t mask = 1 << pin; 46 uint8_t mask = 1 << pin;
46 47
47 pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask)); 48 // we configure output once in init, as pca9555 remembers state when flipping between input/output
48 pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask)); 49 // pca9555_set_output(IC1, PCA9555_PORT0, ALL_HIGH & (~mask));
50 pca9555_set_config(IC1, PCA9555_PORT0, ALL_INPUT & (~mask));
49} 51}
50 52
51static uint16_t read_cols(void) { 53static uint16_t read_cols(void) {
52 uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0); 54 // uint16_t state_1 = pca9555_readPins(IC2, PCA9555_PORT0);
53 uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1); 55 // uint16_t state_2 = pca9555_readPins(IC2, PCA9555_PORT1);
54 56 uint16_t state = pca9555_readAllPins(IC2);
55 // For the XD84 all cols are on the same IC and mapped sequentially 57
56 // while this technically gives 16 column reads, 58 // For the XD84 all cols are on the same IC and mapped sequentially
57 // the 16th column can never be set so is safely ignored 59 // while this technically gives 16 column reads,
58 return ~((state_2 << 8) | state_1); 60 // the 16th column can never be set so is safely ignored
61 // return ~((state_2 << 8) | state_1);
62 return ~state;
59} 63}
60 64
61static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { 65static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
62 // Store last value of row prior to reading 66 // Store last value of row prior to reading
63 matrix_row_t last_row_value = current_matrix[current_row]; 67 matrix_row_t last_row_value = current_matrix[current_row];
64 68
65 // Clear data in matrix row 69 // Clear data in matrix row
66 current_matrix[current_row] = 0; 70 current_matrix[current_row] = 0;
67 71
68 // Select row and wait for row selection to stabilize 72 // Select row and wait for row selection to stabilize
69 select_row(current_row); 73 select_row(current_row);
70 wait_us(30); 74 // Skip the wait_us(30); as i2c is slow enough to debounce the io changes
71 75
72 current_matrix[current_row] = read_cols(); 76 current_matrix[current_row] = read_cols();
73 77
74 // No need to Unselect row as the next `select_row` will blank everything 78 // No need to Unselect row as the next `select_row` will blank everything
75 79
76 return (last_row_value != current_matrix[current_row]); 80 return (last_row_value != current_matrix[current_row]);
77} 81}
78 82
79//_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________ 83//_____CUSTOM MATRIX IMPLEMENTATION____________________________________________________
80 84
81void custom_matrix_init(void) { 85void custom_matrix_init(void) {
82 pca9555_init(IC1); 86 pca9555_init(IC1);
83 pca9555_init(IC2); 87 pca9555_init(IC2);
84 88
85 init_pins(); 89 init_pins();
86} 90}
87 91
88bool custom_matrix_scan(matrix_row_t current_matrix[]) { 92bool custom_matrix_scan(matrix_row_t current_matrix[]) {
89 bool changed = false; 93 bool changed = false;
90 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { 94 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
91 changed |= read_cols_on_row(current_matrix, current_row); 95 changed |= read_cols_on_row(current_matrix, current_row);
92 } 96 }
93 return changed; 97 return changed;
94} \ No newline at end of file 98}