CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/packages/bsp/rockchip/start_bt.sh
Views: 3960
1
#!/bin/bash
2
3
GPIO_CONFIGURED_CHECK_DIRECTORY="/var/run/rtk_bt"
4
GPIO_CONFIGURED_CHECK_FILE="/var/run/rtk_bt/gpio_configured"
5
6
function die_on_error {
7
if [ ! $? = 0 ]; then
8
echo $1
9
exit 1
10
fi
11
}
12
13
# Kill any rtk_hciattach actually running.
14
# Do not complain if we didn't kill anything.
15
killall -q -SIGTERM rtk_hciattach
16
17
# If the GPIO are not yet configured
18
if [ ! -f "$GPIO_CONFIGURED_CHECK_FILE" ];
19
then
20
# We'll create the directory first
21
# So that, if the user is not root
22
# he'll get a user permission error
23
mkdir -p "$GPIO_CONFIGURED_CHECK_DIRECTORY" || die_on_error "Could not create$GPIO_CONFIGURED_CHECK_DIRECTORY"
24
25
echo 146 > /sys/class/gpio/export
26
echo 149 > /sys/class/gpio/export
27
echo 151 > /sys/class/gpio/export
28
echo high > /sys/class/gpio/gpio146/direction
29
echo high > /sys/class/gpio/gpio149/direction
30
echo high > /sys/class/gpio/gpio151/direction
31
32
echo 1 > $GPIO_CONFIGURED_CHECK_FILE || die_on_error "Could not write to $GPIO_CONFIGURED_CHECK_FILE !"
33
fi
34
35
# If you run the rtk_hciattach once
36
# you cannot run it again before`
37
# resetting the device.
38
# Since resetting the device before
39
# the first launch generates no issue,
40
# we always reset the device.
41
42
echo "Resetting the Bluetooth chip"
43
echo 0 > /sys/class/gpio/gpio149/value &&
44
echo -e "\tBluetooth chip power down..." &&
45
sleep 1 &&
46
echo 1 > /sys/class/gpio/gpio149/value &&
47
echo -e "\tBluetooth chip power up..." &&
48
sleep 1
49
echo -e "\tResetting done"
50
51
/usr/bin/rtk_hciattach -n -s 115200 /dev/ttyS0 rtk_h5 || die_on_error "Could not create hci0 through rtk_hciattach"
52
53