From e7a9775cca4b5b1780b55f69c77ed2fc842eff78 Mon Sep 17 00:00:00 2001 From: Keith Short Date: Sat, 24 Apr 2021 11:08:07 -0600 Subject: [PATCH] adc: Move ADC acquisition time macros Move the ADC acquisition time macros so that they can be utiliized by devicetrees. Signed-off-by: Keith Short --- include/drivers/adc.h | 15 +-------------- include/dt-bindings/adc/adc.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) create mode 100644 include/dt-bindings/adc/adc.h diff --git a/include/drivers/adc.h b/include/drivers/adc.h index f3153af5d2c..36e5acf7962 100644 --- a/include/drivers/adc.h +++ b/include/drivers/adc.h @@ -14,6 +14,7 @@ #define ZEPHYR_INCLUDE_DRIVERS_ADC_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -75,20 +76,6 @@ enum adc_reference { ADC_REF_EXTERNAL1, /**< External, input 1. */ }; -/** Acquisition time is expressed in microseconds. */ -#define ADC_ACQ_TIME_MICROSECONDS (1u) -/** Acquisition time is expressed in nanoseconds. */ -#define ADC_ACQ_TIME_NANOSECONDS (2u) -/** Acquisition time is expressed in ADC ticks. */ -#define ADC_ACQ_TIME_TICKS (3u) -/** Macro for composing the acquisition time value in given units. */ -#define ADC_ACQ_TIME(unit, value) (((unit) << 14) | ((value) & BIT_MASK(14))) -/** Value indicating that the default acquisition time should be used. */ -#define ADC_ACQ_TIME_DEFAULT 0 - -#define ADC_ACQ_TIME_UNIT(time) (((time) >> 14) & BIT_MASK(2)) -#define ADC_ACQ_TIME_VALUE(time) ((time) & BIT_MASK(14)) - /** * @brief Structure for specifying the configuration of an ADC channel. */ diff --git a/include/dt-bindings/adc/adc.h b/include/dt-bindings/adc/adc.h new file mode 100644 index 00000000000..ad18d2b4efb --- /dev/null +++ b/include/dt-bindings/adc/adc.h @@ -0,0 +1,31 @@ +/* + * Copyright 2021 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_ + +/* + * Provide the BIT_MASK() macro for when this file is included from + * devicetrees. + */ +#ifndef BIT_MASK +#define BIT_MASK(n) ((1 << (n)) - 1) +#endif + +/** Acquisition time is expressed in microseconds. */ +#define ADC_ACQ_TIME_MICROSECONDS (1) +/** Acquisition time is expressed in nanoseconds. */ +#define ADC_ACQ_TIME_NANOSECONDS (2) +/** Acquisition time is expressed in ADC ticks. */ +#define ADC_ACQ_TIME_TICKS (3) +/** Macro for composing the acquisition time value in given units. */ +#define ADC_ACQ_TIME(unit, value) (((unit) << 14) | ((value) & BIT_MASK(14))) +/** Value indicating that the default acquisition time should be used. */ +#define ADC_ACQ_TIME_DEFAULT 0 + +#define ADC_ACQ_TIME_UNIT(time) (((time) >> 14) & BIT_MASK(2)) +#define ADC_ACQ_TIME_VALUE(time) ((time) & BIT_MASK(14)) + +#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_ */