Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7779.h
3 * @brief Header file of AD7779 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 AD7779_H_
40 #define AD7779_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define AD7779_REG_CH_CONFIG(ch) (0x00 + (ch)) // Channel Configuration
46 #define AD7779_REG_CH_DISABLE 0x08 // Disable clocks to ADC channel
47 #define AD7779_REG_CH_SYNC_OFFSET(ch) (0x09 + (ch)) // Channel SYNC Offset
48 #define AD7779_REG_GENERAL_USER_CONFIG_1 0x11 // General User Config 1
49 #define AD7779_REG_GENERAL_USER_CONFIG_2 0x12 // General User Config 2
50 #define AD7779_REG_GENERAL_USER_CONFIG_3 0x13 // General User Config 3
51 #define AD7779_REG_DOUT_FORMAT 0x14 // Data out format
52 #define AD7779_REG_ADC_MUX_CONFIG 0x15 // Main ADC meter and reference Mux control
53 #define AD7779_REG_GLOBAL_MUX_CONFIG 0x16 // Global diagnostics mux
54 #define AD7779_REG_GPIO_CONFIG 0x17 // GPIO config
55 #define AD7779_REG_GPIO_DATA 0x18 // GPIO Data
56 #define AD7779_REG_BUFFER_CONFIG_1 0x19 // Buffer Config 1
57 #define AD7779_REG_BUFFER_CONFIG_2 0x1A // Buffer Config 2
58 #define AD7779_REG_CH_OFFSET_UPPER_BYTE(ch) (0x1C + (ch) * 6) // Channel offset upper byte
59 #define AD7779_REG_CH_OFFSET_MID_BYTE(ch) (0x1D + (ch) * 6) // Channel offset middle byte
60 #define AD7779_REG_CH_OFFSET_LOWER_BYTE(ch) (0x1E + (ch) * 6) // Channel offset lower byte
61 #define AD7779_REG_CH_GAIN_UPPER_BYTE(ch) (0x1F + (ch) * 6) // Channel gain upper byte
62 #define AD7779_REG_CH_GAIN_MID_BYTE(ch) (0x20 + (ch) * 6) // Channel gain middle byte
63 #define AD7779_REG_CH_GAIN_LOWER_BYTE(ch) (0x21 + (ch) * 6) // Channel gain lower byte
64 #define AD7779_REG_CH_ERR_REG(ch) (0x4C + (ch)) // Channel Status Register
65 #define AD7779_REG_CH0_1_SAT_ERR 0x54 // Channel 0/1 DSP errors
66 #define AD7779_REG_CH2_3_SAT_ERR 0x55 // Channel 2/3 DSP errors
67 #define AD7779_REG_CH4_5_SAT_ERR 0x56 // Channel 4/5 DSP errors
68 #define AD7779_REG_CH6_7_SAT_ERR 0x57 // Channel 6/7 DSP errors
69 #define AD7779_REG_CHX_ERR_REG_EN 0x58 // Channel 0-7 Error Reg Enable
70 #define AD7779_REG_GEN_ERR_REG_1 0x59 // General Errors Register 1
71 #define AD7779_REG_GEN_ERR_REG_1_EN 0x5A // General Errors Register 1 Enable
72 #define AD7779_REG_GEN_ERR_REG_2 0x5B // General Errors Register 2
73 #define AD7779_REG_GEN_ERR_REG_2_EN 0x5C // General Errors Register 2 Enable
74 #define AD7779_REG_STATUS_REG_1 0x5D // Error Status Register 1
75 #define AD7779_REG_STATUS_REG_2 0x5E // Error Status Register 2
76 #define AD7779_REG_STATUS_REG_3 0x5F // Error Status Register 3
77 #define AD7779_REG_SRC_N_MSB 0x60 // Decimation Rate (N) MSB
78 #define AD7779_REG_SRC_N_LSB 0x61 // Decimation Rate (N) LSB
79 #define AD7779_REG_SRC_IF_MSB 0x62 // Decimation Rate (IF) MSB
80 #define AD7779_REG_SRC_IF_LSB 0x63 // Decimation Rate (IF) LSB
81 #define AD7779_REG_SRC_UPDATE 0x64 // SRC load source and load update
82
83 /* AD7779_REG_CHx_CONFIG */
84 #define AD7779_CH_GAIN(x) (((x) & 0x3) << 6)
85 #define AD7779_CH_RX (1 << 4)
86
87 /* AD7779_REG_CH_DISABLE */
88 #define AD7779_CH_DISABLE(x) (1 << (x))
89
90 /* AD7779_REG_GENERAL_USER_CONFIG_1 */
91 #define AD7779_ALL_CH_DIS_MCLK_EN (1 << 7)
92 #define AD7779_MOD_POWERMODE (1 << 6)
93 #define AD7779_PDB_VCM (1 << 5)
94 #define AD7779_PDB_REFOUT_BUF (1 << 4)
95 #define AD7779_PDB_SAR (1 << 3)
96 #define AD7779_PDB_RC_OSC (1 << 2)
97 #define AD7779_SOFT_RESET(x) (((x) & 0x3) << 0)
98
99 /* AD7779_REG_GENERAL_USER_CONFIG_2 */
100 #define AD7771_FILTER_MODE (1 << 6)
101 #define AD7779_SAR_DIAG_MODE_EN (1 << 5)
102 #define AD7779_SDO_DRIVE_STR(x) (((x) & 0x3) << 3)
103 #define AD7779_DOUT_DRIVE_STR(x) (((x) & 0x3) << 1)
104 #define AD7779_SPI_SYNC (1 << 0)
105
106 /* AD7779_REG_GENERAL_USER_CONFIG_3 */
107 #define AD7779_CONVST_DEGLITCH_DIS(x) (((x) & 0x3) << 6)
108 #define AD7779_SPI_SLAVE_MODE_EN (1 << 4)
109 #define AD7779_CLK_QUAL_DIS (1 << 0)
110
111 /* AD7779_REG_DOUT_FORMAT */
112 #define AD7779_DOUT_FORMAT(x) (((x) & 0x3) << 6)
113 #define AD7779_DOUT_HEADER_FORMAT (1 << 5)
114 #define AD7779_DCLK_CLK_DIV(x) (((x) & 0x3) << 1)
115
116 /* AD7779_REG_GLOBAL_MUX_CONFIG */
117 #define AD7779_GLOBAL_MUX_CTRL(x) (((x) & 0x1F) << 3)
118
119 /* AD7779_REG_BUFFER_CONFIG_1 */
120 #define AD7779_REF_BUF_POS_EN (1 << 4)
121 #define AD7779_REF_BUF_NEG_EN (1 << 3)
122
123 /* AD7779_REG_BUFFER_CONFIG_2 */
124 #define AD7779_REFBUFP_PREQ (1 << 7)
125 #define AD7779_REFBUFN_PREQ (1 << 6)
126 #define AD7779_PDB_ALDO1_OVRDRV (1 << 2)
127 #define AD7779_PDB_ALDO2_OVRDRV (1 << 1)
128 #define AD7779_PDB_DLDO_OVRDRV (1 << 0)
129
130 /* AD7779_REG_GEN_ERR_REG_1_EN */
131 #define AD7779_MEMMAP_CRC_TEST_EN (1 << 5)
132 #define AD7779_ROM_CRC_TEST_EN (1 << 4)
133 #define AD7779_SPI_CLK_COUNT_TEST_EN (1 << 3)
134 #define AD7779_SPI_INVALID_READ_TEST_EN (1 << 2)
135 #define AD7779_SPI_INVALID_WRITE_TEST_EN (1 << 1)
136 #define AD7779_SPI_CRC_TEST_EN (1 << 0)
137
138 #define AD7779_CRC8_POLY 0x07
139
140 /******************************************************************************/
141 /*************************** Types Declarations *******************************/
142 /******************************************************************************/
143 typedef enum {
144 AD7779_PIN_CTRL,
145 AD7779_SPI_CTRL,
146 } ad7779_ctrl_mode;
147
148 typedef enum {
149 AD7779_INT_REG,
150 AD7779_SD_CONV,
151 AD7779_SAR_CONV,
152 } ad7779_spi_op_mode;
153
154 typedef enum {
155 AD7779_CH0,
156 AD7779_CH1,
157 AD7779_CH2,
158 AD7779_CH3,
159 AD7779_CH4,
160 AD7779_CH5,
161 AD7779_CH6,
162 AD7779_CH7,
163 } ad7779_ch;
164
165 typedef enum {
166 AD7779_ENABLE,
167 AD7779_DISABLE,
168 } ad7779_state;
169
170 typedef enum {
171 AD7779_GAIN_1,
172 AD7779_GAIN_2,
173 AD7779_GAIN_4,
174 AD7779_GAIN_8,
175 } ad7779_gain;
176
177 typedef enum {
178 AD7779_DCLK_DIV_1,
179 AD7779_DCLK_DIV_2,
180 AD7779_DCLK_DIV_4,
181 AD7779_DCLK_DIV_8,
182 AD7779_DCLK_DIV_16,
183 AD7779_DCLK_DIV_32,
184 AD7779_DCLK_DIV_64,
185 AD7779_DCLK_DIV_128,
186 } ad7768_dclk_div;
187
188 typedef enum {
189 AD7779_HIGH_RES,
190 AD7779_LOW_PWR,
191 } ad7779_pwr_mode;
192
193 typedef enum {
194 AD7779_EXT_REF,
195 AD7779_INT_REF,
196 } ad7779_ref_type;
197
198 typedef enum {
199 AD7779_REFX_P,
200 AD7779_REFX_N,
201 } ad7779_refx_pin;
202
203 typedef enum {
204 AD7779_REF_BUF_ENABLED,
205 AD7779_REF_BUF_PRECHARGED,
206 AD7779_REF_BUF_DISABLED,
207 } ad7779_ref_buf_op_mode;
208
209 typedef enum {
210 AD7779_AUXAINP_AUXAINN,
211 AD7779_DVBE_AVSSX,
212 AD7779_REF1P_REF1N,
213 AD7779_REF2P_REF2N,
214 AD7779_REF_OUT_AVSSX,
215 AD7779_VCM_AVSSX,
216 AD7779_AREG1CAP_AVSSX_ATT,
217 AD7779_AREG2CAP_AVSSX_ATT,
218 AD7779_DREGCAP_DGND_ATT,
219 AD7779_AVDD1A_AVSSX_ATT,
220 AD7779_AVDD1B_AVSSX_ATT,
221 AD7779_AVDD2A_AVSSX_ATT,
222 AD7779_AVDD2B_AVSSX_ATT,
223 AD7779_IOVDD_DGND_ATT,
224 AD7779_AVDD4_AVSSX,
225 AD7779_DGND_AVSS1A_ATT,
226 AD7779_DGND_AVSS1B_ATT,
227 AD7779_DGND_AVSSX_ATT,
228 AD7779_AVDD4_AVSSX_ATT,
229 AD7779_REF1P_AVSSX,
230 AD7779_REF2P_AVSSX,
231 AD7779_AVSSX_AVDD4_ATT,
232 } ad7779_sar_mux;
233
234 typedef struct {
235 /* SPI */
236 spi_device spi_dev;
237 /* GPIO */
238 gpio_device gpio_dev;
239 int8_t gpio_reset;
240 int8_t gpio_mode0;
241 int8_t gpio_mode1;
242 int8_t gpio_mode2;
243 int8_t gpio_mode3;
244 int8_t gpio_dclk0;
245 int8_t gpio_dclk1;
246 int8_t gpio_dclk2;
247 int8_t gpio_sync_in;
248 int8_t gpio_convst_sar;
249 /* Device Settings */
250 ad7779_ctrl_mode ctrl_mode;
251 ad7779_state spi_crc_en;
252 ad7779_spi_op_mode spi_op_mode;
253 ad7779_state state[8];
254 ad7779_gain gain[8];
255 uint16_t dec_rate_int;
256 uint16_t dec_rate_dec;
257 ad7779_ref_type ref_type;
258 ad7779_pwr_mode pwr_mode;
259 ad7768_dclk_div dclk_div;
260 uint8_t sync_offset[8];
261 uint32_t offset_corr[8];
262 uint32_t gain_corr[8];
263 ad7779_ref_buf_op_mode ref_buf_op_mode[2];
264 ad7779_state sar_state;
265 ad7779_sar_mux sar_mux;
266 ad7779_state sinc5_state; // Can be enabled only for AD7771
267 uint8_t cached_reg_val[AD7779_REG_SRC_UPDATE + 1];
268 } ad7779_dev;
269
270 typedef struct {
271 /* SPI */
272 uint8_t spi_chip_select;
273 spi_mode spi_mode;
274 spi_type spi_type;
275 uint32_t spi_device_id;
276 /* GPIO */
277 gpio_type gpio_type;
278 uint32_t gpio_device_id;
279 int8_t gpio_reset;
280 int8_t gpio_mode0;
281 int8_t gpio_mode1;
282 int8_t gpio_mode2;
283 int8_t gpio_mode3;
284 int8_t gpio_dclk0;
285 int8_t gpio_dclk1;
286 int8_t gpio_dclk2;
287 int8_t gpio_sync_in;
288 int8_t gpio_convst_sar;
289 /* Device Settings */
290 ad7779_ctrl_mode ctrl_mode;
291 ad7779_state spi_crc_en;
292 ad7779_state state[8];
293 ad7779_gain gain[8];
294 uint16_t dec_rate_int;
295 uint16_t dec_rate_dec;
296 ad7779_ref_type ref_type;
297 ad7779_pwr_mode pwr_mode;
298 ad7768_dclk_div dclk_div;
299 uint8_t sync_offset[8];
300 uint32_t offset_corr[8];
301 uint32_t gain_corr[8];
302 ad7779_ref_buf_op_mode ref_buf_op_mode[2];
303 ad7779_state sinc5_state; // Can be enabled only for AD7771
304 } ad7779_init_param;
305
306 /******************************************************************************/
307 /************************ Functions Declarations ******************************/
308 /******************************************************************************/
309 /* Compute CRC8 checksum. */
310 uint8_t ad7779_compute_crc8(uint8_t *data,
311 uint8_t data_size);
312 /* SPI read from device. */
313 int32_t ad7779_spi_int_reg_read(ad7779_dev *dev,
314 uint8_t reg_addr,
315 uint8_t *reg_data);
316 /* SPI write to device. */
317 int32_t ad7779_spi_int_reg_write(ad7779_dev *dev,
318 uint8_t reg_addr,
319 uint8_t reg_data);
320 /* SPI read from device using a mask. */
321 int32_t ad7779_spi_int_reg_read_mask(ad7779_dev *dev,
322 uint8_t reg_addr,
323 uint8_t mask,
324 uint8_t *data);
325 /* SPI write to device using a mask. */
326 int32_t ad7779_spi_int_reg_write_mask(ad7779_dev *dev,
327 uint8_t reg_addr,
328 uint8_t mask,
329 uint8_t data);
330 /* SPI SAR conversion code read. */
331 int32_t ad7779_spi_sar_read_code(ad7779_dev *dev,
332 ad7779_sar_mux mux_next_conv,
333 uint16_t *sar_code);
334 /* Set SPI operation mode. */
335 int32_t ad7779_set_spi_op_mode(ad7779_dev *dev,
336 ad7779_spi_op_mode mode);
337 /* Get SPI operation mode. */
338 int32_t ad7779_get_spi_op_mode(ad7779_dev *dev,
339 ad7779_spi_op_mode *mode);
340 /* Set the state (enable, disable) of the channel. */
341 int32_t ad7779_set_state(ad7779_dev *dev,
342 ad7779_ch ch,
343 ad7779_state state);
344 /* Get the state (enable, disable) of the selected channel. */
345 int32_t ad7779_get_state(ad7779_dev *dev,
346 ad7779_ch ch,
347 ad7779_state *state);
348 /* Update the state of the MODEx pins according to the settings specified in
349 * the device structure. */
350 int32_t ad7779_do_update_mode_pins(ad7779_dev *dev);
351 /* Set the gain of the selected channel. */
352 int32_t ad7779_set_gain(ad7779_dev *dev,
353 ad7779_ch ch,
354 ad7779_gain gain);
355 /* Get the gain of the selected channel. */
356 int32_t ad7779_get_gain(ad7779_dev *dev,
357 ad7779_ch ch,
358 ad7779_gain *gain);
359 /* Set the decimation rate. */
360 int32_t ad7779_set_dec_rate(ad7779_dev *dev,
361 uint16_t int_val,
362 uint16_t dec_val);
363 /* Get the decimation rate. */
364 int32_t ad7779_get_dec_rate(ad7779_dev *dev,
365 uint16_t *int_val,
366 uint16_t *dec_val);
367 /* Set the power mode. */
368 int32_t ad7779_set_power_mode(ad7779_dev *dev,
369 ad7779_pwr_mode pwr_mode);
370 /* Get the power mode. */
371 int32_t ad7779_get_power_mode(ad7779_dev *dev,
372 ad7779_pwr_mode *pwr_mode);
373 /* Set the reference type. */
374 int32_t ad7779_set_reference_type(ad7779_dev *dev,
375 ad7779_ref_type ref_type);
376 /* Get the reference type. */
377 int32_t ad7779_get_reference_type(ad7779_dev *dev,
378 ad7779_ref_type *ref_type);
379 /* Set the DCLK divider. */
380 int32_t ad7779_set_dclk_div(ad7779_dev *dev,
381 ad7768_dclk_div div);
382 /* Get the DCLK divider. */
383 int32_t ad7779_get_dclk_div(ad7779_dev *dev,
384 ad7768_dclk_div *div);
385 /* Set the synchronization offset of the selected channel. */
386 int32_t ad7779_set_sync_offset(ad7779_dev *dev,
387 ad7779_ch ch,
388 uint8_t sync_offset);
389 /* Get the synchronization offset of the selected channel. */
390 int32_t ad7779_get_sync_offset(ad7779_dev *dev,
391 ad7779_ch ch,
392 uint8_t *sync_offset);
393 /* Set the offset correction of the selected channel. */
394 int32_t ad7779_set_offset_corr(ad7779_dev *dev,
395 ad7779_ch ch,
396 uint32_t offset);
397 /* Get the offset correction of the selected channel. */
398 int32_t ad7779_get_offset_corr(ad7779_dev *dev,
399 ad7779_ch ch,
400 uint32_t *offset);
401 /* Set the gain correction of the selected channel. */
402 int32_t ad7779_set_gain_corr(ad7779_dev *dev,
403 ad7779_ch ch,
404 uint32_t gain);
405 /* Get the gain correction of the selected channel. */
406 int32_t ad7779_get_gain_corr(ad7779_dev *dev,
407 ad7779_ch ch,
408 uint32_t *gain);
409 /* Set the reference buffer operation mode of the selected pin. */
410 int32_t ad7779_set_ref_buf_op_mode(ad7779_dev *dev,
411 ad7779_refx_pin refx_pin,
412 ad7779_ref_buf_op_mode mode);
413 /* Get the reference buffer operation mode of the selected pin. */
414 int32_t ad7779_get_ref_buf_op_mode(ad7779_dev *dev,
415 ad7779_refx_pin refx_pin,
416 ad7779_ref_buf_op_mode *mode);
417 /* Set the SAR ADC configuration. */
418 int32_t ad7779_set_sar_cfg(ad7779_dev *dev,
419 ad7779_state state,
420 ad7779_sar_mux mux);
421 /* Get the SAR ADC configuration. */
422 int32_t ad7779_get_sar_cfg(ad7779_dev *dev,
423 ad7779_state *state,
424 ad7779_sar_mux *mux);
425 /* Do a single SAR conversion. */
426 int32_t ad7779_do_single_sar_conv(ad7779_dev *dev,
427 ad7779_sar_mux mux,
428 uint16_t *sar_code);
429 /* Do a SPI software reset. */
430 int32_t ad7779_do_spi_soft_reset(ad7779_dev *dev);
431 /* Set the state (enable, disable) of the SINC5 filter. */
432 int32_t ad7771_set_sinc5_filter_state(ad7779_dev *dev,
433 ad7779_state state);
434 /* Get the state (enable, disable) of the SINC5 filter. */
435 int32_t ad7771_get_sinc5_filter_state(ad7779_dev *dev,
436 ad7779_state *state);
437 /* Initialize the device. */
438 int32_t ad7779_setup(ad7779_dev **device,
439 ad7779_init_param init_param);
440 #endif // AD7779_H_