From: Kent Gibson <warthog618@gmail.com>
To: andy pugh <bodgesoc@gmail.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [libgpiod] gpiod_line_get_value_bulk may be broken?
Date: Fri, 28 Jul 2023 13:57:04 +0800 [thread overview]
Message-ID: <ZMNYsOXrOOZgxLeC@sol> (raw)
In-Reply-To: <CAN1+YZXqsgCXVhiVHasBMBzCVs-r=wi93m6m5ojUhOi_NOsOxg@mail.gmail.com>
On Fri, Jul 28, 2023 at 01:39:37AM +0100, andy pugh wrote:
> On Thu, 27 Jul 2023 at 22:55, Kent Gibson <warthog618@gmail.com> 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.
next prev parent reply other threads:[~2023-07-28 5:57 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 15:14 [libgpiod] gpiod_line_get_value_bulk may be broken? andy pugh
2023-07-27 20:53 ` Kent Gibson
2023-07-27 21:17 ` andy pugh
2023-07-27 21:55 ` Kent Gibson
2023-07-27 22:10 ` andy pugh
2023-07-27 22:36 ` Kent Gibson
2023-07-28 0:39 ` andy pugh
2023-07-28 1:07 ` andy pugh
2023-07-28 5:57 ` Kent Gibson [this message]
2023-07-28 19:01 ` andy pugh
2023-07-29 2:03 ` Kent Gibson
2023-08-05 22:55 ` andy pugh
2023-08-06 1:02 ` Kent Gibson
2023-08-06 9:13 ` andy pugh
2023-08-06 9:29 ` Kent Gibson
2023-08-10 0:17 ` andy pugh
2023-08-10 0:46 ` Kent Gibson
2023-08-10 22:07 ` andy pugh
2023-08-11 0:59 ` Kent Gibson
2023-08-11 1:26 ` andy pugh
2023-08-11 1:36 ` Kent Gibson
2023-08-14 22:25 ` How to use gpiod_line_set_flags andy pugh
2023-08-15 0:49 ` Kent Gibson
2023-08-15 18:03 ` andy pugh
2023-08-11 12:19 ` [libgpiod] gpiod_line_get_value_bulk may be broken? Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZMNYsOXrOOZgxLeC@sol \
--to=warthog618@gmail.com \
--cc=bodgesoc@gmail.com \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.