]> git.tdb.fi Git - model-railway-devices.git/blob - firmware/Makefile
Add some utility functions for interfacing with hardware
[model-railway-devices.git] / firmware / Makefile
1 # $Id$
2
3 MCU := atmega328p
4 CLOCK := 16000000
5 CC := avr-gcc
6 CFLAGS := -Wall -Os -ffunction-sections -fdata-sections -mmcu=$(MCU) -DF_CPU=$(CLOCK)
7 LDFLAGS := -Os -Wl,--gc-sections -mmcu=$(MCU)
8 AVRDUDE := avrdude
9 OBJCOPY := avr-objcopy
10 ifeq ($(MCU),atmega168)
11 BAUD := 19200
12 else
13 BAUD := 57600
14 endif
15
16 help:
17         @echo "Targets:"
18         @echo "  %.hex:    Build firmware from %.c"
19         @echo "  upload-%: Upload firmware to AVR"
20         @echo "  clean:    Clean all built files"
21         @echo
22         @echo "Variables:"
23         @echo "  MCU:      Microcontroller type"
24         @echo "            Arduino Duemilanove = atmega328p (default)"
25         @echo "            Arduino Mini = atmega168"
26
27 %.hex: %.elf
28         $(OBJCOPY) -O ihex $< $@
29
30 %.elf: %.o
31         $(CC) $(LDFLAGS) -o $@ $^
32
33 %.o: %.c
34         $(CC) -c $(CFLAGS) -o $@ $<
35
36 upload-%: %.hex
37         $(AVRDUDE) -p$(MCU) -carduino -P/dev/ttyUSB0 -b$(BAUD) -D -Uflash:w:$<:i
38
39 clean:
40         $(RM) *.hex
41         $(RM) *.elf
42         $(RM) *.o
43
44 s88w-t.elf: serial.o timer.o eeprom.o
45 s88w-r.elf: serial.o lcd.o