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
61 changes: 0 additions & 61 deletions src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,6 @@ public void GetPinMode()
Assert.Equal(PinMode.Output, ctrl.GetPinMode(1));
}

[Fact]
[Obsolete("Tests an obsolete feature")]
public void UsingBoardNumberingWorks()
{
// Our mock driver maps physical pin 2 to logical pin 1
_mockedGpioDriver.Setup(x => x.ConvertPinNumberToLogicalNumberingSchemeEx(2)).Returns(1);
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.SetPinModeEx(1, PinMode.Output));
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Output)).Returns(true);
_mockedGpioDriver.Setup(x => x.GetPinModeEx(1)).Returns(PinMode.Output);
_mockedGpioDriver.Setup(x => x.WriteEx(1, PinValue.High));
_mockedGpioDriver.Setup(x => x.ReadEx(1)).Returns(PinValue.High);
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
var ctrl = new GpioController(PinNumberingScheme.Board, _mockedGpioDriver.Object);
ctrl.OpenPin(2, PinMode.Output);
ctrl.Write(2, PinValue.High);
Assert.Equal(PinValue.High, ctrl.Read(2));
ctrl.ClosePin(2);
ctrl.Dispose();
}

[Fact]
public void UsingLogicalNumberingDisposesTheRightPin()
{
Expand All @@ -130,22 +109,6 @@ public void UsingLogicalNumberingDisposesTheRightPin()
ctrl.Dispose();
}

[Fact]
[Obsolete("Tests obsolete features")]
public void UsingBoardNumberingDisposesTheRightPin()
{
// Our mock driver maps physical pin 2 to logical pin 1
_mockedGpioDriver.Setup(x => x.ConvertPinNumberToLogicalNumberingSchemeEx(2)).Returns(1);
_mockedGpioDriver.Setup(x => x.OpenPinEx(1));
_mockedGpioDriver.Setup(x => x.SetPinModeEx(1, PinMode.Output));
_mockedGpioDriver.Setup(x => x.ClosePinEx(1));
_mockedGpioDriver.Setup(x => x.IsPinModeSupportedEx(1, PinMode.Output)).Returns(true);
var ctrl = new GpioController(PinNumberingScheme.Board, _mockedGpioDriver.Object);
ctrl.OpenPin(2, PinMode.Output);
// No close on the pin here, we want to check that the Controller's Dispose works correctly
ctrl.Dispose();
}

[Fact]
public void CallbackOnEventWorks()
{
Expand Down Expand Up @@ -279,28 +242,4 @@ public void WaitForEventSuccess()
Assert.Equal(PinEventTypes.Falling, result.EventTypes);
}

// TODO: This is still broken. See #974
////[Fact]
////public void UsingBoardNumberingForCallbackWorks()
////{
//// // Our mock driver maps physical pin 2 to logical pin 1
//// _mockedGpioDriver.Setup(x => x.ConvertPinNumberToLogicalNumberingSchemeEx(2)).Returns(1);
//// _mockedGpioDriver.Setup(x => x.OpenPinEx(1));
//// _mockedGpioDriver.Setup(x => x.AddCallbackForPinValueChangedEventEx(1,
//// PinEventTypes.Rising, It.IsAny<PinChangeEventHandler>()));
//// var ctrl = new GpioController(PinNumberingScheme.Board, _mockedGpioDriver.Object);
//// ctrl.OpenPin(2); // logical pin 1 on our test board
//// bool callbackSeen = false;
//// ctrl.RegisterCallbackForPinValueChangedEvent(2, PinEventTypes.Rising, (sender, args) =>
//// {
//// callbackSeen = true;
//// Assert.Equal(2, args.PinNumber);
//// Assert.Equal(PinEventTypes.Falling, args.ChangeType);
//// });

//// _mockedGpioDriver.Object.FireEventHandler(1, PinEventTypes.Falling);

