Skip to content

Commit

Permalink
drivers/adc: provide API to access reference voltage
Browse files Browse the repository at this point in the history
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 Aug 1, 2019
1 parent 9f34d17 commit 5a39bca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/adc/adc_nrfx_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/adc/adc_nrfx_saadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions include/drivers/adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct adc_driver_api {
#ifdef CONFIG_ADC_ASYNC
adc_api_read_async read_async;
#endif
u16_t ref_internal; /* mV */
};

/**
Expand Down Expand Up @@ -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>

/**
Expand Down

0 comments on commit 5a39bca

Please sign in to comment.