summaryrefslogtreecommitdiff
path: root/keyboards/kinesis/nguyenvietyen/matrix.c
diff options
context:
space:
mode:
authorViet Yen Nguyen <nguyenvietyen@gmail.com>2020-08-17 03:37:42 +0200
committerGitHub <noreply@github.com>2020-08-16 18:37:42 -0700
commit194dc0984ee3bdaa285125c024b292794fa198d8 (patch)
tree8b66994c35b145b0e84e24d67d291f0b454c8fa7 /keyboards/kinesis/nguyenvietyen/matrix.c
parente071206c58916e74117ebbec1ef7ec4ee957ee38 (diff)
[Keyboard] Kinesis + Pro Micro (#9944)
* [Keyboard] Kinesis + Pro Micro init - docs for DIY - custom matrix = lite - a near-factory dvorak mapping - optimized debouncing for lower latency * chore: reformatting * chore: update doc * chore: cleanups according to PR feedback * chore: PR feedback * fix: compile error * chore: add include * fix: LEDs hanging after USB disconnect * chore: enable QMK goodies by default * chore: use semantic write pin
Diffstat (limited to 'keyboards/kinesis/nguyenvietyen/matrix.c')
-rw-r--r--keyboards/kinesis/nguyenvietyen/matrix.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/keyboards/kinesis/nguyenvietyen/matrix.c b/keyboards/kinesis/nguyenvietyen/matrix.c
new file mode 100644
index 0000000000..3e078946e0
--- /dev/null
+++ b/keyboards/kinesis/nguyenvietyen/matrix.c
@@ -0,0 +1,64 @@
+#include "matrix.h"
+
+#include "quantum.h"
+
+static matrix_row_t read_row(uint8_t row) {
+ matrix_io_delay(); // without this wait read unstable value.
+
+ // keypad and program buttons
+ if (row == 12) {
+ return ~(readPin(B4) | (readPin(B5) << 1) | 0b11111100);
+ }
+
+ return ~(readPin(B6) | readPin(B2) << 1 | readPin(B3) << 2 | readPin(B1) << 3 | readPin(F7) << 4 | readPin(F6) << 5 | readPin(F5) << 6 | readPin(F4) << 7);
+}
+
+static void unselect_rows(void) {
+ // set A,B,C,G to 0
+ PORTD &= 0xF0;
+}
+
+static void select_rows(uint8_t row) {
+ // set A,B,C,G to row value
+ PORTD |= (0x0F & row);
+}
+
+void matrix_init_custom(void) {
+ // output low (multiplexers)
+ setPinOutput(D0);
+ setPinOutput(D1);
+ setPinOutput(D2);
+ setPinOutput(D3);
+
+ // input with pullup (matrix)
+ setPinInputHigh(B6);
+ setPinInputHigh(B2);
+ setPinInputHigh(B3);
+ setPinInputHigh(B1);
+ setPinInputHigh(F7);
+ setPinInputHigh(F6);
+ setPinInputHigh(F5);
+ setPinInputHigh(F4);
+
+ // input with pullup (program and keypad buttons)
+ setPinInputHigh(B4);
+ setPinInputHigh(B5);
+
+ // initialize row and col
+ unselect_rows();
+}
+
+bool matrix_scan_custom(matrix_row_t current_matrix[]) {
+ bool matrix_has_changed = false;
+
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ select_rows(i);
+ matrix_row_t row = read_row(i);
+ unselect_rows();
+ bool row_has_changed = current_matrix[i] != row;
+ matrix_has_changed |= row_has_changed;
+ current_matrix[i] = row;
+ }
+
+ return matrix_has_changed;
+}