-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
97 lines (70 loc) · 2.1 KB
/
Makefile
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
96
97
# Use the full strip
LED_COUNT = 121
# Shift the LED we start at(if not using full strip)
#STARTING_LED = 73
# Max limit per strip = (3A regulator - 500mA MCU) / 2 strips
# A lower setting will make your batteries last longer
CURRENT_LIMIT = 750
# Run at 20Mhz
F_CPU = 20000000UL
# ATmegaXX8a DIP
MCU = atmega168
MOSI = PB3
MOSI_DDR = DDRB
MOSI_PORT = PORTB
SS = PB2
SS_DDR = DDRB
SS_PORT = PORTB
SCK = PB5
SCK_DDR = DDRB
EXT_CRYSTAL_LFUSE = 0xF7
DEFAULT_LFUSE = 0x62
PROGRAMMER = usbtiny
LIBDIR = libs/AVR-APA102-library/src
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRSIZE = avr-size
AVRDUDE = avrdude
TARGET = firmware
SOURCES=$(wildcard src/*.c $(LIBDIR)/*.c)
OBJECTS=$(SOURCES:.c=.o)
HEADERS=$(SOURCES:.c=.h)
CPPFLAGS = -I. -I$(LIBDIR)
CPPFLAGS += -DF_CPU=$(F_CPU)
CPPFLAGS += -DMOSI=$(MOSI) -DMOSI_DDR=$(MOSI_DDR) -DMOSI_PORT=$(MOSI_PORT)
CPPFLAGS += -DSS=$(SS) -DSS_DDR=$(SS_DDR) -DSS_PORT=$(SS_PORT)
CPPFLAGS += -DSCK=$(SCK) -DSCK_DDR=$(SCK_DDR)
CPPFLAGS += -DLED_COUNT=$(LED_COUNT)
ifdef STARTING_LED
CPPFLAGS += -DSTARTING_LED=$(STARTING_LED)
endif
ifdef CURRENT_LIMIT
CURRENT_PER_LED = $$(( $(CURRENT_LIMIT) / $(LED_COUNT) ))
ifeq ($(shell test $(CURRENT_PER_LED) -lt 60; echo $$?), 0)
CPPFLAGS += -DCURRENT_PER_LED=$(CURRENT_PER_LED)UL
endif
endif
CFLAGS = -Os -g -std=c11 -Wall -Wextra -pedantic
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS = -Wl,-Map,$(TARGET).map
LDFLAGS += -Wl,--gc-sections
TARGET_ARCH = -mmcu=$(MCU)
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<;
$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
.PHONY: all flash set_fuses reset_fuses clean
all: $(TARGET).hex
flash: $(TARGET).hex
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU) -U flash:w:$<
set_fuses:
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU) -U lfuse:w:$(EXT_CRYSTAL_LFUSE):m
reset_fuses:
$(AVRDUDE) -c $(PROGRAMMER) -p $(MCU) -U lfuse:w:$(DEFAULT_LFUSE):m
clean:
rm -f *.hex *.elf *.map
rm -f src/*.o $(LIBDIR)/*.o