-
Notifications
You must be signed in to change notification settings - Fork 597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make LibGpiodDriver V2 driver public #2386
Conversation
src/System.Device.Gpio/Interop/Unix/libgpiod/V1/SafeChipHandle.cs
Outdated
Show resolved
Hide resolved
LibgpiodV1.gpiod_chip_iter_free(handle); | ||
// We can't close the chip here, as this would possibly result in it being freed twice, which causes a crash | ||
LibgpiodV1.gpiod_chip_iter_free_noclose(handle); | ||
handle = IntPtr.Zero; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/System.Device.Gpio/Interop/Unix/libgpiod/V1/SafeChipHandle.cs
Outdated
Show resolved
Hide resolved
public LibGpiodDriver(int gpioChip, LibGpiodDriverVersion driverVersion) | ||
private static bool s_isLibgpiodVersion1_5orHigher = IsLibgpiodVersion1_5orHigher(); | ||
|
||
private enum RequestFlag : ulong |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in the interop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only used here. And it's private, so no change necessary.
src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/V1/LibGpiodV1Driver.cs
Outdated
Show resolved
Hide resolved
src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/LibGpiodDriver.cs
Outdated
Show resolved
Hide resolved
src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/V1/LibGpiodV1Driver.cs
Outdated
Show resolved
Hide resolved
src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/V1/LibGpiodV1Driver.cs
Outdated
Show resolved
Hide resolved
/// <inheritdoc/> | ||
protected internal override int PinCount => GetDriver().PinCount; | ||
int numLines = LibgpiodV1.gpiod_chip_num_lines(chip); | ||
string name = Marshal.PtrToStringAnsi(LibgpiodV1.gpiod_chip_name(chip)) ?? string.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try using string marshalling attribute for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and for one below)
/// Returns the list of available chips. | ||
/// </summary> | ||
/// <returns>A list of available chips. Can be used to determine the chipNumber when calling the constructor</returns> | ||
public static IList<GpioChipInfo> GetAvailableChips() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need all of this API public? All of this sounds like implementation details that I'm n ot sure we have a valid use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you need these. There might be a reason to select a non-default chip for various reasons. Also, we now know that our automatic selection of the default chip can fail when the hardware/operating system changes, so this allows the user to make it work correctly for his board, regardless of our possibly flaky detection algorithm.
src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/V2/LibGpiodV2Driver.cs
Show resolved
Hide resolved
/// This can be used to determine the correct gpio chip for constructor calls to <see cref="LibGpiodDriver"/> | ||
/// </summary> | ||
/// <returns>A list of chips detected</returns> | ||
public static IList<GpioChipInfo> GetAvailableChips() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mark this as Experimental? Do we want 2 entries even though there is 1 chip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen in the issue #2366 gpiodetect
does the same and also (sometimes) reports the same chip twice. So I mimiked the behavior of the LibGpiod driver here.
@@ -398,14 +447,20 @@ public override ComponentInformation QueryComponentInformation() | |||
return self; | |||
} | |||
|
|||
/// <inheritdoc /> | |||
public override GpioChipInfo GetChipInfo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You called this MakeSnapshot in one place but GetChipInfo here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MakeSnapShot is part of the internal implementation of the V2 driver and has a different purpose. It's never exposed.
@@ -32,18 +34,39 @@ public static UnixDriver Create() | |||
} | |||
|
|||
UnixDriver? driver = null; | |||
|
|||
if (TryCreate(() => new LibGpiodDriver(0), out driver)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to pass in 0 here? shouldn't this be ()
and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider moving this logic to some other place. We shouldn't have detection logic all over the place that works differently each time.
I would consider obsoleting this, but we can discuss.
src/System.Device.Gpio/System/Device/Gpio/Drivers/SysFsDriver.cs
Outdated
Show resolved
Hide resolved
@@ -628,7 +627,7 @@ private void InitializeInterruptDriver() | |||
{ | |||
try | |||
{ | |||
_interruptDriver = new LibGpiodV1Driver(0); | |||
_interruptDriver = new LibGpiodDriver(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be ()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's more clear to keep it explicit here. This is for RPI3 and 4 only.
src/System.Device.Gpio/System/Device/Gpio/Drivers/LibGpiodV2Driver.cs
Outdated
Show resolved
Hide resolved
/azp run dotnet.iot |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run dotnet.iot |
Azure Pipelines successfully started running 1 pipeline(s). |
…lue is not known
Fixes: #2382
Fixes: #2366
Fixes: #2384