Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyboardHoarders authored Aug 26, 2024
0 parents commit 2b4905f
Show file tree
Hide file tree
Showing 27 changed files with 1,845 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Dim direnv status messages
export DIRENV_LOG_FORMAT=$'\033[2mdirenv: %s\033[0m'

# Use flake
use flake

# Watch additional files
watch_file draw/default.nix
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.dtsi linguist-language=C++
*.keymap linguist-language=C++
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Build ZMK firmware
on:
workflow_dispatch:
push:
paths:
- config/**
- build.yaml

jobs:
build:
uses: zmkfirmware/zmk/.github/workflows/build-user-config.yml@main
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.build
.direnv
.venv
.west
modules
firmware
zmk
# Ignore keymap-drawer output for now
draw/base.svg
draw/base.yaml
2 changes: 2 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proseWrap: "always"
editorconfig: true
106 changes: 106 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
default:
@just --list --unsorted

config := absolute_path('config')
build := absolute_path('.build')
out := absolute_path('firmware')
draw := absolute_path('draw')

# 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="(($attrs | map(. // [.]) | combinations), ((.include // {})[] | $attrs)) | join(\",\")"
echo "$(yq -r "$filter" build.yaml | grep -v "^," | 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 }} -- \
-DZMK_CONFIG="{{ config }}" ${shield:+-DSHIELD="$shield"}

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 }}

# clear all automatically generated files
clean-all: clean
rm -rf .west zmk

# clear nix cache
clean-nix:
nix-collect-garbage --delete-old

# parse & plot keymap
draw:
#!/usr/bin/env bash
set -euo pipefail
keymap -c "{{ draw }}/config.yaml" parse -z "{{ config }}/base.keymap" >"{{ draw }}/base.yaml"
keymap -c "{{ draw }}/config.yaml" draw "{{ draw }}/base.yaml" -k "ferris/sweep" >"{{ draw }}/base.svg"
# initialize west
init:
west init -l config
west update
west zephyr-export

# list build targets
list:
@just _parse_targets all | sed 's/,$//' | sort | column

# update west
update:
west update

# upgrade zephyr-sdk and python dependencies
upgrade-sdk:
nix flake update --flake .
30 changes: 30 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file generates the GitHub Actions matrix
# For simple board + shield combinations, add them
# to the top level board and shield arrays, for more
# control, add individual board + shield combinations to
# the `include` property, e.g:
#
# board: [ "nice_nano_v2" ]
# shield: [ "corne_left", "corne_right" ]
# include:
# - board: bdn9_rev2
# - board: nice_nano_v2
# shield: reviung41
#
---
include:
# - board: planck_rev6
# - board: corneish_zen_v2_left
# - board: corneish_zen_v2_right
# - board: glove80_lh
# - board: glove80_rh
# - board: nice_nano_v2
# shield: corne_left
# - board: nice_nano_v2
# shield: corne_right
- board: nice_nano_v2
shield: corne_left nice_view_adapter nice_view
- board: nice_nano_v2
shield: corne_right nice_view_adapter nice_view
- board: nice_nano_v2
shield: settings_reset
Loading

0 comments on commit 2b4905f

Please sign in to comment.