Re: [libgpiod] gpiod_line_get_value_bulk may be broken?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 28, 2023 at 01:39:37AM +0100, andy pugh wrote:
> On Thu, 27 Jul 2023 at 22:55, Kent Gibson <warthog618@xxxxxxxxx> wrote:
> 
> > > I did try that way first, but it didn't seem to be working for me.
> > > I am currently upgrading the system to Bookworm (gpiod v1.6) to try again.
> > >
> >
> > If you can repeat it, and ideally provide a failing test case, then we can
> > take a look at it.
> 
> Now using gpiod v1.6 in Bookworm. gpiod_line_request_bulk() does not
> seem to set the consumer.
> Also, with the suggested use of bulk requests I still get an error
> return from gpiod_line_get_value_bulk and an errno (22) that suggests
> that it is line_bulk_same_chip() which has caused the problem.
> 
> test output:
> 
> line0 (null) line1 (null) line2 (null)
> Error = Invalid argument (22)
> a.out: test.c:47: main: Assertion `retval == 0' failed.
> Aborted
> 
> 
> 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");
> 

Your problem is that finding lines this way produces gpiod_lines with
different chip pointers, and gpiod_line_request_bulk_input() is taking
that to mean different chips, so the request itself is failing - but you
didn't check.

>   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");
> 

If you change that to:
  retval = gpiod_line_request_bulk_input(&bulk, "test");
  printf("Error = %s (%i)\n", strerror(errno), errno);
  assert (retval == 0);

it will die on the assert.

Try this to find the lines instead:

  // Open GPIO lines
  // (actually this is just a find - the request performs the open)
  line0 = gpiod_chip_find_line(chip, "GPIO17");
  line1 = gpiod_chip_find_line(chip, "GPIO18");
  line2 = gpiod_chip_find_line(chip, "GPIO19");

That then works for me (including the extra Error print above):

$ ./a.out
Error = Success (0)
line0 test line1 test line2 test
Error = Success (0)


Not saying the gpiod_line_request_bulk_input() behaviour is correct, but
given v1 is obsoleted by v2, and there is a reasonable workaround for
v1 (assuming you know the chip the line is on), I'm not sure Bart will
want to fix that quirk.

For the same reason, I would suggest that you try libgpiod v2 and use
that instead if you possibly can - assuming libgpiod is fast enough for
your application.  

Cheers,
Kent.



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux