diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..d202a33 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every week + interval: "weekly" diff --git a/.github/workflows/build-attiny85.yaml b/.github/workflows/build-attiny85.yaml new file mode 100644 index 0000000..6d18acf --- /dev/null +++ b/.github/workflows/build-attiny85.yaml @@ -0,0 +1,47 @@ +name: Build ATtiny85 + +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/build-attiny85.yaml + - boards/attiny85/flake.lock + - boards/attiny85/flake.nix + - boards/attiny85/.cargo/** + - boards/attiny85/.justfile + - boards/attiny85/src/** + - boards/attiny85/avr-unknown-none-attiny85.json + - boards/attiny85/Cargo.lock + - boards/attiny85/Cargo.toml + - boards/attiny85/rust-toolchain.toml + push: + branches: ["main"] + paths: + - .github/workflows/build-attiny85.yaml + - boards/attiny85/flake.lock + - boards/attiny85/flake.nix + - boards/attiny85/.cargo/** + - boards/attiny85/.justfile + - boards/attiny85/src/** + - boards/attiny85/avr-unknown-none-attiny85.json + - boards/attiny85/Cargo.lock + - boards/attiny85/Cargo.toml + - boards/attiny85/rust-toolchain.toml + workflow_dispatch: + +jobs: + build-attiny85: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Build + run: cd boards/attiny85; nix develop --command just build release + - name: Upload firmware + uses: actions/upload-artifact@v4 + with: + name: attiny85-pwm-fan-controller + path: | + target/avr-unknown-none-attiny85/release/attiny85-pwm-fan-controller.elf + attiny85-pwm-fan-controller.hex diff --git a/.github/workflows/cargo-lock-updater.yaml b/.github/workflows/cargo-lock-updater.yaml new file mode 100644 index 0000000..f0fba4b --- /dev/null +++ b/.github/workflows/cargo-lock-updater.yaml @@ -0,0 +1,30 @@ +name: Cargo Lock Updater + +"on": + schedule: + # Once a month on the 5th + - cron: "0 0 5 * *" + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + cargo-lock-updater: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Update ATtiny85 Cargo lock file + run: cd boards/attiny85; nix develop --command cargo update + - name: Update Pico Cargo lock file + run: cd boards/pico; nix develop --command cargo update + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + assignees: ${{ github.repository_owner }} + branch: "update/cargo-lock" + commit-message: "chore(deps): Update Cargo lock files" + title: "chore(deps): Update Cargo lock files" diff --git a/.github/workflows/clippy-attiny85.yaml b/.github/workflows/clippy-attiny85.yaml new file mode 100644 index 0000000..414fcdd --- /dev/null +++ b/.github/workflows/clippy-attiny85.yaml @@ -0,0 +1,18 @@ +name: Lint Rust code with Clippy +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/clippy-attiny85.yaml + - boards/attiny85/flake.lock + - boards/attiny85/**.rs + +jobs: + clippy-attiny85: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Lint Rust code with Clippy + run: cd boards/attiny85; nix develop --command cargo clippy diff --git a/.github/workflows/flake-checker.yaml b/.github/workflows/flake-checker.yaml new file mode 100644 index 0000000..e20dbbc --- /dev/null +++ b/.github/workflows/flake-checker.yaml @@ -0,0 +1,14 @@ +name: Check Nix Flake +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/flake-checker.yaml + - '**/flake.lock' + +jobs: + flake-checker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/flake-checker-action@v9 diff --git a/.github/workflows/flake-lock-updater.yaml b/.github/workflows/flake-lock-updater.yaml new file mode 100644 index 0000000..0530e11 --- /dev/null +++ b/.github/workflows/flake-lock-updater.yaml @@ -0,0 +1,25 @@ +name: Flake ❄️ Lock 🔒️ Updater ✨ + +"on": + schedule: + # Pi o'clock + - cron: '3 14 * * 1,5' + workflow_dispatch: + +jobs: + lock-updater: + name: Flake Lock Updater + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - uses: DeterminateSystems/update-flake-lock@v24 + with: + pr-title: "chore: update flake.lock" + # Labels to be set on the PR + pr-labels: | + dependencies + automated diff --git a/.github/workflows/format-just.yaml b/.github/workflows/format-just.yaml new file mode 100644 index 0000000..f281a24 --- /dev/null +++ b/.github/workflows/format-just.yaml @@ -0,0 +1,19 @@ +name: Format justfiles +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/format-just.yaml + - '**/flake.lock' + - '**/.justfile' + - '**/justfile' + +jobs: + format-just: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Format justfile + run: cd boards/attiny85; nix develop --command just --check --fmt --unstable ../.. diff --git a/.github/workflows/pre-commit-autoupdate.yaml b/.github/workflows/pre-commit-autoupdate.yaml new file mode 100644 index 0000000..6c2fcef --- /dev/null +++ b/.github/workflows/pre-commit-autoupdate.yaml @@ -0,0 +1,30 @@ +name: Pre-commit auto-update + +"on": + schedule: + # Once a month on the 2nd + - cron: "0 0 2 * *" + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + pre-commit-autoupdate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Update pre-commit hooks + run: nix develop --command pre-commit autoupdate + - name: Run pre-commit hooks + run: nix develop --command pre-commit run --all-files + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + assignees: ${{ github.repository_owner }} + branch: "update/pre-commit-hooks" + commit-message: "chore(deps): Update pre-commit hooks" + title: "chore(deps): Update pre-commit hooks" diff --git a/.github/workflows/rustfmt.yaml b/.github/workflows/rustfmt.yaml new file mode 100644 index 0000000..5afe548 --- /dev/null +++ b/.github/workflows/rustfmt.yaml @@ -0,0 +1,18 @@ +name: Format Rust code +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/rustfmt.yaml + - '**/flake.lock' + - '**.rs' + +jobs: + rustfmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Check Rust formatting + run: cd boards/attiny85; nix develop --command nu --commands 'rustfmt --check ../../**/*.rs' diff --git a/.github/workflows/yamllint.yaml b/.github/workflows/yamllint.yaml new file mode 100644 index 0000000..5812309 --- /dev/null +++ b/.github/workflows/yamllint.yaml @@ -0,0 +1,20 @@ +name: yamllint +"on": + pull_request: + branches: ["main"] + paths: + - .github/workflows/yamllint.yaml + - .yamllint.yaml + - '**/flake.lock' + - '**.yaml' + - '**.yml' + +jobs: + yamllint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@v14 + - uses: DeterminateSystems/magic-nix-cache-action@v8 + - name: Check YAML files + run: cd boards/attiny85; nix develop --command yamllint --format github ../.. diff --git a/.gitignore b/.gitignore index 2825aa4..d574953 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,13 @@ target/ # Ignore any built binaries. *.bin +*.hex *.jpg~ *.jpg-autosave.kra + +# direnv +.direnv/ + +# Nix +result/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9d4da43 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,60 @@ +exclude: | + (?x)^( + .idea/.*| + .run/.*| + .vscode/.* + )$ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + args: [--allow-multiple-documents] + - id: end-of-file-fixer + - id: mixed-line-ending + - id: pretty-format-json + args: ["--autofix"] + exclude: ^.vscode/.*\.json$ + - id: trailing-whitespace + - repo: local + hooks: + - id: just + entry: just --fmt --unstable + files: | + (?x)^( + .justfile| + justfile + )$ + language: system + name: just + pass_filenames: false + - id: rustfmt + name: rustfmt + description: Format Rust files with rustfmt. + entry: rustfmt + pass_filenames: true + types: [file, rust] + language: system + - id: rust-clippy-attiny85 + name: Rust clippy ATtiny85 + description: Run cargo clippy on files included in the commit. + entry: cargo -C boards/attiny85 clippy --all-targets --all-features -- -Dclippy::all + pass_filenames: false + types: [file, rust] + language: system + # - id: rust-clippy-pico + # name: Rust clippy Pico + # description: Run cargo clippy on files included in the commit. + # entry: cargo -C boards/pico clippy --all-targets --all-features -- -Dclippy::all + # pass_filenames: false + # types: [file, rust] + # language: system + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.35.1 + hooks: + - id: yamllint diff --git a/.vscode/settings.json b/.vscode/settings.json index 82d4499..daca860 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,16 +6,22 @@ "Asciidoctor", "assumeyes", "attiny", + "autofix", "avrdude", "binutils", "BOOTSEL", "Boxall", + "clippy", "Datasheet", + "Dclippy", "devel", + "dialout", "eabi", + "getent", "ifdef", "ifndef", "ihex", + "justfile", "Libc", "libusbx", "microcontroller", @@ -30,6 +36,7 @@ "Pinouts", "proto", "Protoboard", + "rustfmt", "rustup", "SWCLK", "SWDIO", @@ -38,6 +45,7 @@ "tlsv", "UART", "udev", + "usermod", "VBUS" ] } diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..d214411 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,6 @@ +extends: default + +rules: + document-start: disable + document-end: disable + line-length: disable diff --git a/boards/attiny85/.cargo/config.toml b/boards/attiny85/.cargo/config.toml index 30d224b..c9f46b1 100644 --- a/boards/attiny85/.cargo/config.toml +++ b/boards/attiny85/.cargo/config.toml @@ -1,9 +1,9 @@ [build] -target = "avr-specs/avr-attiny85.json" +target = "avr-unknown-none-attiny85.json" #[target.'cfg(target_arch = "avr")'] # ravedude doesn't support running from an AVR USB programmer like the USB uISP without code modifications. -#runner = "ravedude trinket" +# runner = "ravedude attiny85-usbtiny" [unstable] build-std = ["core"] diff --git a/boards/attiny85/.envrc b/boards/attiny85/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/boards/attiny85/.envrc @@ -0,0 +1 @@ +use flake diff --git a/boards/attiny85/.justfile b/boards/attiny85/.justfile new file mode 100644 index 0000000..98aec62 --- /dev/null +++ b/boards/attiny85/.justfile @@ -0,0 +1,37 @@ +default: build + +alias fmt := format + +format: just-fmt rustfmt + +rustfmt: + cargo fmt + +just-fmt: + just --fmt --unstable + +alias b := build + +build profile="dev": + cargo build + cargo objcopy -- -O ihex attiny85-pwm-fan-controller.hex + +alias f := run +alias flash := run +alias r := run + +run profile="dev": (build profile) + avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:attiny85-pwm-fan-controller.hex:i + +alias p := package +alias pack := package + +package: + nix build + +alias u := update +alias up := package + +update: + nix flake update + cargo update diff --git a/boards/attiny85/README.adoc b/boards/attiny85/README.adoc index f0e8cbb..354d2f7 100644 --- a/boards/attiny85/README.adoc +++ b/boards/attiny85/README.adoc @@ -20,6 +20,7 @@ endif::[] :fish: https://fishshell.com/[fish] :Git: https://git-scm.com/[Git] :Linux: https://www.linuxfoundation.org/[Linux] +:Nix: https://nixos.org/[Nix] :Noctua-NF-P12-redux-1700-PWM-Fan: https://noctua.at/en/nf-p12-redux-1700-pwm[Noctua NF-P12 redux-1700 PWM Fan] :Python: https://www.python.org/[Python] :Rouge: https://rouge.jneen.net/[Rouge] @@ -117,68 +118,65 @@ This should be the pin opposite the one attached to ground on the fan header. . Attach the USB µISP programmer to the 6-pin ISP breakout board. . Connect the 12V power supply to the 2nd pin in the fan header, the one immediately next to ground. -== Program +== Permissions -. Install {rustup}. +. On Fedora Atomic, the _dialout_ group does not exist in the `/etc/group`, so it must be added there. + [,sh] ---- -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh +echo (getent group dialout) | sudo tee -a /etc/group ---- -. Install the AVR GCC toolchain, {AVR-Libc}, and {avrdude}. +. Add the user to the _dialout_ group to access USB without requiring superuser privileges. + [,sh] ---- -sudo dnf --assumeyes install avr-gcc avr-libc avrdude +sudo usermod --append --groups dialout $USER ---- -. Install {cargo-binutils}. +. Create a udev rule to allow access to the USB µISP programmer without requiring root access. + -[,sh] +./etc/udev/rules.d/USBmicroISP.rules +[,udev] ---- -cargo install cargo-binutils +SUBSYSTEM=="usb", ATTR{product}=="USBmicroISP", ATTR{idProduct}=="0c9f", ATTRS{idVendor}=="1781", MODE="0660", GROUP="dialout" ---- -. Install the LLVM tools preview {Rust} component for cargo-binutils. +. Reboot for the group change and Udev rules to take effect. + [,sh] ---- -rustup component add llvm-tools-preview +sudo systemctl reboot ---- -. Clone the repository. -+ -[,sh] ----- -git clone https://github.com/jwillikers/pwm-fan-controller.git ----- +== Develop -. Change to the project's directory. +. Install an implementation of {Nix}, such as https://lix.systems[Lix] used here. + [,sh] ---- -cd pwm-fan-controller/boards/attiny85 +curl -sSf -L https://install.lix.systems/lix | sh -s -- install ---- -. Build the executable. +. Clone the repository. + [,sh] ---- -cargo build +git clone https://github.com/jwillikers/pwm-fan-controller.git ---- -. Convert the executable to the file `pwm.hex` in the Intel hex format. +. Change to the project's directory. + [,sh] ---- -cargo objcopy -- -O ihex pwm.hex +cd pwm-fan-controller/boards/attiny85 ---- -. Flash the `pwm.hex` file on the ATtiny85 with avrdude. + +. Build and flash the executable. + [,sh] ---- -avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:pwm.hex:i +nix develop --commands just flash ---- == Todo diff --git a/boards/attiny85/Ravedude.toml b/boards/attiny85/Ravedude.toml new file mode 100644 index 0000000..ca17b9d --- /dev/null +++ b/boards/attiny85/Ravedude.toml @@ -0,0 +1,10 @@ +[attiny85-usbtiny] +name = "ATtiny85 through USBTiny" + +[attiny85-usbtiny.reset] +automatic = true + +[attiny85-usbtiny.avrdude] +programmer = "USBtiny" +partno = "attiny85" +bitclock = 4 diff --git a/boards/attiny85/avr-specs/avr-attiny85.json b/boards/attiny85/avr-unknown-none-attiny85.json similarity index 89% rename from boards/attiny85/avr-specs/avr-attiny85.json rename to boards/attiny85/avr-unknown-none-attiny85.json index d5334aa..da74364 100644 --- a/boards/attiny85/avr-specs/avr-attiny85.json +++ b/boards/attiny85/avr-unknown-none-attiny85.json @@ -37,5 +37,8 @@ }, "relocation-model": "static", "target-c-int-width": "16", - "target-pointer-width": "16" + "target-pointer-width": "16", + "target-family": "avr", + "vendor": "unknown", + "os": "none" } diff --git a/boards/attiny85/default.nix b/boards/attiny85/default.nix new file mode 100644 index 0000000..9f514dc --- /dev/null +++ b/boards/attiny85/default.nix @@ -0,0 +1,63 @@ +# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/rust/build-rust-package/sysroot/default.nix +{ stdenv +, cargo-binutils +, pkgs +, rustToolchain +# , rust-bin +}: + +let + # rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + rustc = rustToolchain; + cargo = rustToolchain; + # rustc = rust-bin.stable.latest.minimal; + # cargo = rust-bin.stable.latest.minimal; + }; +in +rustPlatform.buildRustPackage { + pname = "attiny85-pwm-fan-controller"; + version = "0.0.1"; + src = ./.; + cargoLock = { + allowBuiltinFetchGit = true; + lockFile = ./Cargo.lock; + }; + __internal_dontAddSysroot = true; + # useSysroot = false; + # env.CARGO_BUILD_TARGET = "${./avr-specs/avr-attiny85.json}"; + # CARGO_BUILD_TARGET = "${./avr-specs/avr-attiny85.json}"; + doCheck = false; + RUSTC_BOOTSTRAP = 1; + cargoExtraArgs = "-Z build-std=core"; + # cargoExtraArgs = "--target avr-specs/avr-attiny85.json"; + # postPatch = '' + # ln -s ${./Cargo.lock} Cargo.lock + # ''; + # buildPhase = '' + # cargoBuildHook + # ''; + # ${rust.envVars.setEnv} cargo cbuild -j $NIX_BUILD_CORES --release --frozen --prefix=${placeholder "out"} --target avr-specs/avr-attiny85.json + buildPhase = '' + runHook preBuild + cargo build -j $NIX_BUILD_CORES --release --frozen --target ${./avr-unknown-none-attiny85.json} -Z build-std=core + cargo objcopy -- -O ihex attiny85-pwm-fan-controller.hex + runHook postBuild + ''; + postBuild = '' + cargo objcopy -- -O ihex attiny85-pwm-fan-controller.hex + ''; + installPhase = '' + mkdir --parents $out/bin + mv attiny85-pwm-fan-controller.hex $out/bin/ + ''; + buildInputs = [ + ]; + nativeBuildInputs = [ + # pkgs.buildPackages.stdenv.cc + cargo-binutils + # rust-bin.stable.latest.minimal + rustToolchain + ]; + # auditable = false; +} diff --git a/boards/attiny85/flake.lock b/boards/attiny85/flake.lock new file mode 100644 index 0000000..f94161e --- /dev/null +++ b/boards/attiny85/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1727122398, + "narHash": "sha256-o8VBeCWHBxGd4kVMceIayf5GApqTavJbTa44Xcg5Rrk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "30439d93eb8b19861ccbe3e581abf97bdc91b093", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1727317727, + "narHash": "sha256-yGYahXzCquyYEgf5GTtvtaN5hXbw20Ok2+o8uVxoaFs=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a3d832f389606d7dc61a45b244c72ea472d1fcd4", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/boards/attiny85/flake.nix b/boards/attiny85/flake.nix new file mode 100644 index 0000000..18c5805 --- /dev/null +++ b/boards/attiny85/flake.nix @@ -0,0 +1,153 @@ +# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md +# https://github.com/oxalica/rust-overlay +# https://github.com/oxalica/rust-overlay/blob/660018f3a78e1f83e4e4aa569d9c6e2a31b0222c/docs/cross_compilation.md +# https://github.com/oxalica/rust-overlay/issues?q=is%3Aissue+callPackage+is%3Aclosed +# https://github.com/ipetkov/crane/blob/master/examples/cross-rust-overlay/flake.nix +# https://github.com/alekseysidorov/nixpkgs-rust-service-example/blob/main/flake.nix +# https://github.com/nix-community/naersk/blob/ee7edec50b49ab6d69b06d62f1de554efccb1ccd/examples/static-musl/flake.nix +{ + 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"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem + (system: + let + overlays = [ + (import rust-overlay) + # (self: super: { + # pkg = super.pkg.overrideAttrs (old: { + # doCheck = false; + # }); + # }) + ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + # todo Try creating toolchain from avrCrossPkgs. + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + + avrCrossPkgs = import nixpkgs { + inherit system overlays; + crossSystem = { + inherit overlays; + config = "avr"; + # rust.rustcTarget = "${./avr-specs/avr-attiny85.json}"; + + # todo I can try this one next. + # rust.rustcTarget = "avr-unknown-none-attiny85"; + # rust.rustcTargetSpec = "avr-unknown-none-attiny85.json"; + # rust.rustcTarget = "avr-unknown-gnu-atmega328"; + # rust.rustcTargetSpec = "${./avr-unknown-none-attiny85.json}"; + # rust.platform = nixpkgs.lib.importJSON "${./avr-specs/avr-unknown-none-attiny85.json}"; + # rust.cargoShortTarget + # rust.cargoEnvVarTarget + rust.isNoStdTarget = true; + + # rust.rustcTargetSpec = nixpkgs.lib.importJSON "${./avr-specs/avr-attiny85.json}"; + + # todo And maybe I need to try this too? + # rustc = { + # config = "${./avr-unknown-none-attiny85.json}"; + # }; + + # rust.rustcTarget = "avr-unknown-none"; + + # rust.platform = { + # arch = "avr"; + # atomic-cas = false; + # cpu = "attiny85"; + # crt-objects-fallback = false; + # data-layout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"; + # eh-frame-header = false; + # exe-suffix = ".elf"; + # late-link-args = { + # gnu-cc = [ + # "-lgcc" + # ]; + # gnu-lld-cc = [ + # "-lgcc" + # ]; + # }; + # linker = "avr-gcc"; + # linker-flavor = "gnu-cc"; + # llvm-target = "avr-unknown-unknown"; + # max-atomic-width = 8; + # metadata = { + # description = null; + # host_tools = null; + # std = null; + # tier = null; + # }; + # no-default-libraries = false; + # pre-link-args = { + # gnu-cc = [ + # "-mmcu=attiny85" + # "-Wl,--as-needed,--print-memory-usage" + # ]; + # gnu-lld-cc = [ + # "-mmcu=attiny85" + # "-Wl,--as-needed,--print-memory-usage" + # ]; + # }; + # relocation-model = "static"; + # target-c-int-width = 16; + # target-pointer-width = 16; + # target-family = "avr"; + # vendor = "unknown"; + # os = "none"; + # }; + }; + config.allowUnsupportedSystem = true; + }; + # todo This should be using avrCrossPkgs for the Rust toolchain, right? + # rust-bin = rust-overlay.lib.mkRustBin { } avrCrossPkgs.buildPackages; + # rustToolchain = avrCrossPkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + # rustToolchain = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + nativeBuildInputs = with pkgs; [ + avrdude + cargo-binutils + clippy + # ravedude + rustfmt + rustToolchain + fish + just + nushell + pkgconf + pre-commit + yamllint + ]; + buildInputs = with pkgs; []; + in + { + packages.default = avrCrossPkgs.callPackage ./default.nix { + inherit rustToolchain; + # inherit rust-bin; + }; + devShells.default = avrCrossPkgs.mkShell { + inherit nativeBuildInputs buildInputs; + }; + apps.default = let + flash = pkgs.writeShellApplication { + name = "flash-attiny85-pwm-fan-controller"; + runtimeInputs = [pkgs.avrdude]; + text = '' + avrdude -c USBtiny -B 4 -p attiny85 -U flash:w:${self.packages.default}/bin/attiny85-pwm-fan-controller.hex:i + ''; + }; + in { + type = "app"; + program = "${flash}/bin/flash-attiny85-pwm-fan-controller"; + }; + } + ); +} diff --git a/boards/attiny85/rust-toolchain.toml b/boards/attiny85/rust-toolchain.toml index 3523320..462b0a0 100644 --- a/boards/attiny85/rust-toolchain.toml +++ b/boards/attiny85/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2024-03-22" -components = ["rust-src"] +components = ["llvm-tools-preview", "rust-src"] profile = "minimal"