From 530370a4336f6663a842516add07f4cd85938c9e Mon Sep 17 00:00:00 2001 From: Simeon Simeonoff Date: Fri, 16 Aug 2024 22:17:12 +0300 Subject: [PATCH] build: setup env for local development --- .envrc | 1 + .gitignore | 8 +++ Justfile | 87 ++++++++++++++++++++++++++++++ config/custom_behavior.dtsi | 2 +- config/splitkb_aurora_corne.keymap | 2 +- config/west.yml | 4 +- 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Justfile diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..94840b3 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +layout python3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cc0972 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.build +.direnv +.venv +.west +modules +firmware +zephyr +zmk diff --git a/Justfile b/Justfile new file mode 100644 index 0000000..d04609c --- /dev/null +++ b/Justfile @@ -0,0 +1,87 @@ +default: + @just --list --unsorted + +config := absolute_path('config') +build := absolute_path('.build') +out := absolute_path('firmware') + +# parse combos.dtsi and adjust settings to not run out of slots +_parse_combos: + #!/usr/bin/env bash + set -euo pipefail + cconf="{{ config / 'combos.dtsi' }}" + if [[ -f $cconf ]]; then + # set MAX_COMBOS_PER_KEY to the most frequent combos count + count=$( + tail -n +10 $cconf | + grep -Eo '[LR][TMBH][0-9]' | + sort | uniq -c | sort -nr | + awk 'NR==1{print $1}' + ) + sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" "{{ config }}"/*.conf + echo "Setting MAX_COMBOS_PER_KEY to $count" + + # set MAX_KEYS_PER_COMBO to the most frequent key count + count=$( + tail -n +10 $cconf | + grep -o -n '[LR][TMBH][0-9]' | + cut -d : -f 1 | uniq -c | sort -nr | + awk 'NR==1{print $1}' + ) + sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" "{{ config }}"/*.conf + echo "Setting MAX_KEYS_PER_COMBO to $count" + fi + +# parse build.yaml and filter targets by expression +_parse_targets $expr: + #!/usr/bin/env bash + attrs="[.board, .shield]" + filter=".include[] | [.board, .shield] | join(\",\")" + echo "$(yq -r "$filter" build.yaml | grep -i "${expr/#all/.*}")" + +# build firmware for single board & shield combination +_build_single $board $shield *west_args: + #!/usr/bin/env bash + set -euo pipefail + artifact="${shield:+$shield-}${board}" + build_dir="{{ build / '$artifact' }}" + + echo "Building firmware for $artifact..." + west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} -- \ + ${shield:+-DSHIELD="$shield"} \ + -DZMK_CONFIG="{{ config }}" \ + + if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then + mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.uf2" "{{ out }}/$artifact.uf2" + else + mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.bin" "{{ out }}/$artifact.bin" + fi + +# build firmware for matching targets +build expr *west_args: _parse_combos + #!/usr/bin/env bash + set -euo pipefail + targets=$(just _parse_targets {{ expr }}) + + [[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1 + echo "$targets" | while IFS=, read -r board shield; do + just _build_single "$board" "$shield" {{ west_args }} + done + +# clear build cache and artifacts +clean: + rm -rf {{ build }} {{ out }} + +# initialize west +init: + west init -l config + west update + west zephyr-export + +# update west +update: + west update + +# list build targets +list: + @just _parse_targets all | sed 's/,$//' | sort | column diff --git a/config/custom_behavior.dtsi b/config/custom_behavior.dtsi index 6fa3a8c..d464fbd 100644 --- a/config/custom_behavior.dtsi +++ b/config/custom_behavior.dtsi @@ -1,6 +1,6 @@ / { behaviors { - swapper: swapper { + sw_win: swapper { compatible = "zmk,behavior-tri-state"; #binding-cells = <0>; bindings = <&kt RGUI>, <&kp TAB>, <&kt RGUI>; // Cmd, Tab, and release Cmd diff --git a/config/splitkb_aurora_corne.keymap b/config/splitkb_aurora_corne.keymap index 828408f..3dbd8c6 100644 --- a/config/splitkb_aurora_corne.keymap +++ b/config/splitkb_aurora_corne.keymap @@ -55,7 +55,7 @@ // | SHFT | | | | | | | | | | | | | // | GUI | | SPC | | ENT | | ALT | bindings = < - &swapper &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp BSPC + &sw_win &kp N1 &kp N2 &kp N3 &kp N4 &kp N5 &kp N6 &kp N7 &kp N8 &kp N9 &kp N0 &kp BSPC &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 &kp LSHFT &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &trans &kp LGUI &trans &kp SPACE &kp RET &trans &kp RALT diff --git a/config/west.yml b/config/west.yml index 0e42b8c..2464aa4 100644 --- a/config/west.yml +++ b/config/west.yml @@ -4,8 +4,7 @@ manifest: url-base: https://github.com/zmkfirmware - name: dhruvinsh url-base: https://github.com/dhruvinsh - # Additional modules containing boards/shields/custom code can be listed here as well - # See https://docs.zephyrproject.org/3.2.0/develop/west/manifest.html#projects + projects: - name: zmk remote: zmkfirmware @@ -14,5 +13,6 @@ manifest: - name: zmk-tri-state remote: dhruvinsh revision: main + path: modules/tri-state self: path: config