Skip to content

Commit

Permalink
Add a generic GPIO driver for Allwinner SoCs and Orange Pi Zero/Lite/…
Browse files Browse the repository at this point in the history
…Lite2 pin map (#1130)

* add cs files

* add csproj

* resolve some feedbacks

* MSBuild fail

* derive from UnixDriver

* reference source files

* reference csproj

* resolve some issues

* using GpioController

* _interruptController is assigned a value in the constructor

* _interruptController nullable type

* nullable check

* SunxiDriver instead of inheriting SysFsDriver; add samples

* add readme; update samples

* add pin mode check; add static to _pinNumberConverter

* call initialize in constructor

* update README.md

* fix init problem; add some validates

* add Orange Pi Lite driver

* clean up; fix cpux-port initial problem; remove internal exceptions

* remove tiny delay

* private opi zero _pinNumberConverter

* add xml comment

* update README.md

* fix error SA1208

* fix copyright headers

* cleanup

* fix error SA1028

* fix CPUX port offset

* count the number of pins; update README.md

* fix typo

* Fix Interop duplication

Co-authored-by: Jose Perez Rodriguez <[email protected]>
  • Loading branch information
ZhangGaoxing and joperezr authored Feb 11, 2021
1 parent 03e3a24 commit fe22a80
Show file tree
Hide file tree
Showing 14 changed files with 748 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/devices/Gpio/Drivers/OrangePiLite2Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for the Orange Pi Lite 2.
/// </summary>
/// <remarks>
/// SoC: Allwinner H6 (sun50iw6p1)
/// </remarks>
public class OrangePiLite2Driver : Sun50iw6p1Driver
{
private static readonly int[] _pinNumberConverter = new int[]
{
-1, -1, -1, MapPinNumber('H', 6), -1, MapPinNumber('H', 5), -1, MapPinNumber('H', 4), MapPinNumber('D', 21), -1,
MapPinNumber('D', 22), MapPinNumber('D', 24), MapPinNumber('C', 9), MapPinNumber('D', 23), -1, MapPinNumber('D', 26),
MapPinNumber('C', 8), -1, MapPinNumber('C', 7), MapPinNumber('C', 2), -1, MapPinNumber('C', 3), MapPinNumber('D', 25),
MapPinNumber('C', 0), MapPinNumber('C', 5), -1, MapPinNumber('H', 3)
};

/// <inheritdoc/>
protected override int PinCount => 17;

/// <inheritdoc/>
protected override int ConvertPinNumberToLogicalNumberingScheme(int pinNumber)
{
int num = _pinNumberConverter[pinNumber];

return num != -1 ? num : throw new ArgumentException($"Board (header) pin {pinNumber} is not a GPIO pin on the {GetType().Name} device.", nameof(pinNumber));
}
}
}
37 changes: 37 additions & 0 deletions src/devices/Gpio/Drivers/OrangePiLiteDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for the Orange Pi Lite.
/// </summary>
/// <remarks>
/// SoC: Allwinner H3 (sun8iw7p1)
/// </remarks>
public class OrangePiLiteDriver : Sun8iw7p1Driver
{
private static readonly int[] _pinNumberConverter = new int[]
{
-1, -1, -1, MapPinNumber('A', 12), -1, MapPinNumber('A', 11), -1, MapPinNumber('A', 6), MapPinNumber('A', 13), -1,
MapPinNumber('A', 14), MapPinNumber('A', 1), MapPinNumber('D', 14), MapPinNumber('A', 0), -1, MapPinNumber('A', 3),
MapPinNumber('C', 4), -1, MapPinNumber('C', 7), MapPinNumber('C', 0), -1, MapPinNumber('C', 1), MapPinNumber('A', 2),
MapPinNumber('C', 2), MapPinNumber('C', 3), -1, MapPinNumber('A', 21), MapPinNumber('A', 19), MapPinNumber('A', 18),
MapPinNumber('A', 7), -1, MapPinNumber('A', 8), MapPinNumber('G', 8), MapPinNumber('A', 9), -1, MapPinNumber('A', 10),
MapPinNumber('G', 9), MapPinNumber('A', 20), MapPinNumber('G', 6), -1, MapPinNumber('G', 7)
};

/// <inheritdoc/>
protected override int PinCount => 28;

/// <inheritdoc/>
protected override int ConvertPinNumberToLogicalNumberingScheme(int pinNumber)
{
int num = _pinNumberConverter[pinNumber];

return num != -1 ? num : throw new ArgumentException($"Board (header) pin {pinNumber} is not a GPIO pin on the {GetType().Name} device.", nameof(pinNumber));
}
}
}
35 changes: 35 additions & 0 deletions src/devices/Gpio/Drivers/OrangePiZeroDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for the Orange Pi Zero.
/// </summary>
/// <remarks>
/// SoC: Allwinner H2+ (sun8iw7p1)
/// </remarks>
public class OrangePiZeroDriver : Sun8iw7p1Driver
{
private static readonly int[] _pinNumberConverter = new int[]
{
-1, -1, -1, MapPinNumber('A', 12), -1, MapPinNumber('A', 11), -1, MapPinNumber('A', 6), MapPinNumber('G', 6), -1,
MapPinNumber('G', 7), MapPinNumber('A', 1), MapPinNumber('A', 7), MapPinNumber('A', 0), -1, MapPinNumber('A', 3),
MapPinNumber('A', 19), -1, MapPinNumber('A', 18), MapPinNumber('A', 15), -1, MapPinNumber('A', 16), MapPinNumber('A', 2),
MapPinNumber('A', 14), MapPinNumber('A', 13), -1, MapPinNumber('A', 10)
};

/// <inheritdoc/>
protected override int PinCount => 17;

/// <inheritdoc/>
protected override int ConvertPinNumberToLogicalNumberingScheme(int pinNumber)
{
int num = _pinNumberConverter[pinNumber];

return num != -1 ? num : throw new ArgumentException($"Board (header) pin {pinNumber} is not a GPIO pin on the {GetType().Name} device.", nameof(pinNumber));
}
}
}
17 changes: 17 additions & 0 deletions src/devices/Gpio/Drivers/Sunxi/Sun50iw2p1Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for Allwinner H5.
/// </summary>
public class Sun50iw2p1Driver : SunxiDriver
{
/// <inheritdoc/>
protected override int CpuxPortBaseAddress => 0x01C20800;

/// <inheritdoc/>
protected override int CpusPortBaseAddress => 0x01F02C00;
}
}
17 changes: 17 additions & 0 deletions src/devices/Gpio/Drivers/Sunxi/Sun50iw6p1Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for Allwinner H6.
/// </summary>
public class Sun50iw6p1Driver : SunxiDriver
{
/// <inheritdoc/>
protected override int CpuxPortBaseAddress => 0x0300B000;

/// <inheritdoc/>
protected override int CpusPortBaseAddress => 0x07022000;
}
}
17 changes: 17 additions & 0 deletions src/devices/Gpio/Drivers/Sunxi/Sun8iw7p1Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Gpio.Drivers
{
/// <summary>
/// A GPIO driver for Allwinner H2+/H3.
/// </summary>
public class Sun8iw7p1Driver : SunxiDriver
{
/// <inheritdoc/>
protected override int CpuxPortBaseAddress => 0x01C20800;

/// <inheritdoc/>
protected override int CpusPortBaseAddress => 0x01F02C00;
}
}
Loading

0 comments on commit fe22a80

Please sign in to comment.