Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD7193.h
3 * @brief Header file of AD7193 Driver.
4 * @author DNechita ([email protected])
5 ********************************************************************************
6 * Copyright 2012(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 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42
43 #ifndef __AD7193_H__
44 #define __AD7193_H__
45
46 /******************************************************************************/
47 /***************************** Include Files **********************************/
48 /******************************************************************************/
49 #include "Communication.h"
50
51 /******************************************************************************/
52 /******************************** AD7193 **************************************/
53 /******************************************************************************/
54
55 /* SPI slave device ID */
56 #define AD7193_SLAVE_ID 1
57
58 /* AD74XX Chip Select Pin declaration */
59 #define AD7193_CS_LOW SPI_CS_LOW
60 #define AD7193_CS_HIGH SPI_CS_HIGH
61
62 /* AD7193 GPIO */
63 #define AD7193_RDY_STATE SPI_MISO
64
65 /* AD7193 Register Map */
66 #define AD7193_REG_COMM 0 // Communications Register (WO, 8-bit)
67 #define AD7193_REG_STAT 0 // Status Register (RO, 8-bit)
68 #define AD7193_REG_MODE 1 // Mode Register (RW, 24-bit
69 #define AD7193_REG_CONF 2 // Configuration Register (RW, 24-bit)
70 #define AD7193_REG_DATA 3 // Data Register (RO, 24/32-bit)
71 #define AD7193_REG_ID 4 // ID Register (RO, 8-bit)
72 #define AD7193_REG_GPOCON 5 // GPOCON Register (RW, 8-bit)
73 #define AD7193_REG_OFFSET 6 // Offset Register (RW, 24-bit
74 #define AD7193_REG_FULLSCALE 7 // Full-Scale Register (RW, 24-bit)
75
76 /* Communications Register Bit Designations (AD7193_REG_COMM) */
77 #define AD7193_COMM_WEN (1 << 7) // Write Enable.
78 #define AD7193_COMM_WRITE (0 << 6) // Write Operation.
79 #define AD7193_COMM_READ (1 << 6) // Read Operation.
80 #define AD7193_COMM_ADDR(x) (((x) & 0x7) << 3) // Register Address.
81 #define AD7193_COMM_CREAD (1 << 2) // Continuous Read of Data Register.
82
83 /* Status Register Bit Designations (AD7193_REG_STAT) */
84 #define AD7193_STAT_RDY (1 << 7) // Ready.
85 #define AD7193_STAT_ERR (1 << 6) // ADC error bit.
86 #define AD7193_STAT_NOREF (1 << 5) // Error no external reference.
87 #define AD7193_STAT_PARITY (1 << 4) // Parity check of the data register.
88 #define AD7193_STAT_CH3 (1 << 3) // Channel 3.
89 #define AD7193_STAT_CH2 (1 << 2) // Channel 2.
90 #define AD7193_STAT_CH1 (1 << 1) // Channel 1.
91 #define AD7193_STAT_CH0 (1 << 0) // Channel 0.
92
93 /* Mode Register Bit Designations (AD7193_REG_MODE) */
94 #define AD7193_MODE_SEL(x) (((unsigned long)(x) & 0x7) << 21) // Operation Mode Select.
95 #define AD7193_MODE_DAT_STA ((unsigned long)1 << 20) // Status Register transmission.
96 #define AD7193_MODE_CLKSRC(x) (((unsigned long)(x) & 0x3) << 18) // Clock Source Select.
97 #define AD7193_MODE_AVG(x) (((unsigned long)(x) & 0x3) << 16) // Fast settling filter.
98 #define AD7193_MODE_SINC3 (1 << 15) // SINC3 Filter Select.
99 #define AD7193_MODE_ENPAR (1 << 13) // Parity Enable.
100 #define AD7193_MODE_CLKDIV (1 << 12) // Clock divide by 2 (AD7190/2 only).
101 #define AD7193_MODE_SCYCLE (1 << 11) // Single cycle conversion.
102 #define AD7193_MODE_REJ60 (1 << 10) // 50/60Hz notch filter.
103 #define AD7193_MODE_RATE(x) ((x) & 0x3FF) // Filter Update Rate Select.
104
105 /* Mode Register: AD7193_MODE_SEL(x) options */
106 #define AD7193_MODE_CONT 0 // Continuous Conversion Mode.
107 #define AD7193_MODE_SINGLE 1 // Single Conversion Mode.
108 #define AD7193_MODE_IDLE 2 // Idle Mode.
109 #define AD7193_MODE_PWRDN 3 // Power-Down Mode.
110 #define AD7193_MODE_CAL_INT_ZERO 4 // Internal Zero-Scale Calibration.
111 #define AD7193_MODE_CAL_INT_FULL 5 // Internal Full-Scale Calibration.
112 #define AD7193_MODE_CAL_SYS_ZERO 6 // System Zero-Scale Calibration.
113 #define AD7193_MODE_CAL_SYS_FULL 7 // System Full-Scale Calibration.
114
115 /* Mode Register: AD7193_MODE_CLKSRC(x) options */
116 #define AD7193_CLK_EXT_MCLK1_2 0 // External crystal. The external crystal
117 // is connected from MCLK1 to MCLK2.
118 #define AD7193_CLK_EXT_MCLK2 1 // External Clock applied to MCLK2
119 #define AD7193_CLK_INT 2 // Internal 4.92 MHz clock.
120 // Pin MCLK2 is tristated.
121 #define AD7193_CLK_INT_CO 3 // Internal 4.92 MHz clock. The internal
122 // clock is available on MCLK2.
123
124 /* Mode Register: AD7193_MODE_AVG(x) options */
125 #define AD7193_AVG_NONE 0 // No averaging (fast settling mode disabled).
126 #define AD7193_AVG_BY_2 1 // Average by 2.
127 #define AD7193_AVG_BY_8 2 // Average by 8.
128 #define AD7193_AVG_BY_16 3 // Average by 16.
129
130 /* Configuration Register Bit Designations (AD7193_REG_CONF) */
131 #define AD7193_CONF_CHOP ((unsigned long)1 << 23) // CHOP enable.
132 #define AD7193_CONF_REFSEL ((unsigned long)1 << 20) // REFIN1/REFIN2 Reference Select.
133 #define AD7193_CONF_PSEUDO ((unsigned long)1 << 18) // Pseudo differential analog inputs.
134 #define AD7193_CONF_CHAN(x) ((unsigned long)((x) & 0x3FF) << 8) // Channel select.
135 #define AD7193_CONF_BURN (1 << 7) // Burnout current enable.
136 #define AD7193_CONF_REFDET (1 << 6) // Reference detect enable.
137 #define AD7193_CONF_BUF (1 << 4) // Buffered Mode Enable.
138 #define AD7193_CONF_UNIPOLAR (1 << 3) // Unipolar/Bipolar Enable.
139 #define AD7193_CONF_GAIN(x) ((x) & 0x7) // Gain Select.
140
141 /* Configuration Register: AD7193_CONF_CHAN(x) options */
142 // Pseudo Bit = 0 Pseudo Bit = 1
143 #define AD7193_CH_0 0 // AIN1(+) - AIN2(-); AIN1 - AINCOM
144 #define AD7193_CH_1 1 // AIN3(+) - AIN4(-); AIN2 - AINCOM
145 #define AD7193_CH_2 2 // AIN5(+) - AIN6(-); AIN3 - AINCOM
146 #define AD7193_CH_3 3 // AIN7(+) - AIN8(-); AIN4 - AINCOM
147 #define AD7193_CH_4 4 // AIN1(+) - AIN2(-); AIN5 - AINCOM
148 #define AD7193_CH_5 5 // AIN3(+) - AIN4(-); AIN6 - AINCOM
149 #define AD7193_CH_6 6 // AIN5(+) - AIN6(-); AIN7 - AINCOM
150 #define AD7193_CH_7 7 // AIN7(+) - AIN8(-); AIN8 - AINCOM
151 #define AD7193_CH_TEMP 8 // Temperature sensor
152 #define AD7193_CH_SHORT 9 // AIN2(+) - AIN2(-); AINCOM(+) - AINCOM(-)
153
154 /* Configuration Register: AD7193_CONF_GAIN(x) options */
155 // ADC Input Range (5 V Reference)
156 #define AD7193_CONF_GAIN_1 0 // Gain 1 +-2.5 V
157 #define AD7193_CONF_GAIN_8 3 // Gain 8 +-312.5 mV
158 #define AD7193_CONF_GAIN_16 4 // Gain 16 +-156.2 mV
159 #define AD7193_CONF_GAIN_32 5 // Gain 32 +-78.125 mV
160 #define AD7193_CONF_GAIN_64 6 // Gain 64 +-39.06 mV
161 #define AD7193_CONF_GAIN_128 7 // Gain 128 +-19.53 mV
162
163 /* ID Register Bit Designations (AD7193_REG_ID) */
164 #define ID_AD7193 0x2
165 #define AD7193_ID_MASK 0x0F
166
167 /* GPOCON Register Bit Designations (AD7193_REG_GPOCON) */
168 #define AD7193_GPOCON_BPDSW (1 << 6) // Bridge power-down switch enable
169 #define AD7193_GPOCON_GP32EN (1 << 5) // Digital Output P3 and P2 enable
170 #define AD7193_GPOCON_GP10EN (1 << 4) // Digital Output P1 and P0 enable
171 #define AD7193_GPOCON_P3DAT (1 << 3) // P3 state
172 #define AD7193_GPOCON_P2DAT (1 << 2) // P2 state
173 #define AD7193_GPOCON_P1DAT (1 << 1) // P1 state
174 #define AD7193_GPOCON_P0DAT (1 << 0) // P0 state
175
176 /******************************************************************************/
177 /************************ Functions Declarations ******************************/
178 /******************************************************************************/
179
180 /*! Checks if the AD7139 part is present. */
181 char AD7193_Init(void);
182
183 /*! Writes data into a register. */
184 void AD7193_SetRegisterValue(unsigned char registerAddress,
185 unsigned long registerValue,
186 unsigned char bytesNumber,
187 unsigned char modifyCS);
188
189 /*! Reads the value of a register. */
190 unsigned long AD7193_GetRegisterValue(unsigned char registerAddress,
191 unsigned char bytesNumber,
192 unsigned char modifyCS);
193
194 /*! Resets the device. */
195 void AD7193_Reset(void);
196
197 /*! Set device to idle or power-down. */
198 void AD7193_SetPower(unsigned char pwrMode);
199
200 /*! Waits for RDY pin to go low. */
201 void AD7193_WaitRdyGoLow(void);
202
203 /*! Selects the channel to be enabled. */
204 void AD7193_ChannelSelect(unsigned short channel);
205
206 /*! Performs the given calibration to the specified channel. */
207 void AD7193_Calibrate(unsigned char mode, unsigned char channel);
208
209 /*! Selects the polarity of the conversion and the ADC input range. */
210 void AD7193_RangeSetup(unsigned char polarity, unsigned char range);
211
212 /*! Returns the result of a single conversion. */
213 unsigned long AD7193_SingleConversion(void);
214
215 /*! Returns the average of several conversion results. */
216 unsigned long AD7193_ContinuousReadAvg(unsigned char sampleNumber);
217
218 /*! Read data from temperature sensor and converts it to Celsius degrees. */
219 float AD7193_TemperatureRead(void);
220
221 /*! Converts 24-bit raw data to volts. */
222 float AD7193_ConvertToVolts(unsigned long rawData, float vRef);
223
224 #endif /* __AD7193_H__ */