Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad7616-sdz/ad7616.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7616.h
3 * @brief Header file of AD7616 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 AD7616_H_
40 #define AD7616_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define AD7616_REG_CONFIG 0x02
46 #define AD7616_REG_CHANNEL 0x03
47 #define AD7616_REG_INPUT_RANGE_A1 0x04
48 #define AD7616_REG_INPUT_RANGE_A2 0x05
49 #define AD7616_REG_INPUT_RANGE_B1 0x06
50 #define AD7616_REG_INPUT_RANGE_B2 0x07
51 #define AD7616_REG_SEQUENCER_STACK(x) (0x20 + (x))
52
53 /* AD7616_REG_CONFIG */
54 #define AD7616_SDEF (1 << 7)
55 #define AD7616_BURSTEN (1 << 6)
56 #define AD7616_SEQEN (1 << 5)
57 #define AD7616_OS(x) (((x) & 0x7) << 2)
58 #define AD7616_STATUSEN (1 << 1)
59 #define AD7616_CRCEN (1 << 0)
60
61 /* AD7616_REG_INPUT_RANGE */
62 #define AD7616_INPUT_RANGE(ch, x) (((x) & 0x3) << (((ch) & 0x3) * 2))
63
64 /* AD7616_REG_SEQUENCER_STACK(x) */
65 #define AD7616_ADDR(x) (((x) & 0x7F) << 9)
66 #define AD7616_SSREN (1 << 8)
67 #define AD7616_BSEL(x) (((x) & 0xF) << 4)
68 #define AD7616_ASEL(x) (((x) & 0xF) << 0)
69
70 /* AD7616_REG_STATUS */
71 #define AD7616_STATUS_A(x) (((x) & 0xF) << 12)
72 #define AD7616_STATUS_B(x) (((x) & 0xF) << 8)
73 #define AD7616_STATUS_CRC(x) (((x) & 0xFF) << 0)
74
75 /******************************************************************************/
76 /*************************** Types Declarations *******************************/
77 /******************************************************************************/
78 typedef enum {
79 AD7616_SW,
80 AD7616_HW,
81 } ad7616_mode;
82
83 typedef enum {
84 AD7616_SERIAL,
85 AD7616_PARALLEL,
86 } ad7616_interface;
87
88 typedef enum {
89 AD7616_VA0,
90 AD7616_VA1,
91 AD7616_VA2,
92 AD7616_VA3,
93 AD7616_VA4,
94 AD7616_VA5,
95 AD7616_VA6,
96 AD7616_VA7,
97 AD7616_VB0,
98 AD7616_VB1,
99 AD7616_VB2,
100 AD7616_VB3,
101 AD7616_VB4,
102 AD7616_VB5,
103 AD7616_VB6,
104 AD7616_VB7,
105 } ad7616_ch;
106
107 typedef enum {
108 AD7616_2V5 = 1,
109 AD7616_5V = 2,
110 AD7616_10V = 3,
111 } ad7616_range;
112
113 typedef enum {
114 AD7616_OSR_0,
115 AD7616_OSR_2,
116 AD7616_OSR_4,
117 AD7616_OSR_8,
118 AD7616_OSR_16,
119 AD7616_OSR_32,
120 AD7616_OSR_64,
121 AD7616_OSR_128,
122 } ad7616_osr;
123
124 typedef struct {
125 /* SPI */
126 spi_device spi_dev;
127 /* GPIO */
128 gpio_device gpio_dev;
129 int8_t gpio_hw_rngsel0;
130 int8_t gpio_hw_rngsel1;
131 int8_t gpio_reset;
132 int8_t gpio_os0;
133 int8_t gpio_os1;
134 int8_t gpio_os2;
135 /* Device Settings */
136 ad7616_interface interface;
137 ad7616_mode mode;
138 ad7616_range va[8];
139 ad7616_range vb[8];
140 ad7616_osr osr;
141 adc_core *core;
142 } ad7616_dev;
143
144 typedef struct {
145 /* SPI */
146 uint8_t spi_chip_select;
147 spi_mode spi_mode;
148 spi_type spi_type;
149 uint32_t spi_device_id;
150 /* GPIO */
151 gpio_type gpio_type;
152 uint32_t gpio_device_id;
153 int8_t gpio_hw_rngsel0;
154 int8_t gpio_hw_rngsel1;
155 int8_t gpio_reset;
156 int8_t gpio_os0;
157 int8_t gpio_os1;
158 int8_t gpio_os2;
159 /* Device Settings */
160 ad7616_mode mode;
161 ad7616_range va[8];
162 ad7616_range vb[8];
163 ad7616_osr osr;
164 } ad7616_init_param;
165
166 /******************************************************************************/
167 /************************ Functions Declarations ******************************/
168 /******************************************************************************/
169 /* SPI read from device. */
170 int32_t ad7616_read(ad7616_dev *dev,
171 uint8_t reg_addr,
172 uint16_t *reg_data);
173 /* SPI write to device. */
174 int32_t ad7616_write(ad7616_dev *dev,
175 uint8_t reg_addr,
176 uint16_t reg_data);
177 /* SPI read from device using a mask. */
178 int32_t ad7616_read_mask(ad7616_dev *dev,
179 uint8_t reg_addr,
180 uint16_t mask,
181 uint16_t *data);
182 /* SPI write to device using a mask. */
183 int32_t ad7616_write_mask(ad7616_dev *dev,
184 uint8_t reg_addr,
185 uint16_t mask,
186 uint16_t data);
187 /* SPI read from device. */
188 int32_t ad7616_spi_read(ad7616_dev *dev,
189 uint8_t reg_addr,
190 uint16_t *reg_data);
191 /* SPI write to device. */
192 int32_t ad7616_spi_write(ad7616_dev *dev,
193 uint8_t reg_addr,
194 uint16_t reg_data);
195 /* PAR read from device. */
196 int32_t ad7616_par_read(ad7616_dev *dev,
197 uint8_t reg_addr,
198 uint16_t *reg_data);
199 /* PAR write to device. */
200 int32_t ad7616_par_write(ad7616_dev *dev,
201 uint8_t reg_addr,
202 uint16_t reg_data);
203 /* Perform a full reset of the device. */
204 int32_t ad7616_reset(ad7616_dev *dev);
205 /* Set the analog input range for the selected analog input channel. */
206 int32_t ad7616_set_range(ad7616_dev *dev,
207 ad7616_ch ch,
208 ad7616_range range);
209 /* Set the operation mode (software or hardware). */
210 int32_t ad7616_set_mode(ad7616_dev *dev,
211 ad7616_mode mode);
212 /* Set the oversampling ratio. */
213 int32_t ad7616_set_oversampling_ratio(ad7616_dev *dev,
214 ad7616_osr osr);
215 /* Initialize the device. */
216 int32_t ad7616_setup(ad7616_dev **device,
217 adc_core *core,
218 ad7616_init_param init_param);
219 #endif