Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up Unicorne w/ KMK #58

Open
mankoff opened this issue May 8, 2024 · 0 comments
Open

Setting up Unicorne w/ KMK #58

mankoff opened this issue May 8, 2024 · 0 comments

Comments

@mankoff
Copy link

mankoff commented May 8, 2024

Hello. I'm trying to get a Unicorne working with KMK. I've had some brief discussions on Discord but thought this might be a better place for technical discussions. I'm not sure what repository to use for this issue, but I think it's a documentation issue.

I've tried both generic CircuitPython + KMK and the boardsource Peg firmware.

If I use generic, everything works for one half, but the split side does nothing. LEDs are on, but nothing beyond that.

If I use boardsource, nothing works at all. No LEDs, no keys.

I'll describe everything I did for each of these options below

Generic

Setup

I use adafruit-circuitpython-boardsource_blok-en_US-9.0.4.uf2 from https://circuitpython.org/board/boardsource_blok/ and flash it to each half.

I clone the latest KMK and copy the kmk sub-folder to each half of the keyboard

gh repo clone KMKfw/kmk_firmware
rsync -ahiu ./kmk_firmware/kmk/ /media/kdm/CIRCUITPY/kmk/

Keymap

kb.py

I'm using the kb.py (same for R and L as far as I can tell) from https://github.com/boardsource/pegBoards/blob/main/keyboards/Boardsource-Unicorne-L/kb.py. I note there are some strange duplicated lines of code here, but it seems to work on the plugged-in side.

import board

from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
from kmk.scanners import DiodeOrientation
from kmk.scanners.keypad import MatrixScanner

class KMKKeyboard(_KMKKeyboard):
    col_pins = (
        board.GP02,
        board.GP03,
        board.GP04,
        board.GP05,
        board.GP06,
        board.GP07,
    )
    row_pins = (board.GP14, board.GP15, board.GP16, board.GP17)
    diode_orientation = DiodeOrientation.COLUMNS
    rx = board.RX
    tx = board.TX
    rgb_pixel_pin = board.GP29
    i2c = board.I2C
    data_pin = board.TX
    rgb_pixel_pin = board.GP29
    i2c = board.I2C
    SCL=board.SCL
    SDA=board.SDA
    brightness_limit = 0.6
    num_pixels = 70
    led_key_pos = [24,23,18,17,10,9,36,37,44,45,50,51,
                25,22,19,16,11,8,35,38,43,46,49,52,
                26,21,20,15,12,7,34,39,42,47,48,53,
                14,13,6,33,40,41,
                2,1,0,27,28,29,3,4,5,32,31,30]
    brightness_limit = 0.5
    num_pixels = 54
    # flake8: noqa
    coord_mapping = [
     0,  1,  2,  3,  4,  5,  29, 28, 27, 26, 25, 24,
     6,  7,  8,  9, 10, 11,  35, 34, 33, 32, 31, 30,
    12, 13, 14, 15, 16, 17,  41, 40, 39, 38, 37, 36,
                21, 22, 23,  47, 46, 45,
    ]

main.py

I'm using the following code to try to link the two sides. First the link snippet, then the entire `main.py`. I note that these lines come from the Boardsource Unicorne main.py (again, no difference between L and R) at https://github.com/boardsource/pegBoards/blob/main/keyboards/Boardsource-Unicorne-L/main.py

from kmk.modules.split import Split, SplitSide, SplitType
split = Split(data_pin=keyboard.rx, data_pin2=keyboard.tx, uart_flip=False)
keyboard.modules.append(split)

My entire main.py, which works for the plugged-in side, is:

from kb import KMKKeyboard

from kmk.extensions.rgb import RGB
from kmk.keys import KC
from kmk.modules.layers import Layers
from kmk.modules.split import Split, SplitSide, SplitType
from kmk.hid import HIDModes

keyboard = KMKKeyboard()

# Adding extensions
rgb = RGB(pixel_pin=keyboard.rgb_pixel_pin, num_pixels=27, val_limit=100, hue_default=190, sat_default=100, val_default=5)

# TODO Comment one of these on each side
# split_side = SplitSide.RIGHT
# split = Split(split_side = SplitSide.LEFT, use_pio = True)

split = Split(data_pin=keyboard.rx, data_pin2=keyboard.tx, uart_flip=False)
keyboard.modules.append(split)

