Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping for nullbits tidbit board with bit-c pro #916

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/nullbitsco/README.md
Original file line number Diff line number Diff line change
@@ -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/).
38 changes: 38 additions & 0 deletions boards/nullbitsco/tidbit/README.md
Original file line number Diff line number Diff line change
@@ -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)

```
58 changes: 58 additions & 0 deletions boards/nullbitsco/tidbit/kb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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

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.<left> , KC.<right>, 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)
21 changes: 21 additions & 0 deletions boards/nullbitsco/tidbit/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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()
32 changes: 32 additions & 0 deletions kmk/quickpin/pro_micro/bitc_promicro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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
Loading