From 0c72554773d49643cf66ceefc9f853fcb8152870 Mon Sep 17 00:00:00 2001 From: Josh Klar Date: Tue, 16 Oct 2018 01:04:36 -0700 Subject: [PATCH] Add support for a Planck Rev 6 spidered to a Feather M4 Express --- kmk/matrix.py | 31 +++++++++++++-- .../klardotsh/feather_m4_express/klarank.py | 39 +++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 user_keymaps/klardotsh/feather_m4_express/klarank.py diff --git a/kmk/matrix.py b/kmk/matrix.py index 0ef14e7..938ef11 100644 --- a/kmk/matrix.py +++ b/kmk/matrix.py @@ -16,6 +16,9 @@ class MatrixScanner: self.cols = cols self.rows = rows + self.len_cols = len(cols) + self.len_rows = len(rows) + self.diode_orientation = diode_orientation self.last_pressed_len = 0 @@ -36,6 +39,18 @@ class MatrixScanner: for pin in self.inputs: pin.switch_to_input(pull=digitalio.Pull.DOWN) + import kmk_keyboard + + self.swap_indicies = getattr(kmk_keyboard, 'swap_indicies', {}) + self.rollover_cols_every_rows = getattr( + kmk_keyboard, + 'rollover_cols_every_rows', + self.len_rows, + ) + + for k, v in self.swap_indicies.items(): + self.swap_indicies[v] = k + def scan_for_pressed(self): pressed = [] @@ -44,9 +59,19 @@ class MatrixScanner: for iidx, ipin in enumerate(self.inputs): if ipin.value(): - pressed.append( - (oidx, iidx) if self.diode_orientation == DiodeOrientation.ROWS else (iidx, oidx) # noqa - ) + if self.diode_orientation == DiodeOrientation.ROWS: + report_tuple = (oidx, iidx) + else: + new_oidx = oidx + self.len_cols * (iidx // self.rollover_cols_every_rows) + new_iidx = iidx - self.rollover_cols_every_rows * ( + iidx // self.rollover_cols_every_rows + ) + report_tuple = (new_iidx, new_oidx) + + if report_tuple in self.swap_indicies: + report_tuple = self.swap_indicies[report_tuple] + + pressed.append(report_tuple) opin.value(False) diff --git a/user_keymaps/klardotsh/feather_m4_express/klarank.py b/user_keymaps/klardotsh/feather_m4_express/klarank.py new file mode 100644 index 0000000..ca479b6 --- /dev/null +++ b/user_keymaps/klardotsh/feather_m4_express/klarank.py @@ -0,0 +1,39 @@ +from kmk.consts import DiodeOrientation, UnicodeModes +from kmk.entrypoints.handwire.circuitpython_samd51 import main +from kmk.keycodes import KC +from kmk.macros.simple import send_string +from kmk.macros.unicode import unicode_string_sequence +from kmk.pins import Pin as P +from kmk.types import AttrDict + +# physical, visible cols (SCK, MO, MI, RX, TX, D4) +# physical, visible rows (10, 11, 12, 13) (9, 6, 5, SCL) +cols = (P.SCK, P.MOSI, P.MISO, P.RX, P.TX, P.D4) +rows = (P.D10, P.D11, P.D12, P.D13, P.D9, P.D6, P.D5, P.SCL) + +swap_indicies = { + (3, 3): (3, 9), + (3, 4): (3, 10), + (3, 5): (3, 11), +} + +rollover_cols_every_rows = 4 + +diode_orientation = DiodeOrientation.COLUMNS + + +# ------------------User level config variables --------------------------------------- +unicode_mode = UnicodeModes.LINUX +debug_enable = True + +keymap = [ + [ + [KC.A, KC.E, KC.I, KC.M, KC.Q, KC.U, KC.N1, KC.N5, KC.N9, KC.HASH, KC.AMPR, KC.UNDS], + [KC.B, KC.F, KC.J, KC.N, KC.R, KC.V, KC.N2, KC.N6, KC.N0, KC.DOLLAR, KC.ASTR, KC.LCBR], + [KC.C, KC.G, KC.K, KC.O, KC.S, KC.W, KC.N3, KC.N7, KC.EXCLAIM, KC.PERCENT, KC.LPRN, KC.RCBR], + [KC.D, KC.H, KC.L, KC.P, KC.T, KC.X, KC.N4, KC.N8, KC.AT, KC.CIRC, KC.RPRN, KC.PIPE], + ], +] + +if __name__ == '__main__': + main()