Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad5761r.h
3 * @brief Header file of AD5761R Driver.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2015(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 /******************************************************************************/
41 /********************** Macros and Constants Definitions **********************/
42 /******************************************************************************/
43
44 #ifndef AD5761R_H_
45 #define AD5761R_H_
46
47 /* Input Shift Register Format */
48 #define AD5761R_INPUT_ZERO_BIT (1 << 20)
49 #define AD5761R_INPUT_ADDR_CMD(x) (((x) & 0xF) << 16)
50 #define AD5761R_INPUT_DATA(x) (((x) & 0xFFFF) << 0)
51
52 #define AD5761R_DATA(x) (((x) & 0xFFFF) << 0)
53 #define AD5721R_DATA(x) (((x) & 0xFFF) << 4)
54
55 /* Input Shift Register Commands */
56 #define CMD_NOP 0x0
57 #define CMD_WR_TO_INPUT_REG 0x1
58 #define CMD_UPDATE_DAC_REG 0x2
59 #define CMD_WR_UPDATE_DAC_REG 0x3
60 #define CMD_WR_CTRL_REG 0x4
61 #define CMD_NOP_ALT_1 0x5
62 #define CMD_NOP_ALT_2 0x6
63 #define CMD_SW_DATA_RESET 0x7
64 #define CMD_RESERVED 0x8
65 #define CMD_DIS_DAISY_CHAIN 0x9
66 #define CMD_RD_INPUT_REG 0xA
67 #define CMD_RD_DAC_REG 0xB
68 #define CMD_RD_CTRL_REG 0xC
69 #define CMD_NOP_ALT_3 0xD
70 #define CMD_NOP_ALT_4 0xE
71 #define CMD_SW_FULL_RESET 0xF
72
73 /* Control Register Format */
74 #define AD5761R_CTRL_SC (1 << 12) // RO
75 #define AD5761R_CTRL_BO (1 << 11) // RO
76 #define AD5761R_CTRL_CV(x) (((x) & 0x3) << 9) // RW
77 #define AD5761R_CTRL_OVR (1 << 8) // RW
78 #define AD5761R_CTRL_B2C (1 << 7) // RW
79 #define AD5761R_CTRL_ETS (1 << 6) // RW
80 #define AD5761R_CTRL_IRO (1 << 5) // RW
81 #define AD5761R_CTRL_PV(x) (((x) & 0x3) << 3) // RW
82 #define AD5761R_CTRL_RA(x) (((x) & 0x7) << 0) // RW
83
84 /* Disable Daisy-Chain Register Format */
85 #define AD5761R_DIS_DAISY_CHAIN_DDC(x) (((x) & 0x1) << 0)
86
87 /******************************************************************************/
88 /*************************** Types Declarations *******************************/
89 /******************************************************************************/
90
91 typedef enum {
92 AD5761R,
93 AD5721R,
94 } ad5761r_type;
95
96 typedef enum {
97 AD5761R_REG_INPUT,
98 AD5761R_REG_DAC,
99 AD5761R_REG_CTRL,
100 } ad5761r_reg;
101
102 typedef enum {
103 AD5761R_SCALE_ZERO,
104 AD5761R_SCALE_HALF,
105 AD5761R_SCALE_FULL,
106 } ad5761r_scale;
107
108 typedef enum {
109 AD5761R_RANGE_M_10V_TO_P_10V,
110 AD5761R_RANGE_0_V_TO_P_10V,
111 AD5761R_RANGE_M_5V_TO_P_5V,
112 AD5761R_RANGE_0V_TO_P_5V,
113 AD5761R_RANGE_M_2V5_TO_P_7V5,
114 AD5761R_RANGE_M_3V_TO_P_3V,
115 AD5761R_RANGE_0V_TO_P_16V,
116 AD5761R_RANGE_0V_TO_P_20V,
117 } ad5761r_range;
118
119 typedef struct {
120 ad5761r_type type;
121 uint8_t spi_ss;
122 uint8_t gpio_reset;
123 uint8_t gpio_reset_value;
124 uint8_t gpio_clr;
125 uint8_t gpio_clr_value;
126 uint8_t gpio_ldac;
127 uint8_t gpio_ldac_value;
128 ad5761r_range ra;
129 ad5761r_scale pv;
130 ad5761r_scale cv;
131 bool int_ref_en;
132 bool exc_temp_sd_en;
133 bool b2c_range_en;
134 bool ovr_en;
135 bool daisy_chain_en;
136 } ad5761r_dev;
137
138 typedef struct {
139 ad5761r_type type;
140 uint8_t spi_ss;
141 uint8_t gpio_reset;
142 uint8_t gpio_reset_value;
143 uint8_t gpio_clr;
144 uint8_t gpio_clr_value;
145 uint8_t gpio_ldac;
146 uint8_t gpio_ldac_value;
147 ad5761r_range out_range;
148 ad5761r_scale pwr_voltage;
149 ad5761r_scale clr_voltage;
150 bool int_ref_en;
151 bool exc_temp_sd_en;
152 bool b2c_range_en;
153 bool ovr_en;
154 bool daisy_chain_en;
155 } ad5761r_init_param;
156
157 /******************************************************************************/
158 /************************ Functions Declarations ******************************/
159 /******************************************************************************/
160 /* Initialize the device. */
161 int32_t ad5761r_init(ad5761r_dev **device,
162 ad5761r_init_param init_param);
163 /* SPI write to device. */
164 int32_t ad5761r_write(ad5761r_dev *dev,
165 uint8_t reg_addr_cmd,
166 uint16_t reg_data);
167 /* SPI read from device. */
168 int32_t ad5761r_read(ad5761r_dev *dev,
169 uint8_t reg_addr_cmd,
170 uint16_t *reg_data);
171 /* Readback the register data. */
172 int32_t ad5761r_register_readback(ad5761r_dev *dev,
173 ad5761r_reg reg,
174 uint16_t *reg_data);
175 /* Configure the part based on the settings stored in the device structure. */
176 int32_t ad5761r_config(ad5761r_dev *dev);
177 /* Enable/disable daisy-chain mode. */
178 int32_t ad5761r_set_daisy_chain_en_dis(ad5761r_dev *dev,
179 bool en_dis);
180 /* Get the status of the daisy-chain mode. */
181 int32_t ad5761r_get_daisy_chain_en_dis(ad5761r_dev *dev,
182 bool *en_dis);
183 /* Set the output_range. */
184 int32_t ad5761r_set_output_range(ad5761r_dev *dev,
185 ad5761r_range out_range);
186 /* Get the output_range. */
187 int32_t ad5761r_get_output_range(ad5761r_dev *dev,
188 ad5761r_range *out_range);
189 /* Set the power up voltage. */
190 int32_t ad5761r_set_power_up_voltage(ad5761r_dev *dev,
191 ad5761r_scale pv);
192 /* Get the power up voltage. */
193 int32_t ad5761r_get_power_up_voltage(ad5761r_dev *dev,
194 ad5761r_scale *pv);
195 /* Set the clear voltage. */
196 int32_t ad5761r_set_clear_voltage(ad5761r_dev *dev,
197 ad5761r_scale cv);
198 /* Get the clear voltage. */
199 int32_t ad5761r_get_clear_voltage(ad5761r_dev *dev,
200 ad5761r_scale *cv);
201 /* Enable/disable internal reference. */
202 int32_t ad5761r_set_internal_reference_en_dis(ad5761r_dev *dev,
203 bool en_dis);
204 /* Get the status of the internal reference. */
205 int32_t ad5761r_get_internal_reference_en_dis(ad5761r_dev *dev,
206 bool *en_dis);
207 /* Enable/disable ETS (exceed temperature shutdown) function. */
208 int32_t ad5761r_set_exceed_temp_shutdown_en_dis(ad5761r_dev *dev,
209 bool en_dis);
210 /* Get the status of the ETS (exceed temperature shutdown) function. */
211 int32_t ad5761r_get_exceed_temp_shutdown_en_dis(ad5761r_dev *dev,
212 bool *en_dis);
213 /* Enable/disable the twos complement bipolar output range. */
214 int32_t ad5761r_set_2c_bipolar_range_en_dis(ad5761r_dev *dev,
215 bool en_dis);
216 /* Get the status of the twos complement bipolar output range. */
217 int32_t ad5761r_get_2c_bipolar_range_en_dis(ad5761r_dev *dev,
218 bool *en_dis);
219 /* Enable/disable the 5% overrange. */
220 int32_t ad5761r_set_overrange_en_dis(ad5761r_dev *dev,
221 bool en_dis);
222 /* Get the status of the 5% overrange. */
223 int32_t ad5761r_get_overrange_en_dis(ad5761r_dev *dev,
224 bool *en_dis);
225 /* Get the short-circuit condition. */
226 int32_t ad5761r_get_short_circuit_condition(ad5761r_dev *dev,
227 bool *sc);
228 /* Get the brownout condition. */
229 int32_t ad5761r_get_brownout_condition(ad5761r_dev *dev,
230 bool *bo);
231 /* Set the reset pin value. */
232 int32_t ad5761r_set_reset_pin(ad5761r_dev *dev,
233 uint8_t value);
234 /* Get the reset pin value. */
235 int32_t ad5761r_get_reset_pin(ad5761r_dev *dev,
236 uint8_t *value);
237 /* Set the clr pin value. */
238 int32_t ad5761r_set_clr_pin(ad5761r_dev *dev,
239 uint8_t value);
240 /* Get the clr pin value. */
241 int32_t ad5761r_get_clr_pin(ad5761r_dev *dev,
242 uint8_t *value);
243 /* Set the ldac pin value. */
244 int32_t ad5761r_set_ldac_pin(ad5761r_dev *dev,
245 uint8_t value);
246 /* Get the ldac pin value. */
247 int32_t ad5761r_get_ldac_pin(ad5761r_dev *dev,
248 uint8_t *value);
249 /* Write to input register. */
250 int32_t ad5761r_write_input_register(ad5761r_dev *dev,
251 uint16_t reg_data);
252 /* Update DAC register. */
253 int32_t ad5761r_update_dac_register(ad5761r_dev *dev);
254 /* Write to input register and update DAC register. */
255 int32_t ad5761r_write_update_dac_register(ad5761r_dev *dev,
256 uint16_t reg_data);
257 /*Software data reset. */
258 int32_t ad5761r_software_data_reset(ad5761r_dev *dev);
259 /* Software full reset. */
260 int32_t ad5761r_software_full_reset(ad5761r_dev *dev);
261
262 #endif // AD5761R_H_