1 /*
2  * Copyright 2021 Google LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #ifndef ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_
7 #define ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_
8 
9 /*
10  * Provide the BIT_MASK() macro for when this file is included from
11  * devicetrees.
12  */
13 #ifndef BIT_MASK
14 #define BIT_MASK(n) ((1 << (n)) - 1)
15 #endif
16 
17 /** Acquisition time is expressed in microseconds. */
18 #define ADC_ACQ_TIME_MICROSECONDS  (1)
19 /** Acquisition time is expressed in nanoseconds. */
20 #define ADC_ACQ_TIME_NANOSECONDS   (2)
21 /** Acquisition time is expressed in ADC ticks. */
22 #define ADC_ACQ_TIME_TICKS         (3)
23 /** Macro for composing the acquisition time value in given units. */
24 #define ADC_ACQ_TIME(unit, value)  (((unit) << 14) | ((value) & BIT_MASK(14)))
25 /** Value indicating that the default acquisition time should be used. */
26 #define ADC_ACQ_TIME_DEFAULT       0
27 #define ADC_ACQ_TIME_MAX           BIT_MASK(14)
28 
29 #define ADC_ACQ_TIME_UNIT(time)    (((time) >> 14) & BIT_MASK(2))
30 #define ADC_ACQ_TIME_VALUE(time)   ((time) & BIT_MASK(14))
31 
32 #endif /* ZEPHYR_INCLUDE_DT_BINDINGS_ADC_ADC_H_ */
33