# The non-binary radio receiver -- SR P1 (FM 89.3 + DAB+ 12B) on a LimeSDR Mini 2.0, one aligned audio stream.
# "make check" first; "make deps" installs the Python package.  Then "make prog-harmonic" (or prog-digital) and
# "make listen".  RECEIVE ONLY.
SECS ?= 60
OUT  ?= p1
OFL  ?= openFPGALoader
# the LimeSDR's JTAG cable by its USB address (another FT2232H -- an Arty's -- may be first: "no device found")
CABLE = $(shell python3 jtag_cable.py)

.PHONY: help check deps prog-harmonic prog-digital listen probe switchover

help:
	@echo "make check            is this machine ready (tools, Python package, the board)"
	@echo "make deps             install the Python package (pyusb)"
	@echo "make prog-harmonic    load the harmonic-mixing image (LO 76 MHz, 32.768 MS/s)"
	@echo "make prog-digital     load the digital-tuning image (LO 155.0 MHz, 155.648 MS/s)"
	@echo "make listen [SECS=60] [OUT=p1]   the one stream for SECS into OUT.wav, the state every 2 s"
	@echo "make probe [SECS=60]  the state alone (the stream waits: nothing plays)"
	@echo "make switchover       harmonic image: 60 s, DAB cut from 25 s to 40 s -- FM fills in"

check:
	python3 check.py

deps:
	python3 -m pip install -r requirements.txt
	@echo "Also needed, not a pip package: openFPGALoader (see README.md)."

prog-harmonic:
	$(OFL) -c ft2232 $(CABLE) firmware/top_comb6.bit

prog-digital:
	$(OFL) -c ft2232 $(CABLE) firmware/top_cdt5.bit

# the stream (ft601_pcm.py, USB 3) and the state (probe.py, JTAG) at once: two different USB devices
listen:
	python3 ft601_pcm.py $(SECS) $(OUT).raw & python3 probe.py $(SECS) 2 $(AT); wait
	python3 ft_pcm.py $(OUT).raw $(OUT).wav

probe:
	python3 probe.py $(SECS) 2

switchover:
	$(MAKE) listen SECS=60 OUT=switchover AT="--at 25:0xF1 40:0xF0"
