AnalogInput.Dispose() does not cleanup native resources


In the Microsoft.SPOT.Hardware.AnalogInput class...
When an AnalogInput is created, its analog channel is enabled in the MCU.
When an AnalogInput is disposed, Port.ReservePin(false) is called to release the hold on GPIOs attached to analog channels. But there is no AnalogInput_DeactiveChannel native code method, and no code is called which can deactivate the analog channel.
A workaround for some analog channels is to check if they are enabled in the GPIO ReservePin native code method. But this only works for analog channels which share pins with GPIOs. For MCU pins which are pure AnalogInputs, there is no way to deactivate them.
Additionally we like to reference count the number of channels being used...so we can shut off the ADC when no more AnalogInputs exist. Since there is no native code cleanup for the analog channel, the ADC can never be turned off.
Could we please add a deactivate native method in the .NET MF 4.3 revision to AnalogInput, and call it from the Dispose(bool) function?
Thank you,
Secret Labs LLC


gus_ghielec wrote Aug 11, 2012 at 4:32 PM

Agree! I am not sure if we reported this yet but we have similar problem. HAL should have Analog_Uninitialize() to release all resources.

We are developing an application that needs to change specific pins from analog to digital and back digital to analog. This works fine on most processors but one of the processors SAM9RL64 (FEZ Hydra) has a specific register to switch the pins to analog, not the register to select the IO feature (COM/SPI). This means once the pin is analog, you can no longer make it digital even if analog was disposed. Even worse, there is no exceptions or errors, the pin will just not work!

The complete port is at https://ghiopensource.codeplex.com/

Please add a method to release analog resource as Chris suggested.


Gus Issa - GHI Electronics

lorenzte wrote Aug 13, 2012 at 5:07 PM

We will defintely take care of this for 4.3

wrote Nov 30, 2012 at 12:41 PM

wrote Dec 19, 2012 at 10:02 AM

wrote Feb 22, 2013 at 12:45 AM

wrote Jun 12, 2013 at 9:32 AM

wrote Jan 19, 2014 at 4:10 AM

wrote Mar 11, 2014 at 3:33 PM