Merge branch 'master' into epx87

This commit is contained in:
Josh Klar
2019-05-20 15:54:10 -07:00
committed by GitHub
10 changed files with 156 additions and 94 deletions

View File

@@ -3,6 +3,7 @@ import board
from kmk.consts import DiodeOrientation
from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware
from kmk.pins import Pin as P
from kmk.util import intify_coordinate as ic
class Firmware(_Firmware):
@@ -17,3 +18,24 @@ class Firmware(_Firmware):
split_offsets = (6, 6, 6, 6, 6)
split_type = "UART"
uart_pin = board.SCL
coord_mapping = []
coord_mapping.extend(ic(0, x) for x in range(12))
coord_mapping.extend(ic(1, x) for x in range(12))
coord_mapping.extend(ic(2, x) for x in range(12))
# Buckle up friends, the bottom row of this keyboard is wild, and making
# our layouts match, visually, what the keyboard looks like, requires some
# surgery on the bottom two rows of coords
# Row index 3 is actually perfectly sane and we _could_ expose it
# just like the above three rows, however, visually speaking, the
# top-right thumb cluster button (when looking at the left-half PCB)
# is more inline with R3, so we'll jam that key (and its mirror) in here
coord_mapping.extend(ic(3, x) for x in range(6))
coord_mapping.append(ic(4, 2))
coord_mapping.append(ic(4, 9))
coord_mapping.extend(ic(3, x) for x in range(6, 12)) # Now, the rest of R3
# And now, to handle R4, which at this point is down to just six keys
coord_mapping.extend(ic(4, x) for x in range(3, 9))

View File

@@ -1,6 +1,27 @@
from kmk.consts import DiodeOrientation
from kmk.mcus.circuitpython_samd51 import Firmware as _Firmware
from kmk.pins import Pin as P
from kmk.util import intify_coordinate as ic
# Implements what used to be handled by Firmware.swap_indicies for this
# board, by flipping various row3 (bottom physical row) keys so their
# coord_mapping matches what the user pressed (even if the wiring
# underneath is sending different coordinates)
_r3_swap_conversions = {
3: 9,
4: 10,
5: 11,
9: 3,
10: 4,
11: 5,
}
def r3_swap(col):
try:
return _r3_swap_conversions[col]
except KeyError:
return col
class Firmware(_Firmware):
@@ -11,8 +32,8 @@ class Firmware(_Firmware):
rollover_cols_every_rows = 4
diode_orientation = DiodeOrientation.COLUMNS
swap_indicies = {
(3, 3): (3, 9),
(3, 4): (3, 10),
(3, 5): (3, 11),
}
coord_mapping = []
coord_mapping.extend(ic(0, x) for x in range(12))
coord_mapping.extend(ic(1, x) for x in range(12))
coord_mapping.extend(ic(2, x) for x in range(12))
coord_mapping.extend(ic(3, r3_swap(x)) for x in range(12))

View File

@@ -48,11 +48,14 @@ import kmk.internal_state # isort:skip
# Thanks for sticking around. Now let's do real work, starting below
from kmk.util import intify_coordinate as ic
class Firmware:
debug_enabled = False
keymap = None
coord_mapping = None
row_pins = None
col_pins = None
@@ -79,6 +82,22 @@ class Firmware:
uart_pin = None
def __init__(self):
# Attempt to sanely guess a coord_mapping if one is not provided
if not self.coord_mapping:
self.coord_mapping = []
rows_to_calc = len(self.row_pins)
cols_to_calc = len(self.col_pins)
if self.split_offsets:
rows_to_calc *= 2
cols_to_calc *= 2
for ridx in range(rows_to_calc):
for cidx in range(cols_to_calc):
self.coord_mapping.append(ic(ridx, cidx))
self._state = InternalState(self)
def _send_hid(self):
@@ -180,7 +199,6 @@ class Firmware:
rows=self.row_pins,
diode_orientation=self.diode_orientation,
rollover_cols_every_rows=getattr(self, 'rollover_cols_every_rows', None),
swap_indicies=getattr(self, 'swap_indicies', None),
)
# Compile string leader sequences

View File

@@ -47,10 +47,26 @@ class InternalState:
return ret
def _find_key_in_map(self, row, col):
ic = intify_coordinate(row, col)
try:
idx = self.config.coord_mapping.index(ic)
except ValueError:
if self.config.debug_enabled:
print(
'No coord_mapping index for value {}, row={} col={}'.format(
ic,
row,
col,
),
)
return None
# Later-added layers have priority. Sift through the layers
# in reverse order until we find a valid keycode object
for layer in self.reversed_active_layers:
layer_key = self.config.keymap[layer][row][col]
layer_key = self.config.keymap[layer][idx]
if not layer_key or layer_key == KC.TRNS:
continue

View File

@@ -1,7 +1,6 @@
import digitalio
from kmk.consts import DiodeOrientation
from kmk.util import intify_coordinate
class MatrixScanner:
@@ -9,7 +8,6 @@ class MatrixScanner:
self, cols, rows,
diode_orientation=DiodeOrientation.COLUMNS,
rollover_cols_every_rows=None,
swap_indicies=None,
):
# A pin cannot be both a row and column, detect this by combining the
# two tuples into a set and validating that the length did not drop
@@ -45,12 +43,6 @@ class MatrixScanner:
for pin in self.inputs:
pin.switch_to_input(pull=digitalio.Pull.DOWN)
self.swap_indicies = {}
if swap_indicies is not None:
for k, v in swap_indicies.items():
self.swap_indicies[intify_coordinate(*k)] = v
self.swap_indicies[intify_coordinate(*v)] = k
self.rollover_cols_every_rows = rollover_cols_every_rows
if self.rollover_cols_every_rows is None:
self.rollover_cols_every_rows = self.len_rows
@@ -100,12 +92,6 @@ class MatrixScanner:
self.report[0] = oidx
self.report[1] = iidx
swap_src = intify_coordinate(self.report[0], self.report[1])
if swap_src in self.swap_indicies:
tgt_row, tgt_col = self.swap_indicies[swap_src]
self.report[0] = tgt_row
self.report[1] = tgt_col
self.report[2] = new_val
self.state[ba_idx] = new_val