def __init__(self, modules, keymap, keyboard_debug_enabled=False, debug_enabled=False): self.debug_enabled = debug_enabled self.keyboard = KMKKeyboard() self.keyboard.debug_enabled = keyboard_debug_enabled self.keyboard.modules = modules self.pins = tuple(DigitalInOut() for k in keymap[0]) self.keyboard.col_pins = (DigitalInOut(), ) self.keyboard.row_pins = self.pins self.keyboard.diode_orientation = DiodeOrientation.COL2ROW self.keyboard.keymap = keymap self.keyboard._init(hid_type=HIDModes.NOOP)
import board import pwmio import time led = pwmio.PWMOut(board.GP25, frequency=60, duty_cycle=1024, variable_frequency=True) import board from kmk.kmk_keyboard import KMKKeyboard from kmk.keys import KC from kmk.matrix import DiodeOrientation from kmk.modules.layers import Layers from kmk.keys import KC, make_key envkb = KMKKeyboard() envkb.col_pins = (board.GP18, board.GP19, board.GP20, board.GP21) envkb.row_pins = (board.GP4, board.GP11, board.GP15) envkb.diode_orientation = DiodeOrientation.COLUMNS rollover_cols_every_rows = 4 envkb.diode_orientation = DiodeOrientation.COLUMNS envkb.debug_enabled = False layers = Layers() envkb.modules = [layers] nokey = KC.NO envkb.keymap = [ [
#PiPi-GHERKIN - Raspberry Pi PICO #Rpi pico keyboard keymap, I used the gherkin keymap as a example :) import board from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.hid import HIDModes envkb = KMKKeyboard() envkb.col_pins = (board.GP18, board.GP19, board.GP20, board.GP21) envkb.row_pins = (board.GP4, board.GP11, board.GP15) envkb.diode_orientation = DiodeOrientation.COLUMNS envkb.debug_enabled = False nokey = KC.NO envkb.keymap = [ [ KC.F13, KC.F14, KC.F15, KC.F16, KC.F17, KC.F18, KC.F19, KC.F20, KC.F21, KC.F22, KC.F23, KC.F24, ], ]
import board import digitalio from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.extensions.media_keys import MediaKeys from kmk.modules.rotaryEncoder import encoder keyboard = KMKKeyboard() keyboard.extensions.append(MediaKeys()) keyboard.col_pins = (board.GP15, board.GP13, board.GP12) keyboard.row_pins = (board.GP8, board.GP9, board.GP10, board.GP11) keyboard.diode_orientation = DiodeOrientation.COLUMNS keyboard.debug_enabled = True pins = [[board.GP0, board.GP1], [board.GP2, board.GP3]] encMap = [[[KC.VOLU, KC.VOLD], [KC.K, KC.J]], [[KC.MEDIA_NEXT_TRACK, KC.MEDIA_PREV_TRACK], [KC.X, KC.Z]]] keyboard.modules.append(encoder(pins, encMap)) keyboard.keymap = [[ KC.AUDIO_MUTE, None, KC.MEDIA_PLAY_PAUSE, KC.F13, KC.F14, KC.C, KC.D, KC.E, KC.F, KC.G, KC.H, KC.I ], [KC.Y, None, KC.Z, KC.L, KC.R, KC.S, KC.T, KC.U, KC.V, KC.W, KC.X, KC.J]] # Onboard Pico LED enable led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT led.value = True if __name__ == "__main__":
import board import digitalio from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.rotaryEncoder import encoder import oledDisplay from kmk.slider import slider keyboard = KMKKeyboard() keyboard.col_pins = (board.GP15, board.GP13, board.GP12) keyboard.row_pins = (board.GP8, board.GP9, board.GP10, board.GP11) keyboard.diode_orientation = DiodeOrientation.COLUMNS keyboard.debug_enabled = True keyboard.enableEncoder = True keyboard.encoders = [encoder(board.GP0, board.GP1), encoder(board.GP2, board.GP3)] keyboard.encoders[0].encMap = [[KC.VOLU, KC.VOLD], [KC.K, KC.J]] keyboard.encoders[1].encMap = [[KC.RIGHT, KC.LEFT], [KC.X, KC.Z]] keyboard.enableOled = True keyboard.oledDisp = oledDisplay.oled(board.GP21, board.GP20, "Hello World") keyboard.keymap = [ [KC.Y, None, KC.Z, KC.A, KC.B, KC.C, KC.D, KC.E, KC.F, KC.G, KC.H, KC.TO(1)], [KC.Y, None, KC.Z, KC.TO(0), KC.R, KC.S, KC.T, KC.U, KC.V, KC.W, KC.X, KC.TO(0)] ] # Onboard Pico LED enable led = digitalio.DigitalInOut(board.GP25) led.direction = digitalio.Direction.OUTPUT
#PiPi-GHERKIN - Raspberry Pi PICO import board from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.hid import HIDModes gherkin = KMKKeyboard() gherkin.col_pins = (board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7) gherkin.row_pins = (board.GP8, board.GP9, board.GP10, board.GP11, board.GP12) #Rotate gherkin so USB on Right Side. Not needed if USB on Left Side. gherkin.col_pins = tuple(reversed(gherkin.col_pins)) gherkin.row_pins = tuple(reversed(gherkin.row_pins)) gherkin.diode_orientation = DiodeOrientation.COLUMNS gherkin.debug_enabled = False gherkin.keymap = [ [ KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I,
import busio from digitalio import DigitalInOut, Direction, Pull from adafruit_mcp230xx.mcp23017 import MCP23017 from kmk.hid import HIDModes from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.modules.layers import Layers # DEBUG_ENABLE = True i2c = busio.I2C(scl=board.SCL, sda=board.SDA, frequency=100000) mcp = MCP23017(i2c, address=0x20) keyboard = KMKKeyboard() layer_ext = Layers keyboard.modules = [layer_ext] _______ = KC.TRNS XXXXXXX = KC.NO FN = KC.MO(1) keyboard.debug_enabled = True keyboard.col_pins = (mcp.get_pin(8), mcp.get_pin(9), mcp.get_pin(10), mcp.get_pin(11), mcp.get_pin(12), mcp.get_pin(13), mcp.get_pin(14), mcp.get_pin(15), mcp.get_pin(4), mcp.get_pin(5), mcp.get_pin(6), mcp.get_pin(7), mcp.get_pin(3), mcp.get_pin(2), mcp.get_pin(1))
#PiPi-GHERKIN - Raspberry Pi PICO #Rpi pico keyboard keymap, I used the gherkin keymap as a example :) print("Keyboard is starting") import board from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.modules.layers import Layers from kmk.matrix import DiodeOrientation from kmk.hid import HIDModes envkb = KMKKeyboard() keyboard = envkb envkb.col_pins = (board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7, board.GP8, board.GP9, board.GP10, board.GP11, board.GP12, board.GP13, board.GP14, board.GP15, board.GP19, board.GP18, board.GP17, board.GP16) envkb.row_pins = (board.GP20, board.GP21, board.GP22, board.GP26, board.GP27, board.GP28) envkb.diode_orientation = DiodeOrientation.COLUMNS envkb.debug_enabled = False nokey = KC.NO layers = Layers() envkb.modules = [layers] from kmk.extensions.RGB import RGB from kmk.extensions.rgb import AnimationModes #rgb_ext = RGB(pixel_pin=rgb_pixel_pin, num_pixels=27) # rgb_ext = RGB(pixel_pin=board.GP0, num_pixels=88, val_limit=100, hue_default=0 sat_default=255, rgb_order=(1, 0, 2), # GRB WS2812
import board from kmk.consts import UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences, send_string from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.types import AttrDict keyboard = KMKKeyboard() keyboard.col_pins = (board.A0, board.A1, board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI, board.MISO, board.RX, board.TX, board.D4) keyboard.row_pins = (board.D10, board.D11, board.D12, board.D13) keyboard.diode_orientation = DiodeOrientation.COLUMNS # ------------------User level config variables --------------------------------------- keyboard.unicode_mode = UnicodeMode.LINUX keyboard.tap_time = 350 keyboard.leader_timeout = 2000 keyboard.debug_enabled = False emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier 'ANGRY_TABLE_FLIP': r'(ノಠ痊ಠ)ノ彡┻━┻', 'CHEER': r'+。:.゚ヽ(´∀。)ノ゚.:。+゚゚+。:.゚ヽ(*´∀)ノ゚.:。+゚', 'TABLE_FLIP': r'(╯°□°)╯︵ ┻━┻', 'WAT': r'⊙.☉', 'FF': r'凸(゚Д゚#)', 'F': r'( ̄^ ̄)凸', 'MEH': r'╮( ̄_ ̄)╭',
class KeyboardTest: def __init__(self, modules, keymap, keyboard_debug_enabled=False, debug_enabled=False): self.debug_enabled = debug_enabled self.keyboard = KMKKeyboard() self.keyboard.debug_enabled = keyboard_debug_enabled self.keyboard.modules = modules self.pins = tuple(DigitalInOut() for k in keymap[0]) self.keyboard.col_pins = (DigitalInOut(), ) self.keyboard.row_pins = self.pins self.keyboard.diode_orientation = DiodeOrientation.COL2ROW self.keyboard.keymap = keymap self.keyboard._init(hid_type=HIDModes.NOOP) @patch('kmk.hid.AbstractHID.hid_send') def test(self, testname, key_events, assert_hid_reports, hid_send): if self.debug_enabled: print(testname, key_events, assert_hid_reports) hid_send_call_arg_list = [] hid_send.side_effect = lambda hid_report: hid_send_call_arg_list.append( hid_report[1:]) for e in key_events: if isinstance(e, int): starttime_ms = time.time_ns() // 1_000_000 while time.time_ns() // 1_000_000 - starttime_ms < e: self.do_main_loop() else: key_pos = e[0] is_pressed = e[1] self.pins[key_pos].value = is_pressed self.do_main_loop() if self.debug_enabled: for hid_report in hid_send_call_arg_list: print(hid_report) assert len(hid_send_call_arg_list) >= len(assert_hid_reports) for i, hid_report in enumerate( hid_send_call_arg_list[-len(assert_hid_reports):]): hid_report_keys = {code for code in hid_report[2:] if code != 0} assert_keys = { k.code for k in assert_hid_reports[i] if not isinstance(k, ModifierKey) } if self.debug_enabled: print( 'assert keys:', hid_report_keys == assert_keys, hid_report_keys, assert_keys, ) assert hid_report_keys == assert_keys hid_report_modifiers = hid_report[0] assert_modifiers = reduce( lambda mod, all_mods: all_mods | mod, { k.code for k in assert_hid_reports[i] if isinstance(k, ModifierKey) }, 0, ) if self.debug_enabled: print( 'assert mods:', hid_report_modifiers == assert_modifiers, hid_report_modifiers, assert_modifiers, ) assert hid_report_modifiers == assert_modifiers
import board from kmk.consts import UnicodeMode from kmk.handlers.sequences import compile_unicode_string_sequences, send_string from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.types import AttrDict keyboard = KMKKeyboard() ''' Converter/handwire: PB5: SCL PB4: SDA PE6: A0 PD7: A1 PC6: A2 PD4: A3 PD0: A4 PB6: D2 PB2: TX PB3: RX PB1: MI PF7: MO PF6: SCK PF5: A5 Mosfet on B5 to control backlight '''
import board from kmk.keys import KC from kmk.kmk_keyboard import KMKKeyboard from kmk.matrix import DiodeOrientation from kmk.handlers.sequences import send_string import digitalio redox_l = KMKKeyboard() #redox_l.debug_enabled = True redox_l.col_pins = (board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7, board.GP8) redox_l.row_pins = (board.GP16, board.GP17, board.GP18, board.GP19, board.GP20) redox_l.diode_orientation = DiodeOrientation.COLUMNS redox_l.split_type = "UART" redox_l.uart_pin = (board.GP0, board.GP1) # Must include this to get pico uart to work. kmk_keyboard.py lines 172, 174 changed from ...x=pin, to x=pin[0 or 1] redox_l.split_flip = True redox_l.split_offsets = [7, 7, 7, 7, 7] qt_strg = send_string("quit()") redox_l.keymap = [ # Qwerty # ,------------------------------------------------. ,------------------------------------------------. # | esc | 1 | 2 | 3 | 4 | 5 |delete| |delete| 6 | 7 | 8 | 9 | 0 | fn | # |------+------+------+------+------+------+------| |------+------+------+------+------+------+------| # | tab | Q | W | E | R | T | esc | | rclck| Y | U | I | O | P |bckspc| # |------+------+------+------+------+-------------| |------+------+------+------+------+-------------| # | ctrl | A | S | D | F | G | {[ | | -_ | H | J | K | L | : | \| | # |------+------+------+------+------+------|------| |------+------+------+------+------+------|------| # | Shift| Z | X | C | V | B | }] | | += | N | M | ,< | .> | ?/ |Shift |