normal:	ot2rs232.hex

all:	clean ot2rs232_2400.hex ot2rs232_9600.hex ot2rs232_19200.hex doc

CC=avr-gcc
OBJCOPY=avr-objcopy
PROGRAMMER=avrispmkII


CFLAGS= -Wall -mmcu=attiny25 -Os

# code
ot2rs232.hex:	ot2rs232.elf
	$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock ot2rs232.elf ot2rs232.hex
	avr-size ot2rs232.elf

ot2rs232.elf:	ot2rs232.c
	$(CC) $(CFLAGS) ot2rs232.c  -o ot2rs232.elf


ot2rs232_2400.hex:	ot2rs232.c
	$(CC) $(CFLAGS) -DBAUD_RATE=2400 ot2rs232.c -o ot2rs232_2400.elf
	$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock ot2rs232_2400.elf ot2rs232_2400.hex

ot2rs232_9600.hex:	ot2rs232.c
	$(CC) $(CFLAGS) -DBAUD_RATE=9600 ot2rs232.c -o ot2rs232_9600.elf
	$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock ot2rs232_9600.elf ot2rs232_9600.hex

ot2rs232_19200.hex:	ot2rs232.c
	$(CC) $(CFLAGS) -DBAUD_RATE=19200 ot2rs232.c -o ot2rs232_19200.elf
	$(OBJCOPY) -O ihex -R .eeprom -R .fuse -R .lock ot2rs232_19200.elf ot2rs232_19200.hex

# fuse configuration (not used for this project)
fuses.hex:	ot2rs232.elf
	avr-objcopy -O ihex -j .fuse --set-section-flags=.fuses="alloc,load" --change-section-lma .fuse=0 --no-change-warnings ot2rs232.elf fuses.hex

lfuse.hex:	fuses.hex
	srec_cat fuses.hex -Intel -crop 0x00 0x01 -offset  0 -O lfuse.hex -Intel -address-length=2


#programmer targets
programRead:
	avrdude -p attiny25 -c $(PROGRAMMER) -v -U flash:r:rom_asm_verify.hex:i

fuseREAD:
	avrdude -p attiny25 -c $(PROGRAMMER) -v

program:	ot2rs232.hex 
	avrdude -p attiny25 -c $(PROGRAMMER) -v -U flash:w:ot2rs232.hex

l_fuse:	lfuse.hex
	echo "Do not change default fuse!!!"
	#avrdude -p attiny25 -c $(PROGRAMMER) -v -U lfuse:w:lfuse.hex
	
clean:
	rm -f *~
	rm -f *.o
	rm -f *.hex *.map *.elf *.bak
	rm -f export.tgz

        
doc:	README.txt
	asciidoc -b html5 -a icons -a toc2 -a theme=flask README.txt
	a2x  -f pdf README.txt

export:	doc all
	tar cvfz export.tgz *.hex *.elf Makefile ot2rs232.c README.*
