Skip to content
Permalink
Browse files

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>
  • Loading branch information...
pabigot authored and carlescufi committed Jul 29, 2019
1 parent 9f34d17 commit 5a39bcae843b2f5545f0660053f925273adbbdd0
Showing with 20 additions and 0 deletions.
  1. +1 −0 drivers/adc/adc_nrfx_adc.c
  2. +1 −0 drivers/adc/adc_nrfx_saadc.c
  3. +18 −0 include/drivers/adc.h
@@ -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
@@ -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
@@ -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>

/**

0 comments on commit 5a39bca

Please sign in to comment.
You can’t perform that action at this time.