//// Assert.True(callbackSeen);
////}

}
45 changes: 3 additions & 42 deletions src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,59 +37,22 @@ public class GpioController : IDisposable
/// Initializes a new instance of the <see cref="GpioController"/> class that will use the logical pin numbering scheme as default.
/// </summary>
public GpioController()
#pragma warning disable CS0612 // PinNumberingScheme is obsolete
: this(PinNumberingScheme.Logical)
#pragma warning restore CS0612
: this(GetBestDriverForBoard())
{
}

/// <summary>
/// Initializes a new instance of the <see cref="GpioController"/> class that will use the specified numbering scheme and driver.
/// Initializes a new instance of the <see cref="GpioController"/> class that will use the specified driver.
/// </summary>
/// <param name="driver">The driver that manages all of the pin operations for the controller.</param>
public GpioController(GpioDriver driver)
{
_driver = driver;

#pragma warning disable CS0612 // PinNumberingScheme is obsolete
NumberingScheme = PinNumberingScheme.Logical;
#pragma warning restore CS0612

_openPins = new ConcurrentDictionary<int, PinValue?>();
_gpioPins = new ConcurrentDictionary<int, GpioPin>();
}

/// <summary>
/// Initializes a new instance of the <see cref="GpioController"/> class that will use the specified numbering scheme and driver.
/// </summary>
/// <param name="numberingScheme">The numbering scheme used to represent pins provided by the controller.</param>
/// <param name="driver">The driver that manages all of the pin operations for the controller.</param>
[Obsolete]
public GpioController(PinNumberingScheme numberingScheme, GpioDriver driver)
{
_driver = driver;
NumberingScheme = numberingScheme;
_openPins = new ConcurrentDictionary<int, PinValue?>();
_gpioPins = new ConcurrentDictionary<int, GpioPin>();
}

/// <summary>
/// Initializes a new instance of the <see cref="GpioController"/> class that will use the specified numbering scheme.
/// The controller will default to use the driver that best applies given the platform the program is executing on.
/// </summary>
/// <param name="numberingScheme">The numbering scheme used to represent pins provided by the controller.</param>
[Obsolete]
public GpioController(PinNumberingScheme numberingScheme)
: this(numberingScheme, GetBestDriverForBoard())
{
}

/// <summary>
/// The numbering scheme used to represent pins provided by the controller.
/// </summary>
[Obsolete]
public PinNumberingScheme NumberingScheme { get; }

/// <summary>
/// The number of pins provided by the controller.
/// </summary>
Expand Down Expand Up @@ -120,9 +83,7 @@ private IEnumerable<GpioPin> OpenPins
/// <returns>The logical pin number in the controller's numbering scheme.</returns>
protected virtual int GetLogicalPinNumber(int pinNumber)
{
#pragma warning disable CS0612 // PinNumberingScheme is obsolete
return (NumberingScheme == PinNumberingScheme.Logical) ? pinNumber : _driver.ConvertPinNumberToLogicalNumberingScheme(pinNumber);
#pragma warning restore CS0612
return pinNumber;
}

/// <summary>
Expand Down
22 changes: 0 additions & 22 deletions src/System.Device.Gpio/System/Device/Gpio/PinNumberingScheme.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Loop()

