CHIPDB_DIR = /usr/share/nextpnr/xilinx-chipdb
XRAY_DATABASE_DIR = /usr/share/xray/database

PART = xc7a35tcsg324-1

.PHONY: all clean prog sim

all: pixelflut.bit

clean:
	rm -f pixelflut.bit pixelflut.fasm pixelflut.frames pixelflut.json
	rm -f dvi_tb.vcd dvi_tb.vvp

prog: pixelflut.bit
	openFPGALoader -b arty_a7_35t $<

sim: dvi_tb.vcd
	gtkwave $<

pixelflut.bit: pixelflut.frames
	xc7frames2bit --part_file "$(XRAY_DATABASE_DIR)/artix7/$(PART)/part.yaml" --part_name $(PART) --frm_file $< --output_file $@

pixelflut.frames: pixelflut.fasm
	fasm2frames --db-root "$(XRAY_DATABASE_DIR)/artix7" --part $(PART) $< > $@

pixelflut.fasm: arty_a7_35t.xdc pixelflut.json
	nextpnr-xilinx --chipdb "$(CHIPDB_DIR)/$(PART).bin" --fasm $@ --json pixelflut.json --xdc arty_a7_35t.xdc

pixelflut.json: pixelflut.v dvi.v
	yosys -q -p 'synth_xilinx -top pixelflut; write_json $@' $^

dvi_tb.vcd: dvi_tb.vvp
	vvp $<

dvi_tb.vvp: dvi_tb.v dvi.v
	iverilog -o $@ $^