# Configuration
# Muligheder: attiny45, attiny2313, attiny24, se resten her: http://www.nongnu.org/avr-libc/user-manual/using_tools.html
TARGET := attiny45
# Navnet p projektet. M IKKE HAVE MELLEMRUM!
NAME := blink
# COM-porten hvor programmren er tilkoblet
COMPORT := COM7

# DO NOT TOUCH
SRCS := $(wildcard *.c) $(wildcard *.cpp)
OBJS = $(wildcard *.o)
BAUD := 19200
PROG := stk500v1
CFLAGS := -I. -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -DF_CPU=8000000 -mmcu=$(TARGET)

all: $(NAME)
	avr-gcc $(CFLAGS) $(OBJS) --output $(NAME).elf
	avr-objcopy -O ihex -R .eeprom $(NAME).elf $(NAME).hex

$(NAME): $(SRCS)
	avr-gcc -c $(CFLAGS) $^

clean:
	@- $(RM) $(NAME).elf
	@- $(RM) $(NAME).hex
	@- $(RM) $(OBJS)

burn:
	avrdude -c $(PROG) -p $(TARGET) -P $(COMPORT) -b $(BAUD) -u -U flash:w:$(NAME).hex

erase:
	avrdude -c $(PROG) -p $(TARGET) -P $(COMPORT) -b $(BAUD) -e

fuses: $(TARGET)_fuses

attiny45_fuses:
	avrdude -c $(PROG) -p $(TARGET) -P $(COMPORT) -b $(BAUD) -e -U efuse:w:0xFF:m -U hfuse:w:0xD7:m -U lfuse:w:0xE2:m

attiny2313_fuses:
	avrdude -c $(PROG) -p $(TARGET) -P $(COMPORT) -b $(BAUD) -e -U efuse:w:0xFF:m -U hfuse:w:0x9F:m -U lfuse:w:0xE4:m

attiny24_fuses:
	avrdude -c $(PROG) -p $(TARGET) -P $(COMPORT) -b $(BAUD) -e -U efuse:w:0xFF:m -U hfuse:w:0xD7:m -U lfuse:w:0xE2:m
