It supposed to read the config and configure GPIOs accordingly, but it looks like it does not handle all the parameters used in your config. As you can see option direction and option active_low from the config file are not even mentioned there.
The following code (from the script) { [ "$value" = "0" ] && echo "low" || echo "high"; } >"$gpio_path/direction"
means that if you set value=0 in the config the script will write "low" to direction.
The meaning of low and high is described here:
"direction" ... reads as either "in" or "out". This value may
normally be written. Writing as "out" defaults to
initializing the value as low. To ensure glitch free
operation, values "low" and "high" may be written to
configure the GPIO as an output with that initial value.
"value" ... reads as either 0 (low) or 1 (high). If the GPIO
is configured as an output, this value may be written;
any nonzero value is treated as high.
I modified the gpio_switch script.
I added the direction variable. I donĀ“t really know if active_low is needed.
If you want to have an input you need to define direction as in, if you need an output define value 0 or 1.
This system config gives:
config gpio_switch 'gpio0'
option name 'gpio0'
option gpio_pin '0'
option direction 'in'
config gpio_switch 'gpio10'
option name 'gpio10'
option gpio_pin '10'
option value '1'
root@OpenWrt:/etc# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-7, parent: platform/gpio-nct5104d, gpio-nct5104d, can sleep:
gpio-0 ( |sysfs ) in hi
gpiochip1: GPIOs 10-17, parent: platform/gpio-nct5104d, gpio-nct5104d, can sleep:
gpio-10 ( |sysfs ) out hi
gpio_switch
#!/bin/sh /etc/rc.common
# Copyright (C) 2015 OpenWrt.org
START=94
STOP=10
USE_PROCD=1
load_gpio_switch()
{
local name
local gpio_pin
local value
local direction
config_get gpio_pin "$1" gpio_pin
config_get name "$1" name
config_get value "$1" value 0
config_get direction "$1" direction 'out'
local gpio_path="/sys/class/gpio/gpio${gpio_pin}"
# export GPIO pin for access
[ -d "$gpio_path" ] || {
echo "$gpio_pin" > /sys/class/gpio/export
# we need to wait a bit until the GPIO appears
[ -d "$gpio_path" ] || sleep 1
}
# direction attribute only exists if the kernel supports changing the
# direction of a GPIO
if [ -e "${gpio_path}/direction" ]
then
if [ "$direction" = "in" ]
then
echo "in" > "$gpio_path/direction"
else
# set the pin to output with high or low pin value
{ [ "$value" = "0" ] && echo "low" || echo "high"; } > "$gpio_path/direction"
fi
fi
}
service_triggers()
{
procd_add_reload_trigger "system"
}
start_service()
{
[ -e /sys/class/gpio/ ] && {
config_load system
config_foreach load_gpio_switch gpio_switch
}
}