Skip to content

Commit aeb91c2

Browse files
committed
Updated default vref to be NAN. Made vref an optional constructor arg
1 parent 746f2f5 commit aeb91c2

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

drivers/AnalogIn.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "platform/SingletonPtr.h"
2626
#include "platform/PlatformMutex.h"
2727

28+
#include <cmath>
29+
2830
namespace mbed {
2931
/** \defgroup mbed-os-public Public API */
3032

@@ -71,14 +73,14 @@ class AnalogIn {
7173
*
7274
* @param pinmap reference to structure which holds static pinmap.
7375
*/
74-
AnalogIn(const PinMap &pinmap);
75-
AnalogIn(const PinMap &&) = delete; // prevent passing of temporary objects
76+
AnalogIn(const PinMap &pinmap, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF);
77+
AnalogIn(const PinMap &&, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF) = delete; // prevent passing of temporary objects
7678

7779
/** Create an AnalogIn, connected to the specified pin
7880
*
7981
* @param pin AnalogIn pin to connect to
8082
*/
81-
AnalogIn(PinName pin);
83+
AnalogIn(PinName pin, float vref = MBED_CONF_TARGET_DEFAULT_ADC_VREF);
8284

8385
/** Read the input voltage, represented as a float in the range [0.0, 1.0]
8486
*
@@ -161,7 +163,7 @@ class AnalogIn {
161163
analogin_t _adc;
162164
static SingletonPtr<PlatformMutex> _mutex;
163165

164-
float vref;
166+
float _vref;
165167

166168
#endif //!defined(DOXYGEN_ONLY)
167169

drivers/source/AnalogIn.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ namespace mbed {
2323

2424
SingletonPtr<PlatformMutex> AnalogIn::_mutex;
2525

26-
AnalogIn::AnalogIn(PinName pin) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF)
26+
27+
AnalogIn::AnalogIn(PinName pin, float vref) : _vref(vref)
2728
{
2829
lock();
2930
analogin_init(&_adc, pin);
3031
unlock();
3132
}
3233

33-
AnalogIn::AnalogIn(const PinMap &pinmap) : vref(MBED_CONF_TARGET_DEFAULT_ADC_VREF)
34+
AnalogIn::AnalogIn(const PinMap &pinmap, float vref) : _vref(vref)
3435
{
3536
lock();
3637
analogin_init_direct(&_adc, &pinmap);
3738
unlock();
3839
}
3940

40-
4141
float AnalogIn::read()
4242
{
4343
lock();
@@ -56,17 +56,17 @@ unsigned short AnalogIn::read_u16()
5656

5757
float AnalogIn::read_voltage()
5858
{
59-
return (this->read() * this->vref);
59+
return (this->read() * this->_vref);
6060
}
6161

6262
void AnalogIn::set_reference_voltage(float vref)
6363
{
64-
this->vref = vref;
64+
this->_vref = vref;
6565
}
6666

6767
float AnalogIn::get_reference_voltage(void)
6868
{
69-
return this->vref;
69+
return this->_vref;
7070
}
7171

7272
} // namespace mbed

targets/targets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
},
8484
"default-adc-vref": {
8585
"help": "Default reference voltage for ADC (float)",
86-
"value": "3.3f"
86+
"value": "NAN"
8787
}
8888
}
8989
},

0 commit comments

Comments
 (0)