6
Vote

AnalogInput.Dispose() does not cleanup native resources

description

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,
 
Chris
Secret Labs LLC
http://www.netduino.com

comments

gus_ghielec wrote Aug 11, 2012 at 5: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.

Regards,

Gus Issa - GHI Electronics

lorenzte wrote Aug 13, 2012 at 6:07 PM

We will defintely take care of this for 4.3