Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/drivers/ad7768/ad7768.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7768.h
3 * @brief Header file of AD7768 Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2016(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39 #ifndef AD7768_H_
40 #define AD7768_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define AD7768_REG_CH_STANDBY 0x00
46 #define AD7768_REG_CH_MODE_A 0x01
47 #define AD7768_REG_CH_MODE_B 0x02
48 #define AD7768_REG_CH_MODE_SEL 0x03
49 #define AD7768_REG_PWR_MODE 0x04
50 #define AD7768_REG_GENERAL_CFG 0x05
51 #define AD7768_REG_DATA_CTRL 0x06
52 #define AD7768_REG_INTERFACE_CFG 0x07
53 #define AD7768_REG_BIST_CTRL 0x08
54 #define AD7768_REG_DEV_STATUS 0x09
55 #define AD7768_REG_REV_ID 0x0A
56 #define AD7768_REG_DEV_ID_MSB 0x0B
57 #define AD7768_REG_DEV_ID_LSB 0x0C
58 #define AD7768_REG_SW_REV_ID 0x0D
59 #define AD7768_REG_GPIO_CTRL 0x0E
60 #define AD7768_REG_GPIO_WR_DATA 0x0F
61 #define AD7768_REG_GPIO_RD_DATA 0x10
62 #define AD7768_REG_PRECHARGE_BUF_1 0x11
63 #define AD7768_REG_PRECHARGE_BUF_2 0x12
64 #define AD7768_REG_POS_REF_BUF 0x13
65 #define AD7768_REG_NEG_REF_BUF 0x14
66 #define AD7768_REG_CH_OFFSET_1(ch) (0x1E + (ch) * 3)
67 #define AD7768_REG_CH_OFFSET_2(ch) (0x1F + (ch) * 3)
68 #define AD7768_REG_CH_OFFSET_3(ch) (0x20 + (ch) * 3)
69 #define AD7768_REG_CH_GAIN_1(ch) (0x36 + (ch) * 3)
70 #define AD7768_REG_CH_GAIN_2(ch) (0x37 + (ch) * 3)
71 #define AD7768_REG_CH_GAIN_3(ch) (0x38 + (ch) * 3)
72 #define AD7768_REG_CH_SYNC_OFFSET(ch) (0x4E + (ch) * 3)
73 #define AD7768_REG_DIAG_METER_RX 0x56
74 #define AD7768_REG_DIAG_CTRL 0x57
75 #define AD7768_REG_DIAG_MOD_DELAY_CTRL 0x58
76 #define AD7768_REG_DIAG_CHOP_CTRL 0x59
77
78 /* AD7768_REG_CH_STANDBY */
79 #define AD7768_CH_STANDBY(x) (1 << (x))
80
81 /* AD7768_REG_CH_MODE_x */
82 #define AD7768_CH_MODE_FILTER_TYPE (1 << 3)
83 #define AD7768_CH_MODE_DEC_RATE(x) (((x) & 0x7) << 0)
84
85 /* AD7768_REG_CH_MODE_SEL */
86 #define AD7768_CH_MODE(x) (1 << (x))
87
88 /* AD7768_REG_PWR_MODE */
89 #define AD7768_PWR_MODE_SLEEP_MODE (1 << 7)
90 #define AD7768_PWR_MODE_POWER_MODE(x) (((x) & 0x3) << 5)
91 #define AD7768_PWR_MODE_LVDS_ENABLE (1 << 3)
92 #define AD7768_PWR_MODE_MCLK_DIV(x) (((x) & 0x3) << 0)
93
94 /* AD7768_REG_DATA_CTRL */
95 #define AD7768_DATA_CTRL_SPI_SYNC (1 << 7)
96 #define AD7768_DATA_CTRL_SINGLE_SHOT_EN (1 << 4)
97 #define AD7768_DATA_CTRL_SPI_RESET(x) (((x) & 0x3) << 0)
98
99 /* AD7768_REG_INTERFACE_CFG */
100 #define AD7768_INTERFACE_CFG_CRC_SEL(x) (((x) & 0x3) << 2)
101 #define AD7768_INTERFACE_CFG_DCLK_DIV(x) (((x) & 0x3) << 0)
102
103 /******************************************************************************/
104 /*************************** Types Declarations *******************************/
105 /******************************************************************************/
106 typedef enum {
107 AD7768_ACTIVE,
108 AD7768_SLEEP,
109 } ad7768_sleep_mode;
110
111 typedef enum {
112 AD7768_ECO = 0,
113 AD7768_MEDIAN = 2,
114 AD7768_FAST = 3,
115 } ad7768_power_mode;
116
117 typedef enum {
118 AD7768_MCLK_DIV_32 = 0,
119 AD7768_MCLK_DIV_8 = 2,
120 AD7768_MCLK_DIV_4 = 3,
121 } ad7768_mclk_div;
122
123 typedef enum {
124 AD7768_DCLK_DIV_8,
125 AD7768_DCLK_DIV_4,
126 AD7768_DCLK_DIV_2,
127 AD7768_DCLK_DIV_1,
128 } ad7768_dclk_div;
129
130 typedef enum {
131 AD7768_PIN_CTRL,
132 AD7768_SPI_CTRL,
133 } ad7768_pin_spi_ctrl;
134
135 typedef enum {
136 AD7768_STANDARD_CONV,
137 AD7768_ONE_SHOT_CONV,
138 } ad7768_conv_op;
139
140 typedef enum {
141 AD7768_NO_CRC,
142 AD7768_CRC_4,
143 AD7768_CRC_16,
144 AD7768_CRC_16_2ND,
145 } ad7768_crc_sel;
146
147 typedef enum {
148 AD7768_CH0,
149 AD7768_CH1,
150 AD7768_CH2,
151 AD7768_CH3,
152 AD7768_CH4,
153 AD7768_CH5,
154 AD7768_CH6,
155 AD7768_CH7,
156 } ad7768_ch;
157
158 typedef enum {
159 AD7768_ENABLED,
160 AD7768_STANDBY,
161 } ad7768_ch_state;
162
163 typedef enum {
164 AD7768_MODE_A,
165 AD7768_MODE_B,
166 } ad7768_ch_mode;
167
168 typedef enum {
169 AD7768_FILTER_WIDEBAND,
170 AD7768_FILTER_SINC,
171 } ad7768_filt_type;
172
173 typedef enum {
174 AD7768_DEC_X32,
175 AD7768_DEC_X64,
176 AD7768_DEC_X128,
177 AD7768_DEC_X256,
178 AD7768_DEC_X512,
179 AD7768_DEC_X1024,
180 AD7768_DEC_X1024_2ND,
181 AD7768_DEC_X1024_3RD,
182 } ad7768_dec_rate;
183
184 typedef struct {
185 spi_device spi_dev;
186 gpio_device gpio_dev;
187 int8_t gpio_reset;
188 uint8_t gpio_reset_value;
189 int8_t gpio_mode0;
190 int8_t gpio_mode1;
191 int8_t gpio_mode2;
192 int8_t gpio_mode3;
193 uint8_t pin_spi_input_value;
194 ad7768_pin_spi_ctrl pin_spi_ctrl;
195 ad7768_sleep_mode sleep_mode;
196 ad7768_power_mode power_mode;
197 ad7768_mclk_div mclk_div;
198 ad7768_dclk_div dclk_div;
199 ad7768_conv_op conv_op;
200 ad7768_crc_sel crc_sel;
201 ad7768_ch_state ch_state[8];
202 ad7768_ch_mode ch_mode[8];
203 ad7768_filt_type filt_type[2];
204 ad7768_dec_rate dec_rate[2];
205 } ad7768_dev;
206
207 typedef struct
208 {
209 /* SPI */
210 uint8_t spi_chip_select;
211 spi_mode spi_mode;
212 spi_type spi_type;
213 uint32_t spi_device_id;
214 /* GPIO */
215 gpio_type gpio_type;
216 uint32_t gpio_device_id;
217 int8_t gpio_reset;
218 uint8_t gpio_reset_value;
219 int8_t gpio_mode0;
220 int8_t gpio_mode1;
221 int8_t gpio_mode2;
222 int8_t gpio_mode3;
223 /* Configuration */
224 uint8_t pin_spi_input_value;
225 ad7768_sleep_mode sleep_mode;
226 ad7768_power_mode power_mode;
227 ad7768_mclk_div mclk_div;
228 ad7768_dclk_div dclk_div;
229 ad7768_conv_op conv_op;
230 ad7768_crc_sel crc_sel;
231 } ad7768_init_param;
232
233 /******************************************************************************/
234 /************************ Functions Declarations ******************************/
235 /******************************************************************************/
236 /* SPI read from device. */
237 int32_t ad7768_spi_read(ad7768_dev *dev,
238 uint8_t reg_addr,
239 uint8_t *reg_data);
240 /* SPI write to device. */
241 int32_t ad7768_spi_write(ad7768_dev *dev,
242 uint8_t reg_addr,
243 uint8_t reg_data);
244 /* SPI read from device using a mask. */
245 int32_t ad7768_spi_read_mask(ad7768_dev *dev,
246 uint8_t reg_addr,
247 uint8_t mask,
248 uint8_t *data);
249 /* SPI write to device using a mask. */
250 int32_t ad7768_spi_write_mask(ad7768_dev *dev,
251 uint8_t reg_addr,
252 uint8_t mask,
253 uint8_t data);
254 /* Set the device sleep mode. */
255 int32_t ad7768_set_sleep_mode(ad7768_dev *dev,
256 ad7768_sleep_mode mode);
257 /* Get the device sleep mode. */
258 int32_t ad7768_get_sleep_mode(ad7768_dev *dev,
259 ad7768_sleep_mode *mode);
260 /* Set the device power mode. */
261 int32_t ad7768_set_power_mode(ad7768_dev *dev,
262 ad7768_power_mode mode);
263 /* Get the device power mode. */
264 int32_t ad7768_get_power_mode(ad7768_dev *dev,
265 ad7768_power_mode *mode);
266 /* Set the MCLK divider. */
267 int32_t ad7768_set_mclk_div(ad7768_dev *dev,
268 ad7768_mclk_div clk_div);
269 /* Get the MCLK divider. */
270 int32_t ad7768_get_mclk_div(ad7768_dev *dev,
271 ad7768_mclk_div *clk_div);
272 /* Set the DCLK divider. */
273 int32_t ad7768_set_dclk_div(ad7768_dev *dev,
274 ad7768_dclk_div clk_div);
275 /* Get the DCLK divider. */
276 int32_t ad7768_get_dclk_div(ad7768_dev *dev,
277 ad7768_dclk_div *clk_div);
278 /* Set the conversion operation mode. */
279 int32_t ad7768_set_conv_op(ad7768_dev *dev,
280 ad7768_conv_op conv_op);
281 /* Get the conversion operation mode. */
282 int32_t ad7768_get_conv_op(ad7768_dev *dev,
283 ad7768_conv_op *conv_op);
284 /* Set the CRC selection. */
285 int32_t ad7768_set_crc_sel(ad7768_dev *dev,
286 ad7768_crc_sel crc_sel);
287 /* Get the CRC selection. */
288 int32_t ad7768_get_crc_sel(ad7768_dev *dev,
289 ad7768_crc_sel *crc_sel);
290 /* Set the channel state. */
291 int32_t ad7768_set_ch_state(ad7768_dev *dev,
292 ad7768_ch ch,
293 ad7768_ch_state state);
294 /* Get the channel state. */
295 int32_t ad7768_get_ch_state(ad7768_dev *dev,
296 ad7768_ch ch,
297 ad7768_ch_state *state);
298 /* Set the mode configuration. */
299 int32_t ad7768_set_mode_config(ad7768_dev *dev,
300 ad7768_ch_mode mode,
301 ad7768_filt_type filt_type,
302 ad7768_dec_rate dec_rate);
303 /* Get the mode configuration. */
304 int32_t ad7768_get_mode_config(ad7768_dev *dev,
305 ad7768_ch_mode mode,
306 ad7768_filt_type *filt_type,
307 ad7768_dec_rate *dec_rate);
308 /* Set the channel mode. */
309 int32_t ad7768_set_ch_mode(ad7768_dev *dev,
310 ad7768_ch ch,
311 ad7768_ch_mode mode);
312 /* Get the channel mode. */
313 int32_t ad7768_get_ch_mode(ad7768_dev *dev,
314 ad7768_ch ch,
315 ad7768_ch_mode *mode);
316 /* Initialize the device. */
317 int32_t ad7768_setup(ad7768_dev **device,
318 ad7768_init_param init_param);
319
320 #endif // AD7768_H_