Skip to content

Commit

Permalink
update kmk, add layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Subhi Dweik committed Apr 19, 2024
1 parent 8e1f05e commit 344c150
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ fp-info-cache
# Exported BOM files
*.xml
*.csv
backplate-gerbers/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ It should now behave as a keyboard.

This macropad uses KMK for it's firmware. KMK is a flexible circuitpython based project for mechanical keyboards that offers a lot of options. The basic firmware for the RSMP is simple, in that every button outputs a letter. To customize the behavior, you can modify `main.py`.

As an example of layers, the bottom left button will output a space when tapped, and when held, the buttons will output numbers and various symbols instead of letters.

## Credits

- [KMK](https://github.com/KMKfw/kmk_firmware) - Keyboard software
Expand Down
1 change: 1 addition & 0 deletions firmware/kmk/extensions/international.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Adds international keys'''

from kmk.extensions import Extension
from kmk.keys import make_key

Expand Down
2 changes: 1 addition & 1 deletion firmware/kmk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def _argumented_key(*user_args, **user_kwargs) -> Key:

if meta:
key = Key(
NEXT_AVAILABLE_KEY, meta=meta, *constructor_args, **constructor_kwargs
NEXT_AVAILABLE_KEY, *constructor_args, meta=meta, **constructor_kwargs
)

NEXT_AVAILABLE_KEY += 1
Expand Down
3 changes: 0 additions & 3 deletions firmware/kmk/kmk_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class KMKKeyboard:
_trigger_powersave_enable = False
_trigger_powersave_disable = False
_go_args = None
_processing_timeouts = False
_resume_buffer = []
_resume_buffer_x = []

Expand All @@ -76,8 +75,6 @@ class KMKKeyboard:
# overhead (the underlying list was never used anyway)
active_layers = [0]

_timeouts = {}

def __repr__(self) -> str:
return self.__class__.__name__

Expand Down
2 changes: 1 addition & 1 deletion firmware/kmk/modules/combos.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def on_timeout(self, keyboard, combo):
self.reset_combo(keyboard, combo)

def send_key_buffer(self, keyboard):
for (int_coord, key, is_pressed) in self._key_buffer:
for int_coord, key, is_pressed in self._key_buffer:
keyboard.resume_process_key(self, key, is_pressed, int_coord)

def activate(self, keyboard, combo):
Expand Down
2 changes: 1 addition & 1 deletion firmware/kmk/modules/holdtap.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def send_key_buffer(self, keyboard):
return

reprocess = False
for (int_coord, key, is_pressed) in self.key_buffer:
for int_coord, key, is_pressed in self.key_buffer:
keyboard.resume_process_key(self, key, is_pressed, int_coord, reprocess)
if isinstance(key.meta, HoldTapKeyMeta):
reprocess = True
Expand Down
1 change: 1 addition & 0 deletions firmware/kmk/modules/layers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''One layer isn't enough. Adds keys to get to more of them'''

from kmk.keys import KC, make_argumented_key
from kmk.modules.holdtap import HoldTap, HoldTapKeyMeta
from kmk.utils import Debug
Expand Down
2 changes: 1 addition & 1 deletion firmware/kmk/modules/pimoroni_trackball.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Extension handles usage of Trackball Breakout by Pimoroni
'''

from micropython import const

import math
Expand Down Expand Up @@ -310,7 +311,6 @@ def __init__(self, trackball, **kwargs):
super().__init__(1, **kwargs)

def deinit(self):
super().deinit()
self.trackball.set_rgbw(0, 0, 0, 0)

def _transmit(self, b):
Expand Down
1 change: 1 addition & 0 deletions firmware/kmk/modules/split.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Enables splitting keyboards wirelessly or wired'''

import busio
from micropython import const
from supervisor import runtime, ticks_ms
Expand Down
43 changes: 43 additions & 0 deletions firmware/kmk/quickpin/pro_micro/liatris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import board

pinout = [
# Left, top->bottom
board.TX,
board.RX,
None, # GND
None, # GND
board.SDA,
board.SCL,
board.D4,
board.D5, # C6
board.D6, # D7
board.D7, # E6
board.D8, # B4
board.D9, # B5
# Right, bottom->top
board.D21, # B6
board.D23, # B2
board.D20, # B3
board.D22, # B1
board.D26, # F7
board.D27, # F6
board.D28, # F5
board.D29, # F4
None, # 3.3v
None, # RST
None, # GND
None, # RAW
# Bottom, left->right
board.D12,
board.D13,
board.D14,
board.D15,
board.D16,
# Internal
board.NEOPIXEL,
board.VBUS_SENSE,
board.POWER_LED,
board.I2C,
board.SPI,
board.UART,
]
42 changes: 14 additions & 28 deletions firmware/kmk/scanners/digitalio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
from kmk.scanners import DiodeOrientation, Scanner


def ensure_DIO(x):
# __class__.__name__ is used instead of isinstance as the MCP230xx lib
# does not use the digitalio.DigitalInOut, but rather a self defined one:
# https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx/blob/3f04abbd65ba5fa938fcb04b99e92ae48a8c9406/adafruit_mcp230xx/digital_inout.py#L33
if x.__class__.__name__ == 'DigitalInOut':
return x
else:
return digitalio.DigitalInOut(x)


class MatrixScanner(Scanner):
def __init__(
self,
Expand Down Expand Up @@ -32,37 +42,13 @@ def __init__(

self.diode_orientation = diode_orientation

# __class__.__name__ is used instead of isinstance as the MCP230xx lib
# does not use the digitalio.DigitalInOut, but rather a self defined one:
# https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx/blob/3f04abbd65ba5fa938fcb04b99e92ae48a8c9406/adafruit_mcp230xx/digital_inout.py#L33

if self.diode_orientation == DiodeOrientation.COL2ROW:
self.anodes = [
x
if x.__class__.__name__ == 'DigitalInOut'
else digitalio.DigitalInOut(x)
for x in cols
]
self.cathodes = [
x
if x.__class__.__name__ == 'DigitalInOut'
else digitalio.DigitalInOut(x)
for x in rows
]
self.anodes = [ensure_DIO(x) for x in cols]
self.cathodes = [ensure_DIO(x) for x in rows]
self.translate_coords = True
elif self.diode_orientation == DiodeOrientation.ROW2COL:
self.anodes = [
x
if x.__class__.__name__ == 'DigitalInOut'
else digitalio.DigitalInOut(x)
for x in rows
]
self.cathodes = [
x
if x.__class__.__name__ == 'DigitalInOut'
else digitalio.DigitalInOut(x)
for x in cols
]
self.anodes = [ensure_DIO(x) for x in rows]
self.cathodes = [ensure_DIO(x) for x in cols]
self.translate_coords = False
else:
raise ValueError(f'Invalid DiodeOrientation: {self.diode_orienttaion}')
Expand Down
1 change: 1 addition & 0 deletions firmware/kmk/transports/pio_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Circuit Python wrapper around PIO implementation of UART
Original source of these examples: https://github.com/adafruit/Adafruit_CircuitPython_PIOASM/tree/main/examples (MIT)
'''

import rp2pio
from array import array

Expand Down
29 changes: 11 additions & 18 deletions firmware/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import board
import digitalio

from kb import KMKKeyboard
from storage import getmount

from kmk.keys import KC
from kmk.modules.layers import Layers
Expand All @@ -13,9 +9,6 @@

layers = Layers()

# data_pin = board.GP1 if split_side == SplitSide.LEFT else board.GP0
# data_pin2 = board.GP0 if split_side == SplitSide.LEFT else board.GP1

layers_ext = Layers()
layers_ext.tap_time = 100

Expand All @@ -26,23 +19,23 @@
# _______ = KC.TRNS
# XXXXXXX = KC.NO

# LYR_LOWER = 1
# LYR_RAISE = 2
# LOWER = KC.MO(LYR_LOWER)
# RAISE = KC.MO(LYR_RAISE)
# ADJUST = KC.LT(3, KC.SPC)

# MT_RSEN = KC.MT(KC.ENT, KC.RSFT)
# KC_LRGR = KC.LT(LYR_LOWER, KC.GRV)
# KC_RSSP = KC.LT(LYR_RAISE, KC.SPC)
LAYER_ALT = 1
KCALT = KC.LT(LAYER_ALT, KC.SPC)

keyboard.keymap = [
[ #QWERTY
[
KC.A, KC.B, KC.C, KC.D,
KC.E, KC.F, KC.J, KC.K,
KC.L, KC.M, KC.N, KC.O,
KC.P, KC.Q, KC.R, KC.S,
KC.T, KC.U, KC.V, KC.W,
KCALT, KC.U, KC.V, KC.W,
],
[
KC.N1, KC.N2, KC.N3, KC.N4,
KC.N5, KC.N6, KC.N7, KC.N8,
KC.N9, KC.N0, KC.LBRACKET, KC.RBRACKET,
KC.QUOTE, KC.COMMA, KC.GRAVE, KC.DOT,
KC.SLASH, KC.MINUS, KC.EQUAL, KC.ENTER,
],
]

Expand Down

0 comments on commit 344c150

Please sign in to comment.