Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/env python3
"""Generate the expensivo ZMK shield pin lists from the PCB hole mapping."""
import os
from layout import KEY_ROWS, THUMBS, key_pins
ROOT = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
SHIELD = os.path.join(ROOT, "zmk", "boards", "shields", "expensivo")
# encoder pins, only wired on the right half (nano on the back)
ENC_A, ENC_B, ENC_S = "P1.01", "P1.07", "P1.02"
def gpio(pin, flags="GPIO_ACTIVE_LOW | GPIO_PULL_UP"):
port, num = pin[1:].split(".")
return f"<&gpio{port} {int(num)} ({flags})>"
def key_order(right):
"""Keys in keymap order for one half: rows, then thumbs, left to right."""
rows = [list(reversed(r)) if right else r for r in KEY_ROWS]
thumbs = list(reversed(THUMBS)) if right else THUMBS
return [k for r in rows for k in r] + thumbs
def overlay(right):
pins = key_pins(back=right)
keys = key_order(right)
lines = [f" {'= ' if i == 0 else ', '}{gpio(pins[k])} // {k}" for i, k in enumerate(keys)]
if right:
lines.append(f" , {gpio(ENC_S)} // encoder push")
out = ["// Generated by scripts/gen_zmk.py -- edit the generator, not this file.",
'#include "expensivo.dtsi"', ""]
if right:
out += ["&default_transform {", " col-offset = <18>;", "};", "",
"&encoder {", " status = \"okay\";", "};", ""]
out += ["&kscan0 {", " input-gpios", *lines, " ;", "};", ""]
return "\n".join(out)
def dtsi():
rows = []
for r in range(3):
l = " ".join(f"RC(0,{r * 5 + c})" for c in range(5))
rr = " ".join(f"RC(0,{18 + r * 5 + c})" for c in range(5))
rows.append(f" {l} {rr}")
rows.append(" RC(0,15) RC(0,16) RC(0,17) "
"RC(0,33) RC(0,34) RC(0,35) RC(0,36)")
return f"""// Generated by scripts/gen_zmk.py -- edit the generator, not this file.
#include <dt-bindings/zmk/matrix_transform.h>
#include "expensivo-layout.dtsi"
// P0.09 / P0.10 are used as key inputs
&uicr {{
nfct-pins-as-gpios;
}};
&expensivo_layout {{
transform = <&default_transform>;
}};
/ {{
chosen {{
zmk,kscan = &kscan0;
zmk,physical-layout = &expensivo_layout;
}};
default_transform: keymap_transform_0 {{
compatible = "zmk,matrix-transform";
columns = <37>;
rows = <1>;
// last entry is the (optional) encoder push on the right half
map = <
{chr(10).join(rows)}
>;
}};
kscan0: kscan {{
compatible = "zmk,kscan-gpio-direct";
wakeup-source;
}};
encoder: encoder {{
compatible = "alps,ec11";
a-gpios = {gpio(ENC_A, "GPIO_ACTIVE_HIGH | GPIO_PULL_UP")};
b-gpios = {gpio(ENC_B, "GPIO_ACTIVE_HIGH | GPIO_PULL_UP")};
steps = <80>;
status = "disabled";
}};
sensors: sensors {{
compatible = "zmk,keymap-sensors";
sensors = <&encoder>;
triggers-per-rotation = <20>;
}};
}};
"""
def main():
os.makedirs(SHIELD, exist_ok=True)
files = {
"expensivo.dtsi": dtsi(),
"expensivo_left.overlay": overlay(False),
"expensivo_right.overlay": overlay(True),
}
for name, text in files.items():
with open(os.path.join(SHIELD, name), "w") as f:
f.write(text)
print("wrote", name)
if __name__ == "__main__":
main()
d635cc727This file is pinned to the selected release. Download the original to open it in your design tool.