summaryrefslogtreecommitdiff
path: root/keyboards/matrix/m20add/matrix.c
diff options
context:
space:
mode:
authoryulei <yuleiz@gmail.com>2020-08-23 04:45:06 +0800
committerGitHub <noreply@github.com>2020-08-22 13:45:06 -0700
commitac3dfa742a92de541f86846b94269aab87d55d3c (patch)
treea14cd8d42a963e8aa2e50b214e57f89973f9ea8e /keyboards/matrix/m20add/matrix.c
parente02f4798f97f7432e8df55846f8eb496b6ac45d1 (diff)
downloadqmk_firmware-ac3dfa742a92de541f86846b94269aab87d55d3c.tar.gz
qmk_firmware-ac3dfa742a92de541f86846b94269aab87d55d3c.zip
[Keyboard] added matrix 8xv2.0 additional (#9470)
* added matrix 8xv2.0 additional keyboard * Apply suggestions from code review Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> * add copyright and speed up the matrix scanning * Update keyboards/matrix/m20add/rules.mk Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'keyboards/matrix/m20add/matrix.c')
-rw-r--r--keyboards/matrix/m20add/matrix.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/keyboards/matrix/m20add/matrix.c b/keyboards/matrix/m20add/matrix.c
new file mode 100644
index 0000000000..b17643fea8
--- /dev/null
+++ b/keyboards/matrix/m20add/matrix.c
@@ -0,0 +1,93 @@
+/**
+ * matrix.c
+ */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include "quantum.h"
+#include "matrix.h"
+#include "tca6424.h"
+#include "m20add.h"
+
+static const uint16_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
+
+void matrix_init_custom(void)
+{
+ tca6424_init();
+ // set port0
+ tca6424_write_config(TCA6424_PORT0, 0);
+ // set port1
+ tca6424_write_config(TCA6424_PORT1, 0);
+ // set port2
+ tca6424_write_config(TCA6424_PORT2, 0xF5);
+
+ // clear output
+ tca6424_write_port(TCA6424_PORT0, 0);
+ tca6424_write_port(TCA6424_PORT1, 0);
+ tca6424_write_port(TCA6424_PORT2, 0);
+}
+
+
+static uint8_t row_mask[] = {ROW1_MASK,ROW2_MASK,ROW3_MASK,ROW4_MASK,ROW5_MASK,ROW6_MASK};
+static uint8_t col_mask[] = {COL1_MASK, COL2_MASK, COL3_MASK, COL4_MASK, COL5_MASK, COL6_MASK, COL7_MASK, COL8_MASK, COL9_MASK, COL10_MASK, COL11_MASK, COL12_MASK, COL13_MASK, COL14_MASK, COL15_MASK, COL16_MASK};
+
+bool matrix_scan_custom(matrix_row_t current_matrix[])
+{
+ bool changed = false;
+ uint8_t p0_data = tca6424_read_port(TCA6424_PORT0);
+
+ for (int col = 0; col < MATRIX_COLS; col++) {
+ // Select col and wait for col selecton to stabilize
+ switch(col) {
+ case 0:
+ set_pin(col_pins[col]);
+ break;
+ case 1 ... 8:
+ tca6424_write_port(TCA6424_PORT1, col_mask[col]);
+ break;
+ default:
+ tca6424_write_port(TCA6424_PORT0, col_mask[col]|(p0_data&0x01));
+ break;
+ }
+ matrix_io_delay();
+
+ // read row port for all rows
+ uint8_t row_value = tca6424_read_port(ROW_PORT);
+ for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
+ uint8_t tmp = row;
+ // Store last value of row prior to reading
+ matrix_row_t last_row_value = current_matrix[tmp];
+
+ // Check row pin state
+ if (row_value & row_mask[row]) {
+ // Pin HI, set col bit
+ current_matrix[tmp] |= (1 << col);
+ } else {
+ // Pin LOW, clear col bit
+ current_matrix[tmp] &= ~(1 << col);
+ }
+
+ // Determine if the matrix changed state
+ if ((last_row_value != current_matrix[tmp]) && !(changed)) {
+ changed = true;
+ }
+ }
+ // Unselect col
+ switch(col) {
+ case 0:
+ clear_pin(col_pins[col]);
+ break;
+ case 8:
+ tca6424_write_port(TCA6424_PORT1, 0);
+ break;
+ case 15:
+ tca6424_write_port(TCA6424_PORT0, p0_data&0x01);
+ break;
+ default:
+ break;
+ }
+ }
+
+ return changed;
+}