Last active
October 4, 2022 19:53
-
-
Save Corteil/e2297184ec1008230669176f2e1b5249 to your computer and use it in GitHub Desktop.
Modified keybow.py file for KMK firmware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
KMK keyboard for Pimoroni Keybow. | |
WARNING: This doesn't currently function correctly on the Raspberry Pi Zero, | |
some of the keys are stuck in the 'pressed' position. There's either a bug in | |
the keypad implementation on the rpi0, or the pin numbers don't match the pins | |
in linux. | |
This is a 4x3 macro pad designed to fit the rpi's GPIO connector. Each key is | |
attached to a single GPIO and has an APA102 LED mounted underneath it. | |
The layout of the board is as follows (GPIO connector on the left): | |
R0 | D20 D6 D22 | |
R1 | D17 D16 D12 | |
R2 | D24 D27 D26 | |
R0 | D13 D5 D23 | |
------------------ | |
C0 C1 C2 | |
This board also functions with an adaptor (see | |
https://learn.adafruit.com/itsybitsy-keybow-mechanical-keypad/) to work with an | |
itsybitsy in place of the rpi, which uses an alternate pin mapping: | |
R0 | A2 A1 A0 | |
R1 | A5 A4 A3 | |
R2 | D10 D9 D7 | |
R3 | D11 D12 D2 | |
------------------ | |
C0 C1 C2 | |
This keyboard file should automatically select the correct mapping at runtime. | |
""" | |
import board | |
import adafruit_dotstar | |
import sys | |
from kmk.extensions.rgb import RGB, AnimationModes | |
from kmk.kmk_keyboard import KMKKeyboard | |
from kmk.scanners.keypad import KeysScanner | |
# fmt: off | |
def raspi_pins(): | |
return [ | |
board.D20, board.D16, board.D26, | |
board.D6, board.D12, board.D13, | |
board.D22, board.D24, board.D5, | |
board.D17, board.D27, board.D23, | |
] | |
def rp2040_pins(): | |
return [ | |
board.GP7, board.GP8, board.GP27, | |
board.GP9, board.GP26, board.GP10, | |
board.GP11, board.GP18, board.GP12, | |
board.GP16, board.GP17, board.GP14 | |
] | |
def itsybitsy_pins(): | |
return [ | |
board.D11, board.D12, board.D2, | |
board.D10, board.D9, board.D7, | |
board.A5, board.A4, board.A3, | |
board.A2, board.A1, board.A0, | |
] | |
# fmt: on | |
def isPi(): | |
return sys.platform == "BROADCOM" | |
def isRP2040(): | |
return sys.platform == "RP2040" | |
if isPi(): | |
_KEY_CFG = raspi_pins() | |
_LED_PINS = (board.SCK, board.MOSI) | |
elif isRP2040(): | |
_KEY_CFG = rp2040_pins() | |
_LED_PINS = (board.GP2, board.GP3) | |
else: | |
_KEY_CFG = itsybitsy_pins() | |
_LED_PINS = (board.SCK, board.MOSI) | |
led_strip = adafruit_dotstar.DotStar(_LED_PINS[0], _LED_PINS[1], 12) | |
rgb_ext = RGB( | |
pixel_pin=0, | |
pixels=led_strip, | |
num_pixels=12, | |
animation_mode=AnimationModes.BREATHING_RAINBOW, | |
) | |
class Keybow(KMKKeyboard): | |
""" | |
Default keyboard config for the Keybow. | |
""" | |
extensions = [rgb_ext] | |
def __init__(self): | |
self.matrix = KeysScanner(_KEY_CFG) |
Updated to conform to black standards
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used a @NeilRedRobotics Pico to Pi adapter.
I followed the setup guide and then I modified the http://keybow.py file in the https://github.com/KMKfw/kmk_firmware boards -> pimoroni -> keybow folder.