# udev rules shipped with this repo (probe-rs probe permissions on Linux)
rules_src := "etc/69-probe-rs.rules"
rules_dst := "/etc/udev/rules.d/69-probe-rs.rules"

# Default: show available recipes
default:
    @just --list

# One-shot dev setup: install toolchain bits + probe permissions
setup: install-tools probe-setup
    @echo "Setup complete. Plug in the probe (re-plug if it was already connected)."

# Install the Rust target and the host tools this project links/flashes with
install-tools:
    rustup target add thumbv7em-none-eabihf

# Set up probe-rs probe access on Linux: install udev rules + reload
# https://probe.rs/docs/getting-started/probe-setup/
probe-setup:
    @echo "Installing udev rules -> {{rules_dst}} (needs sudo)"
    sudo install -m 0644 {{rules_src}} {{rules_dst}}
    sudo udevadm control --reload
    sudo udevadm trigger
    @# plugdev group is referenced by the rules; create it and add the user if missing
    sudo groupadd --system plugdev 2>/dev/null || true
    sudo usermod -aG plugdev "$USER"
    @echo "If the probe was already plugged in, unplug and reconnect it."
    @echo "A new group membership requires a fresh login to take effect."

# List debug probes probe-rs can see (verifies setup worked)
probes:
    probe-rs list

# Build the firmware (debug)
build:
    cargo build

# Build optimized
release:
    cargo build --release

# Flash + run on the target, streaming defmt logs over RTT
run:
    cargo run --release

# Compile checks / lints / format
check:
    cargo check
clippy:
    cargo clippy
fmt:
    cargo fmt

# Remove build artifacts
clean:
    cargo clean
