未验证 提交 7d9d4079 编写于 作者: K Krzysztof Wicher 提交者: GitHub

Make System.Device.Gpio work on Mono (#1095)

上级 94424fc7
......@@ -41,7 +41,7 @@ namespace System.Device.Gpio.Drivers
}
else
{
_internalDriver = new Windows10Driver();
_internalDriver = CreateWindows10GpioDriver();
_setSetRegister = (value) => throw new PlatformNotSupportedException();
_setClearRegister = (value) => throw new PlatformNotSupportedException();
_getSetRegister = () => throw new PlatformNotSupportedException();
......@@ -49,6 +49,16 @@ namespace System.Device.Gpio.Drivers
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static GpioDriver CreateWindows10GpioDriver()
{
// This wrapper is needed to prevent Mono from loading Windows10Driver
// which causes all fields to be loaded - one of such fields is WinRT type which does not
// exist on Linux which causes TypeLoadException.
// Using NoInlining and no explicit type prevents this from happening.
return new Windows10Driver();
}
/// <inheritdoc/>
protected internal override int PinCount => 28;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
namespace System.Device.I2c
{
/// <summary>
......@@ -67,7 +69,7 @@ namespace System.Device.I2c
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return new Windows10I2cDevice(settings);
return CreateWindows10I2cDevice(settings);
}
else
{
......@@ -75,6 +77,16 @@ namespace System.Device.I2c
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static I2cDevice CreateWindows10I2cDevice(I2cConnectionSettings settings)
{
// This wrapper is needed to prevent Mono from loading Windows10I2cDevice
// which causes all fields to be loaded - one of such fields is WinRT type which does not
// exist on Linux which causes TypeLoadException.
// Using NoInlining and no explicit type prevents this from happening.
return new Windows10I2cDevice(settings);
}
/// <inheritdoc cref="IDisposable.Dispose"/>
public void Dispose()
{
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
namespace System.Device.Pwm
{
/// <summary>
......@@ -61,7 +63,7 @@ namespace System.Device.Pwm
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return new Channels.Windows10PwmChannel(
return CreateWindows10PwmChannel(
chip,
channel,
frequency,
......@@ -76,5 +78,19 @@ namespace System.Device.Pwm
dutyCyclePercentage);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static PwmChannel CreateWindows10PwmChannel(int chip, int channel, int frequency, double dutyCyclePercentage)
{
// This wrapper is needed to prevent Mono from loading Windows10PwmChannel
// which causes all fields to be loaded - one of such fields is WinRT type which does not
// exist on Linux which causes TypeLoadException.
// Using NoInlining and no explicit type prevents this from happening.
return new Channels.Windows10PwmChannel(
chip,
channel,
frequency,
dutyCyclePercentage);
}
}
}
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
namespace System.Device.Spi
{
/// <summary>
......@@ -60,7 +62,7 @@ namespace System.Device.Spi
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
return new Windows10SpiDevice(settings);
return CreateWindows10SpiDevice(settings);
}
else
{
......@@ -68,6 +70,16 @@ namespace System.Device.Spi
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static SpiDevice CreateWindows10SpiDevice(SpiConnectionSettings settings)
{
// This wrapper is needed to prevent Mono from loading Windows10SpiDevice
// which causes all fields to be loaded - one of such fields is WinRT type which does not
// exist on Linux which causes TypeLoadException.
// Using NoInlining and no explicit type prevents this from happening.
return new Windows10SpiDevice(settings);
}
/// <inheritdoc cref="IDisposable.Dispose"/>
public void Dispose()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册