Fixed IS31FL3731 LEDs on keybow 2040

This commit is contained in:
Ellie T 2022-02-21 15:28:34 +11:00 committed by Kyle Brown
parent aae476b59f
commit d54fff883d
3 changed files with 36 additions and 30 deletions

View File

@ -1,8 +1,18 @@
from is31fl3731_pixelbuf import Keybow2040Leds
from keybow_2040 import Keybow2040 from keybow_2040 import Keybow2040
from kmk.extensions.rgb import RGB, AnimationModes
from kmk.keys import KC from kmk.keys import KC
rgb_ext = RGB(
pixel_pin=0,
pixels=Keybow2040Leds(16),
num_pixels=16,
animation_mode=AnimationModes.BREATHING_RAINBOW,
)
keybow = Keybow2040() keybow = Keybow2040()
keybow.extensions = [rgb_ext]
# fmt: off # fmt: off
keybow.keymap = [ keybow.keymap = [

View File

@ -0,0 +1,26 @@
'''
Simple PixelBuf wrapper for the IS31FL3731 controller used for the Keybow2040's RGB LEDs.
'''
import board
from adafruit_is31fl3731.keybow2040 import Keybow2040 as KeybowLeds
from adafruit_pixelbuf import PixelBuf
class Keybow2040Leds(PixelBuf):
'''
Minimal PixelBuf wrapper for the Keybow 2040's LED array.
'''
def __init__(self, size: int):
self.leds = KeybowLeds(board.I2C())
self._pixels = size
super().__init__(size, byteorder='RGB')
def _transmit(self, buffer):
for pixel in range(self._pixels):
r = buffer[pixel * 3 + 0]
g = buffer[pixel * 3 + 1]
b = buffer[pixel * 3 + 2]
self.leds.pixelrgb(pixel // 4, pixel % 4, r, g, b)

View File

@ -23,10 +23,6 @@ key switches, then adds [BOOT] in (4,0). [RESET] can't be mapped as a key.
import board import board
from adafruit_is31fl3731.keybow2040 import Keybow2040 as KeybowLeds
from adafruit_pixelbuf import PixelBuf
# from kmk.extensions.rgb import RGB
from kmk.kmk_keyboard import KMKKeyboard from kmk.kmk_keyboard import KMKKeyboard
from kmk.scanners.native_keypad_scanner import keys_scanner from kmk.scanners.native_keypad_scanner import keys_scanner
@ -41,36 +37,10 @@ _KEY_CFG = [
# fmt: on # fmt: on
class Keybow2040Leds(PixelBuf):
'''
Minimal PixelBuf wrapper for the Keybow 2040's LED array.
NOTE: Currently broken.
'''
def __init__(self, size: int):
self.leds = KeybowLeds(board.I2C)
super().__init__(size, byteorder='RGB')
def _transmit(self, buffer):
for pixel in range(self._pixels):
r = buffer[pixel * 3 + 0]
g = buffer[pixel * 3 + 1]
b = buffer[pixel * 3 + 2]
self.leds.pixel(pixel // 4, pixel % 4, (r, g, b))
# rgb_ext = RGB(0, pixels=Keybow2040Leds(16), num_pixels=16)
class Keybow2040(KMKKeyboard): class Keybow2040(KMKKeyboard):
''' '''
Default keyboard config for the Keybow2040. Default keyboard config for the Keybow2040.
TODO: Map the LEDs as well.
''' '''
# extensions = [rgb_ext]
def __init__(self): def __init__(self):
self.matrix = keys_scanner(_KEY_CFG) self.matrix = keys_scanner(_KEY_CFG)