layers = Layers()

keyboard.modules = [layers, split]
keyboard.extensions = [rgb]
#
# Cleaner key names
_______ = KC.TRNS
XXXXXXX = KC.NO

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

RGB_TOG = KC.RGB_TOG
RGB_HUI = KC.RGB_HUI
RGB_HUD = KC.RGB_HUI
RGB_SAI = KC.RGB_SAI
RGB_SAD = KC.RGB_SAD
RGB_VAI = KC.RGB_VAI
RGB_VAD = KC.RGB_VAD


keyboard.keymap = [
    [  #QWERTY
        KC.TAB,    KC.Q,    KC.W,    KC.E,    KC.R,    KC.T,                         KC.Y,    KC.U,    KC.I,    KC.O,   KC.P,  KC.BSPC,\
        KC.LCTL,   KC.A,    KC.S,    KC.D,    KC.F,    KC.G,                         KC.H,    KC.J,    KC.K,    KC.L, KC.SCLN, KC.QUOT,\
        KC.LSFT,   KC.Z,    KC.X,    KC.C,    KC.V,    KC.B,                         KC.N,    KC.M, KC.COMM,  KC.DOT, KC.SLSH, KC.RSFT,\
                                            KC.LGUI,   LOWER,  ADJUST,     KC.ENT,   RAISE,  KC.RALT,
    ],
    [  #LOWER
        KC.ESC,   KC.N1,   KC.N2,   KC.N3,   KC.N4,   KC.N5,                         KC.N6,   KC.N7,  KC.N8,   KC.N9,   KC.N0, KC.BSPC,\
        KC.LCTL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                        KC.LEFT, KC.DOWN, KC.UP,   KC.RIGHT, XXXXXXX, XXXXXXX,\
        KC.LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                        XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\
                                            KC.LGUI,   LOWER,  ADJUST,     KC.ENT,   RAISE,  KC.RALT,
    ],
    [  #RAISE
        KC.ESC, KC.EXLM,   KC.AT, KC.HASH,  KC.DLR, KC.PERC,                         KC.CIRC, KC.AMPR, KC.ASTR, KC.LPRN, KC.RPRN, KC.BSPC,\
        KC.LCTL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                        KC.MINS,  KC.EQL, KC.LCBR, KC.RCBR, KC.PIPE,  KC.GRV,\
        KC.LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                        KC.UNDS, KC.PLUS, KC.LBRC, KC.RBRC, KC.BSLS, KC.TILD,\
                                            KC.LGUI,   LOWER,  ADJUST,     KC.ENT,   RAISE,  KC.RALT,
    ],
    [  #ADJUST
        RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX,                        XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\
        XXXXXXX, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX,                        XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\
        XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                        XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,\
                                            KC.LGUI,   LOWER,  ADJUST,     KC.ENT,   RAISE,  KC.RALT,
    ]
]

if __name__ == '__main__':
    keyboard.go(hid_type=HIDModes.USB)

Boardsource

For the Boardsource setup I'm following instructions at https://github.com/boardsource/pegBoards/blob/786e845803e148077e944df3df8604ccce6f7ac2/docs/board-update.md

I use boardsouce_unicorne.uf2 from https://github.com/boardsource/bs-python/releases/tag/v1.9.3 and flash to each half

From

The device should automatically reboot, and the "flash drive" should be gone. In
many cases, it should be ready to type. If it's not typing, we have some
troubleshooting steps below.
it seems that nothing else is necessary - the keyboard should type just from the firmware?

Unfortunately nothing happens. It appears the firmware works because the RPI-RP2 drive is gone and CIRCUITPY appears (and contains boot_out.txt), but there are no active LEDs on boot-up and no response from key presses.

Trying more stuff, I clone the latest pegeBoards repository and unzip pegBoards/libs/Boardsource-Unicorne-{R,L}.zip to the right and left boards, creating the lib folder there. Still nothing works.

I also tried cloning the latest KMK and copying the kmk sub-folder to each half of the keyboard

gh repo clone KMKfw/kmk_firmware
rsync -ahiu ./kmk_firmware/kmk/ /media/kdm/CIRCUITPY/kmk/

For kb.py and main.py:

Result: No response from the board. No LEDs on boot, and no response to key presses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant