drivers/adc: provide API to access reference voltage

Required for any real-world use of ADC_REF_INTERNAL.

Relates-to: issue #11922
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2019-07-29 09:35:33 -05:00 committed by Carles Cufí
commit 5a39bcae84
3 changed files with 20 additions and 0 deletions

View file

@ -274,6 +274,7 @@ static const struct adc_driver_api adc_nrfx_driver_api = {
#ifdef CONFIG_ADC_ASYNC
.read_async = adc_nrfx_read_async,
#endif
.ref_internal = 1200,
};
#ifdef CONFIG_ADC_0

View file

@ -406,6 +406,7 @@ static const struct adc_driver_api adc_nrfx_driver_api = {
#ifdef CONFIG_ADC_ASYNC
.read_async = adc_nrfx_read_async,
#endif
.ref_internal = 600,
};
#ifdef CONFIG_ADC_0

View file

@ -302,6 +302,7 @@ struct adc_driver_api {
#ifdef CONFIG_ADC_ASYNC
adc_api_read_async read_async;
#endif
u16_t ref_internal; /* mV */
};
/**
@ -394,6 +395,23 @@ static inline int z_impl_adc_read_async(struct device *dev,
}
#endif /* CONFIG_ADC_ASYNC */
/**
* @brief Get the internal reference voltage.
*
* Returns the voltage corresponding to @ref ADC_REF_INTERNAL,
* measured in millivolts.
*
* @return a positive value is the reference voltage value. Returns
* zero if reference voltage information is not available.
*/
static inline u16_t adc_ref_internal(struct device *dev)
{
const struct adc_driver_api *api =
(const struct adc_driver_api *)dev->driver_api;
return api->ref_internal;
}
#include <syscalls/adc.h>
/**