Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file AD7156.h
3 * @brief Header file of AD7156 Driver.
4 * @author DNechita([email protected])
5 ********************************************************************************
6 * Copyright 2013(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 #ifndef __AD7156_H__
41 #define __AD7156_H__
42
43 /******************************************************************************/
44 /*************************** AD7156 Definitions *******************************/
45 /******************************************************************************/
46 /*!< AD7156 slave address */
47 #define AD7156_ADDRESS 0x48
48
49 /*!< AD7156 registers */
50 #define AD7156_REG_STATUS 0x00
51 #define AD7156_REG_CH1_DATA_H 0x01
52 #define AD7156_REG_CH1_DATA_L 0x02
53 #define AD7156_REG_CH2_DATA_H 0x03
54 #define AD7156_REG_CH2_DATA_L 0x04
55 #define AD7156_REG_CH1_AVG_H 0x05
56 #define AD7156_REG_CH1_AVG_L 0x06
57 #define AD7156_REG_CH2_AVG_H 0x07
58 #define AD7156_REG_CH2_AVG_L 0x08
59 #define AD7156_REG_CH1_SENS_THRSH_H 0x09
60 #define AD7156_REG_CH1_TMO_THRSH_L 0x0A
61 #define AD7156_REG_CH1_SETUP 0x0B
62 #define AD7156_REG_CH2_SENS_THRSH_H 0x0C
63 #define AD7156_REG_CH2_TMO_THRSH_L 0x0D
64 #define AD7156_REG_CH2_SETUP 0x0E
65 #define AD7156_REG_CONFIG 0x0F
66 #define AD7156_REG_PWR_DWN_TMR 0x10
67 #define AD7156_REG_CH1_CAPDAC 0x11
68 #define AD7156_REG_CH2_CAPDAC 0x12
69 #define AD7156_REG_SERIAL_N3 0x13
70 #define AD7156_REG_SERIAL_N2 0x14
71 #define AD7156_REG_SERIAL_N1 0x15
72 #define AD7156_REG_SERIAL_N0 0x16
73 #define AD7156_REG_CHIP_ID 0x17
74
75 /*!< AD7156_REG_STATUS definition */
76 #define AD7156_STATUS_PWR_DWN (1 << 7)
77 #define AD7156_STATUS_DAC_STEP2 (1 << 6)
78 #define AD7156_STATUS_OUT2 (1 << 5)
79 #define AD7156_STATUS_DAC_STEP1 (1 << 4)
80 #define AD7156_STATUS_OUT1 (1 << 3)
81 #define AD7156_STATUS_C1_C2 (1 << 2)
82 #define AD7156_STATUS_RDY2 (1 << 1)
83 #define AD7156_STATUS_RDY1 (1 << 0)
84
85 /*!< AD7156_REG_CH1_SETUP definition */
86 #define AD7156_CH1_SETUP_RANGE(x) (((x) & 0x3) << 6)
87 #define AD7156_CH1_SETUP_HYST1 (1 << 4)
88 #define AD7156_CH1_SETUP_THR1(x) ((x) & 0xF)
89
90 /*!< AD7156_REG_CH2_SETUP definition */
91 #define AD7156_CH2_SETUP_RANGE(x) (((x) & 0x3) << 6)
92 #define AD7156_CH2_SETUP_HYST2 (1 << 4)
93 #define AD7156_CH2_SETUP_THR2(x) ((x) & 0xF)
94
95 /*!< AD7156_CH1_SETUP_RANGE(x) and AD7156_CH2_SETUP_RANGE(x) options */
96 #define AD7156_CDC_RANGE_2_PF 0
97 #define AD7156_CDC_RANGE_0_5_PF 1
98 #define AD7156_CDC_RANGE_1_PF 2
99 #define AD7156_CDC_RANGE_4_PF 3
100
101 /*!< AD7156_REG_CONFIG definition */
102 #define AD7156_CONFIG_THR_FIXED (1 << 7)
103 #define AD7156_CONFIG_THR_MD(x) (((x) & 0x3) << 5)
104 #define AD7156_CONFIG_EN_CH1 (1 << 4)
105 #define AD7156_CONFIG_EN_CH2 (1 << 3)
106 #define AD7156_CONFIG_MD(x) ((x) & 0x7)
107
108 /*!< AD7156_CONFIG_THR_FIXED options */
109 #define AD7156_ADAPTIVE_THRESHOLD 0
110 #define AD7156_FIXED_THRESHOLD 1
111
112 /*!< AD7156_CONFIG_THR_MD(x) options */
113 #define AD7156_THR_MODE_NEGATIVE 0
114 #define AD7156_THR_MODE_POSITIVE 1
115 #define AD7156_THR_MODE_IN_WINDOW 2
116 #define AD7156_THR_MODE_OU_WINDOW 3
117
118 /*!< AD7156_CONFIG_MD(x) options */
119 #define AD7156_CONV_MODE_IDLE 0
120 #define AD7156_CONV_MODE_CONT_CONV 1
121 #define AD7156_CONV_MODE_SINGLE_CONV 2
122 #define AD7156_CONV_MODE_PWR_DWN 3
123
124 /*!< AD7156_REG_PWR_DWN_TMR definition */
125 #define AD7156_PWR_DWN_TMR_TIMEOUT(x) (((x) & 0x3F) | (1 << 6))
126
127 /*!< AD7156_REG_CH1_CAPDAC */
128 #define AD7156_CH1_CAPDAC_DAC_EN1 (1 << 7)
129 #define AD7156_CH1_CAPDAC_DAC_AUTO1 (1 << 6)
130 #define AD7156_CH1_CAPDAC_DAC_VAL1(x) ((x) & 0x3F)
131
132 /*!< AD7156_REG_CH2_CAPDAC */
133 #define AD7156_CH2_CAPDAC_DAC_EN2 (1 << 7)
134 #define AD7156_CH2_CAPDAC_DAC_AUTO2 (1 << 6)
135 #define AD7156_CH2_CAPDAC_DAC_VAL2(x) ((x) & 0x3F)
136
137 /*!< Chip identification code */
138 #define AD7156_DEFAULT_ID 0x88
139
140 /*!< AD7156 Reset Command */
141 #define AD7156_RESET_CMD 0xBF
142
143 /*!< AD7156 Channels */
144 #define AD7156_CHANNEL1 1
145 #define AD7156_CHANNEL2 2
146
147 /******************************************************************************/
148 /************************ Functions Declarations ******************************/
149 /******************************************************************************/
150
151 /*!< Performs a burst read of a specified number of registers. */
152 void AD7156_GetRegisterValue(unsigned char* pReadData,
153 unsigned char registerAddress,
154 unsigned char bytesNumber);
155
156 /*!< Writes data into one or two registers.. */
157 void AD7156_SetRegisterValue(unsigned short registerValue,
158 unsigned char registerAddress,
159 unsigned char bytesNumber);
160 /*!< Initializes the communication peripheral and checks if the device is
161 present. */
162 char AD7156_Init(void);
163
164 /*!< Resets the device. */
165 void AD7156_Reset(void);
166
167 /*!< Sets the converter mode of operation. */
168 void AD7156_SetPowerMode(unsigned char pwrMode);
169
170 /*!< Enables or disables conversion on the selected channel. */
171 void AD7156_ChannelState(unsigned char channel, unsigned char enableConv);
172
173 /*!< Sets the input range of the specified channel. */
174 void AD7156_SetRange(unsigned channel, unsigned char range);
175
176 /*!< Reads the range bits from the device and returns the range in pF. */
177 float AD7156_GetRange(unsigned channel);
178
179 /*!< Selects the threshold mode of operation. */
180 void AD7156_SetThresholdMode(unsigned char thrMode, unsigned char thrFixed);
181
182 /*!< Writes to the threshold register when threshold fixed mode is enabled. */
183 void AD7156_SetThreshold(unsigned char channel, float pFthr);
184
185 /*!< Writes a value(pF) to the sensitivity register. This functions
186 should be used when adaptive threshold mode is selected. */
187 void AD7156_SetSensitivity(unsigned char channel, float pFsensitivity);
188
189 /*!< Reads a 12-bit sample from the selected channel */
190 unsigned short AD7156_ReadChannelData(unsigned char channel);
191
192 /*!< Waits for a finished CDC conversion and reads a 12-bit sample from
193 the selected channel. */
194 unsigned short AD7156_WaitReadChannelData(unsigned char channel);
195
196 /*!< Reads a sample the selected channel and converts the data to
197 picofarads(pF). */
198 float AD7156_ReadChannelCapacitance(unsigned char channel);
199
200 /*!< Waits for a finished CDC conversion the selected channel, reads a
201 sample and converts the data to picofarads(pF). */
202 float AD7156_WaitReadChannelCapacitance(unsigned char channel);
203
204 #endif /* __AD7156_H__ */