Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/devices/Gpio/Drivers/OrangePi5BDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 5B (26-pin header).
/// </summary>
/// <remarks>
/// SoC: Rockchip RK3588S
/// Pin mapping sourced from wiringOP (orangepi-xunlong/wiringOP).
/// </remarks>
public class OrangePi5BDriver : Rk3588Driver
{
// Mapping from physical header pin (index) to GPIO logical number.
// -1 indicates power, ground, or non-GPIO pins.
private static readonly int[] _physicalToGpio = new int[]
{
-1, // 0 (no pin)
-1, -1, // 1 = 3.3V, 2 = 5V
MapPinNumber(1, 'B', 7), -1, // 3 = GPIO1_B7 (47), 4 = 5V
MapPinNumber(1, 'B', 6), -1, // 5 = GPIO1_B6 (46), 6 = GND
MapPinNumber(1, 'C', 6), MapPinNumber(4, 'A', 3), // 7 = GPIO1_C6 (54), 8 = GPIO4_A3 (131)
-1, MapPinNumber(4, 'A', 4), // 9 = GND, 10 = GPIO4_A4 (132)
MapPinNumber(4, 'B', 2), MapPinNumber(0, 'D', 5), // 11 = GPIO4_B2 (138), 12 = GPIO0_D5 (29)
MapPinNumber(4, 'B', 3), -1, // 13 = GPIO4_B3 (139), 14 = GND
MapPinNumber(0, 'D', 4), MapPinNumber(1, 'D', 3), // 15 = GPIO0_D4 (28), 16 = GPIO1_D3 (59)
-1, MapPinNumber(1, 'D', 2), // 17 = 3.3V, 18 = GPIO1_D2 (58)
MapPinNumber(1, 'C', 1), -1, // 19 = GPIO1_C1 (49), 20 = GND
MapPinNumber(1, 'C', 0), -1, // 21 = GPIO1_C0 (48), 22 = NC
MapPinNumber(1, 'C', 2), MapPinNumber(1, 'C', 4), // 23 = GPIO1_C2 (50), 24 = GPIO1_C4 (52)
-1, MapPinNumber(1, 'A', 3), // 25 = GND, 26 = GPIO1_A3 (35)
};

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

/// <summary>
/// Maps a physical header pin number (1-26) to the driver's logical GPIO number.
/// </summary>
/// <param name="physicalPin">Physical pin number on the 26-pin header (1-26).</param>
/// <returns>Logical GPIO pin number for use with <see cref="System.Device.Gpio.GpioController"/>.</returns>
/// <exception cref="ArgumentException">The pin is not a GPIO pin (power, ground, etc.).</exception>
public static int MapPhysicalPinNumber(int physicalPin)
{
if (physicalPin <= 0 || physicalPin >= _physicalToGpio.Length)
{
throw new ArgumentException($"Physical pin {physicalPin} is out of range (1-26).", nameof(physicalPin));
}

int gpio = _physicalToGpio[physicalPin];
return gpio != -1
? gpio
: throw new ArgumentException($"Physical pin {physicalPin} is not a GPIO pin (power/ground).", nameof(physicalPin));
}
}
}
59 changes: 59 additions & 0 deletions src/devices/Gpio/Drivers/OrangePi5Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 5 (26-pin header).
/// </summary>
/// <remarks>
/// SoC: Rockchip RK3588S
/// Pin mapping sourced from wiringOP (orangepi-xunlong/wiringOP).
/// </remarks>
public class OrangePi5Driver : Rk3588Driver
{
// Mapping from physical header pin (index) to GPIO logical number.
// -1 indicates power, ground, or non-GPIO pins.
private static readonly int[] _physicalToGpio = new int[]
{
-1, // 0 (no pin)
-1, -1, // 1 = 3.3V, 2 = 5V
MapPinNumber(1, 'B', 7), -1, // 3 = GPIO1_B7 (47), 4 = 5V
MapPinNumber(1, 'B', 6), -1, // 5 = GPIO1_B6 (46), 6 = GND
MapPinNumber(1, 'C', 6), MapPinNumber(4, 'A', 3), // 7 = GPIO1_C6 (54), 8 = GPIO4_A3 (131)
-1, MapPinNumber(4, 'A', 4), // 9 = GND, 10 = GPIO4_A4 (132)
MapPinNumber(4, 'B', 2), MapPinNumber(0, 'D', 5), // 11 = GPIO4_B2 (138), 12 = GPIO0_D5 (29)
MapPinNumber(4, 'B', 3), -1, // 13 = GPIO4_B3 (139), 14 = GND
MapPinNumber(0, 'D', 4), MapPinNumber(1, 'D', 3), // 15 = GPIO0_D4 (28), 16 = GPIO1_D3 (59)
-1, MapPinNumber(1, 'D', 2), // 17 = 3.3V, 18 = GPIO1_D2 (58)
MapPinNumber(1, 'C', 1), -1, // 19 = GPIO1_C1 (49), 20 = GND
MapPinNumber(1, 'C', 0), MapPinNumber(2, 'D', 4), // 21 = GPIO1_C0 (48), 22 = GPIO2_D4 (92)
MapPinNumber(1, 'C', 2), MapPinNumber(1, 'C', 4), // 23 = GPIO1_C2 (50), 24 = GPIO1_C4 (52)
-1, MapPinNumber(1, 'A', 3), // 25 = GND, 26 = GPIO1_A3 (35)
};

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

/// <summary>
/// Maps a physical header pin number (1-26) to the driver's logical GPIO number.
/// </summary>
/// <param name="physicalPin">Physical pin number on the 26-pin header (1-26).</param>
/// <returns>Logical GPIO pin number for use with <see cref="System.Device.Gpio.GpioController"/>.</returns>
/// <exception cref="ArgumentException">The pin is not a GPIO pin (power, ground, etc.).</exception>
public static int MapPhysicalPinNumber(int physicalPin)
{
if (physicalPin <= 0 || physicalPin >= _physicalToGpio.Length)
{
throw new ArgumentException($"Physical pin {physicalPin} is out of range (1-26).", nameof(physicalPin));
}

int gpio = _physicalToGpio[physicalPin];
return gpio != -1
? gpio
: throw new ArgumentException($"Physical pin {physicalPin} is not a GPIO pin (power/ground).", nameof(physicalPin));
}
}
}
66 changes: 66 additions & 0 deletions src/devices/Gpio/Drivers/OrangePi5MaxDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 5 Max (40-pin header).
/// </summary>
/// <remarks>
/// SoC: Rockchip RK3588
/// Pin mapping sourced from wiringOP (orangepi-xunlong/wiringOP).
/// </remarks>
public class OrangePi5MaxDriver : Rk3588Driver
{
// Mapping from physical header pin (index) to GPIO logical number.
// -1 indicates power, ground, or non-GPIO pins.
private static readonly int[] _physicalToGpio = new int[]
{
-1, // 0 (no pin)
-1, -1, // 1 = 3.3V, 2 = 5V
MapPinNumber(0, 'C', 0), -1, // 3 = GPIO0_C0 (16), 4 = 5V
MapPinNumber(0, 'B', 7), -1, // 5 = GPIO0_B7 (15), 6 = GND
MapPinNumber(1, 'A', 7), MapPinNumber(0, 'B', 5), // 7 = GPIO1_A7 (39), 8 = GPIO0_B5 (13)
-1, MapPinNumber(0, 'B', 6), // 9 = GND, 10 = GPIO0_B6 (14)
MapPinNumber(1, 'A', 0), MapPinNumber(4, 'A', 6), // 11 = GPIO1_A0 (32), 12 = GPIO4_A6 (134)
MapPinNumber(1, 'A', 1), -1, // 13 = GPIO1_A1 (33), 14 = GND
MapPinNumber(1, 'A', 2), MapPinNumber(1, 'A', 3), // 15 = GPIO1_A2 (34), 16 = GPIO1_A3 (35)
-1, MapPinNumber(1, 'A', 4), // 17 = 3.3V, 18 = GPIO1_A4 (36)
MapPinNumber(1, 'B', 2), -1, // 19 = GPIO1_B2 (42), 20 = GND
MapPinNumber(1, 'B', 1), MapPinNumber(1, 'B', 0), // 21 = GPIO1_B1 (41), 22 = GPIO1_B0 (40)
MapPinNumber(1, 'B', 3), MapPinNumber(1, 'B', 4), // 23 = GPIO1_B3 (43), 24 = GPIO1_B4 (44)
-1, MapPinNumber(1, 'B', 5), // 25 = GND, 26 = GPIO1_B5 (45)
MapPinNumber(1, 'B', 7), MapPinNumber(1, 'B', 6), // 27 = GPIO1_B7 (47), 28 = GPIO1_B6 (46)
MapPinNumber(3, 'C', 1), -1, // 29 = GPIO3_C1 (113), 30 = GND
MapPinNumber(3, 'B', 5), MapPinNumber(1, 'D', 6), // 31 = GPIO3_B5 (109), 32 = GPIO1_D6 (62)
MapPinNumber(3, 'B', 6), -1, // 33 = GPIO3_B6 (110), 34 = GND
MapPinNumber(3, 'C', 2), MapPinNumber(1, 'D', 7), // 35 = GPIO3_C2 (114), 36 = GPIO1_D7 (63)
MapPinNumber(4, 'A', 7), MapPinNumber(3, 'C', 0), // 37 = GPIO4_A7 (135), 38 = GPIO3_C0 (112)
-1, MapPinNumber(3, 'B', 7), // 39 = GND, 40 = GPIO3_B7 (111)
};

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

/// <summary>
/// Maps a physical header pin number (1-40) to the driver's logical GPIO number.
/// </summary>
/// <param name="physicalPin">Physical pin number on the 40-pin header (1-40).</param>
/// <returns>Logical GPIO pin number for use with <see cref="System.Device.Gpio.GpioController"/>.</returns>
/// <exception cref="ArgumentException">The pin is not a GPIO pin (power, ground, etc.).</exception>
public static int MapPhysicalPinNumber(int physicalPin)
{
if (physicalPin <= 0 || physicalPin >= _physicalToGpio.Length)
{
throw new ArgumentException($"Physical pin {physicalPin} is out of range (1-40).", nameof(physicalPin));
}

int gpio = _physicalToGpio[physicalPin];
return gpio != -1
? gpio
: throw new ArgumentException($"Physical pin {physicalPin} is not a GPIO pin (power/ground).", nameof(physicalPin));
}
}
}
66 changes: 66 additions & 0 deletions src/devices/Gpio/Drivers/OrangePi5PlusDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 5 Plus (40-pin header).
/// </summary>
/// <remarks>
/// SoC: Rockchip RK3588
/// Pin mapping sourced from wiringOP (orangepi-xunlong/wiringOP).
/// </remarks>
public class OrangePi5PlusDriver : Rk3588Driver
{
// Mapping from physical header pin (index) to GPIO logical number.
// -1 indicates power, ground, or non-GPIO pins.
private static readonly int[] _physicalToGpio = new int[]
{
-1, // 0 (no pin)
-1, -1, // 1 = 3.3V, 2 = 5V
MapPinNumber(0, 'C', 0), -1, // 3 = GPIO0_C0 (16), 4 = 5V
MapPinNumber(0, 'B', 7), -1, // 5 = GPIO0_B7 (15), 6 = GND
MapPinNumber(1, 'D', 6), MapPinNumber(1, 'A', 1), // 7 = GPIO1_D6 (62), 8 = GPIO1_A1 (33)
-1, MapPinNumber(1, 'A', 0), // 9 = GND, 10 = GPIO1_A0 (32)
MapPinNumber(1, 'A', 4), MapPinNumber(3, 'A', 1), // 11 = GPIO1_A4 (36), 12 = GPIO3_A1 (97)
MapPinNumber(1, 'A', 7), -1, // 13 = GPIO1_A7 (39), 14 = GND
MapPinNumber(1, 'B', 0), MapPinNumber(3, 'B', 5), // 15 = GPIO1_B0 (40), 16 = GPIO3_B5 (109)
-1, MapPinNumber(3, 'B', 6), // 17 = 3.3V, 18 = GPIO3_B6 (110)
MapPinNumber(1, 'B', 2), -1, // 19 = GPIO1_B2 (42), 20 = GND
MapPinNumber(1, 'B', 1), MapPinNumber(1, 'A', 2), // 21 = GPIO1_B1 (41), 22 = GPIO1_A2 (34)
MapPinNumber(1, 'B', 3), MapPinNumber(1, 'B', 4), // 23 = GPIO1_B3 (43), 24 = GPIO1_B4 (44)
-1, MapPinNumber(1, 'B', 5), // 25 = GND, 26 = GPIO1_B5 (45)
MapPinNumber(1, 'B', 7), MapPinNumber(1, 'B', 6), // 27 = GPIO1_B7 (47), 28 = GPIO1_B6 (46)
MapPinNumber(1, 'D', 7), -1, // 29 = GPIO1_D7 (63), 30 = GND
MapPinNumber(3, 'A', 0), MapPinNumber(1, 'A', 3), // 31 = GPIO3_A0 (96), 32 = GPIO1_A3 (35)
MapPinNumber(3, 'C', 2), -1, // 33 = GPIO3_C2 (114), 34 = GND
MapPinNumber(3, 'A', 2), MapPinNumber(3, 'A', 5), // 35 = GPIO3_A2 (98), 36 = GPIO3_A5 (101)
MapPinNumber(3, 'C', 1), MapPinNumber(3, 'A', 4), // 37 = GPIO3_C1 (113), 38 = GPIO3_A4 (100)
-1, MapPinNumber(3, 'A', 3), // 39 = GND, 40 = GPIO3_A3 (99)
};

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

/// <summary>
/// Maps a physical header pin number (1-40) to the driver's logical GPIO number.
/// </summary>
/// <param name="physicalPin">Physical pin number on the 40-pin header (1-40).</param>
/// <returns>Logical GPIO pin number for use with <see cref="System.Device.Gpio.GpioController"/>.</returns>
/// <exception cref="ArgumentException">The pin is not a GPIO pin (power, ground, etc.).</exception>
public static int MapPhysicalPinNumber(int physicalPin)
{
if (physicalPin <= 0 || physicalPin >= _physicalToGpio.Length)
{
throw new ArgumentException($"Physical pin {physicalPin} is out of range (1-40).", nameof(physicalPin));
}

int gpio = _physicalToGpio[physicalPin];
return gpio != -1
? gpio
: throw new ArgumentException($"Physical pin {physicalPin} is not a GPIO pin (power/ground).", nameof(physicalPin));
}
}
}
66 changes: 66 additions & 0 deletions src/devices/Gpio/Drivers/OrangePi5ProDriver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 5 Pro (40-pin header).
/// </summary>
/// <remarks>
/// SoC: Rockchip RK3588S
/// Pin mapping sourced from wiringOP (orangepi-xunlong/wiringOP).
/// </remarks>
public class OrangePi5ProDriver : Rk3588Driver
{
// Mapping from physical header pin (index) to GPIO logical number.
// -1 indicates power, ground, or non-GPIO pins.
private static readonly int[] _physicalToGpio = new int[]
{
-1, // 0 (no pin)
-1, -1, // 1 = 3.3V, 2 = 5V
MapPinNumber(1, 'D', 3), -1, // 3 = GPIO1_D3 (59), 4 = 5V
MapPinNumber(1, 'D', 2), -1, // 5 = GPIO1_D2 (58), 6 = GND
MapPinNumber(1, 'B', 7), MapPinNumber(0, 'B', 5), // 7 = GPIO1_B7 (47), 8 = GPIO0_B5 (13)
-1, MapPinNumber(0, 'B', 6), // 9 = GND, 10 = GPIO0_B6 (14)
MapPinNumber(4, 'B', 2), MapPinNumber(1, 'A', 7), // 11 = GPIO4_B2 (138), 12 = GPIO1_A7 (39)
MapPinNumber(4, 'B', 3), -1, // 13 = GPIO4_B3 (139), 14 = GND
MapPinNumber(1, 'B', 6), MapPinNumber(1, 'A', 1), // 15 = GPIO1_B6 (46), 16 = GPIO1_A1 (33)
-1, MapPinNumber(1, 'A', 0), // 17 = 3.3V, 18 = GPIO1_A0 (32)
MapPinNumber(1, 'B', 2), -1, // 19 = GPIO1_B2 (42), 20 = GND
MapPinNumber(1, 'B', 1), MapPinNumber(1, 'B', 0), // 21 = GPIO1_B1 (41), 22 = GPIO1_B0 (40)
MapPinNumber(1, 'B', 3), MapPinNumber(1, 'B', 4), // 23 = GPIO1_B3 (43), 24 = GPIO1_B4 (44)
-1, MapPinNumber(1, 'B', 5), // 25 = GND, 26 = GPIO1_B5 (45)
MapPinNumber(1, 'A', 2), MapPinNumber(1, 'A', 3), // 27 = GPIO1_A2 (34), 28 = GPIO1_A3 (35)
MapPinNumber(1, 'A', 4), -1, // 29 = GPIO1_A4 (36), 30 = GND
MapPinNumber(1, 'A', 6), MapPinNumber(1, 'D', 6), // 31 = GPIO1_A6 (38), 32 = GPIO1_D6 (62)
MapPinNumber(1, 'D', 7), -1, // 33 = GPIO1_D7 (63), 34 = GND
MapPinNumber(4, 'A', 7), MapPinNumber(4, 'A', 3), // 35 = GPIO4_A7 (135), 36 = GPIO4_A3 (131)
MapPinNumber(4, 'A', 6), MapPinNumber(4, 'A', 4), // 37 = GPIO4_A6 (134), 38 = GPIO4_A4 (132)
-1, MapPinNumber(4, 'A', 5), // 39 = GND, 40 = GPIO4_A5 (133)
};

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

/// <summary>
/// Maps a physical header pin number (1-40) to the driver's logical GPIO number.
/// </summary>
/// <param name="physicalPin">Physical pin number on the 40-pin header (1-40).</param>
/// <returns>Logical GPIO pin number for use with <see cref="System.Device.Gpio.GpioController"/>.</returns>
/// <exception cref="ArgumentException">The pin is not a GPIO pin (power, ground, etc.).</exception>
public static int MapPhysicalPinNumber(int physicalPin)
{
if (physicalPin <= 0 || physicalPin >= _physicalToGpio.Length)
{
throw new ArgumentException($"Physical pin {physicalPin} is out of range (1-40).", nameof(physicalPin));
}

int gpio = _physicalToGpio[physicalPin];
return gpio != -1
? gpio
: throw new ArgumentException($"Physical pin {physicalPin} is not a GPIO pin (power/ground).", nameof(physicalPin));
}
Comment on lines +47 to +64
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

}
}
Loading
Loading