dotnet / dotnet/iot

Take advantage of libgpiod get/set multiple

Open
#1,097 4 comments 1 reaction 0 assignees View on GitHub
api-suggestion help wanted Priority:2
Dominant language
C#
Stars
2.4k
Forks
630
Avg merge
11d 3h
Merged PRs (30d)
2

Description

**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.

https://github.com/dotnet/iot/blob/00f9da195e6c3bb296450ab88303e031ad55aff8/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs#L331-L354

**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.

```csharp
internal virtual void Write(ReadOnlySpan pinValuePairs)
{
//...
}

internal virtual void Read(Span pinValuePairs)
{
//...
}
```

Then `LibGpiodDriver` can override these methods with calls to the appropriate functions.
- [gpiod_ctxless_get_value_multiple](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h#n137)
- [gpiod_ctxless_set_value](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/include/gpiod.h#n177)

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.