From 8b37d595e06352663992d3cb1dfb9dc6843ca30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fagundes?= Date: Tue, 20 Sep 2022 12:28:28 +0100 Subject: [PATCH] Miscelaneous improvements (#2) --- nanoFramework.GiantGecko.Adc/AdcChannel.cs | 11 ++--- nanoFramework.GiantGecko.Adc/AdcController.cs | 6 +-- .../ReferenceVoltage.cs | 49 ++++++++++++++++--- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/nanoFramework.GiantGecko.Adc/AdcChannel.cs b/nanoFramework.GiantGecko.Adc/AdcChannel.cs index c6da97e..fbd790b 100644 --- a/nanoFramework.GiantGecko.Adc/AdcChannel.cs +++ b/nanoFramework.GiantGecko.Adc/AdcChannel.cs @@ -26,7 +26,6 @@ public class AdcChannel : AdcChannelBase, IDisposable [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)] private readonly int _channelNumber; private readonly AdcChannelConfiguration _adcChannelConfiguration; - private int _averageCount; #pragma warning restore IDE0052 // Remove unread private members /// @@ -71,9 +70,7 @@ public override int ReadValue() } // set average count to 1 for single sample - _averageCount = 1; - - return NativeReadValue(); + return NativeReadValue(1); } } @@ -88,9 +85,7 @@ public override int ReadValueAveraged(int count) throw new ObjectDisposedException(); } - _averageCount = count; - - return NativeReadValue(); + return NativeReadValue(count); } } @@ -138,7 +133,7 @@ public void Dispose() #region Native Calls [MethodImpl(MethodImplOptions.InternalCall)] - private extern int NativeReadValue(); + private extern int NativeReadValue(int count); [MethodImpl(MethodImplOptions.InternalCall)] private extern void NativeDisposeChannel(); diff --git a/nanoFramework.GiantGecko.Adc/AdcController.cs b/nanoFramework.GiantGecko.Adc/AdcController.cs index 35651d0..d580795 100644 --- a/nanoFramework.GiantGecko.Adc/AdcController.cs +++ b/nanoFramework.GiantGecko.Adc/AdcController.cs @@ -26,7 +26,7 @@ public class AdcController : AdcControllerBase private int _averageCount; private bool _continuousSamplingStarted; - private readonly AdcConfiguration _acdConfiguration; + private readonly AdcConfiguration _adcConfiguration; /// public override int ChannelCount @@ -49,7 +49,7 @@ public override SampleResolution[] SupportedResolutionsInBits /// /// Initialization configuration for . /// - public AdcConfiguration AcdConfiguration => _acdConfiguration; + public AdcConfiguration AcdConfiguration => _adcConfiguration; /// /// Gets an array with the last samples from an ongoing scan operation. @@ -101,7 +101,7 @@ public AdcController(AdcConfiguration acdInitialization) // check if this device is already opened if (_syncLock == null) { - _acdConfiguration = acdInitialization; + _adcConfiguration = acdInitialization; // call native init to allow HAL/PAL inits related with ADC hardware // this is also used to check if the requested ADC actually exists diff --git a/nanoFramework.GiantGecko.Adc/ReferenceVoltage.cs b/nanoFramework.GiantGecko.Adc/ReferenceVoltage.cs index 786aefa..e8a9bca 100644 --- a/nanoFramework.GiantGecko.Adc/ReferenceVoltage.cs +++ b/nanoFramework.GiantGecko.Adc/ReferenceVoltage.cs @@ -15,36 +15,71 @@ public enum ReferenceVoltage /// /// Internal 1.25 V reference. /// - Internal1_25V, + Internal1_25V = 0, /// /// Internal 2.5 V reference. /// - Internal2_5V, + Internal2_5V = 1, /// /// Buffered VDD. /// - BufferedVdd, + BufferedVdd = 2, /// /// Internal differential 5 V reference. /// - InternalDifferencial_5V, + InternalDifferencial_5V = 3, /// /// Single-ended external reference from pin 6. /// - SingleEndedExternalPin6, + SingleEndedExternalPin6 = 4, /// /// Differential external reference from pin 6 and 7. /// - DiffExternalPin6And7, + DiffExternalPin6And7 = 5, /// /// Unbuffered 2xVDD. /// - Unbuffered2Vdd, + Unbuffered2Vdd = 6, + + /// + /// Internal Bandgap reference. Custom VFS. + /// + InternalBandgap = 128, + + /// + /// Scaled AVDD: AVDD * VREFATT. + /// + ScaledAvdd = 129, + + /// + /// Scaled singled ended external reference from pin 6: VREFP * VREFATT. + /// + ScaledSingleEndedExternalPin6 = 130, + + /// + /// Raw single-ended external reference from pin 6. + /// + RawSingleEndedExternalPin6 = 131, + + /// + /// Special mode for entropy generation. + /// + EntropyGeneration = 132, + + /// + /// Scaled differential external Vref from pin 6 and 7: (VREFP - VREFN) * VREFATT. + /// + ScaledExternalPin6And7 = 133, + + /// + /// Raw differential external Vref from pin 6 and 7: VREFP - VREFN. + /// + RawExternalPin6And7 = 134 } }