Debian Codegraph @

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

raw symbols SCIP
1 /**************************************************************************//**
2 * @file AD717X.h
3 * @brief AD717X header file.
4 * @devices AD7172-2, AD7172-4, AD7173-8, AD7175-2, AD7175-8, AD7176-2,
5 * AD7177-2
6 * @author acozma ([email protected])
7 * dnechita ([email protected])
8 *******************************************************************************
9 * Copyright 2015(c) Analog Devices, Inc.
10 *
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * - Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 * - Neither the name of Analog Devices, Inc. nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 * - The use of this software may or may not infringe the patent rights
25 * of one or more patent holders. This license does not release you
26 * from the requirement that you obtain separate licenses from these
27 * patent holders to use this software.
28 * - Use of the software either in source or binary form, must be run
29 * on or directly connected to an Analog Devices Inc. component.
30 *
31 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
33 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
38 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ******************************************************************************/
42
43 #ifndef __AD717X_H__
44 #define __AD717X_H__
45
46 /*****************************************************************************/
47 /***************************** Include Files *********************************/
48 /*****************************************************************************/
49 #include <stdint.h>
50
51 typedef enum ad717x_crc_mode ad717x_crc_mode;
52
53 enum ad717x_crc_mode
54 {
55 AD717X_DISABLE,
56 AD717X_USE_CRC,
57 AD717X_USE_XOR,
58 };
59
60 /*! AD717X register info */
61 typedef struct _ad717x_st_reg
62 {
63 int32_t addr;
64 int32_t value;
65 int32_t size;
66 }ad717x_st_reg;
67
68 /*
69 * The structure describes the device and is used with the ad717x driver.
70 * @slave_select_id: The ID of the Slave Select to be passed to the SPI calls.
71 * @regs: A reference to the register list of the device that the user must
72 * provide when calling the Setup() function.
73 * @num_regs: The length of the register list.
74 * @userCRC: Error check type to use on SPI transfers.
75 */
76 struct ad717x_device {
77 uint8_t slave_select_id;
78 ad717x_st_reg *regs;
79 uint8_t num_regs;
80 ad717x_crc_mode useCRC;
81 };
82
83 /*****************************************************************************/
84 /***************** AD717X Register Definitions *******************************/
85 /*****************************************************************************/
86
87 /* AD717X Register Map */
88 #define AD717X_COMM_REG 0x00
89 #define AD717X_STATUS_REG 0x00
90 #define AD717X_ADCMODE_REG 0x01
91 #define AD717X_IFMODE_REG 0x02
92 #define AD717X_REGCHECK_REG 0x03
93 #define AD717X_DATA_REG 0x04
94 #define AD717X_GPIOCON_REG 0x06
95 #define AD717X_ID_REG 0x07
96 #define AD717X_CHMAP0_REG 0x10
97 #define AD717X_CHMAP1_REG 0x11
98 #define AD717X_CHMAP2_REG 0x12
99 #define AD717X_CHMAP3_REG 0x13
100 #define AD717X_CHMAP4_REG 0x14
101 #define AD717X_CHMAP5_REG 0x15
102 #define AD717X_CHMAP6_REG 0x16
103 #define AD717X_CHMAP7_REG 0x17
104 #define AD717X_CHMAP8_REG 0x18
105 #define AD717X_CHMAP9_REG 0x19
106 #define AD717X_CHMAP10_REG 0x1A
107 #define AD717X_CHMAP11_REG 0x1B
108 #define AD717X_CHMAP12_REG 0x1C
109 #define AD717X_CHMAP13_REG 0x1D
110 #define AD717X_CHMAP14_REG 0x1E
111 #define AD717X_CHMAP15_REG 0x1F
112 #define AD717X_SETUPCON0_REG 0x20
113 #define AD717X_SETUPCON1_REG 0x21
114 #define AD717X_SETUPCON2_REG 0x22
115 #define AD717X_SETUPCON3_REG 0x23
116 #define AD717X_SETUPCON4_REG 0x24
117 #define AD717X_SETUPCON5_REG 0x25
118 #define AD717X_SETUPCON6_REG 0x26
119 #define AD717X_SETUPCON7_REG 0x27
120 #define AD717X_FILTCON0_REG 0x28
121 #define AD717X_FILTCON1_REG 0x29
122 #define AD717X_FILTCON2_REG 0x2A
123 #define AD717X_FILTCON3_REG 0x2B
124 #define AD717X_FILTCON4_REG 0x2C
125 #define AD717X_FILTCON5_REG 0x2D
126 #define AD717X_FILTCON6_REG 0x2E
127 #define AD717X_FILTCON7_REG 0x2F
128 #define AD717X_OFFSET0_REG 0x30
129 #define AD717X_OFFSET1_REG 0x31
130 #define AD717X_OFFSET2_REG 0x32
131 #define AD717X_OFFSET3_REG 0x33
132 #define AD717X_OFFSET4_REG 0x34
133 #define AD717X_OFFSET5_REG 0x35
134 #define AD717X_OFFSET6_REG 0x36
135 #define AD717X_OFFSET7_REG 0x37
136 #define AD717X_GAIN0_REG 0x38
137 #define AD717X_GAIN1_REG 0x39
138 #define AD717X_GAIN2_REG 0x3A
139 #define AD717X_GAIN3_REG 0x3B
140 #define AD717X_GAIN4_REG 0x3C
141 #define AD717X_GAIN5_REG 0x3D
142 #define AD717X_GAIN6_REG 0x3E
143 #define AD717X_GAIN7_REG 0x3F
144
145 /* Communication Register bits */
146 #define AD717X_COMM_REG_WEN (0 << 7)
147 #define AD717X_COMM_REG_WR (0 << 6)
148 #define AD717X_COMM_REG_RD (1 << 6)
149 #define AD717X_COMM_REG_RA(x) ((x) & 0x3F)
150
151 /* Status Register bits */
152 #define AD717X_STATUS_REG_RDY (1 << 7)
153 #define AD717X_STATUS_REG_ADC_ERR (1 << 6)
154 #define AD717X_STATUS_REG_CRC_ERR (1 << 5)
155 #define AD717X_STATUS_REG_REG_ERR (1 << 4)
156 #define AD717X_STATUS_REG_CH(x) ((x) & 0x03)
157
158 /* ADC Mode Register bits */
159 #define AD717X_ADCMODE_REG_REF_EN (1 << 15)
160 #define AD717X_ADCMODE_SING_CYC (1 << 13)
161 #define AD717X_ADCMODE_REG_DELAY(x) (((x) & 0x7) << 8)
162 #define AD717X_ADCMODE_REG_MODE(x) (((x) & 0x7) << 4)
163 #define AD717X_ADCMODE_REG_CLKSEL(x)) (((x) & 0x3) << 2)
164
165 /* ADC Mode Register additional bits for AD7172-2 and AD7172-4 */
166 #define AD717X_ADCMODE_REG_HIDE_DELAY (1 << 14)
167
168 /* Interface Mode Register bits */
169 #define AD717X_IFMODE_REG_ALT_SYNC (1 << 12)
170 #define AD717X_IFMODE_REG_IOSTRENGTH (1 << 11)
171 #define AD717X_IFMODE_REG_HIDE_DELAY (1 << 10)
172 #define AD717X_IFMODE_REG_DOUT_RESET (1 << 8)
173 #define AD717X_IFMODE_REG_CONT_READ (1 << 7)
174 #define AD717X_IFMODE_REG_DATA_STAT (1 << 6)
175 #define AD717X_IFMODE_REG_REG_CHECK (1 << 5)
176 #define AD717X_IFMODE_REG_XOR_EN (0x01 << 2)
177 #define AD717X_IFMODE_REG_CRC_EN (0x02 << 2)
178 #define AD717X_IFMODE_REG_XOR_STAT(x) (((x) & AD717X_IFMODE_REG_XOR_EN) == AD717X_IFMODE_REG_XOR_EN)
179 #define AD717X_IFMODE_REG_CRC_STAT(x) (((x) & AD717X_IFMODE_REG_CRC_EN) == AD717X_IFMODE_REG_CRC_EN)
180 #define AD717X_IFMODE_REG_DATA_WL16 (1 << 0)
181
182 /* GPIO Configuration Register bits */
183 #define AD717X_GPIOCON_REG_MUX_IO (1 << 12)
184 #define AD717X_GPIOCON_REG_SYNC_EN (1 << 11)
185 #define AD717X_GPIOCON_REG_ERR_EN(x) (((x) & 0x3) << 9)
186 #define AD717X_GPIOCON_REG_ERR_DAT (1 << 8)
187 #define AD717X_GPIOCON_REG_IP_EN1 (1 << 5)
188 #define AD717X_GPIOCON_REG_IP_EN0 (1 << 4)
189 #define AD717X_GPIOCON_REG_OP_EN1 (1 << 3)
190 #define AD717X_GPIOCON_REG_OP_EN0 (1 << 2)
191 #define AD717X_GPIOCON_REG_DATA1 (1 << 1)
192 #define AD717X_GPIOCON_REG_DATA0 (1 << 0)
193
194 /* GPIO Configuration Register additional bits for AD7172-4, AD7173-8 */
195 #define AD717X_GPIOCON_REG_GP_DATA3 (1 << 7)
196 #define AD717X_GPIOCON_REG_GP_DATA2 (1 << 6)
197 #define AD717X_GPIOCON_REG_GP_DATA1 (1 << 1)
198 #define AD717X_GPIOCON_REG_GP_DATA0 (1 << 0)
199
200 /* GPIO Configuration Register additional bits for AD7173-8 */
201 #define AD717X_GPIOCON_REG_PDSW (1 << 14)
202 #define AD717X_GPIOCON_REG_OP_EN2_3 (1 << 13)
203
204 /* Channel Map Register 0-3 bits */
205 #define AD717X_CHMAP_REG_CH_EN (1 << 15)
206 #define AD717X_CHMAP_REG_SETUP_SEL(x) (((x) & 0x3) << 12)
207 #define AD717X_CHMAP_REG_AINPOS(x) (((x) & 0x1F) << 5)
208 #define AD717X_CHMAP_REG_AINNEG(x) (((x) & 0x1F) << 0)
209
210 /* Setup Configuration Register 0-3 bits */
211 #define AD717X_SETUP_CONF_REG_BI_UNIPOLAR (1 << 12)
212 #define AD717X_SETUP_CONF_REG_REF_SEL(x) (((x) & 0x3) << 4)
213
214 /* Setup Configuration Register additional bits for AD7173-8 */
215 #define AD717X_SETUP_CONF_REG_REF_BUF(x) (((x) & 0x3) << 10)
216 #define AD717X_SETUP_CONF_REG_AIN_BUF(x) (((x) & 0x3) << 8)
217 #define AD717X_SETUP_CONF_REG_BURNOUT_EN (1 << 7)
218 #define AD717X_SETUP_CONF_REG_BUFCHOPMAX (1 << 6)
219
220 /* Setup Configuration Register additional bits for AD7172-2, AD7172-4, AD7175-2 */
221 #define AD717X_SETUP_CONF_REG_REFBUF_P (1 << 11)
222 #define AD717X_SETUP_CONF_REG_REFBUF_N (1 << 10)
223 #define AD717X_SETUP_CONF_REG_AINBUF_P (1 << 9)
224 #define AD717X_SETUP_CONF_REG_AINBUF_N (1 << 8)
225
226 /* Filter Configuration Register 0-3 bits */
227 #define AD717X_FILT_CONF_REG_SINC3_MAP (1 << 15)
228 #define AD717X_FILT_CONF_REG_ENHFILTEN (1 << 11)
229 #define AD717X_FILT_CONF_REG_ENHFILT(x) (((x) & 0x7) << 8)
230 #define AD717X_FILT_CONF_REG_ORDER(x) (((x) & 0x3) << 5)
231 #define AD717X_FILT_CONF_REG_ODR(x) (((x) & 0x1F) << 0)
232
233 /*****************************************************************************/
234 /******************* AD717X Constants ****************************************/
235 /*****************************************************************************/
236 #define AD717X_CRC8_POLYNOMIAL_REPRESENTATION 0x07 /* x8 + x2 + x + 1 */
237
238 /*****************************************************************************/
239 /************************ Functions Declarations *****************************/
240 /*****************************************************************************/
241
242 /*! Retrieves a pointer to the register that matches the given address */
243 ad717x_st_reg *AD717X_GetReg(struct ad717x_device *device, uint8_t reg_address);
244
245 /*! Reads the value of the specified register. */
246 int32_t AD717X_ReadRegister(struct ad717x_device *device, uint8_t addr);
247
248 /*! Writes the value of the specified register. */
249 int32_t AD717X_WriteRegister(struct ad717x_device *device, uint8_t);
250
251 /*! Resets the device. */
252 int32_t AD717X_Reset(struct ad717x_device *device);
253
254 /*! Waits until a new conversion result is available. */
255 int32_t AD717X_WaitForReady(struct ad717x_device *device, uint32_t timeout);
256
257 /*! Reads the conversion result from the device. */
258 int32_t AD717X_ReadData(struct ad717x_device *device, int32_t* pData);
259
260 /*! Computes the CRC checksum for a data buffer. */
261 uint8_t AD717X_ComputeCRC8(uint8_t* pBuf, uint8_t bufSize);
262
263 /*! Computes the XOR checksum for a data buffer. */
264 uint8_t AD717X_ComputeXOR8(uint8_t * pBuf, uint8_t bufSize);
265
266 /*! Updates the CRC settings. */
267 int32_t AD717X_UpdateCRCSetting(struct ad717x_device *device);
268
269 /*! Initializes the AD717X. */
270 int32_t AD717X_Setup(struct ad717x_device *device, uint8_t slave_select,
271 ad717x_st_reg *regs, uint8_t num_regs);
272
273 #endif /* __AD717X_H__ */