-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
95 lines (72 loc) · 2.6 KB
/
Copy pathMakefile
File metadata and controls
95 lines (72 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Project: Chrome Dino Auto-Player (ATtiny85 HID Keyboard)
# Hardware: Digispark ATtiny85 + LM393 LDR Sensor
# USB Stack: V-USB
# --- Configuration ---
DEVICE = attiny85
F_CPU = 16500000
FUSE_L = 0xE1
FUSE_H = 0xDD # RSTDISBL NOT programmed: PB5 stays as RESET (safe, reprogrammable)
# ISP Programmer
SERIAL_PORT ?= /dev/ttyACM0
PROGRAMMER ?= -c stk500v1 -b 19200 -P $(SERIAL_PORT)
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
SUDO ?= sudo
# --- AVR Toolchain ---
CC = avr-gcc
OBJCOPY = avr-objcopy
SIZE = avr-size
CFLAGS = -Wall -Os -DF_CPU=$(F_CPU) -mmcu=$(DEVICE) -Iusbdrv -Isrc -DDEBUG_LEVEL=0
LDFLAGS = -mmcu=$(DEVICE)
# --- Host Toolchain (micronucleus uploader) ---
HOSTCC = gcc
HOSTCFLAGS = -Wall -DUSE_HOSTCC
HOSTLFLAGS = $(shell pkg-config --libs --cflags libusb-1.0)
# --- Sources ---
OBJECTS = src/main.o usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o
MNUC_DIR = tools/micronucleus
MNUC_SRC = $(MNUC_DIR)/littleWire_util.c $(MNUC_DIR)/micronucleus_lib.c $(MNUC_DIR)/micronucleus.c
MNUC_BIN = $(MNUC_DIR)/micronucleus
# --- Targets ---
.PHONY: all hex micronucleus upload flash fuse program clean help
all: hex micronucleus
help:
@echo "Available targets:"
@echo " make all - Build firmware + micronucleus uploader"
@echo " make hex - Build firmware only (main.hex)"
@echo " make micronucleus - Build micronucleus uploader tool"
@echo " make upload - Build all, then flash via micronucleus"
@echo " make flash - Flash firmware via avrdude (ISP programmer)"
@echo " make fuse - Program fuse bits (requires ISP programmer)"
@echo " make program - Flash fuses + firmware via avrdude"
@echo " make clean - Remove build artifacts"
# --- Firmware ---
hex: main.hex
main.elf: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^
main.hex: main.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(SIZE) main.elf
@cp $@ hex/dino-player-v1.hex
src/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@
usbdrv/%.o: usbdrv/%.c
$(CC) $(CFLAGS) -c $< -o $@
usbdrv/%.o: usbdrv/%.S
$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
# --- Micronucleus uploader ---
micronucleus: $(MNUC_BIN)
$(MNUC_BIN): $(MNUC_SRC)
$(HOSTCC) $(HOSTCFLAGS) -o $@ $^ $(HOSTLFLAGS)
# --- Flash targets ---
upload: hex micronucleus
@echo ">>> Plug in Digispark ATtiny85 now..."
@echo " (To skip sudo: make upload SUDO='')"
$(SUDO) $(MNUC_BIN) --run main.hex
flash: main.hex
$(AVRDUDE) -U flash:w:main.hex:i
fuse:
$(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
program: flash fuse
# --- Cleanup ---
clean:
rm -f main.hex main.elf src/*.o usbdrv/*.o $(MNUC_BIN)