diff --git a/src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs b/src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs index 0f60f54453..4b8441250a 100644 --- a/src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs +++ b/src/System.Device.Gpio.Tests/GpioControllerSoftwareTests.cs @@ -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() { @@ -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() { @@ -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())); - //// 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); - ////} - } diff --git a/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs b/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs index 8342b39d83..b59eae384c 100644 --- a/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs +++ b/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs @@ -37,59 +37,22 @@ public class GpioController : IDisposable /// Initializes a new instance of the class that will use the logical pin numbering scheme as default. /// public GpioController() -#pragma warning disable CS0612 // PinNumberingScheme is obsolete - : this(PinNumberingScheme.Logical) -#pragma warning restore CS0612 + : this(GetBestDriverForBoard()) { } /// - /// Initializes a new instance of the class that will use the specified numbering scheme and driver. + /// Initializes a new instance of the class that will use the specified driver. /// /// The driver that manages all of the pin operations for the controller. public GpioController(GpioDriver driver) { _driver = driver; -#pragma warning disable CS0612 // PinNumberingScheme is obsolete - NumberingScheme = PinNumberingScheme.Logical; -#pragma warning restore CS0612 - - _openPins = new ConcurrentDictionary(); - _gpioPins = new ConcurrentDictionary(); - } - - /// - /// Initializes a new instance of the class that will use the specified numbering scheme and driver. - /// - /// The numbering scheme used to represent pins provided by the controller. - /// The driver that manages all of the pin operations for the controller. - [Obsolete] - public GpioController(PinNumberingScheme numberingScheme, GpioDriver driver) - { - _driver = driver; - NumberingScheme = numberingScheme; _openPins = new ConcurrentDictionary(); _gpioPins = new ConcurrentDictionary(); } - /// - /// Initializes a new instance of the 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. - /// - /// The numbering scheme used to represent pins provided by the controller. - [Obsolete] - public GpioController(PinNumberingScheme numberingScheme) - : this(numberingScheme, GetBestDriverForBoard()) - { - } - - /// - /// The numbering scheme used to represent pins provided by the controller. - /// - [Obsolete] - public PinNumberingScheme NumberingScheme { get; } - /// /// The number of pins provided by the controller. /// @@ -120,9 +83,7 @@ private IEnumerable OpenPins /// The logical pin number in the controller's numbering scheme. 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; } /// diff --git a/src/System.Device.Gpio/System/Device/Gpio/PinNumberingScheme.cs b/src/System.Device.Gpio/System/Device/Gpio/PinNumberingScheme.cs deleted file mode 100644 index b46612884d..0000000000 --- a/src/System.Device.Gpio/System/Device/Gpio/PinNumberingScheme.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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 System.Device.Gpio; - -/// -/// Different numbering schemes supported by GPIO controllers and drivers. -/// -[Obsolete] -public enum PinNumberingScheme -{ - /// - /// The logical representation of the GPIOs. Refer to the microcontroller's datasheet to find this information. - /// - Logical, - - /// - /// The physical pin numbering that is usually accessible by the board headers. - /// - Board -} diff --git a/src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs b/src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs index 95b73a225f..5066315789 100644 --- a/src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs +++ b/src/devices/Arduino/samples/ApiChecker/ArduinoCompilerSampleMethods.cs @@ -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(); } diff --git a/src/devices/Ccs811/README.md b/src/devices/Ccs811/README.md index d6033b6493..a58ec7baa0 100644 --- a/src/devices/Ccs811/README.md +++ b/src/devices/Ccs811/README.md @@ -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); ``` diff --git a/src/devices/Dhtxx/README.md b/src/devices/Dhtxx/README.md index 1008da0f35..559d8e8bd8 100644 --- a/src/devices/Dhtxx/README.md +++ b/src/devices/Dhtxx/README.md @@ -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); ``` diff --git a/src/devices/Ft232H/README.md b/src/devices/Ft232H/README.md index a06e86ac39..b409988d91 100644 --- a/src/devices/Ft232H/README.md +++ b/src/devices/Ft232H/README.md @@ -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: diff --git a/src/devices/Ft4222/README.md b/src/devices/Ft4222/README.md index 93bb24b8ea..0f1a76ba49 100644 --- a/src/devices/Ft4222/README.md +++ b/src/devices/Ft4222/README.md @@ -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); diff --git a/src/devices/Gpio/Drivers/Rockchip/README.md b/src/devices/Gpio/Drivers/Rockchip/README.md index 9ab799344e..be0bb667a2 100644 --- a/src/devices/Gpio/Drivers/Rockchip/README.md +++ b/src/devices/Gpio/Drivers/Rockchip/README.md @@ -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); @@ -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); diff --git a/src/devices/Gpio/Drivers/Sunxi/README.md b/src/devices/Gpio/Drivers/Sunxi/README.md index 62f137d472..fa9649f504 100644 --- a/src/devices/Gpio/Drivers/Sunxi/README.md +++ b/src/devices/Gpio/Drivers/Sunxi/README.md @@ -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); @@ -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); diff --git a/src/devices/Gpio/README.md b/src/devices/Gpio/README.md index 2623ab96fa..5af2b9808f 100644 --- a/src/devices/Gpio/README.md +++ b/src/devices/Gpio/README.md @@ -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); diff --git a/src/devices/Gpio/samples/GpioSpeedBenchmark.cs b/src/devices/Gpio/samples/GpioSpeedBenchmark.cs index 09f13fcccd..f18702605a 100644 --- a/src/devices/Gpio/samples/GpioSpeedBenchmark.cs +++ b/src/devices/Gpio/samples/GpioSpeedBenchmark.cs @@ -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"); diff --git a/src/devices/Hcsr501/README.md b/src/devices/Hcsr501/README.md index 0201968797..314660bff8 100644 --- a/src/devices/Hcsr501/README.md +++ b/src/devices/Hcsr501/README.md @@ -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; diff --git a/src/devices/KeyMatrix/README.md b/src/devices/KeyMatrix/README.md index b7405206c1..4eea549e3b 100644 --- a/src/devices/KeyMatrix/README.md +++ b/src/devices/KeyMatrix/README.md @@ -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 outputs = new int[] { 26, 19, 13, 6 }; IEnumerable inputs = new int[] { 21, 20, 16, 12 }; KeyMatrix mk = new KeyMatrix(outputs, inputs, TimeSpan.FromMilliseconds(20), gpio, true); diff --git a/src/devices/Mcp23xxx/README.md b/src/devices/Mcp23xxx/README.md index 7a550b1950..da770dca6f 100644 --- a/src/devices/Mcp23xxx/README.md +++ b/src/devices/Mcp23xxx/README.md @@ -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); ``` diff --git a/src/devices/README.md b/src/devices/README.md index 28aad0ce00..75628a598d 100755 --- a/src/devices/README.md +++ b/src/devices/README.md @@ -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 diff --git a/src/devices/Tm16xx/samples/Program.cs b/src/devices/Tm16xx/samples/Program.cs index 2e71cd5201..7739a47609 100644 --- a/src/devices/Tm16xx/samples/Program.cs +++ b/src/devices/Tm16xx/samples/Program.cs @@ -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);