Skip to content

Commit

Permalink
re-organize
Browse files Browse the repository at this point in the history
  • Loading branch information
juliamertz committed Sep 29, 2024
1 parent 465f41e commit d638f2a
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 177 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
Based on [Matt Sturgeon's config](https://github.com/MattSturgeon/glove80-config)

# Usage

## Build firmware

```sh
nix build
# This will output the firmware file to `/result/glove80.uf2`
nix build
```

This will output the firmware file to `/result/glove80.uf2`

## Flash firmware

TODO: flash both halves with one script
```sh
# Connect the right half (in bootloader mode)
Run nix run
# Connect the left half (in bootloader mode)
Run nix run
```

```sh
# Connect half (in bootloader mode) then run this. repeat this for both halves
nix run
```

# Credits

Layout adapted from [MoErgo's template](https://github.com/moergo-sc/glove80-zmk-config)
Nix flake based on [Matt Sturgeon's config](https://github.com/MattSturgeon/glove80-config)
Empty file removed config/glove80.conf
Empty file.
30 changes: 30 additions & 0 deletions firmware.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{ inputs, ... }:
{
perSystem =
{
config,
pkgs,
system,
...
}:
{
packages.firmware =
let
firmware = import inputs.glove80-zmk { inherit pkgs; };

keymap = ./glove80.keymap;
kconfig = pkgs.writeText "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;
};
}
44 changes: 22 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@
};
};

outputs = {
nixpkgs,
flake-parts,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
outputs =
{ nixpkgs, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;

imports = [
./packages
./flash.nix
./firmware.nix
];

perSystem = {
config,
pkgs,
system,
...
}: {
# `nix run`
apps.default = {
type = "app";
program = config.packages.flash;
};
perSystem =
{
config,
pkgs,
system,
...
}:
{
# `nix run`
apps.default = {
type = "app";
program = config.packages.flash;
};

# `nix build`
packages.default = config.packages.firmware;
# `nix build`
packages.default = config.packages.firmware;

formatter = pkgs.alejandra;
};
formatter = pkgs.alejandra;
};
};
}
93 changes: 93 additions & 0 deletions flash.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
perSystem =
{
config,
pkgs,
system,
...
}:
{
# Builds the firmware and copies it to the plugged-in keyboard half
packages.flash = pkgs.writeShellApplication {
name = "flash";
text =
# sh
''
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]}"
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!"
'';
};
};
}
File renamed without changes.
6 changes: 0 additions & 6 deletions packages/default.nix

This file was deleted.

26 changes: 0 additions & 26 deletions packages/firmware.nix

This file was deleted.

91 changes: 0 additions & 91 deletions packages/flash.nix

This file was deleted.

0 comments on commit d638f2a

Please sign in to comment.