forked from ZakSN/sd_mux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switcher
executable file
·66 lines (55 loc) · 1.11 KB
/
switcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
# This script allows selects which device (host or target) the micro SD card is
# connected to
# assumptions:
# 1. this script is running on a rpi3 model b and that the mux select pin is attached to gpio 23
# 2. target is device 1, host is device 2
# 3. host plug is plugged into ugen0.4
toggle_pin=23
host_select=0
target_select=1
host_device=0.4
usage()
{
echo "usage: switcher [-h|-t]"
echo "-h Attach to host"
echo "-t Attach to target"
exit 1
}
setup_gpio()
{
gpioctl -c $toggle_pin OUT
}
configure_host_usb()
{
usbconfig -d "${host_device}" power_off
usbconfig -d "${host_device}" power_on
}
host()
{
echo "attaching to host"
setup_gpio
gpioctl $toggle_pin $host_select
configure_host_usb
}
target()
{
echo "attaching to target"
setup_gpio
gpioctl $toggle_pin $target_select
configure_host_usb
# Ideally the target device is connected to a controllable power source
# and set to reboot on a power cycle. During testing no such
# power source was available so:
echo "please power cycle target"
}
if [ $# -ne 1 ];
then
usage
fi
case $1 in
"-h") host;;
"-t") target;;
*) usage;;
esac
exit 1