# 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
A=avr-as
L=avr-gcc -mmcu=$M -Wall -Os

# fuer avrdude-Aufruf unter Linux:
TTY=/dev/ttyUSB0
# 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 nimm.hex biber.hex

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

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

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

biber.hex: biber.cc
	$L biber.cc -o biber.elf
	avr-objcopy -O ihex -R .eeprom biber.elf biber.hex
	avr-objdump -h -S biber.elf > biber.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:0xD9:m  #EEPROM wird geloescht
	avrdude -p $N -c $P -P $(TTY) -U hfuse:w:0xD1:m  #EEPROM nicht loeschen

eeinlesen: # funktioniert mit avrdude 5.11 nicht korrekt
	avrdude -p $N -c $P -P $(TTY) -U eeprom:r:eepromtest.raw:r
eeinlesenhex: # funktioniert mit avrdude 5.11 nicht korrekt
	avrdude -p $N -c $P -P $(TTY) -U eeprom:r:eepromtest.hex:i

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

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

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

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

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