Skip to content

Commit

Permalink
[Peripheral] Gpio callback return pin value from structure. (Samsung#…
Browse files Browse the repository at this point in the history
…2798)

Change implementation so interrupted callback reads pin value from
structure rather than invoking Read() method.

Signed-off-by: Ernest Borowski <[email protected]>

Co-authored-by: WonYoung Choi <[email protected]>
  • Loading branch information
xerrni and WonyoungChoi authored Apr 28, 2021
1 parent 589e8ae commit 22f535d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion internals/src/Tizen.Peripheral/Interop/Gpio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public enum EdgeType
Falling,
Both
}
[StructLayout(LayoutKind.Sequential)]
public struct callbackInfo
{
public int vermagic;
public int gpioPinValue;
// skip the rest fields in structure as we do not need it
}
[StructLayout(LayoutKind.Sequential)]
public struct PeripherialGpio
{
public int vermagic;
public callbackInfo cbInfo;
// skip the rest fields in structure as we do not need it
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void InterruptedEventCallback(IntPtr handle, ErrorCode error, IntPtr data);
Expand Down Expand Up @@ -67,4 +81,4 @@ public enum EdgeType
internal static extern ErrorCode UnsetInterruptedCb(IntPtr handle);
}
}
}
}
13 changes: 12 additions & 1 deletion internals/src/Tizen.Peripheral/Tizen.Peripheral/Gpio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,18 @@ private void SetIntteruptedCallback()

private void OnInterrupted(IntPtr handle, ErrorCode error, IntPtr data)
{
ValueChanged?.Invoke(this, new PinUpdatedEventArgs(PinNumber, Read()));
NativeGpio.PeripherialGpio pio = (NativeGpio.PeripherialGpio)
System.Runtime.InteropServices.Marshal.PtrToStructure(handle,
typeof(NativeGpio.PeripherialGpio));
// check magic values to verify capi structures integrity
if (pio.vermagic != 13712 || pio.cbInfo.vermagic != 14469)
{
Log.Error("Peripheral",
"Unable to parse gpio structure in callback - vermagic is wrong");
return;
}
ValueChanged?.Invoke(this, new PinUpdatedEventArgs(PinNumber, pio.cbInfo.gpioPinValue == 1 ?
GpioPinValue.High : GpioPinValue.Low));
}

/// <summary>
Expand Down

0 comments on commit 22f535d

Please sign in to comment.