Remove a ton of leftover MicroPython code and abstractions, including all of kmk.pins
This commit is contained in:
parent
86c8e006e0
commit
8c57844a22
@ -1,9 +1,10 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.D9, P.D10, P.D11, P.D12, P.D13, P.SCL)
|
||||
row_pins = (P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
col_pins = (board.D9, board.D10, board.D11, board.D12, board.D13, board.SCL)
|
||||
row_pins = (board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
|
@ -2,12 +2,29 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.TX, P.RX, P.SDA, P.SCL, P.D13, P.D12, P.D11, P.D10)
|
||||
col_pins = (
|
||||
board.A0,
|
||||
board.A1,
|
||||
board.A2,
|
||||
board.A3,
|
||||
board.A4,
|
||||
board.A5,
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
)
|
||||
row_pins = (
|
||||
board.TX,
|
||||
board.RX,
|
||||
board.SDA,
|
||||
board.SCL,
|
||||
board.D13,
|
||||
board.D12,
|
||||
board.D11,
|
||||
board.D10,
|
||||
)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.D9
|
||||
rgb_num_pixels = 12
|
||||
|
@ -2,10 +2,19 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.RX, P.D13, P.A0, P.D11, P.A4, P.A5, P.D10, P.D9, P.SCK)
|
||||
col_pins = (
|
||||
board.RX,
|
||||
board.D13,
|
||||
board.A0,
|
||||
board.D11,
|
||||
board.A4,
|
||||
board.A5,
|
||||
board.D10,
|
||||
board.D9,
|
||||
board.SCK,
|
||||
)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.A0, P.D11, P.D10, P.D9)
|
||||
col_pins = (board.A1, board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
row_pins = (board.A0, board.D11, board.D10, board.D9)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D11, P.D10, P.D9, P.D7, P.D13)
|
||||
col_pins = (board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
row_pins = (board.D11, board.D10, board.D9, board.D7, board.D13)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -3,15 +3,14 @@ import board
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.matrix import intify_coordinate as ic
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
# 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 = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D11, P.D10, P.D9, P.RX, P.D13)
|
||||
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
|
||||
|
@ -2,11 +2,27 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.SDA, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.TX, P.A0, P.RX, P.A1, P.D11, P.D9, P.D12, P.D10)
|
||||
col_pins = (
|
||||
board.SDA,
|
||||
board.A2,
|
||||
board.A3,
|
||||
board.A4,
|
||||
board.A5,
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
)
|
||||
row_pins = (
|
||||
board.TX,
|
||||
board.A0,
|
||||
board.RX,
|
||||
board.A1,
|
||||
board.D11,
|
||||
board.D9,
|
||||
board.D12,
|
||||
board.D10,
|
||||
)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.D13
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.A0)
|
||||
row_pins = (P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.A2, board.A3, board.A4, board.A5, board.SCK, board.A0)
|
||||
row_pins = (board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D13, P.D11, P.D10, P.D9)
|
||||
col_pins = (board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
row_pins = (board.D13, board.D11, board.D10, board.D9)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
|
||||
split_type = 'UART'
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
row_pins = (board.D13, board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.RX, P.A1, P.A2, P.A3, P.A4, P.A5)
|
||||
row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.RX, board.A1, board.A2, board.A3, board.A4, board.A5)
|
||||
row_pins = (board.D13, board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
|
||||
split_type = 'UART'
|
||||
|
@ -2,13 +2,21 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
# Will need additional work and testing
|
||||
col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI, P.D12)
|
||||
row_pins = (P.A0, P.D13, P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (
|
||||
board.A1,
|
||||
board.A2,
|
||||
board.A3,
|
||||
board.A4,
|
||||
board.A5,
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
board.D12,
|
||||
)
|
||||
row_pins = (board.A0, board.D13, board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D11, P.D10, P.D9, P.RX, P.D13)
|
||||
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
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -1,9 +1,29 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.TX, P.RX, P.SDA, P.SCL, P.D9, P.D10, P.D12, P.D11, P.D13)
|
||||
col_pins = (
|
||||
board.A0,
|
||||
board.A1,
|
||||
board.A2,
|
||||
board.A3,
|
||||
board.A4,
|
||||
board.A5,
|
||||
board.SCK,
|
||||
board.MOSI,
|
||||
)
|
||||
row_pins = (
|
||||
board.TX,
|
||||
board.RX,
|
||||
board.SDA,
|
||||
board.SCL,
|
||||
board.D9,
|
||||
board.D10,
|
||||
board.D12,
|
||||
board.D11,
|
||||
board.D13,
|
||||
)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI)
|
||||
row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.A1, board.A2, board.A3, board.A4, board.A5, board.SCK, board.MOSI)
|
||||
row_pins = (board.D13, board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK)
|
||||
row_pins = (P.D13, P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.A0, board.A1, board.A2, board.A3, board.A4, board.A5, board.SCK)
|
||||
row_pins = (board.D13, board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.A5, P.A4, P.A3, P.A2, P.A1, P.A0)
|
||||
row_pins = (P.D7, P.D9, P.D10, P.D11)
|
||||
col_pins = (board.A5, board.A4, board.A3, board.A2, board.A1, board.A0)
|
||||
row_pins = (board.D7, board.D9, board.D10, board.D11)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -2,12 +2,11 @@ import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
col_pins = (P.MOSI, P.SCK, P.A5, P.A4, P.A3, P.A2)
|
||||
row_pins = (P.D11, P.D10, P.D9, P.D7)
|
||||
col_pins = (board.MOSI, board.SCK, board.A5, board.A4, board.A3, board.A2)
|
||||
row_pins = (board.D11, board.D10, board.D9, board.D7)
|
||||
diode_orientation = DiodeOrientation.COLUMNS
|
||||
rgb_pixel_pin = board.TX
|
||||
uart_pin = board.SCL
|
||||
|
@ -1,7 +1,8 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
from kmk.matrix import intify_coordinate as ic
|
||||
from kmk.mcus.circuitpython_usbhid import KeyboardConfig as _KeyboardConfig
|
||||
from kmk.pins import Pin as P
|
||||
|
||||
# Implements what used to be handled by KeyboardConfig.swap_indicies for this
|
||||
# board, by flipping various row3 (bottom physical row) keys so their
|
||||
@ -20,8 +21,17 @@ def r3_swap(col):
|
||||
class KeyboardConfig(_KeyboardConfig):
|
||||
# physical, visible cols (SCK, MO, MI, RX, TX, D4)
|
||||
# physical, visible rows (10, 11, 12, 13) (9, 6, 5, SCL)
|
||||
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)
|
||||
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
|
||||
|
||||
|
@ -4,7 +4,6 @@ except Exception:
|
||||
KMK_RELEASE = 'copied-from-git'
|
||||
|
||||
CIRCUITPYTHON = 'CircuitPython'
|
||||
MICROPYTHON = 'MicroPython'
|
||||
|
||||
|
||||
class HIDReportTypes:
|
||||
|
60
kmk/hid.py
60
kmk/hid.py
@ -1,3 +1,5 @@
|
||||
import usb_hid
|
||||
|
||||
from kmk.consts import HID_REPORT_SIZES, HIDReportTypes, HIDUsage, HIDUsagePage
|
||||
from kmk.keys import FIRST_KMK_INTERNAL_KEY, ConsumerKey, ModifierKey
|
||||
|
||||
@ -152,44 +154,36 @@ class USB_HID:
|
||||
return self
|
||||
|
||||
|
||||
try:
|
||||
import usb_hid
|
||||
class CircuitPythonUSB_HID(USB_HID):
|
||||
REPORT_BYTES = 9
|
||||
|
||||
PLATFORM_CIRCUITPYTHON = True
|
||||
except ImportError:
|
||||
PLATFORM_CIRCUITPYTHON = False
|
||||
else:
|
||||
def post_init(self):
|
||||
self.devices = {}
|
||||
|
||||
class CircuitPythonUSB_HID(USB_HID):
|
||||
REPORT_BYTES = 9
|
||||
for device in usb_hid.devices:
|
||||
us = device.usage
|
||||
up = device.usage_page
|
||||
|
||||
def post_init(self):
|
||||
self.devices = {}
|
||||
if up == HIDUsagePage.CONSUMER and us == HIDUsage.CONSUMER:
|
||||
self.devices[HIDReportTypes.CONSUMER] = device
|
||||
continue
|
||||
|
||||
for device in usb_hid.devices:
|
||||
us = device.usage
|
||||
up = device.usage_page
|
||||
if up == HIDUsagePage.KEYBOARD and us == HIDUsage.KEYBOARD:
|
||||
self.devices[HIDReportTypes.KEYBOARD] = device
|
||||
continue
|
||||
|
||||
if up == HIDUsagePage.CONSUMER and us == HIDUsage.CONSUMER:
|
||||
self.devices[HIDReportTypes.CONSUMER] = device
|
||||
continue
|
||||
if up == HIDUsagePage.MOUSE and us == HIDUsage.MOUSE:
|
||||
self.devices[HIDReportTypes.MOUSE] = device
|
||||
continue
|
||||
|
||||
if up == HIDUsagePage.KEYBOARD and us == HIDUsage.KEYBOARD:
|
||||
self.devices[HIDReportTypes.KEYBOARD] = device
|
||||
continue
|
||||
if up == HIDUsagePage.SYSCONTROL and us == HIDUsage.SYSCONTROL:
|
||||
self.devices[HIDReportTypes.SYSCONTROL] = device
|
||||
continue
|
||||
|
||||
if up == HIDUsagePage.MOUSE and us == HIDUsage.MOUSE:
|
||||
self.devices[HIDReportTypes.MOUSE] = device
|
||||
continue
|
||||
def hid_send(self, evt):
|
||||
# int, can be looked up in HIDReportTypes
|
||||
reporting_device_const = self.report_device[0]
|
||||
|
||||
if up == HIDUsagePage.SYSCONTROL and us == HIDUsage.SYSCONTROL:
|
||||
self.devices[HIDReportTypes.SYSCONTROL] = device
|
||||
continue
|
||||
|
||||
def hid_send(self, evt):
|
||||
# int, can be looked up in HIDReportTypes
|
||||
reporting_device_const = self.report_device[0]
|
||||
|
||||
return self.devices[reporting_device_const].send_report(
|
||||
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
|
||||
)
|
||||
return self.devices[reporting_device_const].send_report(
|
||||
evt[1 : HID_REPORT_SIZES[reporting_device_const] + 1]
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import digitalio
|
||||
import gc
|
||||
|
||||
from kmk.consts import DiodeOrientation
|
||||
|
||||
@ -15,28 +16,29 @@ class MatrixScanner:
|
||||
diode_orientation=DiodeOrientation.COLUMNS,
|
||||
rollover_cols_every_rows=None,
|
||||
):
|
||||
self.len_cols = len(cols)
|
||||
self.len_rows = len(rows)
|
||||
|
||||
# A pin cannot be both a row and column, detect this by combining the
|
||||
# two tuples into a set and validating that the length did not drop
|
||||
#
|
||||
# repr() hackery is because CircuitPython Pin objects are not hashable
|
||||
unique_pins = {repr(c) for c in cols} | {repr(r) for r in rows}
|
||||
if len(unique_pins) != len(cols) + len(rows):
|
||||
raise ValueError('Cannot use a pin as both a column and row')
|
||||
|
||||
self.cols = cols
|
||||
self.rows = rows
|
||||
self.len_cols = len(cols)
|
||||
self.len_rows = len(rows)
|
||||
assert (
|
||||
len(unique_pins) == self.len_cols + self.len_rows
|
||||
), 'Cannot use a pin as both a column and row'
|
||||
del unique_pins
|
||||
gc.collect()
|
||||
|
||||
self.diode_orientation = diode_orientation
|
||||
|
||||
if self.diode_orientation == DiodeOrientation.COLUMNS:
|
||||
self.outputs = self.cols
|
||||
self.inputs = self.rows
|
||||
self.outputs = [digitalio.DigitalInOut(x) for x in cols]
|
||||
self.inputs = [digitalio.DigitalInOut(x) for x in rows]
|
||||
self.translate_coords = True
|
||||
elif self.diode_orientation == DiodeOrientation.ROWS:
|
||||
self.outputs = self.rows
|
||||
self.inputs = self.cols
|
||||
self.outputs = [digitalio.DigitalInOut(x) for x in rows]
|
||||
self.inputs = [digitalio.DigitalInOut(x) for x in cols]
|
||||
self.translate_coords = False
|
||||
else:
|
||||
raise ValueError(
|
||||
@ -68,7 +70,7 @@ class MatrixScanner:
|
||||
any_changed = False
|
||||
|
||||
for oidx, opin in enumerate(self.outputs):
|
||||
opin.value(True)
|
||||
opin.value = True
|
||||
|
||||
for iidx, ipin in enumerate(self.inputs):
|
||||
# cast to int to avoid
|
||||
@ -82,7 +84,7 @@ class MatrixScanner:
|
||||
# I haven't dived too far into what causes this, but it's
|
||||
# almost certainly because bool types in Python aren't just
|
||||
# aliases to int values, but are proper pseudo-types
|
||||
new_val = int(ipin.value())
|
||||
new_val = int(ipin.value)
|
||||
old_val = self.state[ba_idx]
|
||||
|
||||
if old_val != new_val:
|
||||
@ -108,7 +110,7 @@ class MatrixScanner:
|
||||
|
||||
ba_idx += 1
|
||||
|
||||
opin.value(False)
|
||||
opin.value = False
|
||||
if any_changed:
|
||||
break
|
||||
|
||||
|
99
kmk/pins.py
99
kmk/pins.py
@ -1,99 +0,0 @@
|
||||
from micropython import const
|
||||
|
||||
from kmk.consts import CIRCUITPYTHON, MICROPYTHON
|
||||
|
||||
PULL_UP = const(1)
|
||||
PULL_DOWN = const(2)
|
||||
|
||||
|
||||
try:
|
||||
import board
|
||||
import digitalio
|
||||
|
||||
PLATFORM = CIRCUITPYTHON
|
||||
PIN_SOURCE = board
|
||||
except ImportError:
|
||||
import machine
|
||||
|
||||
PLATFORM = MICROPYTHON
|
||||
PIN_SOURCE = machine.Pin.board
|
||||
|
||||
|
||||
def get_pin(pin):
|
||||
'''
|
||||
Cross-platform method to find a pin by string.
|
||||
|
||||
The pin definitions are platform-dependent, but this provides
|
||||
a way to say "I'm using pin D20" without rolling a D20 and
|
||||
having to actually learn MicroPython/CircuitPython and the
|
||||
differences in how they handle pinouts.
|
||||
|
||||
This also makes the keymap sanity checker actually work for
|
||||
CircuitPython boards, since it's not possible in CPY to
|
||||
define a module stub for `board` that uses Passthrough
|
||||
natively (which is how the MicroPython stub worked originally)
|
||||
'''
|
||||
return getattr(PIN_SOURCE, pin)
|
||||
|
||||
|
||||
class AbstractedDigitalPin:
|
||||
def __init__(self, pin):
|
||||
self.raw_pin = pin
|
||||
|
||||
if PLATFORM == CIRCUITPYTHON:
|
||||
self.pin = digitalio.DigitalInOut(pin)
|
||||
elif PLATFORM == MICROPYTHON:
|
||||
self.pin = machine.Pin(pin)
|
||||
else:
|
||||
self.pin = pin
|
||||
|
||||
self.call_value = callable(self.pin.value)
|
||||
|
||||
def __repr__(self):
|
||||
return 'AbstractedPin({})'.format(repr(self.raw_pin))
|
||||
|
||||
def switch_to_input(self, pull=None):
|
||||
if PLATFORM == CIRCUITPYTHON:
|
||||
if pull == PULL_UP:
|
||||
return self.pin.switch_to_input(pull=digitalio.Pull.UP)
|
||||
elif pull == PULL_DOWN:
|
||||
return self.pin.switch_to_input(pull=digitalio.Pull.DOWN)
|
||||
|
||||
return self.pin.switch_to_input(pull=pull)
|
||||
|
||||
elif PLATFORM == MICROPYTHON:
|
||||
if pull == PULL_UP:
|
||||
return self.pin.init(machine.Pin.IN, machine.Pin.PULL_UP)
|
||||
elif pull == PULL_DOWN:
|
||||
return self.pin.init(machine.Pin.IN, machine.Pin.PULL_DOWN)
|
||||
|
||||
raise ValueError('only PULL_UP and PULL_DOWN supported on MicroPython')
|
||||
|
||||
raise NotImplementedError('switch_to_input not supported on platform')
|
||||
|
||||
def switch_to_output(self):
|
||||
if PLATFORM == CIRCUITPYTHON:
|
||||
return self.pin.switch_to_output()
|
||||
elif PLATFORM == MICROPYTHON:
|
||||
return self.pin.init(machine.Pin.OUT)
|
||||
|
||||
raise NotImplementedError('switch_to_output not supported on platform')
|
||||
|
||||
def value(self, value=None):
|
||||
if value is None:
|
||||
if self.call_value:
|
||||
return self.pin.value()
|
||||
return self.pin.value
|
||||
|
||||
if self.call_value:
|
||||
return self.pin.value(value)
|
||||
self.pin.value = value
|
||||
return value
|
||||
|
||||
|
||||
class PinLookup:
|
||||
def __getattr__(self, attr):
|
||||
return AbstractedDigitalPin(get_pin(attr))
|
||||
|
||||
|
||||
Pin = PinLookup()
|
@ -18,5 +18,6 @@ exclude = '''
|
||||
| build
|
||||
| docs
|
||||
| user_keymaps
|
||||
| mnt
|
||||
)/
|
||||
'''
|
||||
|
@ -1,5 +1,5 @@
|
||||
[flake8]
|
||||
exclude = .git,__pycache__,vendor,.venv,build,dist,.compiled
|
||||
exclude = .git,__pycache__,vendor,.venv,build,dist,.compiled,mnt
|
||||
# match black expectations
|
||||
max_line_length = 88
|
||||
|
||||
@ -47,6 +47,7 @@ known_standard_library =
|
||||
ubluepy,
|
||||
uio,
|
||||
uos,
|
||||
usb_hid,
|
||||
|
||||
# black compat
|
||||
multi_line_output=3
|
||||
|
@ -1,8 +1,9 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation, 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.pins import Pin as P
|
||||
from kmk.types import AttrDict
|
||||
|
||||
keyboard = KeyboardConfig()
|
||||
@ -29,8 +30,8 @@ PF5: A5
|
||||
Mosfet on B5 to control backlight
|
||||
'''
|
||||
|
||||
keyboard.col_pins = (P.A4, P.A2, P.A3, P.A1, P.A0, P.SDA)
|
||||
keyboard.row_pins = (P.D2, P.TX, P.RX, P.MISO, P.MOSI)
|
||||
keyboard.col_pins = (board.A4, board.A2, board.A3, board.A1, board.A0, board.SDA)
|
||||
keyboard.row_pins = (board.D2, board.TX, board.RX, board.MISO, board.MOSI)
|
||||
|
||||
# Kyle is fucking stupid
|
||||
keyboard.col_pins = tuple(reversed(keyboard.col_pins))
|
||||
|
@ -1,14 +1,15 @@
|
||||
import board
|
||||
|
||||
from kmk.consts import DiodeOrientation, 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.pins import Pin as P
|
||||
from kmk.types import AttrDict
|
||||
|
||||
keyboard = KeyboardConfig()
|
||||
|
||||
keyboard.col_pins = (P.A0, P.A1, P.A2, P.A3, P.A4, P.A5, P.SCK, P.MOSI, P.MISO, P.RX, P.TX, P.D4)
|
||||
keyboard.row_pins = (P.D10, P.D11, P.D12, P.D13)
|
||||
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user