Re: [libgpiod] Either a bug or a misunderstanding regarding bulk operations

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

 



On Thu, Sep 29, 2022 at 08:13:36AM -0500, Mark Locascio wrote:
>   Hi,
> 
> I was working with libgpiod and I noticed some unintuitive behavior. I
> can't say for sure that it's a bug, but at the very least, it's
> confusing, and I want to get clarification. Sample code is attached.
> 
> Let's say I have four lines that I want to use as outputs. I can
> request them all at once like this:
> 
> struct gpiod_chip* chip = gpiod_chip_open("/dev/gpiochip0");
> struct gpiod_line_bulk lines;
> uint32_t offsets[NUMOUTPUTS] = {6, 13, 19, 26};
> int get_lines_result = gpiod_chip_get_lines(chip, offsets, NUMOUTPUTS, &lines);
> int32_t values[NUMOUTPUTS] = {0, 0, 0, 0};
> int set_dir_result = gpiod_line_request_bulk_output(&lines, "testgpio", values);
> 
> And then when I want to set new values, I can update the "values"
> array and then do:
> 
> int set_result = gpiod_line_set_value_bulk(&lines, values);
> 
> This works exactly as expected. However, I need to maintain an array
> of the current values of all the output lines. If I didn't want to do
> that, perhaps because I was wrapping this in a function, I thought it
> could make sense to get a single line object from the bulk object, and
> then just set that one value.
> 

The line bulk are "Convenience data structures and helper functions for
storing and operating on multiple lines at once."

They are intended to operate on all the requested lines at once, e.g. so
the lines on a bus can be switched at the same time (or as close as
the kernel can manage).
If you would rather treat the lines separately then request them
separately.

AIUI, the purpose of gpiod_line_bulk_get_line() is to allow the user to
access the results of a bulk operation on a per-line basis, not to allow
them to perform per-line operations on the bulk.  The kernel API requires
that the operations for a bulk are on the bulk, and libgpiod v1 doesn't
keep track of the values of the other lines, so when you perform
operations on the single line returned by gpiod_line_bulk_get_line()
libgpiod assumes that it is a single line operation and only sets one
value - which the kernel sees as being for the first line in the bulk.
The remaining lines are zeroed.
Not sure if that is a bug or a feature, but that is my understanding.

libgpiod v2 [1](a WIP) changes this part of the API completely, and IIRC
does allow sets on individual lines in a bulk (now referred to as a line
request), by tracking the requested values for all lines in the bulk.
I'm sure Bart would consider any patches for v1 that you would care to
offer, though at this stage I would lean towards documentation
clarifications over code changes.

Cheers,
Kent.

[1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git -
next/libgpiod-2.0 branch



[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