Skip to content

Commit

Permalink
Switch sysfs GPIO ABI to pigpiod
Browse files Browse the repository at this point in the history
The sysfs GPIO ABI has been deprecated in 2015 and Raspberry Pi OS
bookworm no longer supports it.
  • Loading branch information
DigitalBrains1 committed Jan 3, 2025
1 parent fffc85a commit 313116f
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 54 deletions.
26 changes: 26 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

ensure_pigpiod() {
local TRIES
if ! which socat pigpiod pigs >/dev/null; then
echo Please install all of the following packages:
echo sudo apt install socat pigpiod pigpio-tools
exit 1
fi
socat OPEN:/dev/null TCP6:localhost:8888 2>/dev/null && return
socat OPEN:/dev/null TCP4:localhost:8888 2>/dev/null && return
if ! sudo systemctl start pigpiod.service; then
echo "Could not start pigpiod.service; please fix."
exit 1
fi
TRIES=15
while [ $TRIES -gt 0 ]; do
socat OPEN:/dev/null TCP6:localhost:8888,retry=1,interval=0.1 2>/dev/null && break
socat OPEN:/dev/null TCP4:localhost:8888,retry=1,interval=0.1 2>/dev/null && break
TRIES=$((TRIES - 1))
done
if [ $TRIES -eq 0 ]; then
echo Timed out waiting for pigpiod to start
exit 1
fi
}
13 changes: 4 additions & 9 deletions reset_ec.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio25 ]
then
echo "25" > /sys/class/gpio/export
fi
. ./functions.sh

ensure_pigpiod
pigs modes 25 w write 25 0
sleep 0.1
echo "out" > /sys/class/gpio/gpio25/direction
echo 0 > /sys/class/gpio/gpio25/value
sleep 0.1
echo 1 > /sys/class/gpio/gpio25/value

pigs write 25 1
13 changes: 4 additions & 9 deletions reset_soc.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio24 ]
then
echo "24" > /sys/class/gpio/export
fi
. ./functions.sh

ensure_pigpiod
pigs modes 24 w write 24 0
sleep 0.1
echo "out" > /sys/class/gpio/gpio24/direction
echo 0 > /sys/class/gpio/gpio24/value
sleep 0.1
echo 1 > /sys/class/gpio/gpio24/value

pigs write 24 1
10 changes: 3 additions & 7 deletions uart_fpga.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio18 ]
then
echo "18" > /sys/class/gpio/export
fi
. ./functions.sh

sleep 0.1
echo "out" > /sys/class/gpio/gpio18/direction
echo "1" > /sys/class/gpio/gpio18/value
ensure_pigpiod
pigs modes 18 w write 18 1
10 changes: 3 additions & 7 deletions uart_up5k.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio18 ]
then
echo "18" > /sys/class/gpio/export
fi
. ./functions.sh

sleep 0.1
echo "out" > /sys/class/gpio/gpio18/direction
echo "0" > /sys/class/gpio/gpio18/value
ensure_pigpiod
pigs modes 18 w write 18 0
12 changes: 4 additions & 8 deletions vbus.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/bin/sh

. ./functions.sh

if [ "$1" != "0" ] && [ "$1" != "1" ]; then
echo "Needs an argument of 0 or 1"
exit 0
fi

if [ ! -d /sys/class/gpio/gpio21 ]
then
echo "21" > /sys/class/gpio/export
fi

sleep 0.1
echo "out" > /sys/class/gpio/gpio21/direction
echo $1 > /sys/class/gpio/gpio21/value
ensure_pigpiod
pigs modes 21 w write 21 $1
10 changes: 3 additions & 7 deletions vbus_off.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio21 ]
then
echo "21" > /sys/class/gpio/export
fi
. ./functions.sh

sleep 0.1
echo "out" > /sys/class/gpio/gpio21/direction
echo "0" > /sys/class/gpio/gpio21/value
ensure_pigpiod
pigs modes 21 w write 21 0
10 changes: 3 additions & 7 deletions vbus_on.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/bin/sh

if [ ! -d /sys/class/gpio/gpio21 ]
then
echo "21" > /sys/class/gpio/export
fi
. ./functions.sh

sleep 0.1
echo "out" > /sys/class/gpio/gpio21/direction
echo "1" > /sys/class/gpio/gpio21/value
ensure_pigpiod
pigs modes 21 w write 21 1

0 comments on commit 313116f

Please sign in to comment.