Skip to content

Instantly share code, notes, and snippets.

@frankgould
Last active January 23, 2022 20:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankgould/db38ca5e40b3d2368f8d7765e346f8c5 to your computer and use it in GitHub Desktop.
Save frankgould/db38ca5e40b3d2368f8d7765e346f8c5 to your computer and use it in GitHub Desktop.
RPi4B files for bluetooth headsets on Arch Linux ARM 4.19
#!/bin/sh
HCIATTACH=/usr/bin/hciattach
if grep -q "Pi 4" /proc/device-tree/model; then
BDADDR=
else
SERIAL=`cat /proc/device-tree/serial-number | cut -c9-`
B1=`echo $SERIAL | cut -c3-4`
B2=`echo $SERIAL | cut -c5-6`
B3=`echo $SERIAL | cut -c7-8`
BDADDR=`printf b8:27:eb:%02x:%02x:%02x $((0x$B1 ^ 0xaa)) $((0x$B2 ^ 0xaa)) $((0x$B3 ^ 0xaa))`
fi
uart0="`cat /proc/device-tree/aliases/uart0`"
serial1="`cat /proc/device-tree/aliases/serial1`"
if [ "$uart0" = "$serial1" ] ; then
uart0_pins="`wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' '`"
if [ "$uart0_pins" = "16" ] ; then
$HCIATTACH /dev/serial1 bcm43xx 3000000 flow - $BDADDR
else
$HCIATTACH /dev/serial1 bcm43xx 921600 noflow - $BDADDR
fi
else
$HCIATTACH /dev/serial1 bcm43xx 460800 noflow - $BDADDR
fi
[Unit]
Description=Configure Bluetooth Modems connected by UART
#ConditionFileNotEmpty=/proc/device-tree/soc/gpio@7e200000/bt_pins/brcm,pins
Requires=dev-serial1.device
After=dev-serial1.device
[Service]
Type=forking
ExecStart=/usr/bin/btuart
[Install]
WantedBy=multi-user.target
sudo pacman -S pulseaudio-alsa pulseaudio-bluetooth bluez-utils libmm-glib modemmanager
sudo systemctl start ModemManager
sudo systemctl enable ModemManager
sudo systemctl start bluetooth
sudo systemctl enable bluetooth
## copy btuart to /usr/bin folder and chmod 777
sudo cp <your folder containing file>/btuart /usr/bin/.
sudo chmod 777 /usr/bin/btuart
## copy hciuart.service to /etc/systemd/system folder
sudo cp <your folder containing file>/hciuart.service /etc/systemd/system/.
# Add permanent link for serial1 as udev rule:
sudo nano /etc/udev/rules.d/99_ttyAMA0.rules
KERNEL=="ttyAMA0", SYMLINK+="serial1"
reboot
cd /home/<your folder>
git clone https://aur.archlinux.org/hciattach-rpi3.git
cd hciattach-rpi3/
makepkg -Asri
sudo cp /usr/bin/hciattach-rpi3 /usr/bin/hciattach
sudo systemctl start bluetooth
sudo systemctl enable bluetooth
sudo systemctl start hciuart
sudo systemctl enable hciuart
bluetoothctl
#[bluetooth]power on
#[bluetooth]scan on
#(Multiple bluetooth devices in your area should appear per line with MAC addresses)
#[bluetooth]pair <yourheadset as: ##:##:##:##:##:##>
#[yourheadset brand]connect ##:##:##:##:##:##
#[yourheadset brand]trust ##:##:##:##:##:##
# ADD two lines below somewhere near the top of lists in this file:
sudo nano /etc/pulse/default.pa
# Automatically switch to newly-connected devices
load-module module-switch-on-connect
# Uncomment and set `AutoEnable=true` in [Policy] section of the file:
sudo nano /etc/bluetooth/main.conf
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment