On Thu, Jul 27, 2023 at 04:14:38PM +0100, andy pugh wrote: > I am using v1.2 on a Raspberry Pi under Buster (as that is the > installed version) > > However, the code appears to be the same in v1.6. > > As far as I can see gpiod_line_get_value_bulk() always fails if the > bulk contains more than one line. The problem(I think) is that > gpiod_line_same_chip() always returns -EINVAL > > Test code output: > > Chips line 0 0x3f1280 gpiochip0 > Chips line 1 0x3f2af0 gpiochip0 > Chips line 2 0x3f4350 gpiochip0 > > ie, all the same chip _name_ but the result of gpiod_line_get_chip (if > displayed as a pointer with %p) differs. > > Test code > > ```` > #include <gpiod.h> > #include <stdio.h> > #include <unistd.h> > #include <assert.h> > #include <errno.h> > #include <string.h> > > int main(int argc, char **argv) > { > struct gpiod_chip *chip; > struct gpiod_line *line0, *line1, *line2; > struct gpiod_line_bulk bulk; > int retval; > int val[4] = {0}; > > // Open GPIO chip > chip = gpiod_chip_open_by_name("gpiochip0"); > > // Open GPIO lines > line0 = gpiod_line_find("GPIO17"); > line1 = gpiod_line_find("GPIO18"); > line2 = gpiod_line_find("GPIO19"); > > gpiod_line_request_input(line0, "test"); > gpiod_line_request_input(line1, "test"); > gpiod_line_request_input(line2, "test"); > > gpiod_line_bulk_init(&bulk); > gpiod_line_bulk_add(&bulk, line0); > gpiod_line_bulk_add(&bulk, line1); > gpiod_line_bulk_add(&bulk, line2); > > // Compare the return value of gpiod_line_get_chip() for each line > printf("Chips line 0 %p %s\n", gpiod_line_get_chip(line0), > gpiod_chip_name(gpiod_line_get_chip(line0))); > printf("Chips line 1 %p %s\n", gpiod_line_get_chip(line1), > gpiod_chip_name(gpiod_line_get_chip(line1))); > printf("Chips line 2 %p %s\n", gpiod_line_get_chip(line2), > gpiod_chip_name(gpiod_line_get_chip(line2))); > > // try to read the IO lines > retval = gpiod_line_get_value_bulk(&bulk, val); > assert (retval == 0); > That is not how the line_bulk API is used. You don't request the lines separately and then add them to the bulk, you add them to the bulk then request them with gpiod_line_request_bulk_input(), or one of the other gpiod_line_request_bulk_XXX() functions. e.g. gpiod_line_bulk_init(&bulk); gpiod_line_bulk_add(&bulk, line0); gpiod_line_bulk_add(&bulk, line1); gpiod_line_bulk_add(&bulk, line2); gpiod_line_request_bulk_input(&bulk, "test"); // try to read the IO lines retval = gpiod_line_get_value_bulk(&bulk, val); assert (retval == 0); Refer to the test cases in libgpiod/tests/tests-line.c. e.g. the request_bulk_output test case. Btw, the primary use case for the bulk is for when you need to perform operations on a set of lines as simultaneously as possible. The downside is that they have to be requested at the same time. If you don't require the simultaneity, it may be simpler to request them separately, and operate on them separately. You might also want to consider looking at libgpiod v2, which is the latest release and has a new API that is hopefully less confusing. The get_multiple_line_values[1] example is similar to what you are doing in your example. You can use gpiod_chip_get_line_offset_from_name() to perform the name to offset mapping, if necessary. OTOH, libgpiod v2 hasn't made its way to many distros yet, and will never get to Raspbian Buster, so you would need to download and build it yourself, and your kernel may not even support it (libgpiod v2 requires kernel 5.10 or later). Cheers, Kent. [1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/examples/get_multiple_line_values.c