diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46021b9..f6f41ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,4 +34,4 @@ jobs: - name: Compile Sketch (via Makefile) shell: bash - run: make compile + run: make prepare_and_compile diff --git a/.gitignore b/.gitignore index 1233aae..40c3ac7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .secrets +.arduino_cache/ +bin/ diff --git a/Makefile b/Makefile index 31569cd..aa7809b 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,58 @@ PORT ?= /dev/ttyACM0 BOARD = arduino:renesas_uno:unor4wifi SKETCH = arduino_pong.ino +CACHE_DIR = $(shell pwd)/.arduino_cache +BIN_DIR = $(shell pwd)/bin +CLI = $(BIN_DIR)/arduino-cli --config-file $(CACHE_DIR)/arduino-cli.yaml + +YELLOW := \033[0;33m +GREEN := \033[0;32m +CLEAR := \033[0m + +prepare: + @mkdir -p $(BIN_DIR) + @mkdir -p $(CACHE_DIR) + @if [ ! -f $(BIN_DIR)/arduino-cli ]; then \ + echo -e "📥 $(YELLOW)Downloading arduino-cli...$(CLEAR)"; \ + curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=$(BIN_DIR) sh; \ + fi + @if [ ! -f $(CACHE_DIR)/arduino-cli.yaml ]; then \ + echo -e "⚙️ $(YELLOW)Initializing local config...$(CLEAR)"; \ + $(CLI) config init --dest-dir $(CACHE_DIR); \ + $(CLI) config set directories.data $(CACHE_DIR)/data; \ + $(CLI) config set directories.downloads $(CACHE_DIR)/downloads; \ + $(CLI) config set directories.user $(CACHE_DIR)/user; \ + fi + @if ! $(CLI) core list | grep -q "arduino:renesas_uno"; then \ + echo -e "$(YELLOW)📥 Installing board core...$(CLEAR)"; \ + $(CLI) core update-index; \ + $(CLI) core install arduino:renesas_uno; \ + fi compile: - arduino-cli compile -b $(BOARD) $(SKETCH) + @echo -e "$(GREEN)🛠️ Compiling $(SKETCH)...$(CLEAR)" + @$(CLI) compile -b $(BOARD) $(SKETCH) + +prepare_and_compile: + make prepare --no-print-directory + make compile --no-print-directory upload: - arduino-cli upload -b $(BOARD) -p $(PORT) + @echo -e "$(GREEN)🚀 Uploading $(SKETCH)...$(CLEAR)" + @$(CLI) upload -b $(BOARD) -p $(PORT) upload_verbose: - arduino-cli upload -b $(BOARD) -p $(PORT) -v + @echo -e "$(GREEN)🚀 Uploading (Verbose) $(SKETCH)...$(CLEAR)" + @$(CLI) upload -b $(BOARD) -p $(PORT) -v monitor: - arduino-cli monitor -p $(PORT) + @$(CLI) monitor -p $(PORT) run: - make compile - make upload - make monitor + make compile --no-print-directory + make upload --no-print-directory + make monitor --no-print-directory + +run_init: + make prepare --no-print-directory + make run --no-print-directory diff --git a/README.md b/README.md index fa71f53..4967d4a 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,11 @@ This project includes a `Makefile` to automate the workflow using `arduino-cli`. ### Commands | Command | Description | | :--- | :--- | +| `make prepare` | Downloads arduino-cli locally and installs the UNO R4 core. | | `make compile` | Compiles the sketch without uploading. | | `make upload` | Uploads the compiled binary to `/dev/ttyACM0`. | | `make monitor` | Opens the Serial Monitor. | | `make run` | Full cycle: Compile + Upload + Monitor. | +| `make run_init` | Full first-time setup: Prepare env + Compile + Upload + Monitor. | > **Note:** If your board is on a different port, edit the `Makefile` or override it: `make upload PORT=/dev/ttyUSB0`.