From 313116fddae49f894817d8d984395a99bdf48831 Mon Sep 17 00:00:00 2001 From: Peter Lebbing Date: Fri, 3 Jan 2025 15:42:58 +0100 Subject: [PATCH] Switch sysfs GPIO ABI to pigpiod The sysfs GPIO ABI has been deprecated in 2015 and Raspberry Pi OS bookworm no longer supports it. --- functions.sh | 26 ++++++++++++++++++++++++++ reset_ec.sh | 13 ++++--------- reset_soc.sh | 13 ++++--------- uart_fpga.sh | 10 +++------- uart_up5k.sh | 10 +++------- vbus.sh | 12 ++++-------- vbus_off.sh | 10 +++------- vbus_on.sh | 10 +++------- 8 files changed, 50 insertions(+), 54 deletions(-) create mode 100755 functions.sh diff --git a/functions.sh b/functions.sh new file mode 100755 index 0000000..ad3d001 --- /dev/null +++ b/functions.sh @@ -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 +} diff --git a/reset_ec.sh b/reset_ec.sh index 92d6abf..9b89f2b 100755 --- a/reset_ec.sh +++ b/reset_ec.sh @@ -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 diff --git a/reset_soc.sh b/reset_soc.sh index 566e0e8..64039c0 100755 --- a/reset_soc.sh +++ b/reset_soc.sh @@ -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 diff --git a/uart_fpga.sh b/uart_fpga.sh index a37cb68..50e538f 100755 --- a/uart_fpga.sh +++ b/uart_fpga.sh @@ -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 diff --git a/uart_up5k.sh b/uart_up5k.sh index 3faa1e8..aedb05b 100755 --- a/uart_up5k.sh +++ b/uart_up5k.sh @@ -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 diff --git a/vbus.sh b/vbus.sh index 3af9f47..aae7a3d 100755 --- a/vbus.sh +++ b/vbus.sh @@ -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 diff --git a/vbus_off.sh b/vbus_off.sh index 76ab74d..19f1486 100755 --- a/vbus_off.sh +++ b/vbus_off.sh @@ -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 diff --git a/vbus_on.sh b/vbus_on.sh index d6f5bbe..a531355 100755 --- a/vbus_on.sh +++ b/vbus_on.sh @@ -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