From 84eb03602e27ef18c8d305b93313b18ad945fb92 Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Mon, 4 Dec 2023 07:35:57 -0500 Subject: [PATCH 1/3] Adds nullbits tidbit board and bitc promicro mapping --- boards/nullbitsco/README.md | 2 + boards/nullbitsco/tidbit/README.md | 38 ++++++++++++++++ boards/nullbitsco/tidbit/kb.py | 60 +++++++++++++++++++++++++ boards/nullbitsco/tidbit/main.py | 20 +++++++++ kmk/quickpin/pro_micro/bitc_promicro.py | 34 ++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 boards/nullbitsco/README.md create mode 100644 boards/nullbitsco/tidbit/README.md create mode 100755 boards/nullbitsco/tidbit/kb.py create mode 100755 boards/nullbitsco/tidbit/main.py create mode 100644 kmk/quickpin/pro_micro/bitc_promicro.py diff --git a/boards/nullbitsco/README.md b/boards/nullbitsco/README.md new file mode 100644 index 000000000..15d7077b7 --- /dev/null +++ b/boards/nullbitsco/README.md @@ -0,0 +1,2 @@ +Mappings for [nullbits](https://nullbits.co/) keyboards, +often based on the [BIT-C pro micro MCU](https://nullbits.co/bit-c/). diff --git a/boards/nullbitsco/tidbit/README.md b/boards/nullbitsco/tidbit/README.md new file mode 100644 index 000000000..62b6ab66f --- /dev/null +++ b/boards/nullbitsco/tidbit/README.md @@ -0,0 +1,38 @@ +Keyboard mapping for the [nullbits tidbit](https://nullbits.co/tidbit/). + +Copy `kb.py` and `main.py` to your top level circuitpython folder beside the kmk folder. +Edit the key mapping in `main.py` to match your build, +for example the number and location of encoders and double-size keys. + +The Keyboard constructor supports a couple of optional arguments (see `kb.py`). + +If you're setting your tidbit up in landscape mode, +with the USB connector at top right instead of top left, pass +`landscape_layout=True`. + +You can specify the active encoder positions by passing a list like +`active_encoders=[0, 2]` which corresponds to the 1st and 3rd positions shown +in [step 6](https://github.com/nullbitsco/docs/blob/main/tidbit/build_guide_en.md#6-optional-solder-rotary-encoder-led-matrix-andor-oled-display) of the build guide. +The default is for a single encoder in either of the top two locations labeled 1 +in the build diagram, i.e. `active_encoders=[0]`. Pass an empty list if you skipped +adding any encoders. + +You can control the RGB backlights with the [RGB extension](http://kmkfw.io/docs/rgb). +Here's an example: + +```python +from kb import KMKKeyboard +from kmk.extensions.rgb import RGB, AnimationModes + +keyboard = KMKKeyboard(active_encoders=[0], landscape_layout=True) + +rgb = RGB( + pixel_pin=keyboard.pixel_pin, + num_pixels=8, + animation_mode=AnimationModes.BREATHING, + animation_speed=3, + breathe_center=2, +) +keyboard.extensions.append(rgb) + +``` diff --git a/boards/nullbitsco/tidbit/kb.py b/boards/nullbitsco/tidbit/kb.py new file mode 100755 index 000000000..4d8399256 --- /dev/null +++ b/boards/nullbitsco/tidbit/kb.py @@ -0,0 +1,60 @@ +import board + +from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard +from kmk.quickpin.pro_micro.bitc_promicro import pinout as pins + +from kmk.scanners import DiodeOrientation +from kmk.modules.encoder import EncoderHandler + + +encoder_pinout = [ + (pins[13], pins[14], None), # enc 0, button mapped in matrix + (pins[10], pins[11], None), # enc 1 (optional) + (pins[5], pins[4], None), # enc 2 (optional) + (pins[0], pins[1], None), # enc 3 (optional) +] + + +class KMKKeyboard(_KMKKeyboard): + """" + Create a nullbits tidbit keyboard. + optional constructor arguments: + + active_encoders=[0, 2] to list installed encoder positions (first=0) + then declare keyboard.encoders.map = [(KC. , KC., None), (...)] + landscape_layout=True to orient USB port top right rather than left (default) + """ +# led = digitalio.DigitalInOut(board.D21) +# led.direction = digitalio.Direction.OUTPUT +# led.value = False + row_pins = ( + pins[15], + pins[9], + pins[8], + pins[7], + pins[6], + ) + col_pins = ( + pins[19], + pins[18], + pins[17], + pins[16], + ) + pixel_pin = pins[12] + diode_orientation = DiodeOrientation.ROW2COL + i2c = board.I2C #TODO ?? + + def __init__(self, active_encoders=[0], landscape_layout=False): + super().__init__() + + if landscape_layout: + self.coord_mapping = [ + row * len(self.col_pins) + col + for col in range(len(self.col_pins)) + for row in reversed(range(len(self.row_pins))) + ] + + if active_encoders: + self.encoders = EncoderHandler() + self.encoders.pins = tuple([encoder_pinout[i] for i in active_encoders]) + self.modules.append(self.encoders) diff --git a/boards/nullbitsco/tidbit/main.py b/boards/nullbitsco/tidbit/main.py new file mode 100755 index 000000000..df6e86c9a --- /dev/null +++ b/boards/nullbitsco/tidbit/main.py @@ -0,0 +1,20 @@ +from kb import KMKKeyboard +from kmk.keys import KC + +# add active_encoders=[0, 2] to constructor if first and third encoders installed +keyboard = KMKKeyboard() + +XXXXX = KC.NO + +keyboard.keymap = [ + [ + XXXXX, KC.PSLS, KC.PAST, KC.PMNS, + KC.P7, KC.P8, KC.P9, KC.PPLS, + KC.P4, KC.P5, KC.P6, KC.PPLS, + KC.P1, KC.P2, KC.P3, KC.PENT, + KC.P0, KC.P0, KC.PDOT, KC.PENT, + ] +] + +if __name__ == '__main__': + keyboard.go() diff --git a/kmk/quickpin/pro_micro/bitc_promicro.py b/kmk/quickpin/pro_micro/bitc_promicro.py new file mode 100644 index 000000000..ef74f2148 --- /dev/null +++ b/kmk/quickpin/pro_micro/bitc_promicro.py @@ -0,0 +1,34 @@ +import board + +# Bit-C-Pro RP2040 pinout for reference, see https://nullbits.co/bit-c-pro/ +# (unused) +pinout = [ + board.D0, # Enc 3 + board.D1, # Enc 3 + None, # GND + None, # GND + board.D2, # Enc 2 + board.D3, # Enc 2 + board.D4, # Row 4 + breakout SDA + board.D5, # Row 3 + breakout SCL + board.D6, # Row 2 + board.D7, # Row 1 + board.D8, # Enc 1 + board.D9, # Enc 1 + + # Unconnected breakout pins D11, D12, GND, D13, D14 + + board.D21, # WS2812 LEDs labeled D10/GP21 but only board.D21 is defined + board.D23, # MOSI - Enc 0 + board.D20, # MISO - Enc 0 + board.D22, # SCK - Row 0 + board.D26, # A0 - Col 3 + board.D27, # A1 - Col 2 + board.D28, # A2 - Col 1 + board.D29, # A3 - Col 0 + None, # 3.3v + None, # RST + None, # GND + None, # RAW +] +# also defined: board.LED_RED, board.LED_GREEN, and board.LED_BLUE == board.LED From 98f5287d38e951f0992d8f0ccc53dfcdff407e56 Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Wed, 6 Dec 2023 09:04:51 -0500 Subject: [PATCH 2/3] lint --- boards/nullbitsco/tidbit/kb.py | 18 ++++++++---------- boards/nullbitsco/tidbit/main.py | 1 + kmk/quickpin/pro_micro/bitc_promicro.py | 22 ++++++++++------------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/boards/nullbitsco/tidbit/kb.py b/boards/nullbitsco/tidbit/kb.py index 4d8399256..7cca62eb0 100755 --- a/boards/nullbitsco/tidbit/kb.py +++ b/boards/nullbitsco/tidbit/kb.py @@ -1,11 +1,9 @@ import board from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard +from kmk.modules.encoder import EncoderHandler from kmk.quickpin.pro_micro.bitc_promicro import pinout as pins - from kmk.scanners import DiodeOrientation -from kmk.modules.encoder import EncoderHandler - encoder_pinout = [ (pins[13], pins[14], None), # enc 0, button mapped in matrix @@ -29,15 +27,15 @@ class KMKKeyboard(_KMKKeyboard): # led.value = False row_pins = ( pins[15], - pins[9], - pins[8], - pins[7], + pins[9], + pins[8], + pins[7], pins[6], ) col_pins = ( - pins[19], - pins[18], - pins[17], + pins[19], + pins[18], + pins[17], pins[16], ) pixel_pin = pins[12] @@ -49,7 +47,7 @@ def __init__(self, active_encoders=[0], landscape_layout=False): if landscape_layout: self.coord_mapping = [ - row * len(self.col_pins) + col + row * len(self.col_pins) + col for col in range(len(self.col_pins)) for row in reversed(range(len(self.row_pins))) ] diff --git a/boards/nullbitsco/tidbit/main.py b/boards/nullbitsco/tidbit/main.py index df6e86c9a..817a1a637 100755 --- a/boards/nullbitsco/tidbit/main.py +++ b/boards/nullbitsco/tidbit/main.py @@ -1,4 +1,5 @@ from kb import KMKKeyboard + from kmk.keys import KC # add active_encoders=[0, 2] to constructor if first and third encoders installed diff --git a/kmk/quickpin/pro_micro/bitc_promicro.py b/kmk/quickpin/pro_micro/bitc_promicro.py index ef74f2148..8c2bcf152 100644 --- a/kmk/quickpin/pro_micro/bitc_promicro.py +++ b/kmk/quickpin/pro_micro/bitc_promicro.py @@ -3,21 +3,19 @@ # Bit-C-Pro RP2040 pinout for reference, see https://nullbits.co/bit-c-pro/ # (unused) pinout = [ - board.D0, # Enc 3 - board.D1, # Enc 3 + board.D0, # Enc 3 + board.D1, # Enc 3 None, # GND None, # GND - board.D2, # Enc 2 - board.D3, # Enc 2 - board.D4, # Row 4 + breakout SDA - board.D5, # Row 3 + breakout SCL - board.D6, # Row 2 - board.D7, # Row 1 - board.D8, # Enc 1 - board.D9, # Enc 1 - + board.D2, # Enc 2 + board.D3, # Enc 2 + board.D4, # Row 4 + breakout SDA + board.D5, # Row 3 + breakout SCL + board.D6, # Row 2 + board.D7, # Row 1 + board.D8, # Enc 1 + board.D9, # Enc 1 # Unconnected breakout pins D11, D12, GND, D13, D14 - board.D21, # WS2812 LEDs labeled D10/GP21 but only board.D21 is defined board.D23, # MOSI - Enc 0 board.D20, # MISO - Enc 0 From 961efc3d85084d280018ff840621218e01ff92bb Mon Sep 17 00:00:00 2001 From: Patrick Surry Date: Wed, 6 Dec 2023 09:07:39 -0500 Subject: [PATCH 3/3] lint doesn't match GHA? --- boards/nullbitsco/tidbit/kb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/nullbitsco/tidbit/kb.py b/boards/nullbitsco/tidbit/kb.py index 7cca62eb0..80837fc21 100755 --- a/boards/nullbitsco/tidbit/kb.py +++ b/boards/nullbitsco/tidbit/kb.py @@ -14,14 +14,14 @@ class KMKKeyboard(_KMKKeyboard): - """" + ''' Create a nullbits tidbit keyboard. optional constructor arguments: active_encoders=[0, 2] to list installed encoder positions (first=0) then declare keyboard.encoders.map = [(KC. , KC., None), (...)] landscape_layout=True to orient USB port top right rather than left (default) - """ + ''' # led = digitalio.DigitalInOut(board.D21) # led.direction = digitalio.Direction.OUTPUT # led.value = False