Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace System.Device.Gpio.Drivers;

/// <summary>
/// A GPIO driver for the Raspberry Pi 3 or 4, running Raspbian (or, with some limitations, ubuntu)
/// A GPIO driver for the Raspberry Pi 3 or 4, running Raspbian or Raspberry Pi OS (or, with some limitations, ubuntu)
/// </summary>
public class RaspberryPi3Driver : GpioDriver
{
Expand Down
37 changes: 32 additions & 5 deletions src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class GpioController : IDisposable
private const string BaseBoardProductRegistryValue = @"SYSTEM\HardwareConfig\Current\BaseBoardProduct";
private const string RaspberryPi2Product = "Raspberry Pi 2";
private const string RaspberryPi3Product = "Raspberry Pi 3";
private const string RaspberryPi5Product = "Raspberry Pi 5";

private const string HummingBoardProduct = "HummingBoard-Edge";
private const string HummingBoardHardware = @"Freescale i.MX6 Quad/DualLite (Device Tree)";
Expand Down Expand Up @@ -469,14 +470,40 @@ private static GpioDriver GetBestDriverForBoard()
/// <returns>A driver that works with the board the program is executing on.</returns>
private static GpioDriver GetBestDriverForBoardOnLinux()
{
RaspberryPi3LinuxDriver? internalDriver = RaspberryPi3Driver.CreateInternalRaspberryPi3LinuxDriver(out _);
var boardInfo = RaspberryBoardInfo.LoadBoardInfo();

if (internalDriver is object)
switch (boardInfo.BoardModel)
{
return new RaspberryPi3Driver(internalDriver);
}
case RaspberryBoardInfo.Model.RaspberryPi3B:
case RaspberryBoardInfo.Model.RaspberryPi3APlus:
case RaspberryBoardInfo.Model.RaspberryPi3BPlus:
case RaspberryBoardInfo.Model.RaspberryPiZeroW:
case RaspberryBoardInfo.Model.RaspberryPiZero2W:
case RaspberryBoardInfo.Model.RaspberryPi4:
case RaspberryBoardInfo.Model.RaspberryPi400:
case RaspberryBoardInfo.Model.RaspberryPiComputeModule4:
case RaspberryBoardInfo.Model.RaspberryPiComputeModule3:

RaspberryPi3LinuxDriver? internalDriver = RaspberryPi3Driver.CreateInternalRaspberryPi3LinuxDriver(out _);

if (internalDriver is object)
{
return new RaspberryPi3Driver(internalDriver);
}

return UnixDriver.Create();

return UnixDriver.Create();
case RaspberryBoardInfo.Model.RaspberryPi5:

// For now, for Raspberry Pi 5, we'll use the LibGpiodDriver.
// We need to create a new driver for the Raspberry Pi 5,
// because the Raspberry Pi 5 uses an entirely different GPIO controller (RP1)
return new LibGpiodDriver(4);

default:

return UnixDriver.Create();
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public enum Model
/// Compute module 4.
/// </summary>
RaspberryPiComputeModule4,

/// <summary>
/// Pi 5 Model B+
/// </summary>
RaspberryPi5,
}

#region Fields
Expand Down Expand Up @@ -166,6 +171,7 @@ public Model BoardModel
0x3111 or 0x3112 or 0x3114 or 0x3115 => Model.RaspberryPi4,
0x3140 or 0x3141 => Model.RaspberryPiComputeModule4,
0x3130 or 0x3131 => Model.RaspberryPi400,
0x4170 => Model.RaspberryPi5,
_ => Model.Unknown,
};

Expand Down