generated from moergo-sc/glove80-zmk-config
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1e6f1a
commit a8e4e71
Showing
7 changed files
with
200 additions
and
175 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
imports = [ | ||
./flash.nix | ||
./firmware.nix | ||
./draw.nix | ||
./keymap-drawer.nix | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
perSystem = { | ||
config, | ||
pkgs, | ||
system, | ||
... | ||
}: { | ||
# Draw SVG images of the keymap | ||
packages.draw = pkgs.writeShellApplication { | ||
name = "draw"; | ||
runtimeInputs = [ | ||
pkgs.yq-go | ||
config.packages.keymap-drawer | ||
]; | ||
text = '' | ||
set +e | ||
out=./img | ||
keymap_dir=./config | ||
cmd() { | ||
keymap --config "$keymap_dir"/keymap_drawer.yaml "$@" | ||
} | ||
for file in "$keymap_dir"/*.keymap | ||
do | ||
name="$(basename --suffix=".keymap" "$file")" | ||
config="$out/$name.yaml" | ||
echo "Found $name keymap" | ||
echo "- Removing old images" | ||
rm "$out"/"$name".yaml | ||
rm "$out"/"$name".svg | ||
rm "$out"/"$name"_*.svg | ||
echo "- Parsing keymap-drawer" | ||
cmd parse --zmk-keymap "$file" > "$config" | ||
echo "- Drawing all layers" | ||
cmd draw "$config" > "$out"/"$name".svg | ||
layers=$(yq '.layers | keys | .[]' "$config") | ||
for layer in $layers | ||
do | ||
echo "- Drawing $layer layer" | ||
cmd draw "$config" --select-layers "$layer" > "$out"/"$name"_"$layer".svg | ||
done | ||
done | ||
''; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{inputs, ...}: { | ||
perSystem = { | ||
config, | ||
pkgs, | ||
system, | ||
... | ||
}: { | ||
packages.firmware = let | ||
firmware = import inputs.glove80-zmk {inherit pkgs;}; | ||
|
||
keymap = ../config/glove80.keymap; | ||
kconfig = ../config/glove80.conf; | ||
|
||
left = firmware.zmk.override { | ||
inherit keymap kconfig; | ||
board = "glove80_lh"; | ||
}; | ||
|
||
right = firmware.zmk.override { | ||
inherit keymap kconfig; | ||
board = "glove80_rh"; | ||
}; | ||
in | ||
firmware.combine_uf2 left right; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
{ | ||
perSystem = { | ||
config, | ||
pkgs, | ||
system, | ||
... | ||
}: { | ||
# Builds the firmware and copies it to the plugged-in keyboard half | ||
packages.flash = pkgs.writeShellApplication { | ||
name = "flash"; | ||
text = '' | ||
set +e | ||
# Disable -u because empty arrays are treated as "unbound" | ||
set +u | ||
# Enable nullglob so that non-matching globs have no output | ||
shopt -s nullglob | ||
# Indent piped input 4 spaces | ||
indent() { | ||
sed -e 's/^/ /' | ||
} | ||
# Platform specific disk candidates | ||
declare -a disks | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
# Linux/GNU | ||
# - /run/media/<user>/<disk> | ||
disks=(/run/media/"$(whoami)"/GLV80*) | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
# Mac OSX | ||
# - /Volumes/<disk> | ||
disks=(/Volumes/GLV80*) | ||
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then | ||
# Cygwin or Msys2 | ||
# - /<drive letter> | ||
disks=(/?) | ||
elif (grep -sq Microsoft /proc/version); then | ||
# WSL | ||
# - /mnt/<drive letter> | ||
disks=(/mnt/?) | ||
else | ||
echo "Error: Unable to detect platform!" | ||
echo "OSTYPE=$OSTYPE" | ||
echo "/proc/version" | ||
indent < /proc/version | ||
exit 1 | ||
fi | ||
# Disks that have a matching INFO_UF2 | ||
declare -a matches | ||
for disk in "''${disks[@]}"; do | ||
if (grep -sq Glove80 "$disk"/INFO_UF2.TXT); then | ||
matches+=("$disk") | ||
fi | ||
done | ||
# Assert we found exactly one keyboard | ||
count="''${#matches[@]}" | ||
if [[ "$count" -lt 1 ]]; then | ||
# No matches. Exit | ||
echo "Error: No Glove80 connected!" | ||
exit 1 | ||
elif [[ "$count" -gt 1 ]]; then | ||
# Multiple matches. Print them and exit | ||
echo "Error: $count Glove80s connected. Expected 1!" | ||
for i in "''${!matches[@]}"; do | ||
kb="''${matches[$i]}" | ||
# Print the relevant lines from INFO_UF2 | ||
echo "$((i + 1)). $kb" | ||
grep --no-filename --color=never Glove80 "$kb"/INFO_UF2.TXT | indent | ||
done | ||
exit 1 | ||
fi | ||
# We have a winner! | ||
kb="''${matches[0]}" | ||
echo "Found keyboard:" | ||
echo "$kb" | ||
indent < "$kb"/INFO_UF2.TXT | ||
echo | ||
# Flash by copying the firmware package | ||
echo "Flashing firmware..." | ||
cp -r "${config.packages.firmware}" "$kb" \ | ||
&& echo "Done!" || echo "Error: Unable to flash firmware!" | ||
''; | ||
}; | ||
}; | ||
} |
Oops, something went wrong.