#!/usr/bin/env bash
set -euo pipefail
DTS=./src/misc/pcm1862-i2s.dts
DTBO=pcm1862-i2s.dtbo
OUT=/boot/firmware/overlays

# build
dtc -@ -I dts -O dtb -o "$DTBO" "$DTS"

# install
sudo install -m 0644 "$DTBO" "$OUT/$DTBO"

# NOTE: also add 
# dtparam=i2c_arm=on
# dtoverlay=pcm1862-i2s
# to /boot/firmware/config.txt

echo "Built and installed $DTBO to $OUT."
echo "Now either reboot to load the installed overlay"
