* Re: Help regarding IO configuration of multiple lines
2026-03-06 11:09 Help regarding IO configuration of multiple lines joussemetmathis
@ 2026-03-07 2:13 ` Kent Gibson
0 siblings, 0 replies; 2+ messages in thread
From: Kent Gibson @ 2026-03-07 2:13 UTC (permalink / raw)
To: joussemetmathis; +Cc: linux-gpio
On Fri, Mar 06, 2026 at 12:09:50PM +0100, joussemetmathis@gmail.com wrote:
> Hello,
>
> I am trying to learn how to use libgpiod on a Pi 5. I created for that
> goal a simple circuit with a push button and 2 LEDs, one of which turns
> on on a button press.
> Since I want to keep my program as modular as possible, I created a
> pinconfig function that configures the pins according to the parameters
> passed in main.
> However, when trying to pass an enum array of gpiod_line_direction to
> the function, the code no longer works and the LEDs no longer turn on.
> I suspect it is due to the way the array is handled, but since this use
> case isn't shown in the examples and that online ressources seems to
> only talk about v1 of gpiod, I'm a bit stuck.
> Could someone help me? You'll find my code attached in a zip in this
> email.
>
Yeah, the example code doesn't provide a good example of requesting
lines with different settings.
The closest is get_multiple_line_values.c. Though that applies settings for
each line individually when it could just use a single
gpiod_line_config_add_line_settings() call, as all the lines have the
same settings. Not sure why. ¯\_(ツ)_/¯
The relevant section of your code, which seems to follow that example, is:
gpiod_line_settings_set_direction(line_settings, *direction);
// ...
for (int i = 0; i < line_nbr; i++) {
gpiod_line_config_add_line_settings(line_config, &pin_list[i], 1, line_settings);
}
That applies the first entry in your direction array as the direction for all
lines. Definitely not what you want.
See if this works for you:
for (int i = 0; i < line_nbr; i++) {
gpiod_line_settings_set_direction(line_settings, direction[i]);
gpiod_line_config_add_line_settings(line_config, &pin_list[i], 1, line_settings);
}
That applies the direction for each line individually, with other line
settings being the same.
Cheers,
Kent.
^ permalink raw reply [flat|nested] 2+ messages in thread