# Processortyp M fuer Compiler, N fuer avrdude:
M=atmega1284p
#M=atmega128  # provisorisch fuer alten Compiler
N=m1284p
# Compileraufrufe:
C=avr-gcc -mmcu=$M -Wall -Os -c #moeglichst kompakt
C3=avr-gcc -mmcu=$M -Wall -O3 -c #moeglichst schnell
A=avr-as
L=avr-gcc -mmcu=$M -Wall -Os  # -Os fuer moeglichst kompakt, -O3 fuer moeglichst schnell

# fuer avrdude-Aufruf unter Linux:
TTY=/dev/ttyUSB0
TTY1=/dev/ttyUSB1
# fuer avrdude-Aufruf unter MacOSX:
#TTY=/dev/tty.serial-0001

# verwendeter Programmer:
#P=avr910  #fuer mySmartUSB MK2
P=stk500v2 #fuer mySmartUSB light

#all: test1.hex test2.hex kartonschach.hex
all: kartonschach.hex

test2.hex: test2.cc lcdmodul2.h lcdmodul2.o
	$L test2.cc lcdmodul2.o -o test2.elf
	avr-objcopy -O ihex -R .eeprom test2.elf test2.hex
	avr-objdump -h -S test2.elf > test2.lss

kartonschach.hex: kartonschach.cc schach-engine.h schach-engine.o lcdmodul2.h lcdmodul2.o
	$L kartonschach.cc schach-engine.o lcdmodul2.o -o kartonschach.elf
	avr-objcopy -O ihex -R .eeprom kartonschach.elf kartonschach.hex
	avr-objdump -h -S kartonschach.elf > kartonschach.lss

lcdmodul2.o:  lcdmodul2.h lcdmodul2.cc
	$C lcdmodul2.cc -o lcdmodul2.o

schach-engine.o:  schach-engine.h schach-engine.cc
	$(C3) -DAVRSCHACH=1 schach-engine.cc -o schach-engine.o

hall.hex: hall.cc
	$L hall.cc -o hall.elf
	avr-objcopy -O ihex -R .eeprom hall.elf hall.hex
	avr-objdump -h -S hall.elf > hall.lss

check:
	avrdude -p $N -c $P -P $(TTY) -v
check2:
	avrdude -p $N -F -c $P -P $(TTY) -v

# Fuses fuer 20MHz Quarz, fuer ATmega1284P:
fusesetzen:
	avrdude -p $N -c $P -P $(TTY) -U lfuse:w:0xFF:m
	avrdude -p $N -c $P -P $(TTY) -U hfuse:w:0xD1:m

install: kartonschach.hex
	avrdude -p $N -c $P -P $(TTY) -U flash:w:kartonschach.hex:i

installusb1: kartonschach.hex
	avrdude -p $N -c $P -P $(TTY1) -U flash:w:kartonschach.hex:i

install2: test2.hex
	avrdude -p $N -c $P -P $(TTY) -U flash:w:test2.hex:i

clean:
	rm -f *~  *.elf
clean_all:
	rm -f *~ *.o *.elf *.lss *.hex
