Able to build a VERY basic KMK image for Feather M4 Express, flashable over UF2 only
This commit is contained in:
@@ -2,6 +2,7 @@ import digitalio
|
||||
|
||||
from kmk.common.abstract.matrix_scanner import AbstractMatrixScanner
|
||||
from kmk.common.consts import DiodeOrientation
|
||||
from kmk.common.event_defs import matrix_changed
|
||||
|
||||
|
||||
class MatrixScanner(AbstractMatrixScanner):
|
||||
@@ -17,6 +18,7 @@ class MatrixScanner(AbstractMatrixScanner):
|
||||
self.cols = [digitalio.DigitalInOut(pin) for pin in cols]
|
||||
self.rows = [digitalio.DigitalInOut(pin) for pin in rows]
|
||||
self.diode_orientation = diode_orientation
|
||||
self.last_pressed_len = 0
|
||||
|
||||
if self.diode_orientation == DiodeOrientation.COLUMNS:
|
||||
self.outputs = self.cols
|
||||
@@ -35,15 +37,22 @@ class MatrixScanner(AbstractMatrixScanner):
|
||||
for pin in self.inputs:
|
||||
pin.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
|
||||
def _normalize_matrix(self, matrix):
|
||||
return super()._normalize_matrix(matrix)
|
||||
def scan_for_pressed(self):
|
||||
pressed = []
|
||||
|
||||
def raw_scan(self):
|
||||
matrix = []
|
||||
|
||||
for opin in self.outputs:
|
||||
for oidx, opin in enumerate(self.outputs):
|
||||
opin.value = True
|
||||
matrix.append([ipin.value for ipin in self.inputs])
|
||||
|
||||
for iidx, ipin in enumerate(self.inputs):
|
||||
if ipin.value:
|
||||
pressed.append(
|
||||
(oidx, iidx) if self.diode_orientation == DiodeOrientation.ROWS else (iidx, oidx) # noqa
|
||||
)
|
||||
|
||||
opin.value = False
|
||||
|
||||
return self._normalize_matrix(matrix)
|
||||
if len(pressed) != self.last_pressed_len:
|
||||
self.last_pressed_len = len(pressed)
|
||||
return matrix_changed(pressed)
|
||||
|
||||
return None # The default, but for explicitness
|
||||
|
31
kmk/entrypoints/handwire/feather_m4_express.py
Normal file
31
kmk/entrypoints/handwire/feather_m4_express.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import sys
|
||||
from logging import DEBUG
|
||||
|
||||
from kmk.circuitpython.matrix import MatrixScanner
|
||||
from kmk.common.consts import UnicodeModes
|
||||
from kmk.firmware import Firmware
|
||||
|
||||
|
||||
def main():
|
||||
from kmk_keyboard_user import cols, diode_orientation, keymap, rows
|
||||
|
||||
try:
|
||||
from kmk_keyboard_user import unicode_mode
|
||||
except Exception:
|
||||
unicode_mode = UnicodeModes.NOOP
|
||||
|
||||
try:
|
||||
firmware = Firmware(
|
||||
keymap=keymap,
|
||||
row_pins=rows,
|
||||
col_pins=cols,
|
||||
diode_orientation=diode_orientation,
|
||||
unicode_mode=unicode_mode,
|
||||
log_level=DEBUG,
|
||||
matrix_scanner=MatrixScanner,
|
||||
)
|
||||
|
||||
firmware.go()
|
||||
except Exception as e:
|
||||
sys.print_exception(e)
|
||||
sys.exit(1)
|
@@ -3,18 +3,17 @@ import logging
|
||||
from kmk.common.event_defs import init_firmware
|
||||
from kmk.common.internal_state import ReduxStore, kmk_reducer
|
||||
|
||||
try:
|
||||
from kmk.circuitpython.matrix import MatrixScanner
|
||||
except ImportError:
|
||||
from kmk.micropython.matrix import MatrixScanner
|
||||
|
||||
|
||||
class Firmware:
|
||||
def __init__(
|
||||
self, keymap, row_pins, col_pins,
|
||||
diode_orientation, unicode_mode=None,
|
||||
hid=None, log_level=logging.NOTSET,
|
||||
matrix_scanner=None,
|
||||
):
|
||||
assert matrix_scanner is not None
|
||||
self.matrix_scanner = matrix_scanner
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(log_level)
|
||||
|
||||
@@ -25,14 +24,14 @@ class Firmware:
|
||||
lambda state, action: self._subscription(state, action),
|
||||
)
|
||||
|
||||
if not hid:
|
||||
if hid:
|
||||
self.hid = hid(store=self.store, log_level=log_level)
|
||||
else:
|
||||
logger.warning(
|
||||
"Must provide a HIDHelper (arg: hid), disabling HID\n"
|
||||
"Board will run in debug mode",
|
||||
)
|
||||
|
||||
self.hid = hid(store=self.store, log_level=log_level)
|
||||
|
||||
self.store.dispatch(init_firmware(
|
||||
keymap=keymap,
|
||||
row_pins=row_pins,
|
||||
@@ -43,7 +42,7 @@ class Firmware:
|
||||
|
||||
def _subscription(self, state, action):
|
||||
if not self.hydrated:
|
||||
self.matrix = MatrixScanner(
|
||||
self.matrix = self.matrix_scanner(
|
||||
state.col_pins,
|
||||
state.row_pins,
|
||||
state.diode_orientation,
|
||||
|
Reference in New Issue
Block a user