Debian Codegraph @

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

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad5766.h
3 * @brief Header file of AD5766 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 AD5766_H_
40 #define AD5766_H_
41
42 /******************************************************************************/
43 /********************** Macros and Constants Definitions **********************/
44 /******************************************************************************/
45 #define AD5766_CMD_NOP_MUX_OUT 0x00
46 #define AD5766_CMD_SDO_CNTRL 0x01
47 #define AD5766_CMD_WR_IN_REG(x) (0x10 | ((x) & 0xF))
48 #define AD5766_CMD_WR_DAC_REG(x) (0x20 | ((x) & 0xF))
49 #define AD5766_CMD_SW_LDAC 0x30
50 #define AD5766_CMD_SPAN_REG 0x40
51 #define AD5766_CMD_WR_PWR_DAC 0x50
52 #define AD5766_CMD_WR_PWR_DITHER 0x51
53 #define AD5766_CMD_WR_DAC_REG_ALL 0x60
54 #define AD5766_CMD_SW_FULL_RESET 0x70
55 #define AD5766_CMD_READBACK_REG(x) (0x80 | ((x) & 0xF))
56 #define AD5766_CMD_DITHER_SIG_1 0x90
57 #define AD5766_CMD_DITHER_SIG_2 0xA0
58 #define AD5766_CMD_INV_DITHER 0xB0
59 #define AD5766_CMD_DITHER_SCALE_1 0xC0
60 #define AD5766_CMD_DITHER_SCALE_2 0xD0
61
62 /* AD5766_CMD_SDO_CNTRL */
63 #define AD5766_SDO_EN (1 << 0)
64
65 /* AD5766_CMD_SW_LDAC */
66 #define AD5766_LDAC(x) (1 << ((x) & 0xF))
67
68 /* AD5766_CMD_SPAN_REG */
69 #define AD5766_CFG_CLR(x) (((x) & 0x3) << 3)
70 #define AD5766_SPAN(x) (((x) & 0x7) << 0)
71
72 /* AD5766_CMD_WR_PWR_DAC, AD5766_CMD_WR_PWR_DITHER */
73 #define AD5766_PWDN(x) (1 << ((x) & 0xF))
74
75 /* AD5766_CMD_SW_FULL_RESET */
76 #define AD5766_RESET 0x1234
77
78 /* AD5766_CMD_DITHER_SIG_x */
79 #define AD5766_N0(x) (1 << (2 * ((x) & 0xF)))
80 #define AD5766_N1(x) (2 << (2 * ((x) & 0xF)))
81
82 /* AD5766_CMD_INV_DITHER */
83 #define AD5766_INV_D(x) (1 << ((x) & 0xF))
84
85 /* AD5766_CMD_DITHER_SCALE_x */
86 #define AD5766_75(x) (1 << (2 * ((x) & 0xF)))
87 #define AD5766_50(x) (2 << (2 * ((x) & 0xF)))
88 #define AD5766_25(x) (3 << (2 * ((x) & 0xF)))
89
90 /******************************************************************************/
91 /*************************** Types Declarations *******************************/
92 /******************************************************************************/
93 typedef enum {
94 AD5766_ENABLE,
95 AD5766_DISABLE,
96 } ad5766_state;
97
98 typedef enum {
99 AD5766_DAC_0,
100 AD5766_DAC_1,
101 AD5766_DAC_2,
102 AD5766_DAC_3,
103 AD5766_DAC_4,
104 AD5766_DAC_5,
105 AD5766_DAC_6,
106 AD5766_DAC_7,
107 AD5766_DAC_8,
108 AD5766_DAC_9,
109 AD5766_DAC_10,
110 AD5766_DAC_11,
111 AD5766_DAC_12,
112 AD5766_DAC_13,
113 AD5766_DAC_14,
114 AD5766_DAC_15,
115 } ad5766_dac;
116
117 typedef enum {
118 AD5766_M_20V_TO_0V,
119 AD5766_M_16V_TO_0V,
120 AD5766_M_10V_TO_0V,
121 AD5766_M_12V_TO_P_14V,
122 AD5766_M_16V_TO_P_10V,
123 AD5766_M_5V_TO_P_6V,
124 AD5766_M_10V_TO_P_10V,
125 } ad5766_span;
126
127 typedef enum {
128 AD5766_ZERO,
129 AD5766_MID,
130 AD5766_FULL,
131 } ad5766_clr;
132
133 typedef struct {
134 /* SPI */
135 spi_device spi_dev;
136 /* GPIO */
137 gpio_device gpio_dev;
138 int8_t gpio_reset;
139 /* Device Settings */
140 ad5766_state daisy_chain_en;
141 } ad5766_dev;
142
143 typedef struct {
144 /* SPI */
145 uint8_t spi_chip_select;
146 spi_mode spi_mode;
147 spi_type spi_type;
148 uint32_t spi_device_id;
149 /* GPIO */
150 gpio_type gpio_type;
151 uint32_t gpio_device_id;
152 int8_t gpio_reset;
153 /* Device Settings */
154 ad5766_state daisy_chain_en;
155 ad5766_clr clr;
156 ad5766_span span;
157 uint16_t pwr_dac_setting;
158 uint16_t pwr_dither_setting;
159 uint32_t dither_signal_setting;
160 uint16_t inv_dither_setting;
161 uint32_t dither_scale_setting;
162 } ad5766_init_param;
163
164 /******************************************************************************/
165 /************************ Functions Declarations ******************************/
166 /******************************************************************************/
167 /* SPI command write to device. */
168 int32_t ad5766_spi_cmd_write(ad5766_dev *dev,
169 uint8_t cmd,
170 uint16_t data);
171 /* SPI readback register from device. */
172 int32_t ad5766_spi_readback_reg(ad5766_dev *dev,
173 ad5766_dac dac,
174 uint32_t *data);
175 /* Set software LDAC for the selected channels. */
176 int32_t ad5766_set_sw_ldac(ad5766_dev *dev,
177 uint16_t setting);
178 /* Set clear code and span settings. */
179 int32_t ad5766_set_clr_span(ad5766_dev *dev,
180 ad5766_clr clr,
181 ad5766_span span);
182 /* Power down the selected channels. */
183 int32_t ad5766_set_pwr_dac(ad5766_dev *dev,
184 uint16_t setting);
185 /* Power down the dither block for the selected channels. */
186 int32_t ad5766_set_pwr_dither(ad5766_dev *dev,
187 uint16_t setting);
188 /* Enable the dither signal for the selected channels. */
189 int32_t ad5766_set_dither_signal(ad5766_dev *dev,
190 uint32_t setting);
191 /* Invert the dither signal for the selected channels. */
192 int32_t ad5766_set_inv_dither(ad5766_dev *dev,
193 uint16_t setting);
194 /* Enable the dither scaling for the selected channels. */
195 int32_t ad5766_set_dither_scale(ad5766_dev *dev,
196 uint32_t setting);
197 /* Do a software reset. */
198 int32_t ad5766_do_soft_reset(ad5766_dev *dev);
199 /* Set the input register for the selected channel. */
200 int32_t ad5766_set_in_reg(ad5766_dev *dev,
201 ad5766_dac dac,
202 uint16_t data);
203 /* Set the DAC register for the selected channel. */
204 int32_t ad5766_set_dac_reg(ad5766_dev *dev,
205 ad5766_dac dac,
206 uint16_t data);
207 /* Set the DAC register for all channels. */
208 int32_t ad5766_set_dac_reg_all(ad5766_dev *dev,
209 ad5766_dac dac,
210 uint16_t data);
211 /* Initialize the device. */
212 int32_t ad5766_setup(ad5766_dev **device,
213 ad5766_init_param init_param);
214 #endif // AD5766_H_