initial proof of concept code for kmk std ardux on paintbrush + kb2040 from adafruit

This commit is contained in:
KemoNine 2023-04-19 08:31:18 -04:00
parent 69f2363278
commit f14f4bcb41
5 changed files with 166 additions and 0 deletions

1
README.md Normal file
View file

@ -0,0 +1 @@
This code is experimental.

52
boot.py Normal file
View file

@ -0,0 +1,52 @@
print('START boot.py')
# http://kmkfw.io/docs/boot/
# Below is a fully working example, which disables USB storage, CDC and enables BIOS mode.
import supervisor
import board
import digitalio
import os
import storage
import usb_cdc
import usb_hid
from kmk.quickpin.pro_micro.kb2040 import pinout as pins
from kb import KMKKeyboard
from usb_hid import Device
# Enable use w/ BIOS
usb_hid.enable((Device.KEYBOARD, Device.MOUSE), boot_device=1)
# If this key is held during boot, don't run the code which hides the storage and disables serial
# bottom row, index finger key / bottom row pinky key
key_1 = digitalio.DigitalInOut(pins[12])
key_2 = digitalio.DigitalInOut(pins[15])
key_1.switch_to_input(pull=digitalio.Pull.UP)
key_2.switch_to_input(pull=digitalio.Pull.UP)
# Pull up means 'active low' so invert pin values for positive logic below
key_1_val = not (key_1.value)
key_2_val = not (key_2.value)
if not (key_1_val or key_2_val):
if not os.getenv('ARDUX_KMK_USB_DISK_ALWAYS'):
storage.disable_usb_drive()
usb_cdc.disable() # Equivalent to usb_cdc.enable(console=False, data=False)
# Deinit pins so they can be setup per the kmk keymap post-boot
key_1.deinit()
key_2.deinit()
if os.getenv('ARDUX_KMK_DEBUGGING'):
print('START env')
print('CIRCUITPY_BLE_NAME:', os.getenv('CIRCUITPY_BLE_NAME'))
print('ARDUX_KMK_DEBUGGING:', os.getenv('ARDUX_KMK_DEBUGGING'))
print('ARDUX_KMK_USB_DISK_ALWAYS:', os.getenv('ARDUX_KMK_USB_DISK_ALWAYS'))
print('ARDUX_SIZE:', os.getenv('ARDUX_SIZE'))
print('ARDUX_HAND:', os.getenv('ARDUX_HAND'))
print('ARDUX_BOARD:', os.getenv('ARDUX_BOARD'))
print('END env')
print('END boot.py')

27
kb.py Normal file
View file

@ -0,0 +1,27 @@
import board
from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
from kmk.quickpin.pro_micro.kb2040 import pinout as pins
from kmk.scanners.keypad import KeysScanner
# Direct wire config
_KEY_CFG = [
pins[16],
pins[17],
pins[18],
pins[19],
pins[12],
pins[13],
pins[14],
pins[15]
]
class KMKKeyboard(_KMKKeyboard):
def __init__(self):
# create and register the scanner for direct wire
self.matrix = KeysScanner(_KEY_CFG)
coord_mapping = [
0, 1, 2, 3,
4, 5, 6, 7,
]

80
main.py Normal file
View file

@ -0,0 +1,80 @@
import board
import os
from kb import KMKKeyboard
from kmk.keys import KC
keyboard = KMKKeyboard()
#####
# Enable debugging
if os.getenv('ARDUX_KMK_DEBUGGING'):
keyboard.debug_enabled = True
#####
# NeoPixel on kb2040 (tune accordingly / remove if different mcu)
from kmk.extensions.RGB import RGB, AnimationModes
rgb_ext = RGB(
pixel_pin=board.NEOPIXEL,
num_pixels=1,
val_limit=100,
val_default=25,
animation_mode=AnimationModes.RAINBOW
)
keyboard.extensions.append(rgb_ext)
#####
# Layers
from kmk.modules.layers import Layers
keyboard.modules.append(Layers())
#####
# Combos
from kmk.modules.combos import Combos, Chord
combos = Combos()
keyboard.modules.append(combos)
class KmNChord(Chord):
def __init__(
self,
match: Tuple[Union[Key, int], ...],
result: Key,
fast_reset=None,
per_key_timeout=None,
timeout=None,
match_coord=None,
keyboard=None,
layers=[],
):
super().__init__(match, result, fast_reset, per_key_timeout, match_coord)
self.keyboard = keyboard
self.layers = layers
def matches(self, key: Key, int_coord: int):
if keyboard is None or len(self.layers) == 0 or any(i in self.keyboard.active_layers for i in self.layers):
return super().matches(key, int_coord)
return False
combos.combos = []
combo_enter = KmNChord((KC.A, KC.E), KC.ENTER, keyboard=keyboard, layers=[0])
combos.combos.append(combo_enter)
combo_space = KmNChord((KC.O, KC.I, KC.Y, KC.E), KC.SPACE, keyboard=keyboard, layers=[1])
combos.combos.append(combo_space)
#####
# Keymap
keyboard.keymap = [
[KC.S, KC.T, KC.R, KC.A,
KC.O, KC.I, KC.Y, KC.E]
]
#####
# Main
if __name__ == '__main__':
print('begin main.py')
keyboard.go()
print('end main.py')

6
settings.toml Normal file
View file

@ -0,0 +1,6 @@
CIRCUITPY_BLE_NAME = "ARDUX [L|R] [board]"
ARDUX_KMK_DEBUGGING = 1 # Code only looks for value ; Uncomment/Comment to enable/disable
ARDUX_KMK_USB_DISK_ALWAYS = 1 # Code only looks for value ; Uncomment/Comment to enable/disable
ARDUX_SIZE = "[STANDARD|BIG|40%]"
ARDUX_HAND = "[LEFT|RIGHT]"
ARDUX_BOARD = "[NAME_OF_BOARD]"