public static void RunBlink(int pin, int delay)
{
var gpioController = new GpioController(PinNumberingScheme.Logical, new ArduinoNativeGpioDriver());
var gpioController = new GpioController(new ArduinoNativeGpioDriver());
SimpleLedBinding blink = new SimpleLedBinding(gpioController, pin, delay);
blink.Loop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ccs811/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ To create a device using an external chipset like FT4222 to offer GPIO and I2C s

```csharp
var ftdiI2C = new Ft4222I2c(new I2cConnectionSettings(0, Ccs811Sensor.I2cFirstAddress));
var gpioController = new GpioController(PinNumberingScheme.Board, new Ft4222Gpio());
var gpioController = new GpioController(new Ft4222Gpio());
ccs811 = new Ccs811Sensor(ftdiI2C, gpioController, 3, 2, -1, false);
```

Expand Down
2 changes: 1 addition & 1 deletion src/devices/Dhtxx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ See this [issue 1145](https://github.com/dotnet/iot/issues/1145). We're actively

```csharp
GpioDriver driver = new RaspberryPi3Driver();
var controller = new GpioController(PinNumberingScheme.Logical, driver);
var controller = new GpioController(driver);
// This uses pin 4 in the logical schema so pin 7 in the physical schema
var dht = new Dht11(4, gpioController: controller);
```
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ft232H/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Let's assume your device is the first one, you'll be able to create a GPIO Contr
```csharp
var ft232h = new Ft232HDevice(devices[0]);
var gpio = ft232h.CreateGpioDriver();
GpioController controller = new(PinNumberingScheme.Board, gpio);
GpioController controller = new(gpio);
```

> Important notes:
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ft4222/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The example below shows how to blink a led on GPIO2 and then read the value. It'

```csharp
const int Gpio2 = 2;
var gpioController = new GpioController(PinNumberingScheme.Board, new Ft4222Gpio());
var gpioController = new GpioController(new Ft4222Gpio());

// Opening GPIO2
gpioController.OpenPin(Gpio2);
Expand Down
4 changes: 2 additions & 2 deletions src/devices/Gpio/Drivers/Rockchip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This project contains a **full function(PULL-UP, PULL-DOWN)** generic GPIO drive
### Special GPIO driver: `OrangePi4Driver`

```C#
using GpioController gpio = new GpioController(PinNumberingScheme.Board, new OrangePi4Driver());
using GpioController gpio = new GpioController(new OrangePi4Driver());

gpio.OpenPin(7);
gpio.SetPinMode(7, PinMode.Output);
Expand All @@ -20,7 +20,7 @@ gpio.Write(7, PinValue.High);
```C#
// Beacuse this is a generic driver, the pin scheme can only be Logical.
// The base addresses can be found in the corresponding SoC datasheet.
using GpioController gpio = new GpioController(PinNumberingScheme.Logical, new RockchipDriver(gpioRegisterAddresses: new uint[] { 0xFF72_0000, 0xFF73_0000, 0xFF78_0000, 0xFF78_8000, 0xFF79_0000 });
using GpioController gpio = new GpioController(new RockchipDriver(gpioRegisterAddresses: new uint[] { 0xFF72_0000, 0xFF73_0000, 0xFF78_0000, 0xFF78_8000, 0xFF79_0000 });

// Convert pin number to logical scheme.
int pinNumber = RockchipDriver.MapPinNumber(gpioNumber: 4, port: 'C', portNumber: 6);
Expand Down
4 changes: 2 additions & 2 deletions src/devices/Gpio/Drivers/Sunxi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

```C#
// For Orange Pi Zero
using GpioController gpio = new GpioController(PinNumberingScheme.Board, new OrangePiZeroDriver());
using GpioController gpio = new GpioController(new OrangePiZeroDriver());

// Open the GPIO pin.
gpio.OpenPin(7);
Expand All @@ -23,7 +23,7 @@ PinValue value = gpio.Read(7);
```C#
// Beacuse this is a generic driver, the pin scheme can only be Logical.
// The base addresses can be found in the corresponding SoC datasheet.
using GpioController gpio = new GpioController(PinNumberingScheme.Logical, new SunxiDriver(cpuxPortBaseAddress: 0x01C20800, cpusPortBaseAddress: 0x01F02C00));
using GpioController gpio = new GpioController(new SunxiDriver(cpuxPortBaseAddress: 0x01C20800, cpusPortBaseAddress: 0x01F02C00));

// Convert pin number to logical scheme.
int pinNumber = SunxiDriver.MapPinNumber(portController: 'A', port: 10);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Gpio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int pin = 7;

Console.WriteLine($"Let's blink an on-board LED!");

using GpioController controller = new GpioController(PinNumberingScheme.Board, new OrangePiZeroDriver());
using GpioController controller = new GpioController(new OrangePiZeroDriver());
using BoardLed led = new BoardLed("orangepi:red:status");

controller.OpenPin(pin, PinMode.InputPullUp);
Expand Down
6 changes: 3 additions & 3 deletions src/devices/Gpio/samples/GpioSpeedBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ static void Main(string[] args)
switch (key)
{
case "1":
controller = new GpioController(PinNumberingScheme.Logical, new SysFsDriver());
controller = new GpioController(new SysFsDriver());
break;
case "2":
controller = new GpioController(PinNumberingScheme.Logical, new LibGpiodDriver());
controller = new GpioController(new LibGpiodDriver());
break;
case "3":
controller = new GpioController(PinNumberingScheme.Logical, new OrangePiZeroDriver());
controller = new GpioController(new OrangePiZeroDriver());
break;
default:
Console.WriteLine("Exit");
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Hcsr501/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ HC-SR501 is used to detect motion based on the infrared heat in the surrounding
## Usage

```C#
using(Hcsr501 sensor = new Hcsr501(hcsr501Pin, PinNumberingScheme.Logical))
using(Hcsr501 sensor = new Hcsr501(hcsr501Pin))
{
// detect motion
bool isDetected = sensor.IsMotionDetected;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/KeyMatrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ You can use as well any GpioController like the MCP23017 in the following exampl
var settings = new System.Device.I2c.I2cConnectionSettings(1, 0x20);
var i2cDevice = System.Device.I2c.I2cDevice.Create(settings);
var mcp23017 = new Iot.Device.Mcp23xxx.Mcp23017(i2cDevice);
GpioController gpio = new GpioController(PinNumberingScheme.Logical, mcp23017);
GpioController gpio = new GpioController(mcp23017);
IEnumerable<int> outputs = new int[] { 26, 19, 13, 6 };
IEnumerable<int> inputs = new int[] { 21, 20, 16, 12 };
KeyMatrix mk = new KeyMatrix(outputs, inputs, TimeSpan.FromMilliseconds(20), gpio, true);
Expand Down
4 changes: 2 additions & 2 deletions src/devices/Mcp23xxx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ for you:

```csharp
// Gpio controller from parent device (eg. Raspberry Pi)
_gpioController = new GpioController(PinNumberingScheme.Logical);
_gpioController = new GpioController();
_i2c = I2cDevice.Create(new I2cConnectionSettings(1, 0x21));
// The "InterruptA" line of the Mcp23017 is connected to GPIO input 11 of the Raspi
_device = new Mcp23017(_i2c, -1, 11, -1, _gpioController, false);
GpioController theDeviceController = new GpioController(PinNumberingScheme.Logical, _device);
GpioController theDeviceController = new GpioController(_device);
theDeviceController.OpenPin(1, PinMode.Input);
theDeviceController.RegisterCallbackForPinValueChangedEvent(1, PinEventTypes.Rising, Callback);
```
Expand Down
4 changes: 2 additions & 2 deletions src/devices/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,10 @@ private GpioController _controller;
private bool _shouldDispose;
private int _pinToUse;

public MyBinding(int pinToUse, GpioController controller = null, PinNumberingScheme pinNumberingScheme = PinNumberingScheme.Logical, bool shouldDispose = true)
public MyBinding(int pinToUse, GpioController controller = null, bool shouldDispose = true)
{
_shouldDispose = gpioController is null || shouldDispose;
_controller = gpioController ?? new GpioController(pinNumberingScheme);
_controller = gpioController ?? new GpioController();
_pinToUse = pinToUse;
_controller.OpenPin(_pinToUse);
// Initialize the rest of initialization
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Tm16xx/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void Main(string[] args)
// Create an instance of TM1637, using Gpio 23 for clock and 24 for IO.
using (Tm1637 tm1637 = new Tm1637(23, 24))
{
// When creating the instance without GpioController provided, a new instance of GpioController is created using PinNumberingScheme.Logical from default constructor. The instance of GpioController is disposed with the instance of Tm16xx.
// When creating the instance without GpioController provided, a new instance of GpioController is created using the default constructor. The instance of GpioController is disposed with the instance of Tm16xx.
// Provides an instance of GpioController when constructing Tm16xx instance when specified factory of GpioController is required or for reusing. The instance of GpioContoller provided is not disposed with the instance of Tm16xx.
// Some board need a delay for self initializing.
Thread.Sleep(100);
Expand Down
Loading