Make user keymaps fully declarative
This removes the need for the user to define... most things, honestly. Notably, `main()` is no longer the end user's responsibility. This also allows us to do fun stuff going forward like validating keymaps for sanity (ex: the key assigned to `KC_MO(x)` should be assigned to `KC_TRNS` on the target layer or the user will never be able to escape that layer). This also disambiguates `BOARD` to always refer to an actual slab of silicon, renaming to `USER_KEYMAP`. Entrypoints are now a bit more wild, and mostly-unsupported boards no longer have working entrypoints. It's probably just time to scrap those boards for now (until we have BLE HID and/or bitbang USB HID, at least).
This commit is contained in:
parent
5f9f3be966
commit
97091ff4fd
@ -1,13 +0,0 @@
|
|||||||
- Arch dependencies: adafruit-ampy python-dotenv wget
|
|
||||||
- Optional Arch dependencies: picocom (serial interface)
|
|
||||||
- `pip3 install --user adafruit nrfutil`
|
|
||||||
- `mkdir feather_flashing && cd feather_flashing`
|
|
||||||
- `git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader.git && cd Adafruit_nRF52_Bootloader`
|
|
||||||
- `make BOARD=feather_nrf52832 VERSION=2.0.1 SERIAL=/dev/ttyUSB0 dfu-flash` (no
|
|
||||||
root req)
|
|
||||||
- `cd .. && git clone git@github.com:adafruit/circuitpython.git && cd circuitpython`
|
|
||||||
- `git submodule update --init`
|
|
||||||
- `make -C mpy-cross`
|
|
||||||
- `cd ports/nrf`
|
|
||||||
- `./drivers/bluetooth/download_ble_stack.sh`
|
|
||||||
- `make BOARD=feather_nrf52832 SERIAL=/dev/ttyUSB0 dfu-gen dfu-flash`
|
|
44
Makefile
44
Makefile
@ -18,7 +18,7 @@ lint: devdeps
|
|||||||
@pipenv run flake8
|
@pipenv run flake8
|
||||||
|
|
||||||
fix-isort: devdeps
|
fix-isort: devdeps
|
||||||
@find kmk/ boards/ entrypoints/ -name "*.py" | xargs pipenv run isort
|
@find kmk/ user_keymaps/ -name "*.py" | xargs pipenv run isort
|
||||||
|
|
||||||
.submodules: .gitmodules
|
.submodules: .gitmodules
|
||||||
@echo "===> Pulling dependencies, this may take several minutes"
|
@echo "===> Pulling dependencies, this may take several minutes"
|
||||||
@ -86,28 +86,28 @@ circuitpy-build-nrf:
|
|||||||
|
|
||||||
circuitpy-flash-nrf: circuitpy-build-nrf
|
circuitpy-flash-nrf: circuitpy-build-nrf
|
||||||
@echo "===> Flashing CircuitPython with KMK and your keymap"
|
@echo "===> Flashing CircuitPython with KMK and your keymap"
|
||||||
@make -C vendor/circuitpython/ports/nrf BOARD=feather_nrf52832 SERIAL=${AMPY_PORT} SD=s132 FROZEN_MPY_DIR=freeze dfu-gen dfu-flash
|
@sudo make -C vendor/circuitpython/ports/nrf BOARD=feather_nrf52832 SERIAL=${AMPY_PORT} SD=s132 FROZEN_MPY_DIR=freeze dfu-gen dfu-flash
|
||||||
|
|
||||||
micropython-build-teensy3.1:
|
micropython-build-teensy3.1:
|
||||||
@cp entrypoints/teensy31.py vendor/micropython/ports/teensy/memzip_files/main.py
|
#@cp entrypoints/teensy31.py vendor/micropython/ports/teensy/memzip_files/main.py
|
||||||
@make -C vendor/micropython/ports/teensy/ BOARD=TEENSY_3.1 all
|
@make -C vendor/micropython/ports/teensy/ BOARD=TEENSY_3.1 all
|
||||||
|
|
||||||
micropython-flash-teensy3.1: micropython-build-teensy3.1
|
micropython-flash-teensy3.1: micropython-build-teensy3.1
|
||||||
@make -C vendor/micropython/ports/teensy/ BOARD=TEENSY_3.1 deploy
|
@sudo make -C vendor/micropython/ports/teensy/ BOARD=TEENSY_3.1 deploy
|
||||||
|
|
||||||
micropython-build-pyboard:
|
micropython-build-pyboard:
|
||||||
@make -j4 -C vendor/micropython/ports/stm32/ BOARD=PYBV11 FROZEN_MPY_DIR=freeze all
|
@make -j4 -C vendor/micropython/ports/stm32/ BOARD=PYBV11 FROZEN_MPY_DIR=freeze all
|
||||||
|
|
||||||
micropython-flash-pyboard: micropython-build-pyboard
|
micropython-flash-pyboard: micropython-build-pyboard
|
||||||
@make -j4 -C vendor/micropython/ports/stm32/ BOARD=PYBV11 FROZEN_MPY_DIR=freeze deploy
|
@sudo make -j4 -C vendor/micropython/ports/stm32/ BOARD=PYBV11 FROZEN_MPY_DIR=freeze deploy
|
||||||
|
|
||||||
micropython-flash-pyboard-entrypoint:
|
micropython-flash-pyboard-entrypoint:
|
||||||
@echo "===> Flashing entrypoints if they doesn't already exist"
|
@echo "===> Flashing entrypoints if they doesn't already exist"
|
||||||
@sleep 4
|
@sleep 4
|
||||||
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} rm /flash/main.py 2>/dev/null
|
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} rm /flash/main.py 2>/dev/null
|
||||||
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} rm /flash/boot.py 2>/dev/null
|
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} rm /flash/boot.py 2>/dev/null
|
||||||
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put entrypoints/pyboard.py /flash/main.py
|
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put kmk/entrypoints/global.py /flash/main.py
|
||||||
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put entrypoints/pyboard_boot.py /flash/boot.py
|
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put kmk/entrypoints/handwire/pyboard_boot.py /flash/boot.py
|
||||||
@echo "===> Flashed keyboard successfully!"
|
@echo "===> Flashed keyboard successfully!"
|
||||||
|
|
||||||
circuitpy-flash-nrf-entrypoint:
|
circuitpy-flash-nrf-entrypoint:
|
||||||
@ -117,57 +117,57 @@ circuitpy-flash-nrf-entrypoint:
|
|||||||
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put entrypoints/feather_nrf52832.py main.py
|
@-timeout -k 5s 10s pipenv run ampy -p ${AMPY_PORT} -d ${AMPY_DELAY} -b ${AMPY_BAUD} put entrypoints/feather_nrf52832.py main.py
|
||||||
@echo "===> Flashed keyboard successfully!"
|
@echo "===> Flashed keyboard successfully!"
|
||||||
|
|
||||||
ifndef BOARD
|
ifndef USER_KEYMAP
|
||||||
build-feather-nrf52832:
|
build-feather-nrf52832:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
|
|
||||||
flash-feather-nrf52832:
|
flash-feather-nrf52832:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
else
|
else
|
||||||
build-feather-nrf52832: lint devdeps circuitpy-deps circuitpy-freeze-kmk-nrf
|
build-feather-nrf52832: lint devdeps circuitpy-deps circuitpy-freeze-kmk-nrf
|
||||||
@echo "===> Preparing keyboard script for bundling into CircuitPython"
|
@echo "===> Preparing keyboard script for bundling into CircuitPython"
|
||||||
@cp -av ${BOARD} vendor/circuitpython/ports/nrf/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/circuitpython/ports/nrf/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) circuitpy-build-nrf
|
@$(MAKE) circuitpy-build-nrf
|
||||||
|
|
||||||
flash-feather-nrf52832: lint devdeps circuitpy-deps circuitpy-freeze-kmk-nrf
|
flash-feather-nrf52832: lint devdeps circuitpy-deps circuitpy-freeze-kmk-nrf
|
||||||
@echo "===> Preparing keyboard script for bundling into CircuitPython"
|
@echo "===> Preparing keyboard script for bundling into CircuitPython"
|
||||||
@cp -av ${BOARD} vendor/circuitpython/ports/nrf/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/circuitpython/ports/nrf/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) circuitpy-flash-nrf circuitpy-flash-nrf-entrypoint
|
@$(MAKE) circuitpy-flash-nrf circuitpy-flash-nrf-entrypoint
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef BOARD
|
ifndef USER_KEYMAP
|
||||||
build-teensy-3.1:
|
build-teensy-3.1:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
|
|
||||||
flash-teensy-3.1:
|
flash-teensy-3.1:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
else
|
else
|
||||||
build-teensy-3.1: lint devdeps micropython-deps micropython-freeze-kmk-teensy3.1
|
build-teensy-3.1: lint devdeps micropython-deps micropython-freeze-kmk-teensy3.1
|
||||||
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
||||||
@cp -av ${BOARD} vendor/micropython/ports/teensy/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/micropython/ports/teensy/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) ARDUINO=${ARDUINO} micropython-build-teensy3.1
|
@$(MAKE) ARDUINO=${ARDUINO} micropython-build-teensy3.1
|
||||||
|
|
||||||
flash-teensy-3.1: lint devdeps micropython-deps micropython-freeze-kmk-teensy3.1
|
flash-teensy-3.1: lint devdeps micropython-deps micropython-freeze-kmk-teensy3.1
|
||||||
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
||||||
@cp -av ${BOARD} vendor/micropython/ports/teensy/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/micropython/ports/teensy/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) ARDUINO=${ARDUINO} micropython-flash-teensy3.1
|
@$(MAKE) ARDUINO=${ARDUINO} micropython-flash-teensy3.1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef BOARD
|
ifndef USER_KEYMAP
|
||||||
build-pyboard:
|
build-pyboard:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
|
|
||||||
flash-pyboard:
|
flash-pyboard:
|
||||||
@echo "===> Must provide a board (usually from boards/...) to build!"
|
@echo "===> Must provide a USER_KEYMAP (usually from user_keymaps/...) to build!"
|
||||||
else
|
else
|
||||||
build-pyboard: lint devdeps micropython-deps micropython-freeze-kmk-stm32
|
build-pyboard: lint devdeps micropython-deps micropython-freeze-kmk-stm32
|
||||||
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
||||||
@cp -av ${BOARD} vendor/micropython/ports/stm32/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/micropython/ports/stm32/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) AMPY_PORT=/dev/ttyACM0 AMPY_BAUD=115200 micropython-build-pyboard
|
@$(MAKE) AMPY_PORT=/dev/ttyACM0 AMPY_BAUD=115200 micropython-build-pyboard
|
||||||
|
|
||||||
flash-pyboard: lint devdeps micropython-deps micropython-freeze-kmk-stm32
|
flash-pyboard: lint devdeps micropython-deps micropython-freeze-kmk-stm32
|
||||||
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
@echo "===> Preparing keyboard script for bundling into MicroPython"
|
||||||
@cp -av ${BOARD} vendor/micropython/ports/stm32/freeze/kmk_keyboard_user.py
|
@cp -av ${USER_KEYMAP} vendor/micropython/ports/stm32/freeze/kmk_keyboard_user.py
|
||||||
@$(MAKE) AMPY_PORT=/dev/ttyACM0 AMPY_BAUD=115200 micropython-flash-pyboard micropython-flash-pyboard-entrypoint
|
@$(MAKE) AMPY_PORT=/dev/ttyACM0 AMPY_BAUD=115200 micropython-flash-pyboard micropython-flash-pyboard-entrypoint
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
from logging import DEBUG
|
|
||||||
|
|
||||||
import machine
|
|
||||||
|
|
||||||
from kmk.common.consts import DiodeOrientation
|
|
||||||
from kmk.common.keycodes import KC
|
|
||||||
from kmk.firmware import Firmware
|
|
||||||
from kmk.micropython.pyb_hid import HIDHelper
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
p = machine.Pin.board
|
|
||||||
|
|
||||||
cols = (p.X10, p.X11, p.X12)
|
|
||||||
rows = (p.X1, p.X2, p.X3)
|
|
||||||
|
|
||||||
diode_orientation = DiodeOrientation.COLUMNS
|
|
||||||
|
|
||||||
keymap = [
|
|
||||||
[
|
|
||||||
[KC.MO(1), KC.H, KC.RESET],
|
|
||||||
[KC.MO(2), KC.I, KC.ENTER],
|
|
||||||
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.TRNS, KC.B, KC.C],
|
|
||||||
[KC.NO, KC.D, KC.E],
|
|
||||||
[KC.F, KC.G, KC.H],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
[KC.X, KC.Y, KC.Z],
|
|
||||||
[KC.TRNS, KC.N, KC.O],
|
|
||||||
[KC.R, KC.P, KC.Q],
|
|
||||||
],
|
|
||||||
]
|
|
||||||
|
|
||||||
firmware = Firmware(
|
|
||||||
keymap=keymap,
|
|
||||||
row_pins=rows,
|
|
||||||
col_pins=cols,
|
|
||||||
diode_orientation=diode_orientation,
|
|
||||||
hid=HIDHelper,
|
|
||||||
log_level=DEBUG,
|
|
||||||
)
|
|
||||||
|
|
||||||
firmware.go()
|
|
@ -1,12 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from kmk.circuitpython.util import feather_red_led_flash
|
|
||||||
from kmk_keyboard_user import main
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as e:
|
|
||||||
sys.print_exception(e)
|
|
||||||
feather_red_led_flash(duration=10, rate=0.5)
|
|
||||||
sys.exit(1)
|
|
@ -1,10 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from kmk_keyboard_user import main
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as e:
|
|
||||||
sys.print_exception(e)
|
|
||||||
sys.exit(1)
|
|
@ -1,10 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
from kmk_keyboard_user import main
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
main()
|
|
||||||
except Exception as e:
|
|
||||||
sys.print_exception(e)
|
|
||||||
sys.exit(1)
|
|
0
kmk/entrypoints/__init__.py
Normal file
0
kmk/entrypoints/__init__.py
Normal file
4
kmk/entrypoints/global.py
Normal file
4
kmk/entrypoints/global.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from kmk_keyboard_user import main
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
11
kmk/entrypoints/handwire/Pipfile
Normal file
11
kmk/entrypoints/handwire/Pipfile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
[[source]]
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
name = "pypi"
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.7"
|
0
kmk/entrypoints/handwire/__init__.py
Normal file
0
kmk/entrypoints/handwire/__init__.py
Normal file
24
kmk/entrypoints/handwire/pyboard.py
Normal file
24
kmk/entrypoints/handwire/pyboard.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import sys
|
||||||
|
from logging import DEBUG
|
||||||
|
|
||||||
|
from kmk.firmware import Firmware
|
||||||
|
from kmk.micropython.pyb_hid import HIDHelper
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
from kmk_keyboard_user import cols, diode_orientation, keymap, rows
|
||||||
|
|
||||||
|
try:
|
||||||
|
firmware = Firmware(
|
||||||
|
keymap=keymap,
|
||||||
|
row_pins=rows,
|
||||||
|
col_pins=cols,
|
||||||
|
diode_orientation=diode_orientation,
|
||||||
|
hid=HIDHelper,
|
||||||
|
log_level=DEBUG,
|
||||||
|
)
|
||||||
|
|
||||||
|
firmware.go()
|
||||||
|
except Exception as e:
|
||||||
|
sys.print_exception(e)
|
||||||
|
sys.exit(1)
|
@ -3,7 +3,7 @@ exclude = .git,__pycache__,vendor,.venv
|
|||||||
max_line_length = 99
|
max_line_length = 99
|
||||||
ignore = X100
|
ignore = X100
|
||||||
per-file-ignores =
|
per-file-ignores =
|
||||||
boards/**/*.py: E501
|
user_keymaps/**/*.py: F401,E501
|
||||||
|
|
||||||
[isort]
|
[isort]
|
||||||
known_third_party = analogio,bitbangio,bleio,board,busio,digitalio,framebuf,gamepad,gc,microcontroller,micropython,pulseio,pyb,pydux,uio,ubluepy,machine,pyb
|
known_third_party = analogio,bitbangio,bleio,board,busio,digitalio,framebuf,gamepad,gc,microcontroller,micropython,pulseio,pyb,pydux,uio,ubluepy,machine,pyb
|
||||||
|
29
user_keymaps/klardotsh/threethree_matrix_pyboard.py
Normal file
29
user_keymaps/klardotsh/threethree_matrix_pyboard.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import machine
|
||||||
|
|
||||||
|
from kmk.common.consts import DiodeOrientation
|
||||||
|
from kmk.common.keycodes import KC
|
||||||
|
from kmk.entrypoints.handwire.pyboard import main
|
||||||
|
|
||||||
|
p = machine.Pin.board
|
||||||
|
cols = (p.X10, p.X11, p.X12)
|
||||||
|
rows = (p.X1, p.X2, p.X3)
|
||||||
|
|
||||||
|
diode_orientation = DiodeOrientation.COLUMNS
|
||||||
|
|
||||||
|
keymap = [
|
||||||
|
[
|
||||||
|
[KC.MO(1), KC.H, KC.RESET],
|
||||||
|
[KC.MO(2), KC.I, KC.ENTER],
|
||||||
|
[KC.LCTRL, KC.SPACE, KC.LSHIFT],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[KC.TRNS, KC.B, KC.C],
|
||||||
|
[KC.NO, KC.D, KC.E],
|
||||||
|
[KC.F, KC.G, KC.H],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[KC.X, KC.Y, KC.Z],
|
||||||
|
[KC.TRNS, KC.N, KC.O],
|
||||||
|
[KC.R, KC.P, KC.Q],
|
||||||
|
],
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user