#! /bin/bash set -ex # add stuff we want to config.txt config="mnt/boot/config.txt" add_file="$(mktemp)" trap 'rm -f "$add_file"' EXIT cat >"$add_file" <<'END' dtparam=spi=on # we can adjust these values as needed dtparam=cooling_fan=on,fan_temp0=62000,fan_temp0_hyst=8000,fan_temp0_speed=80,fan_temp1=70000,fan_temp1_hyst=5000,fan_temp1_speed=100,fan_temp2=76000,fan_temp2_hyst=4000,fan_temp2_speed=170,fan_temp3=80000,fan_temp3_hyst=3000,fan_temp3_speed=250 # enable i2s for audio dtparam=i2s=on # use an external antenna instead of the pcb antenna on the CM dtparam=ant2 # load our audio driver dtoverlay=toesaudio # enable gpio12 which we use to reset the audio codec gpio=12=op,dh # enable serial over usb in gadget/peripheral mode dtoverlay=dwc2,dr_mode=peripheral END if ! sudo grep -qx 'dtparam=spi=on' "$config"; then echo "missing dtparam=spi=on in $config" >&2 exit 1 fi sudo awk -v add_file="$add_file" ' $0 == "dtparam=spi=on" && !done { while ((getline line < add_file) > 0) { print line } close(add_file) done = 1 next } { print } ' "$config" | sudo tee "$config.tmp" >/dev/null sudo mv "$config.tmp" "$config" # we don't need fancy graphics. we don't have a screen. printf '\ngpu_mem=16\n' | sudo tee -a "$config" >/dev/null