# --
# Copyright (c) 2016, Lukasz Marcin Podkalicki <lpodkalicki@gmail.com>
# --

MCU=attiny26
FUSE_L=0xe4
FUSE_H=0x17
#F_CPU=14285999
F_CPU=8000000
CC=avr-gcc
LD=avr-ld
OBJCOPY=avr-objcopy
SIZE=avr-size
AVRDUDE=avrdude
CFLAGS=-std=c99 -Wall -g -Os -mmcu=${MCU} -DF_CPU=${F_CPU} -I.
TARGET=main
CPUNAME=at26
DATE=`(date +%F_%T)| sed 's/://g' | sed 's/-//g'`

SRCS = main.c light_ws2812.c

all:
	${CC} ${CFLAGS} -o bin/${TARGET}.o ${SRCS}
	${LD} -o bin/${TARGET}.elf bin/${TARGET}.o
	${OBJCOPY} -j .text -j .data -O ihex bin/${TARGET}.o bin/${TARGET}.hex
	${SIZE} -C --mcu=${MCU} bin/${TARGET}.elf

flash:
	${AVRDUDE} -p ${MCU} -c usbasp -B10 -U flash:w:bin/${TARGET}.hex:i -F -P usb

readfb:
	avrdude -c usbasp -p ${MCU} -U lfuse:r:fusebits/lf-${CPUNAME}-${DATE}.hex:h -U hfuse:r:fusebits/hf-${CPUNAME}-${DATE}.hex:h -U efuse:r:fusebits/ef-${CPUNAME}-${DATE}.hex:h

clean:
	rm -f *.c~ bin/*.o bin/*.elf bin/*.hex

fuse:
	$(AVRDUDE) -p ${MCU} -c usbasp -B10 -U hfuse:w:${FUSE_H}:m -U lfuse:w:${FUSE_L}:m