Skip to content

Commit 530370a

Browse files
committed
build: setup env for local development
1 parent 7bf3f64 commit 530370a

6 files changed

+100
-4
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
layout python3

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.build
2+
.direnv
3+
.venv
4+
.west
5+
modules
6+
firmware
7+
zephyr
8+
zmk

Justfile

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
default:
2+
@just --list --unsorted
3+
4+
config := absolute_path('config')
5+
build := absolute_path('.build')
6+
out := absolute_path('firmware')
7+
8+
# parse combos.dtsi and adjust settings to not run out of slots
9+
_parse_combos:
10+
#!/usr/bin/env bash
11+
set -euo pipefail
12+
cconf="{{ config / 'combos.dtsi' }}"
13+
if [[ -f $cconf ]]; then
14+
# set MAX_COMBOS_PER_KEY to the most frequent combos count
15+
count=$(
16+
tail -n +10 $cconf |
17+
grep -Eo '[LR][TMBH][0-9]' |
18+
sort | uniq -c | sort -nr |
19+
awk 'NR==1{print $1}'
20+
)
21+
sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" "{{ config }}"/*.conf
22+
echo "Setting MAX_COMBOS_PER_KEY to $count"
23+
24+
# set MAX_KEYS_PER_COMBO to the most frequent key count
25+
count=$(
26+
tail -n +10 $cconf |
27+
grep -o -n '[LR][TMBH][0-9]' |
28+
cut -d : -f 1 | uniq -c | sort -nr |
29+
awk 'NR==1{print $1}'
30+
)
31+
sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" "{{ config }}"/*.conf
32+
echo "Setting MAX_KEYS_PER_COMBO to $count"
33+
fi
34+
35+
# parse build.yaml and filter targets by expression
36+
_parse_targets $expr:
37+
#!/usr/bin/env bash
38+
attrs="[.board, .shield]"
39+
filter=".include[] | [.board, .shield] | join(\",\")"
40+
echo "$(yq -r "$filter" build.yaml | grep -i "${expr/#all/.*}")"
41+
42+
# build firmware for single board & shield combination
43+
_build_single $board $shield *west_args:
44+
#!/usr/bin/env bash
45+
set -euo pipefail
46+
artifact="${shield:+$shield-}${board}"
47+
build_dir="{{ build / '$artifact' }}"
48+
49+
echo "Building firmware for $artifact..."
50+
west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} -- \
51+
${shield:+-DSHIELD="$shield"} \
52+
-DZMK_CONFIG="{{ config }}" \
53+
54+
if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then
55+
mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.uf2" "{{ out }}/$artifact.uf2"
56+
else
57+
mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.bin" "{{ out }}/$artifact.bin"
58+
fi
59+
60+
# build firmware for matching targets
61+
build expr *west_args: _parse_combos
62+
#!/usr/bin/env bash
63+
set -euo pipefail
64+
targets=$(just _parse_targets {{ expr }})
65+
66+
[[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1
67+
echo "$targets" | while IFS=, read -r board shield; do
68+
just _build_single "$board" "$shield" {{ west_args }}
69+
done
70+
71+
# clear build cache and artifacts
72+
clean:
73+
rm -rf {{ build }} {{ out }}
74+
75+
# initialize west
76+
init:
77+
west init -l config
78+
west update
79+
west zephyr-export
80+
81+
# update west
82+
update:
83+
west update
84+
85+
# list build targets
86+
list:
87+
@just _parse_targets all | sed 's/,$//' | sort | column

config/custom_behavior.dtsi

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/ {
22
behaviors {
3-
swapper: swapper {
3+
sw_win: swapper {
44
compatible = "zmk,behavior-tri-state";
55
#binding-cells = <0>;
66
bindings = <&kt RGUI>, <&kp TAB>, <&kt RGUI>; // Cmd, Tab, and release Cmd

config/splitkb_aurora_corne.keymap

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
// | SHFT | | | | | | | | | | | | |
5656
// | GUI | | SPC | | ENT | | ALT |
5757
bindings = <
58-
&swapper &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp BSPC
58+
&sw_win &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp BSPC
5959
&bt BT_CLR &bt BT_SEL 0 &bt BT_SEL 1 &bt BT_SEL 2 &bt BT_SEL 3 &bt BT_SEL 4 &kp LEFT &kp DOWN &kp UP &kp RIGHT &trans &trans
6060
&kp LSHFT &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans
6161
&kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT

config/west.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ manifest:
44
url-base: https://github.com/zmkfirmware
55
- name: dhruvinsh
66
url-base: https://github.com/dhruvinsh
7-
# Additional modules containing boards/shields/custom code can be listed here as well
8-
# See https://docs.zephyrproject.org/3.2.0/develop/west/manifest.html#projects
7+
98
projects:
109
- name: zmk
1110
remote: zmkfirmware
@@ -14,5 +13,6 @@ manifest:
1413
- name: zmk-tri-state
1514
remote: dhruvinsh
1615
revision: main
16+
path: modules/tri-state
1717
self:
1818
path: config

0 commit comments

Comments
 (0)