mirror of https://github.com/ARMmbed/mbed-os.git
Updated default vref to be NAN. Made vref an optional constructor arg
parent
746f2f5fb5
commit
aeb91c2598
|
|
@ -25,6 +25,8 @@
|
|||
#include "platform/SingletonPtr.h"
|
||||
#include "platform/PlatformMutex.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mbed {
|
||||
/** \defgroup mbed-os-public Public API */
|
||||
|
||||
|
|
@ -71,14 +73,14 @@ public:
|
|||
*
|
||||
* @param pinmap reference to structure which holds static pinmap.
|
||||
*/
|
||||
AnalogIn(const PinMap &pinmap);
|
||||
AnalogIn(const PinMap &&) = delete; // prevent passing of temporary objects
|
||||
AnalogIn(const PinMap &pinmap, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF);
|
||||
AnalogIn(const PinMap &&, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF) = delete; // prevent passing of temporary objects
|
||||
|
||||
/** Create an AnalogIn, connected to the specified pin
|
||||
*
|
||||
* @param pin AnalogIn pin to connect to
|
||||
*/
|
||||
AnalogIn(PinName pin);
|
||||
AnalogIn(PinName pin, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF);
|
||||
|
||||
/** Read the input voltage, represented as a float in the range [0.0, 1.0]
|
||||
*
|
||||
|
|
@ -161,7 +163,7 @@ protected:
|
|||
analogin_t _adc;
|
||||
static SingletonPtr<PlatformMutex> _mutex;
|
||||
|
||||
float vref;
|
||||
float _vref;
|
||||
|
||||
#endif //!defined(DOXYGEN_ONLY)
|
||||
|
||||
|
|
|
|||
|
|
@ -23,21 +23,21 @@ namespace mbed {
|
|||
|
||||
SingletonPtr<PlatformMutex> AnalogIn::_mutex;
|
||||
|
||||
AnalogIn::AnalogIn(PinName pin) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF)
|
||||
|
||||
AnalogIn::AnalogIn(PinName pin, float vref) : _vref(vref)
|
||||
{
|
||||
lock();
|
||||
analogin_init(&_adc, pin);
|
||||
unlock();
|
||||
}
|
||||
|
||||
AnalogIn::AnalogIn(const PinMap &pinmap) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF)
|
||||
AnalogIn::AnalogIn(const PinMap &pinmap, float vref) : _vref(vref)
|
||||
{
|
||||
lock();
|
||||
analogin_init_direct(&_adc, &pinmap);
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
float AnalogIn::read()
|
||||
{
|
||||
lock();
|
||||
|
|
@ -56,17 +56,17 @@ unsigned short AnalogIn::read_u16()
|
|||
|
||||
float AnalogIn::read_voltage()
|
||||
{
|
||||
return (this->read() * this->vref);
|
||||
return (this->read() * this->_vref);
|
||||
}
|
||||
|
||||
void AnalogIn::set_reference_voltage(float vref)
|
||||
{
|
||||
this->vref = vref;
|
||||
this->_vref = vref;
|
||||
}
|
||||
|
||||
float AnalogIn::get_reference_voltage(void)
|
||||
{
|
||||
return this->vref;
|
||||
return this->_vref;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
},
|
||||
"default-adc-vref": {
|
||||
"help": "Default reference voltage for ADC (float)",
|
||||
"value": "3.3f"
|
||||
"value": "NAN"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue