You may want to be more specific in what you intend to do.
If you want to do something from boot without software interaction, device tree overlays are probably the way to go. gpio-led suggest you can add an entry like dtoverlay=gpio-led,gpio=19,label=heart,trigger=heartbeat to your configuration.
thanks for your replies, @alanb128 yes I’m aware of these documentations, but they’re not testify my needs.
I need a way to turn a specific to behave like LED, so when I export it the OS will provide a “trigger” FD
For example:
/sys/class/gpio/gpio4/trigger
@TJvV
What about after boot? say we want to change the blink rate of a GPIO in real time.
Currently we are doing it using goroutines, but it would be much better by setting a GPIO FD with a dutycycle
Coming back with a few findings,
Tested this on a raspberrypi4 with balenaOS 4.0.26.
Adding the following to your configuration (“Define DT overlays”): "gpio-led,label=test-led,gpio=26,trigger=timer" gives you an entry /sys/class/leds/test-led that can be used to control GPIO 26. The default values for the timer trigger is 500ms on, 500ms off.
To change the frequency and duty cycle of the pulse, you can change /sys/class/leds/test-led/delay_on and /sys/class/leds/test-led/delay_off. (ex. echo 1000 > /sys/class/leds/test-led/delay_on to have it on for a full second)
If you want to hook it up to a GPIO input, you can change /sys/class/leds/test-led/trigger (or the trigger in the dtoverlay config) to gpio and write the relevant GPIO number to /sys/class/leds/test-led/gpio.
Sadly, I haven’t been successful in changing the timer delays, or the GPIO assignment in config.txt line (yet), only through sysfs after booting.
I think your best bet for now is to simply change it when your container starts up.
That’s where you have the most control.
it can be as simple as wrapping your current command in a shell script.
Something like:
#!/bin/sh
LED_DIR=/sys/class/leds/test-led
if [ -n "${led_on_ms}" ]; then
echo "${led_on_ms}" > ${LED_DIR}/delay_on
fi
if [ -n "${led_off_ms}" ]; then
echo "${led_off_ms}" > ${LED_DIR}/delay_off
fi
<actual command> $@
This should set the delay_on and delay_off to values if specified in environment variables, and then call your actual command with the parameters you gave the script.