From 5a39bcae843b2f5545f0660053f925273adbbdd0 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Mon, 29 Jul 2019 09:35:33 -0500 Subject: [PATCH] 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 --- drivers/adc/adc_nrfx_adc.c | 1 + drivers/adc/adc_nrfx_saadc.c | 1 + include/drivers/adc.h | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/drivers/adc/adc_nrfx_adc.c b/drivers/adc/adc_nrfx_adc.c index de607a158a6..5fbed6d9aa8 100644 --- a/drivers/adc/adc_nrfx_adc.c +++ b/drivers/adc/adc_nrfx_adc.c @@ -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 diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index 8bda534e2ce..516771f2ce5 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -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 diff --git a/include/drivers/adc.h b/include/drivers/adc.h index 467ae82def7..1bb85220bdf 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -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 /**