#chiprog makefile


all:
	gcc chiprog.c -o chiprog -lusb-1.0 -s

help:
	@echo 
	@echo "Make targets: all clean install uninstall" \
         " testflash testub2 testbb3uart" 
	@echo "              testbb3uartdbus testub2usb testice testicedbus"

clean:
	rm -f ./chiprog testfiles/*.out

install:
	cp chiprog /usr/local/bin

uninstall:
	rm -f /usr/local/bin/chiprog


testflash:
	./chiprog w sflash testfiles/SPIflash-random.bin 300 debug
	./chiprog r sflash testfiles/SPIflash-random.out 300 debug
	diff testfiles/SPIflash-random.bin testfiles/SPIflash-random.out

testub2: #EFM8UB2 through C2 protocol
	./chiprog w efm8 testfiles/SiLabs-LEDon-port4-EFMUB2-QFP48.bin 0 debug  # 0: automatic
	./chiprog r efm8 testfiles/SiLabs-LEDon-port4-EFMUB2-QFP48.out 6 debug
	diff testfiles/SiLabs-LEDon-port4-EFMUB2-QFP48.bin testfiles/SiLabs-LEDon-port4-EFMUB2-QFP48.out

testbb3uart: #EFM8BB3 through UART of FTDI
	./chiprog w efm8uart testfiles/SiLabs-LEDon-port0_0-EFM8BB3-QFP32.bin 0 debug

testbb3uartdbus: #EFM8BB3 through UART of FTDI using only DBUS lines
	./chiprog w efm8uartdbus testfiles/SiLabs-LEDon-port0_0-EFM8BB3-QFP32.bin 0 debug

testub2usb:
	./chiprog w efm8usb testfiles/SiLabs-LEDblink-port4-EFM8UB2-QFP48-USB_bootloader_start_fix.bin 0 debug

testice:
	./chiprog w ice40 testfiles/Lattice-LEDon-pin1-LP384QN32.bin 0 debug
#	chiprog r ice40 testfiles/Lattice-LEDon-pin1-LP384QN32.out 7872 debug
#	diff testfiles/Lattice-LEDon-pin1-LP384QN32.bin \
#         testfiles/Lattice-LEDon-pin1-LP384QN32.out

testicedbus:
	./chiprog w ice40dbus testfiles/Lattice-LEDon-pin1-LP384QN32.bin 0 debug
