Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/gpio-linux-libgpiod.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The following table shows which driver supports which library version
| V2 | 2.x |

NOTE: Due to a [breaking change in the values of enums in the libgpiod](
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/commit/?id=783ff2e3c70788cdd1c65cba9ee0398bda5ebcda), only libgpiod versions 1.1 and later can be expected to function reliably with the V1 driver.
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/commit/?id=783ff2e3c70788cdd1c65cba9ee0398bda5ebcda), only libgpiod versions 1.1 and later can be expected to function reliably with the V1 driver.
To check what libgpiod packages you have on a deb based system, use: ``` $apt show libgpiod* ```

## Choose LibGpiodDriver Version
Expand Down
12 changes: 3 additions & 9 deletions src/System.Device.Gpio.Tests/GpioControllerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,10 @@ void Callback(object sender, PinValueChangedEventArgs e)
[Fact]
public void AddCallbackRemoveAllCallbackTest()
{
using GpioDriver testDriver = GetTestDriver();
// Skipping the test for now when using the SysFsDriver or the RaspberryPi3Driver given that this test is flaky for those drivers.
// Issue tracking this problem is https://github.com/dotnet/iot/issues/629
if (testDriver is SysFsDriver || testDriver is RaspberryPi3Driver)
{
return;
}

RetryHelper.Execute(() =>
{
int risingEventOccurredCount = 0, fallingEventOccurredCount = 0;
using (GpioController controller = new GpioController(testDriver))
using (GpioController controller = new GpioController(GetTestDriver()))
{
controller.OpenPin(InputPin, PinMode.Input);
controller.OpenPin(OutputPin, PinMode.Output);
Expand Down Expand Up @@ -454,6 +446,7 @@ public void WaitForEventRisingEdgeTest()
using (GpioController controller = new GpioController(GetTestDriver()))
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(20));
controller.OpenPin(InputPin, PinMode.Input);
controller.OpenPin(OutputPin, PinMode.Output);
controller.Write(OutputPin, PinValue.Low);
Expand All @@ -479,6 +472,7 @@ public void WaitForEventFallingEdgeTest()
using (GpioController controller = new GpioController(GetTestDriver()))
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
tokenSource.CancelAfter(TimeSpan.FromSeconds(30));
controller.OpenPin(InputPin, PinMode.Input);
controller.OpenPin(OutputPin, PinMode.Output);
controller.Write(OutputPin, PinValue.Low);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Diagnostics;
using System.Linq;
using System.Diagnostics.CodeAnalysis;

using System.Globalization;
using LibgpiodV1 = Interop.LibgpiodV1;

namespace System.Device.Gpio.Drivers;
Expand Down Expand Up @@ -114,7 +114,6 @@ public static IList<GpioChipInfo> GetAvailableChips()
{
List<GpioChipInfo> result = new List<GpioChipInfo>();
var iterator = new SafeChipIteratorHandle(LibgpiodV1.gpiod_chip_iter_new());
int index = 0;
while (true)
{
SafeChipHandle chip = new SafeChipHandle(LibgpiodV1.gpiod_chip_iter_next_noclose(iterator));
Expand All @@ -129,8 +128,26 @@ public static IList<GpioChipInfo> GetAvailableChips()
if (!result.Any(x => x.Label == label && x.NumLines == numLines))
{
// The iterator may find duplicates, but we skip them here
result.Add(new GpioChipInfo(index, name, label, numLines));
index++;
// Need to find the number at the end of the name (e.g. 15 in gpiochip15)
int id = 0;
int numberOfDigitsAtEnd = 0;
for (var i = name.Length - 1; i >= 0; i--)
{
if (!char.IsDigit(name[i]))
{
break;
}

numberOfDigitsAtEnd++;
}

string theNumber = name[^numberOfDigitsAtEnd..];
if (!Int32.TryParse(theNumber, CultureInfo.InvariantCulture, out id))
{
id = 0;
}

result.Add(new GpioChipInfo(id, name, label, numLines));
}

chip.Dispose();
Expand Down
Loading