-
Notifications
You must be signed in to change notification settings - Fork 596
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
base: main
Are you sure you want to change the base?
Conversation
Probably not the final idea yet
And fix SysFsDriver: Now also supports selecting the chip
This reverts commit c49a652. # Conflicts: # src/System.Device.Gpio/Interop/Unix/libgpiod/V2/Proxies/LibGpiodChipInfo.cs # src/System.Device.Gpio/System/Device/Gpio/Drivers/Libgpiod/LibGpiodDriverFactory.cs
…lue is not known
@@ -19,6 +19,7 @@ public SafeChipHandle() | |||
protected override bool ReleaseHandle() | |||
{ | |||
LibgpiodV1.gpiod_chip_close(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.
Where is this handle being set to something other than 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.
Rewritten to make this more clear. Using a handle as return type to a pinvoke call sets the value implicitly.
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
|
||
/// <inheritdoc/> | ||
protected internal override WaitForEventResult WaitForEvent(int pinNumber, PinEventTypes eventTypes, CancellationToken cancellationToken) | ||
[Experimental(DiagnosticIds.SDGPIO0001, UrlFormat = DiagnosticIds.UrlFormat)] // TODO: necessary? |
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, let's keep the diagnostic for now :)
/// <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
/// 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.
did we lock on the names here? We should be consistent
@@ -3,6 +3,7 @@ | |||
|
|||
using System.Device.Gpio.Drivers; | |||
using System.Diagnostics; | |||
using System.IO; |
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.
Ensure GpioChipInfo is part of QueryComponentInformation
Fixes: #2382
Fixes: #2366
Fixes: #2384