Skip to content

Take advantage of libgpiod get/set multiple #1097

@rubberduck203

Description

@rubberduck203

Is your feature request related to a problem? Please describe.

One of the advantages of libgpiod over the sysfs gpio interface is the ability to read and write to multiple pins simultaneously.

The current implementation does not take advantage of this.
The GpioController just loops through the collection of pins.

/// <summary>
/// Write the given pins with the given values.
/// </summary>
/// <param name="pinValuePairs">The pin/value pairs to write.</param>
public void Write(ReadOnlySpan<PinValuePair> pinValuePairs)
{
for (int i = 0; i < pinValuePairs.Length; i++)
{
Write(pinValuePairs[i].PinNumber, pinValuePairs[i].PinValue);
}
}
/// <summary>
/// Read the given pins with the given pin numbers.
/// </summary>
/// <param name="pinValuePairs">The pin/value pairs to read.</param>
public void Read(Span<PinValuePair> pinValuePairs)
{
for (int i = 0; i < pinValuePairs.Length; i++)
{
int pin = pinValuePairs[i].PinNumber;
pinValuePairs[i] = new PinValuePair(pin, Read(pin));
}
}

Describe the ideal solution

Add two new virtual methods to GpioDriver for read/write multiple and move the logic from GpioController into them. e.g.

        internal virtual void Write(ReadOnlySpan<PinValuePair> pinValuePairs)
        {
             //...
        }

        internal virtual void Read(Span<PinValuePair> pinValuePairs)
        {
            //...
        }

Then LibGpiodDriver can override these methods with calls to the appropriate functions.

This allows the vast majority of drivers to continue functioning as they do today, while allowing us to take advantage of the simultaneous read/writes of libgpiod.
I believe this is a backward compatible change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:2Work that is important, but not critical for the releaseapi-suggestionEarly API idea and discussion, it is NOT ready for implementationhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions