class KMKKeyboard(_KMKKeyboard): # physical, visible cols (SCK, MO, MI, RX, TX, D4) # physical, visible rows (10, 11, 12, 13) (9, 6, 5, SCL) col_pins = (board.SCK, board.MOSI, board.MISO, board.RX, board.TX, board.D4) row_pins = ( board.D10, board.D11, board.D12, board.D13, board.D9, board.D6, board.D5, board.SCL, ) rollover_cols_every_rows = 4 diode_orientation = DiodeOrientation.COLUMNS coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) coord_mapping.extend(ic(3, r3_swap(x)) for x in range(12)) layers_ext = Layers() modules = [layers_ext]
class KMKKeyboard(_KMKKeyboard): col_pins = ( board.P0_22, board.P0_24, board.P1_00, board.P0_11, board.P1_04, board.P1_06, ) row_pins = ( board.P0_31, board.P0_29, board.P0_02, board.P1_15, board.P1_13, board.P1_11, board.P0_10, ) diode_orientation = DiodeOrientation.COLUMNS rgb_pixel_pin = board.P0_06 rgb_num_pixels = 11 i2c = board.I2C powersave_pin = board.P0_13 coord_mapping = [] coord_mapping.extend(ic(0, x, 12) for x in range(12)) coord_mapping.extend(ic(1, x, 12) for x in range(12)) coord_mapping.extend(ic(2, x, 12) for x in range(12)) # And now, to handle R3, which at this point is down to just five keys coord_mapping.extend(ic(3, x, 12) for x in range(5))
class KMKKeyboard(_KMKKeyboard): row_pins = (board.P0_24, board.P1_00, board.P0_11, board.P1_04) col_pins = ( board.P0_29, board.P0_02, board.P1_15, board.P1_13, board.P1_11, board.P0_10, board.P0_09, ) diode_orientation = DiodeOrientation.COLUMNS led_pin = board.P1_06 rgb_pixel_pin = board.P0_06 rgb_num_pixels = 12 data_pin = board.P0_08 i2c = board.I2C powersave_pin = board.P0_13 coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(14)) coord_mapping.extend(ic(1, x) for x in range(14)) coord_mapping.extend(ic(2, x) for x in range(14)) # And now, to handle R3, which at this point is down to just six keys coord_mapping.extend(ic(3, x) for x in range(3, 12))
class KMKKeyboard(_KMKKeyboard): col_pins = ( board.P0_31, board.P0_29, board.P0_02, board.P1_15, board.P1_13, board.P1_11, ) row_pins = (board.P0_22, board.P0_24, board.P1_00, board.P0_11) diode_orientation = DiodeOrientation.COLUMNS split_type = 'UART' # TODO add bluetooth support as well split_flip = True split_offsets = [6, 6, 6, 6, 6] uart_pin = board.P0_08 rgb_pixel_pin = board.P0_06 extra_data_pin = board.SDA # TODO This is incorrect. Find better solution coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) # And now, to handle R3, which at this point is down to just six keys coord_mapping.extend(ic(3, x) for x in range(3, 9))
class KMKKeyboard(_KMKKeyboard): col_pins = ( board.P0_02, board.P1_15, board.P1_13, board.P1_11, board.P0_10, board.P0_09, ) row_pins = (board.P0_24, board.P1_00, board.P0_11, board.P1_04, board.P1_06) diode_orientation = DiodeOrientation.COLUMNS uart_pin = board.P0_08 rgb_pixel_pin = board.P0_06 data_pin = board.P0_08 i2c = board.I2C powersave_pin = board.P0_13 coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) coord_mapping.extend(ic(3, x) for x in range(12)) # And now, to handle R4, which at this point is down to just ten keys coord_mapping.extend(ic(4, x) for x in range(1, 11))
class KMKKeyboard(_KMKKeyboard): row_pins = (board.GP12, board.GP13, board.GP14, board.GP15) col_pins = (board.GP21, board.GP20, board.GP19, board.GP18, board.GP17, board.GP16) diode_orientation = DiodeOrientation.COLUMNS coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) coord_mapping.extend(ic(3, x) for x in range(2, 10))
class KMKKeyboard(_KMKKeyboard): col_pins = ( board.D29, board.D28, board.D27, board.D26, board.D22, board.D20, board.D23, board.D21, ) row_pins = (board.D8, board.D7, board.D6, board.D4) diode_orientation = DiodeOrientation.COL2ROW data_pin = board.RX rgb_pixel_pin = board.D0 encoder_pin_0 = board.D9 encoder_pin_1 = board.D5 coord_mapping = [] coord_mapping.extend(ic(0, x, 8) for x in range(6)) coord_mapping.extend(ic(4, x, 8) for x in range(5, -1, -1)) coord_mapping.extend(ic(1, x, 8) for x in range(6)) coord_mapping.extend(ic(5, x, 8) for x in range(5, -1, -1)) coord_mapping.extend(ic(2, x, 8) for x in range(8)) coord_mapping.extend(ic(6, x, 8) for x in range(7, -1, -1)) coord_mapping.extend(ic(3, x, 8) for x in range(3, 8)) coord_mapping.extend(ic(7, x, 8) for x in range(7, 2, -1))
class KMKKeyboard(_KMKKeyboard): col_pins = ( board.A3, board.A2, board.A1, board.A0, board.SCK, board.MISO, ) row_pins = (board.D4, board.D5, board.D6, board.D7) diode_orientation = DiodeOrientation.COLUMNS data_pin = board.RX rgb_pixel_pin = board.D0 i2c = board.I2C coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) # And now, to handle R3, which at this point is down to just six keys coord_mapping.extend(ic(3, x) for x in range(3, 9))
class KMKKeyboard(_KMKKeyboard): # Pin mappings for converter board found at hardware/README.md # QMK: MATRIX_COL_PINS { F6, F7, B1, B3, B2, B6 } # QMK: MATRIX_ROW_PINS { D7, E6, B4, D2, D4 } col_pins = (board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI) row_pins = (board.D11, board.D10, board.D9, board.RX, board.D13) diode_orientation = DiodeOrientation.COLUMNS split_flip = True split_offsets = (6, 6, 6, 6, 6) split_type = 'UART' data_pin = board.SCL data_pin2 = board.SDA rgb_num_pixels = 12 i2c = board.I2C rgb_pixel_pin = board.TX led_pin = board.D7 coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) # Buckle up friends, the bottom row of this keyboard is wild, and making # our layouts match, visually, what the keyboard looks like, requires some # surgery on the bottom two rows of coords # Row index 3 is actually perfectly sane and we _could_ expose it # just like the above three rows, however, visually speaking, the # top-right thumb cluster button (when looking at the left-half PCB) # is more inline with R3, so we'll jam that key (and its mirror) in here coord_mapping.extend(ic(3, x) for x in range(6)) coord_mapping.append(ic(4, 2)) coord_mapping.append(ic(4, 9)) coord_mapping.extend(ic(3, x) for x in range(6, 12)) # Now, the rest of R3 # And now, to handle R4, which at this point is down to just six keys coord_mapping.extend(ic(4, x) for x in range(3, 9))
class KMKKeyboard(_KMKKeyboard): row_pins = (board.P1_00, board.P0_11, board.P1_04, board.P0_08, board.P0_22) col_pins = ( board.P0_02, board.P1_15, board.P1_13, board.P1_11, board.P0_10, board.P0_09, ) diode_orientation = DiodeOrientation.COLUMNS led_pin = board.P1_06 rgb_pixel_pin = board.P0_06 rgb_num_pixels = 12 i2c = board.I2C data_pin = board.P0_20 powersave_pin = board.P0_13 coord_mapping = [] coord_mapping.extend(ic(0, x) for x in range(12)) coord_mapping.extend(ic(1, x) for x in range(12)) coord_mapping.extend(ic(2, x) for x in range(12)) # Buckle up friends, the bottom row of this keyboard is wild, and making # our layouts match, visually, what the keyboard looks like, requires some # surgery on the bottom two rows of coords # Row index 3 is actually perfectly sane and we _could_ expose it # just like the above three rows, however, visually speaking, the # top-right thumb cluster button (when looking at the left-half PCB) # is more inline with R3, so we'll jam that key (and its mirror) in here coord_mapping.extend(ic(3, x) for x in range(6)) coord_mapping.append(ic(4, 2)) coord_mapping.append(ic(4, 9)) coord_mapping.extend(ic(3, x) for x in range(6, 12)) # Now, the rest of R3 # And now, to handle R4, which at this point is down to just six keys coord_mapping.extend(ic(4, x) for x in range(3, 9))
def go(self, hid_type=HIDModes.USB): assert self.keymap, 'must define a keymap with at least one row' assert self.row_pins, 'no GPIO pins defined for matrix rows' assert self.col_pins, 'no GPIO pins defined for matrix columns' assert self.diode_orientation is not None, 'diode orientation must be defined' assert (hid_type in HIDModes.ALL_MODES ), 'hid_type must be a value from kmk.consts.HIDModes' # Attempt to sanely guess a coord_mapping if one is not provided if not self.coord_mapping: self.coord_mapping = [] rows_to_calc = len(self.row_pins) cols_to_calc = len(self.col_pins) if self.split_offsets: rows_to_calc *= 2 cols_to_calc *= 2 for ridx in range(rows_to_calc): for cidx in range(cols_to_calc): self.coord_mapping.append(ic(ridx, cidx)) self._state = InternalState(self) if hid_type == HIDModes.NOOP: self.hid_helper = AbstractHID elif hid_type == HIDModes.USB: self.hid_helper = USBHID elif hid_type == HIDModes.BLE: self.hid_helper = BLEHID self._hid_helper_inst = self.hid_helper() # Split keyboard Init if self.split_type is not None: try: # Working around https://github.com/adafruit/circuitpython/issues/1769 self._hid_helper_inst.create_report([]).send() self.is_master = True # Sleep 2s so master portion doesn't "appear" to boot quicker than # dependent portions (which will take ~2s to time out on the HID send) sleep_ms(2000) except OSError: self.is_master = False if self.split_flip and not self.is_master: self.col_pins = list(reversed(self.col_pins)) if self.split_side == 'Left': self.split_master_left = self.is_master elif self.split_side == 'Right': self.split_master_left = not self.is_master else: self.is_master = True if self.uart_pin is not None: self.uart = self.init_uart(self.uart_pin) if self.rgb_pixel_pin: self.pixels = rgb.RGB(self.rgb_config, self.rgb_pixel_pin) self.rgb_config = None # No longer needed self.pixels.loopcounter = 0 else: self.pixels = None if self.led_pin: self.led = led.led(self.led_pin, self.led_config) self.led_config = None # No longer needed else: self.led = None self.matrix = MatrixScanner( cols=self.col_pins, rows=self.row_pins, diode_orientation=self.diode_orientation, rollover_cols_every_rows=getattr(self, 'rollover_cols_every_rows', None), ) # Compile string leader sequences for k, v in self.leader_dictionary.items(): if not isinstance(k, tuple): new_key = tuple(KC[c] for c in k) self.leader_dictionary[new_key] = v for k, v in self.leader_dictionary.items(): if not isinstance(k, tuple): del self.leader_dictionary[k] gc.collect() self._print_debug_cycle(init=True) while True: state_changed = False if self.split_type is not None and self.is_master: update = self._receive_from_slave() if update is not None: self._handle_matrix_report(update) state_changed = True update = self.matrix.scan_for_changes() if update is not None: if self.is_master: self._handle_matrix_report(update) state_changed = True else: # This keyboard is a slave, and needs to send data to master self._send_to_master(update) if self._state.hid_pending: self._send_hid() old_timeouts_len = len(self._state.timeouts) self._state.process_timeouts() new_timeouts_len = len(self._state.timeouts) if old_timeouts_len != new_timeouts_len: state_changed = True if self._state.hid_pending: self._send_hid() if self.pixels and self.pixels.animation_mode: self.pixels.loopcounter += 1 if self.pixels.loopcounter >= 7: self.pixels = self.pixels.animate() self.pixels.loopcounter = 0 if self.led and self.led.enabled and self.led.animation_mode: self.led = self.led.animate() if state_changed: self._print_debug_cycle()