From 2b28b99503e96e30b242f11a4d47bcc40dcfb097 Mon Sep 17 00:00:00 2001 From: Kyle Brown Date: Thu, 25 Oct 2018 23:00:11 -0700 Subject: [PATCH] Finalize docs, and unbreak failed rebase --- docs/split_keyboards.md | 38 ++++++++++++++++++++++++ kmk/firmware.py | 47 +++++++++++++++++++----------- user_keymaps/kdb424/levinson_m4.py | 5 ++-- 3 files changed, 71 insertions(+), 19 deletions(-) create mode 100644 docs/split_keyboards.md diff --git a/docs/split_keyboards.md b/docs/split_keyboards.md new file mode 100644 index 0000000..ea83ac7 --- /dev/null +++ b/docs/split_keyboards.md @@ -0,0 +1,38 @@ +# Split Keyboards +Split keyboards are mostly the same as unsplit and very easy to adapt a keymap for. Currently +UART is supported, though other modes will come later such as Bluetooth and i2c. + +Useful config options: +```python +keyboard.split_type = "UART" # Sets split mode to UART +keyboard.split_flip = True # If your boards are identical but one is flipped, this option is for you +keyboard.split_offsets = [6, 6, 6, 6] # This is the how many keys are on each column on the "Master" half +``` + +## Master Half +Choosing the master half can be done one of 2 ways. You can set this true or false if you only pleg in on one side. +```python +keyboard.split_master_left = True +``` + +## EE HANDS +If you want to plug in on either side, it can be done fairly easily but requires setup. + +On each half of your keyboard make a file called kmk_side.py and add one of these lines to the file +depending on where each piece is physically located. +```python +split_side = "Left" +OR +split_side = "Right" +``` + +and then in your keymap, add the line +```python +from kmk_side import split_side +``` + +# UART +To enable uart it's as simple as adding this line, of course changing the pin +```python +keyboard.uart = keyboard.init_uart(tx=board.SCL) +``` diff --git a/kmk/firmware.py b/kmk/firmware.py index 9cf9fdd..c21de5c 100644 --- a/kmk/firmware.py +++ b/kmk/firmware.py @@ -34,7 +34,6 @@ import kmk.internal_state # isort:skip # Thanks for sticking around. Now let's do real work, starting below -import board import busio import gc @@ -66,7 +65,7 @@ class Firmware: split_flip = False split_master_left = True uart = None - uart_flip = False + uart_flip = True def __init__(self): self._state = InternalState(self) @@ -92,8 +91,13 @@ class Firmware: update[2], ) - if self._state.hid_pending: - self._send_hid() + if self._state.hid_pending: + self._send_hid() + + if self.debug_enabled: + print('New State: {}'.format(self._state._to_dict())) + + self._state.process_timeouts() for key in self._state.pending_keys: self._send_key(key) @@ -105,9 +109,6 @@ class Firmware: self._state.resolve_macro() - if self.debug_enabled: - print('New State: {}'.format(self._state._to_dict())) - def _send_to_master(self, update): if self.uart is not None: @@ -118,7 +119,9 @@ class Firmware: def _receive_from_slave(self): if self.uart is not None and self.uart.in_waiting > 0: - update = bytearray(self.uart.read()) + update = bytearray(self.uart.read(3)) + if self.split_master_left: + update[1] -= self.split_offsets[update[0]] return update return None @@ -146,6 +149,17 @@ class Firmware: if self.split_flip and not self._master_half(): self.col_pins = list(reversed(self.col_pins)) + if self.split_side == "Left": + if supervisor.runtime.serial_connected: + self.split_master_left = True + else: + self.split_master_left = False + else: + if supervisor.runtime.serial_connected: + self.split_master_left = False + else: + self.split_master_left = True + self.matrix = MatrixScanner( cols=self.col_pins, rows=self.row_pins, @@ -163,17 +177,16 @@ class Firmware: if self.split_type is not None and self._master_half: update = self._receive_from_slave() if update is not None: - print(str(update)) self._handle_update(update) - for update in self.matrix.scan_for_changes(): - if update is not None: - # Abstract this later. Bluetooth will fail here - if self._master_half(): - self._handle_update(update) + update = self.matrix.scan_for_changes() - else: - # This keyboard is a slave, and needs to send data to master - self._send_to_master(update) + if update is not None: + if self._master_half(): + self._handle_update(update) + + else: + # This keyboard is a slave, and needs to send data to master + self._send_to_master(update) gc.collect() diff --git a/user_keymaps/kdb424/levinson_m4.py b/user_keymaps/kdb424/levinson_m4.py index 2c53c03..9560964 100644 --- a/user_keymaps/kdb424/levinson_m4.py +++ b/user_keymaps/kdb424/levinson_m4.py @@ -19,13 +19,14 @@ keyboard.diode_orientation = DiodeOrientation.COLUMNS # ------------------User level config variables --------------------------------------- keyboard.unicode_mode = UnicodeModes.LINUX -keyboard.tap_time = 900 +keyboard.tap_time = 350 keyboard.leader_timeout = 2000 -keyboard.debug_enabled = True +keyboard.debug_enabled = False keyboard.split_type = "UART" keyboard.split_flip = True keyboard.split_offsets = [6, 6, 6, 6] keyboard.uart = keyboard.init_uart(tx=board.TX, rx=board.RX) +keyboard.uart_flip = False emoticons = compile_unicode_string_sequences({ # Emoticons, but fancier