2022-02-21 02:34:44 +01:00
|
|
|
'''
|
|
|
|
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
|
2022-04-10 14:46:40 +02:00
|
|
|
from kmk.scanners.keypad import KeysScanner
|
2022-02-21 02:34:44 +01:00
|
|
|
|
|
|
|
# fmt: off
|
2022-09-29 22:28:02 +02:00
|
|
|
|
2022-10-02 18:36:41 +02:00
|
|
|
|
2022-02-21 02:34:44 +01:00
|
|
|
def raspi_pins():
|
|
|
|
return [
|
2022-04-10 21:28:19 +02:00
|
|
|
board.D20, board.D16, board.D26,
|
|
|
|
board.D6, board.D12, board.D13,
|
|
|
|
board.D22, board.D24, board.D5,
|
|
|
|
board.D17, board.D27, board.D23,
|
2022-02-21 02:34:44 +01:00
|
|
|
]
|
|
|
|
|
2022-10-02 18:36:41 +02:00
|
|
|
|
2022-09-29 22:28:02 +02:00
|
|
|
def rp2040_pins():
|
|
|
|
return [
|
|
|
|
board.GP7, board.GP8, board.GP27,
|
|
|
|
board.GP9, board.GP26, board.GP10,
|
2022-10-02 18:36:41 +02:00
|
|
|
board.GP11, board.GP18, board.GP12,
|
2022-09-29 22:28:02 +02:00
|
|
|
board.GP16, board.GP17, board.GP14
|
|
|
|
]
|
2022-10-02 18:36:41 +02:00
|
|
|
|
2022-02-21 02:34:44 +01:00
|
|
|
|
|
|
|
def itsybitsy_pins():
|
|
|
|
return [
|
2022-04-10 21:28:19 +02:00
|
|
|
board.D11, board.D12, board.D2,
|
|
|
|
board.D10, board.D9, board.D7,
|
|
|
|
board.A5, board.A4, board.A3,
|
|
|
|
board.A2, board.A1, board.A0,
|
2022-10-02 18:36:41 +02:00
|
|
|
]
|
2022-09-29 22:28:02 +02:00
|
|
|
|
2022-02-21 02:34:44 +01:00
|
|
|
# fmt: on
|
|
|
|
|
|
|
|
|
|
|
|
def isPi():
|
|
|
|
return sys.platform == 'BROADCOM'
|
2022-10-02 18:36:41 +02:00
|
|
|
|
|
|
|
|
2022-09-29 22:28:02 +02:00
|
|
|
def isRP2040():
|
|
|
|
return sys.platform == 'RP2040'
|
2022-02-21 02:34:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
if isPi():
|
|
|
|
_KEY_CFG = raspi_pins()
|
|
|
|
_LED_PINS = (board.SCK, board.MOSI)
|
2022-09-29 22:28:02 +02:00
|
|
|
elif isRP2040():
|
|
|
|
_KEY_CFG = rp2040_pins()
|
|
|
|
_LED_PINS = (board.GP2, board.GP3)
|
|
|
|
|
2022-02-21 02:34:44 +01:00
|
|
|
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):
|
2022-04-10 14:46:40 +02:00
|
|
|
self.matrix = KeysScanner(_KEY_CFG)
|