|
| 1 | +# Makefile for Arduino Nano Quantizer |
| 2 | +# Uses arduino-cli for compilation and upload |
| 3 | + |
| 4 | +# Configuration |
| 5 | +ARDUINO_CLI ?= arduino-cli |
| 6 | +BOARD_FQBN = arduino:avr:nano |
| 7 | +SKETCH_DIR = . |
| 8 | +SKETCH = $(SKETCH_DIR)/eurorack-quantizer-software.ino |
| 9 | +PORT ?= /dev/ttyUSB0 |
| 10 | +BAUD_RATE ?= 115200 |
| 11 | + |
| 12 | +# Default target |
| 13 | +.PHONY: all |
| 14 | +all: compile |
| 15 | + |
| 16 | +# Compile the sketch |
| 17 | +.PHONY: compile |
| 18 | +compile: |
| 19 | + @echo "Compiling $(SKETCH)..." |
| 20 | + $(ARDUINO_CLI) compile -vt --fqbn $(BOARD_FQBN) $(SKETCH_DIR) |
| 21 | + |
| 22 | +# Upload to Arduino |
| 23 | +.PHONY: upload |
| 24 | +upload: compile |
| 25 | + @echo "Uploading to $(PORT)..." |
| 26 | + $(ARDUINO_CLI) upload -vt -p $(PORT) --fqbn $(BOARD_FQBN) $(SKETCH_DIR) |
| 27 | + |
| 28 | +# Compile and upload in one step |
| 29 | +.PHONY: build-upload |
| 30 | +build-upload: upload |
| 31 | + |
| 32 | +# Open serial monitor |
| 33 | +.PHONY: monitor |
| 34 | +monitor: |
| 35 | + @echo "Opening serial monitor on $(PORT)..." |
| 36 | + $(ARDUINO_CLI) monitor -p $(PORT) --config $(BAUD_RATE) |
| 37 | + |
| 38 | +# Clean build artifacts |
| 39 | +.PHONY: clean |
| 40 | +clean: |
| 41 | + @echo "Cleaning build artifacts..." |
| 42 | + rm -rf $(SKETCH_DIR)/build |
| 43 | + |
| 44 | +# List available ports |
| 45 | +.PHONY: ports |
| 46 | +ports: |
| 47 | + $(ARDUINO_CLI) board list |
| 48 | + |
| 49 | +# Check if arduino-cli is installed |
| 50 | +.PHONY: check |
| 51 | +check: |
| 52 | + @which $(ARDUINO_CLI) > /dev/null || (echo "Error: $(ARDUINO_CLI) not found. Install it from https://arduino.github.io/arduino-cli/" && exit 1) |
| 53 | + @echo "✓ $(ARDUINO_CLI) found" |
| 54 | + |
| 55 | +# Help target |
| 56 | +.PHONY: help |
| 57 | +help: |
| 58 | + @echo "Available targets:" |
| 59 | + @echo " make compile - Compile the sketch" |
| 60 | + @echo " make upload - Compile and upload to Arduino (uses PORT=$(PORT))" |
| 61 | + @echo " make build-upload - Same as upload" |
| 62 | + @echo " make monitor - Open serial monitor (uses PORT=$(PORT), BAUD_RATE=$(BAUD_RATE))" |
| 63 | + @echo " make ports - List available serial ports" |
| 64 | + @echo " make clean - Remove build artifacts" |
| 65 | + @echo " make check - Verify arduino-cli is installed" |
| 66 | + @echo "" |
| 67 | + @echo "Override PORT: make upload PORT=/dev/ttyACM0" |
| 68 | + @echo "Override ARDUINO_CLI: make compile ARDUINO_CLI=arduino-cli" |
| 69 | + |
0 commit comments