Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ cargo install cargo-make --locked
> cargo make --cwd inputmodule-control run -- --version
```

## Using the Nix flake

If you have Nix with flakes enabled, you can build and run everything without
installing a toolchain yourself.

```sh
# Drop into a dev shell with rustup, flip-link, cargo-make, elf2uf2-rs, etc.
nix develop

# Build the host control tool (default package)
nix build

# Run it directly
nix run . -- --list

# Build firmware ELFs for a specific module
nix build .#ledmatrix
nix build .#b1display
nix build .#c1minimal
nix build .#qtpy
```

Each firmware build drops both the ELF and a ready-to-flash UF2 in
`result/bin/`, e.g. `result/bin/ledmatrix.elf` and `result/bin/ledmatrix.uf2`.
Put the module in bootloader mode and copy the `.uf2` onto the drive it
exposes.

### Check the firmware version of the device

###### In-band using commandline
Expand Down
82 changes: 82 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

128 changes: 128 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
description = "Framework Laptop 16 Input Module firmware and control tool";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};

rustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [ "thumbv6m-none-eabi" ];
extensions = [ "rust-src" "rustfmt" "clippy" ];
};

rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};

src = ./.;

cargoLock = {
lockFile = ./Cargo.lock;
# st7306 is a git dependency; fetch it via builtins.fetchGit so we
# don't have to hand-maintain an outputHash entry.
allowBuiltinFetchGit = true;
};

firmwareTarget = "thumbv6m-none-eabi";

mkFirmware = pname:
rustPlatform.buildRustPackage {
inherit pname src cargoLock;
version = "0.2.0";

nativeBuildInputs = [ pkgs.flip-link pkgs.elf2uf2-rs ];

# buildRustPackage's cargoBuildHook hard-codes --target to the host
# triple, which breaks no_std firmware builds. Replace the build
# and install phases instead of fighting the hook.
buildPhase = ''
runHook preBuild
cargo build \
--release \
--frozen \
--target ${firmwareTarget} \
-p ${pname}
runHook postBuild
'';

checkPhase = ''
runHook preCheck
runHook postCheck
'';

installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp target/${firmwareTarget}/release/${pname} $out/bin/${pname}.elf
elf2uf2-rs \
target/${firmwareTarget}/release/${pname} \
$out/bin/${pname}.uf2
runHook postInstall
'';

meta.description = "Framework Input Module firmware (${pname})";
};

inputmodule-control = rustPlatform.buildRustPackage {
pname = "inputmodule-control";
version = "0.2.0";
inherit src cargoLock;

nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.udev ];

cargoBuildFlags = [ "-p" "inputmodule-control" ];
# Override the workspace-default embedded target so this builds
# natively for the host.
CARGO_BUILD_TARGET = pkgs.stdenv.hostPlatform.rust.rustcTarget;

doCheck = false;

meta = {
description = "Host-side control tool for Framework Input Modules";
mainProgram = "inputmodule-control";
};
};
in {
packages = {
default = inputmodule-control;
inherit inputmodule-control;
ledmatrix = mkFirmware "ledmatrix";
b1display = mkFirmware "b1display";
c1minimal = mkFirmware "c1minimal";
qtpy = mkFirmware "qtpy";
};

apps.default = {
type = "app";
program = "${inputmodule-control}/bin/inputmodule-control";
};

devShells.default = pkgs.mkShell {
nativeBuildInputs = [
rustToolchain
pkgs.flip-link
pkgs.cargo-make
pkgs.pkg-config
pkgs.elf2uf2-rs
];
buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [ pkgs.udev ];
};

formatter = pkgs.nixpkgs-fmt;
});
}
Loading