MCU=atmega168p

CC=avr-gcc
OBJCOPY=avr-objcopy
CFLAGS+=-O2 -Wall -mmcu=$(MCU) -DF_CPU=8000000
DUDEFLAGS=-p $(MCU) -c usbtiny

all: meter.hex

meter.elf: meter.o
	$(CC) $(CFLAGS) $< -o $@

%.hex: %.elf
	$(OBJCOPY) -j .text -j .data -O ihex $< $@

burn: meter.hex
	avrdude $(DUDEFLAGS) -U lfuse:w:0xE2:m -U hfuse:w:0xD5:m -U flash:w:$<:i

clean:
	$(RM) *.o *.hex *.elf

.PHONY: all clean fuses burn
