Continue to shuffle and burn stuff
- Remove the concept of "mcus". With only one target platform (CircuitPython), it no longer makes a bunch of sense and has been kept around for "what if" reasons, complicating our import chains and eating up RAM for pointless subclasses. If you're a `board`, you derive from `KeyboardConfig`. If you're a handwire, the user will derive from `KeyboardConfig`. The end. As part of this, `kmk.hid` was refactored heavily to emphasize that CircuitPython is our only supported HID stack, with stubs for future HID implementations (`USB_HID` becomes `AbstractHID`, probably only usable for testing purposes, `CircuitPython_USB_HID` becomes `USBHID`, and `BLEHID` is added with an immediate `NotImplementedError` on instantiation) - `KeyboardConfig` can now take a HID type at runtime. The NRF52840 boards will happily run in either configuration once CircuitPython support is in place, and a completely separate `mcu` subclass for each mode made no sense. This also potentially allows runtime *swaps* of HID driver down the line, but no code has been added to this effect. The default, and only functional value, for this is `HIDModes.USB` - Most consts have been moved to more logical homes - often, the main or, often only, component that uses them. `DiodeOrientation` moved to `kmk.matrix`, and anything HID-related moved to `kmk.hid`
This commit is contained in:
parent
eb566b0f71
commit
6baaf5e5d4
@ -18,9 +18,7 @@ interface between end users and the inner workings of KMK. Let's dive in!
|
||||
some day.
|
||||
|
||||
- Import the `KeyboardConfig` object for your keyboard from `kmk.boards` (or, if
|
||||
handwiring your keyboard, import `KeyboardConfig` from the appropriate MCU for your
|
||||
board from `kmk.mcus`. See `hardware.md` for the list of supported boards and
|
||||
map this to the correct Python module under either of those paths.
|
||||
handwiring your keyboard, import `KeyboardConfig` from `kmk.keyboard_config`).
|
||||
|
||||
- Assign a `KeyboardConfig` instance to a variable (ex. `keyboard = KeyboardConfig()` - note
|
||||
the parentheses)
|
||||
@ -37,6 +35,8 @@ if __name__ == '__main__':
|
||||
for example:
|
||||
|
||||
```python
|
||||
from kmk.matrix import DiodeOrientation
|
||||
|
||||
col_pins = (P.SCK, P.MOSI, P.MISO, P.RX, P.TX, P.D4)
|
||||
row_pins = (P.D10, P.D11, P.D12, P.D13, P.D9, P.D6, P.D5, P.SCL)
|
||||
rollover_cols_every_rows = 4
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,8 +1,8 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.matrix import intify_coordinate as ic
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,7 +1,7 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
|
@ -1,8 +1,8 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.matrix import intify_coordinate as ic
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
# Implements what used to be handled by KeyboardConfig.swap_indicies for this
|
||||
# board, by flipping various row3 (bottom physical row) keys so their
|
||||
|
@ -3,49 +3,6 @@ try:
|
||||
except Exception:
|
||||
KMK_RELEASE = 'copied-from-git'
|
||||
|
||||
CIRCUITPYTHON = 'CircuitPython'
|
||||
|
||||
|
||||
class HIDReportTypes:
|
||||
KEYBOARD = 1
|
||||
MOUSE = 2
|
||||
CONSUMER = 3
|
||||
SYSCONTROL = 4
|
||||
|
||||
|
||||
class HIDUsage:
|
||||
KEYBOARD = 0x06
|
||||
MOUSE = 0x02
|
||||
CONSUMER = 0x01
|
||||
SYSCONTROL = 0x80
|
||||
|
||||
|
||||
class HIDUsagePage:
|
||||
CONSUMER = 0x0C
|
||||
KEYBOARD = MOUSE = SYSCONTROL = 0x01
|
||||
|
||||
|
||||
# Currently only used by the CircuitPython HIDHelper because CircuitPython
|
||||
# actually enforces these limits with a ValueError. Unused on PyBoard because
|
||||
# we can happily send full reports there and it magically works.
|
||||
HID_REPORT_SIZES = {
|
||||
HIDReportTypes.KEYBOARD: 8,
|
||||
HIDReportTypes.MOUSE: 4,
|
||||
HIDReportTypes.CONSUMER: 2,
|
||||
HIDReportTypes.SYSCONTROL: 8, # TODO find the correct value for this
|
||||
}
|
||||
|
||||
|
||||
class DiodeOrientation:
|
||||
'''
|
||||
Orientation of diodes on handwired boards. You can think of:
|
||||
COLUMNS = vertical
|
||||
ROWS = horizontal
|
||||
'''
|
||||
|
||||
COLUMNS = 0
|
||||
ROWS = 1
|
||||
|
||||
|
||||
class UnicodeMode:
|
||||
NOOP = 0
|
||||
|
47
kmk/hid.py
47
kmk/hid.py
@ -1,10 +1,44 @@
|
||||
import usb_hid
|
||||
|
||||
from kmk.consts import HID_REPORT_SIZES, HIDReportTypes, HIDUsage, HIDUsagePage
|
||||
from kmk.keys import FIRST_KMK_INTERNAL_KEY, ConsumerKey, ModifierKey
|
||||
|
||||
|
||||
class USB_HID:
|
||||
class HIDModes:
|
||||
NOOP = 0 # currently unused; for testing?
|
||||
USB = 1
|
||||
BLE = 2 # currently unused; for bluetooth
|
||||
|
||||
ALL_MODES = (NOOP, USB, BLE)
|
||||
|
||||
|
||||
class HIDReportTypes:
|
||||
KEYBOARD = 1
|
||||
MOUSE = 2
|
||||
CONSUMER = 3
|
||||
SYSCONTROL = 4
|
||||
|
||||
|
||||
class HIDUsage:
|
||||
KEYBOARD = 0x06
|
||||
MOUSE = 0x02
|
||||
CONSUMER = 0x01
|
||||
SYSCONTROL = 0x80
|
||||
|
||||
|
||||
class HIDUsagePage:
|
||||
CONSUMER = 0x0C
|
||||
KEYBOARD = MOUSE = SYSCONTROL = 0x01
|
||||
|
||||
|
||||
HID_REPORT_SIZES = {
|
||||
HIDReportTypes.KEYBOARD: 8,
|
||||
HIDReportTypes.MOUSE: 4,
|
||||
HIDReportTypes.CONSUMER: 2,
|
||||
HIDReportTypes.SYSCONTROL: 8, # TODO find the correct value for this
|
||||
}
|
||||
|
||||
|
||||
class AbstractHID:
|
||||
REPORT_BYTES = 8
|
||||
|
||||
def __init__(self):
|
||||
@ -154,7 +188,7 @@ class USB_HID:
|
||||
return self
|
||||
|
||||
|
||||
class CircuitPythonUSB_HID(USB_HID):
|
||||
class USBHID(AbstractHID):
|
||||
REPORT_BYTES = 9
|
||||
|
||||
def post_init(self):
|
||||
@ -187,3 +221,10 @@ class CircuitPythonUSB_HID(USB_HID):
|
||||
return self.devices[reporting_device_const].send_report(
|
||||
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
|
||||
)
|
||||
|
||||
|
||||
class BLEHID(AbstractHID):
|
||||
def __init__(self, *args, **kwargs):
|
||||
raise NotImplementedError(
|
||||
'BLE HID is not supported by upstream CircuitPython yet'
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import gc
|
||||
|
||||
from kmk import led, rgb
|
||||
from kmk.consts import KMK_RELEASE, LeaderMode, UnicodeMode
|
||||
from kmk.hid import USB_HID
|
||||
from kmk.hid import BLEHID, USBHID, AbstractHID, HIDModes
|
||||
from kmk.internal_state import InternalState
|
||||
from kmk.keys import KC
|
||||
from kmk.kmktime import sleep_ms
|
||||
@ -34,8 +34,6 @@ class KeyboardConfig:
|
||||
leader_dictionary = {}
|
||||
leader_timeout = 1000
|
||||
|
||||
hid_helper = USB_HID
|
||||
|
||||
# Split config
|
||||
extra_data_pin = None
|
||||
split_offsets = ()
|
||||
@ -192,11 +190,14 @@ class KeyboardConfig:
|
||||
else:
|
||||
return busio.UART(tx=pin, rx=None, timeout=timeout)
|
||||
|
||||
def go(self):
|
||||
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
|
||||
|
||||
@ -216,6 +217,13 @@ class KeyboardConfig:
|
||||
|
||||
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
|
||||
|
@ -1,13 +1,22 @@
|
||||
import digitalio
|
||||
import gc
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
|
||||
|
||||
def intify_coordinate(row, col):
|
||||
return row << 8 | col
|
||||
|
||||
|
||||
class DiodeOrientation:
|
||||
'''
|
||||
Orientation of diodes on handwired boards. You can think of:
|
||||
COLUMNS = vertical
|
||||
ROWS = horizontal
|
||||
'''
|
||||
|
||||
COLUMNS = 0
|
||||
ROWS = 1
|
||||
|
||||
|
||||
class MatrixScanner:
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -1,6 +0,0 @@
|
||||
from kmk.hid import CircuitPythonUSB_HID
|
||||
from kmk.keyboard_config import KeyboardConfig as _KeyboardConfig
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
hid_helper = CircuitPythonUSB_HID
|
@ -28,7 +28,7 @@ import kmk.kmktime # isort:skip
|
||||
import kmk.types # isort:skip
|
||||
|
||||
from kmk.consts import LeaderMode, UnicodeMode, KMK_RELEASE # isort:skip
|
||||
from kmk.hid import USB_HID # isort:skip
|
||||
from kmk.hid import USBHID # isort:skip
|
||||
from kmk.internal_state import InternalState # isort:skip
|
||||
from kmk.keys import KC # isort:skip
|
||||
from kmk.matrix import MatrixScanner # isort:skip
|
||||
|
@ -1,9 +1,10 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation, UnicodeMode
|
||||
from kmk.consts import UnicodeMode
|
||||
from kmk.handlers.sequences import compile_unicode_string_sequences, send_string
|
||||
from kmk.keys import KC
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig
|
||||
from kmk.types import AttrDict
|
||||
|
||||
keyboard = KeyboardConfig()
|
||||
|
@ -1,9 +1,10 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation, UnicodeMode
|
||||
from kmk.consts import UnicodeMode
|
||||
from kmk.handlers.sequences import compile_unicode_string_sequences, send_string
|
||||
from kmk.keys import KC
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig
|
||||
from kmk.matrix import DiodeOrientation
|
||||
from kmk.keyboard_config import KeyboardConfig
|
||||
from kmk.types import AttrDict
|
||||
|
||||
keyboard = KeyboardConfig()
|
||||
|
Loading…
Reference in New Issue
Block a user