diff --git a/drivers/adc/adc_nrfx_adc.c b/drivers/adc/adc_nrfx_adc.c index 9731c0f88ff..794405478b2 100644 --- a/drivers/adc/adc_nrfx_adc.c +++ b/drivers/adc/adc_nrfx_adc.c @@ -7,6 +7,7 @@ #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" #include +#include #define LOG_LEVEL CONFIG_ADC_LOG_LEVEL #include @@ -14,6 +15,17 @@ LOG_MODULE_REGISTER(adc_nrfx_adc); #define DT_DRV_COMPAT nordic_nrf_adc +/* Ensure that definitions in nrf-adc.h match MDK. */ +BUILD_ASSERT((NRF_ADC_AIN0 == NRF_ADC_CONFIG_INPUT_0) && + (NRF_ADC_AIN1 == NRF_ADC_CONFIG_INPUT_1) && + (NRF_ADC_AIN2 == NRF_ADC_CONFIG_INPUT_2) && + (NRF_ADC_AIN3 == NRF_ADC_CONFIG_INPUT_3) && + (NRF_ADC_AIN4 == NRF_ADC_CONFIG_INPUT_4) && + (NRF_ADC_AIN5 == NRF_ADC_CONFIG_INPUT_5) && + (NRF_ADC_AIN6 == NRF_ADC_CONFIG_INPUT_6) && + (NRF_ADC_AIN7 == NRF_ADC_CONFIG_INPUT_7), + "Definitions from nrf-adc.h do not match those from nrf_adc.h"); + struct driver_data { struct adc_context ctx; diff --git a/drivers/adc/adc_nrfx_saadc.c b/drivers/adc/adc_nrfx_saadc.c index bc4ecc9dde0..74646f2c809 100644 --- a/drivers/adc/adc_nrfx_saadc.c +++ b/drivers/adc/adc_nrfx_saadc.c @@ -7,6 +7,7 @@ #define ADC_CONTEXT_USES_KERNEL_TIMER #include "adc_context.h" #include +#include #define LOG_LEVEL CONFIG_ADC_LOG_LEVEL #include @@ -14,6 +15,21 @@ LOG_MODULE_REGISTER(adc_nrfx_saadc); #define DT_DRV_COMPAT nordic_nrf_saadc +BUILD_ASSERT((NRF_SAADC_AIN0 == NRF_SAADC_INPUT_AIN0) && + (NRF_SAADC_AIN1 == NRF_SAADC_INPUT_AIN1) && + (NRF_SAADC_AIN2 == NRF_SAADC_INPUT_AIN2) && + (NRF_SAADC_AIN3 == NRF_SAADC_INPUT_AIN3) && + (NRF_SAADC_AIN4 == NRF_SAADC_INPUT_AIN4) && + (NRF_SAADC_AIN5 == NRF_SAADC_INPUT_AIN5) && + (NRF_SAADC_AIN6 == NRF_SAADC_INPUT_AIN6) && + (NRF_SAADC_AIN7 == NRF_SAADC_INPUT_AIN7) && + (NRF_SAADC_AIN7 == NRF_SAADC_INPUT_AIN7) && +#if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5) + (NRF_SAADC_VDDHDIV5 == NRF_SAADC_INPUT_VDDHDIV5) && +#endif + (NRF_SAADC_VDD == NRF_SAADC_INPUT_VDD), + "Definitions from nrf-adc.h do not match those from nrf_saadc.h"); + struct driver_data { struct adc_context ctx; diff --git a/dts/arm/nordic/nrf_common.dtsi b/dts/arm/nordic/nrf_common.dtsi index 76c2a227423..6abd7e2748b 100644 --- a/dts/arm/nordic/nrf_common.dtsi +++ b/dts/arm/nordic/nrf_common.dtsi @@ -4,8 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include +#include +#include #include +#include #include #include diff --git a/include/zephyr/dt-bindings/adc/nrf-adc.h b/include/zephyr/dt-bindings/adc/nrf-adc.h new file mode 100644 index 00000000000..1d875b8eb35 --- /dev/null +++ b/include/zephyr/dt-bindings/adc/nrf-adc.h @@ -0,0 +1,32 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2022 Nordic Semiconductor ASA + */ + +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ + +#include + +#define NRF_ADC_AIN0 BIT(0) +#define NRF_ADC_AIN1 BIT(1) +#define NRF_ADC_AIN2 BIT(2) +#define NRF_ADC_AIN3 BIT(3) +#define NRF_ADC_AIN4 BIT(4) +#define NRF_ADC_AIN5 BIT(5) +#define NRF_ADC_AIN6 BIT(6) +#define NRF_ADC_AIN7 BIT(7) + +#define NRF_SAADC_AIN0 1 +#define NRF_SAADC_AIN1 2 +#define NRF_SAADC_AIN2 3 +#define NRF_SAADC_AIN3 4 +#define NRF_SAADC_AIN4 5 +#define NRF_SAADC_AIN5 6 +#define NRF_SAADC_AIN6 7 +#define NRF_SAADC_AIN7 8 +#define NRF_SAADC_VDD 9 +#define NRF_SAADC_VDDHDIV5 13 + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_NRF_ADC_H_ */