From 6cc8964d9db75be65d7e0e761e5c623acd948bbd Mon Sep 17 00:00:00 2001 From: Jacob Guilbeau Date: Tue, 2 Aug 2022 16:33:48 -0700 Subject: [PATCH 1/2] Further support GPIO lazy loading Furthered the support for GPIO lazy loading by changing references to the internal object to use the lazy loader property instead ensuring proper GPIO instantiation. --- AtomCommon/AtomBase.cs | 2 +- nanoFramework.Fire/Fire.cs | 10 ++++------ nanoFramework.M5Core/M5Core.cs | 10 ++++------ nanoFramework.M5StickCommon/M5StickCBase.cs | 9 ++++++--- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/AtomCommon/AtomBase.cs b/AtomCommon/AtomBase.cs index a193e969..fe855f7b 100644 --- a/AtomCommon/AtomBase.cs +++ b/AtomCommon/AtomBase.cs @@ -43,7 +43,7 @@ public static GpioButton Button { if (_button == null) { - _button = new(39, _gpio, false); + _button = new(39, GpioController, false); } return _button; diff --git a/nanoFramework.Fire/Fire.cs b/nanoFramework.Fire/Fire.cs index 8e67d69a..b956b933 100644 --- a/nanoFramework.Fire/Fire.cs +++ b/nanoFramework.Fire/Fire.cs @@ -53,7 +53,7 @@ public static GpioButton ButtonLeft { if (_left == null) { - _left = new(39, _gpio, false); + _left = new(39, GpioController, false); } return _left; @@ -69,7 +69,7 @@ public static GpioButton ButtonCenter { if (_center == null) { - _center = new(38, _gpio, false); + _center = new(38, GpioController, false); } return _center; @@ -85,7 +85,7 @@ public static GpioButton ButtonRight { if (_right == null) { - _right = new(37, _gpio, false); + _right = new(37, GpioController, false); } return _right; @@ -166,9 +166,7 @@ static Fire() _power.ChargingCutOffCurrent = ChargingCutOffCurrent.C500mA; _power.ChargingCuttOffVoltage = ChargingCutOffVoltage.V4_2; - // Setup buttons - _gpio = new(); - + // Config GPIOs for SPI (screen and SD Card) Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI); Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO); diff --git a/nanoFramework.M5Core/M5Core.cs b/nanoFramework.M5Core/M5Core.cs index 7fdbebc3..4cd3f1e9 100644 --- a/nanoFramework.M5Core/M5Core.cs +++ b/nanoFramework.M5Core/M5Core.cs @@ -34,7 +34,7 @@ public static GpioButton ButtonLeft { if (_left == null) { - _left = new(39, _gpio, false); + _left = new(39, GpioController, false); } return _left; @@ -50,7 +50,7 @@ public static GpioButton ButtonCenter { if (_center == null) { - _center = new(38, _gpio, false); + _center = new(38, GpioController, false); } return _center; @@ -66,7 +66,7 @@ public static GpioButton ButtonRight { if (_right == null) { - _right = new(37, _gpio, false); + _right = new(37, GpioController, false); } return _right; @@ -151,9 +151,7 @@ static M5Core() _power.ChargingCutOffCurrent = ChargingCutOffCurrent.C500mA; _power.ChargingCuttOffVoltage = ChargingCutOffVoltage.V4_2; - // Setup buttons - _gpio = new(); - + // Config GPIOs for SPI (screen and SD Card) Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI); Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISO); diff --git a/nanoFramework.M5StickCommon/M5StickCBase.cs b/nanoFramework.M5StickCommon/M5StickCBase.cs index 8b76037f..c8ec6349 100644 --- a/nanoFramework.M5StickCommon/M5StickCBase.cs +++ b/nanoFramework.M5StickCommon/M5StickCBase.cs @@ -31,7 +31,10 @@ public static partial class M5StickCPlus private static Axp192 _power; private static GpioButton _buttonM5; private static GpioButton _buttonRight; + + // lazy loaded - please reference class property GPIOController to ensure instantiation private static GpioController _gpio; + private static GpioPin _led; private static TransmitterChannel _irLed; private static Mpu6886AccelerometerGyroscope _accelerometer; @@ -52,7 +55,7 @@ public static GpioButton ButtonM5 { if (_buttonM5 == null) { - _buttonM5 = new(37, _gpio, false); + _buttonM5 = new(37, GpioController, false); } return _buttonM5; @@ -68,7 +71,7 @@ public static GpioButton ButtonRight { if (_buttonRight == null) { - _buttonRight = new(39, _gpio, false); + _buttonRight = new(39, GpioController, false); } return _buttonRight; @@ -84,7 +87,7 @@ public static GpioPin Led { if (_led == null) { - _led = _gpio.OpenPin(10, PinMode.Output); + _led = GpioController.OpenPin(10, PinMode.Output); } return _led; From 7d6f7a7402b0b8e6f07e48970a04316892db4aab Mon Sep 17 00:00:00 2001 From: Jacob Guilbeau Date: Tue, 2 Aug 2022 16:48:04 -0700 Subject: [PATCH 2/2] Remove unneeded comment Remove unneeded comment --- nanoFramework.M5StickCommon/M5StickCBase.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/nanoFramework.M5StickCommon/M5StickCBase.cs b/nanoFramework.M5StickCommon/M5StickCBase.cs index c8ec6349..005b2134 100644 --- a/nanoFramework.M5StickCommon/M5StickCBase.cs +++ b/nanoFramework.M5StickCommon/M5StickCBase.cs @@ -31,10 +31,7 @@ public static partial class M5StickCPlus private static Axp192 _power; private static GpioButton _buttonM5; private static GpioButton _buttonRight; - - // lazy loaded - please reference class property GPIOController to ensure instantiation private static GpioController _gpio; - private static GpioPin _led; private static TransmitterChannel _irLed; private static Mpu6886AccelerometerGyroscope _accelerometer;