no-OS
ad5766.h
Go to the documentation of this file.
1 /***************************************************************************/
33 #ifndef AD5766_H_
34 #define AD5766_H_
35 
36 /******************************************************************************/
37 /***************************** Include Files **********************************/
38 /******************************************************************************/
39 #include <stdint.h>
40 #include "no_os_delay.h"
41 #include "no_os_gpio.h"
42 #include "no_os_spi.h"
43 
44 /******************************************************************************/
45 /********************** Macros and Constants Definitions **********************/
46 /******************************************************************************/
47 #define AD5766_CMD_NOP_MUX_OUT 0x00
48 #define AD5766_CMD_SDO_CNTRL 0x01
49 #define AD5766_CMD_WR_IN_REG(x) (0x10 | ((x) & 0xF))
50 #define AD5766_CMD_WR_DAC_REG(x) (0x20 | ((x) & 0xF))
51 #define AD5766_CMD_SW_LDAC 0x30
52 #define AD5766_CMD_SPAN_REG 0x40
53 #define AD5766_CMD_WR_PWR_DAC 0x50
54 #define AD5766_CMD_WR_PWR_DITHER 0x51
55 #define AD5766_CMD_WR_DAC_REG_ALL 0x60
56 #define AD5766_CMD_SW_FULL_RESET 0x70
57 #define AD5766_CMD_READBACK_REG(x) (0x80 | ((x) & 0xF))
58 #define AD5766_CMD_DITHER_SIG_1 0x90
59 #define AD5766_CMD_DITHER_SIG_2 0xA0
60 #define AD5766_CMD_INV_DITHER 0xB0
61 #define AD5766_CMD_DITHER_SCALE_1 0xC0
62 #define AD5766_CMD_DITHER_SCALE_2 0xD0
63 
64 /* AD5766_CMD_SDO_CNTRL */
65 #define AD5766_SDO_EN (1 << 0)
66 
67 /* AD5766_CMD_SW_LDAC */
68 #define AD5766_LDAC(x) (1 << ((x) & 0xF))
69 
70 /* AD5766_CMD_SPAN_REG */
71 #define AD5766_CFG_CLR(x) (((x) & 0x3) << 3)
72 #define AD5766_SPAN(x) (((x) & 0x7) << 0)
73 
74 /* AD5766_CMD_WR_PWR_DAC, AD5766_CMD_WR_PWR_DITHER */
75 #define AD5766_PWDN(x) (1 << ((x) & 0xF))
76 
77 /* AD5766_CMD_SW_FULL_RESET */
78 #define AD5766_RESET 0x1234
79 
80 /* AD5766_CMD_DITHER_SIG_x */
81 #define AD5766_N0(x) (1 << (2 * ((x) & 0xF)))
82 #define AD5766_N1(x) (2 << (2 * ((x) & 0xF)))
83 
84 /* AD5766_CMD_INV_DITHER */
85 #define AD5766_INV_D(x) (1 << ((x) & 0xF))
86 
87 /* AD5766_CMD_DITHER_SCALE_x */
88 #define AD5766_75(x) (1 << (2 * ((x) & 0xF)))
89 #define AD5766_50(x) (2 << (2 * ((x) & 0xF)))
90 #define AD5766_25(x) (3 << (2 * ((x) & 0xF)))
91 
92 /******************************************************************************/
93 /*************************** Types Declarations *******************************/
94 /******************************************************************************/
98 };
99 
117 };
118 
127 };
128 
133 };
134 
135 struct ad5766_dev {
136  /* SPI */
138  /* GPIO */
140  /* Device Settings */
142 };
143 
145  /* SPI */
147  /* GPIO */
149  /* Device Settings */
153  uint16_t pwr_dac_setting;
158 };
159 
160 /******************************************************************************/
161 /************************ Functions Declarations ******************************/
162 /******************************************************************************/
163 /* SPI command write to device. */
164 int32_t ad5766_spi_cmd_write(struct ad5766_dev *dev,
165  uint8_t cmd,
166  uint16_t data);
167 /* SPI readback register from device. */
168 int32_t ad5766_spi_readback_reg(struct ad5766_dev *dev,
169  enum ad5766_dac dac,
170  uint32_t *data);
171 /* Set software LDAC for the selected channels. */
172 int32_t ad5766_set_sw_ldac(struct ad5766_dev *dev,
173  uint16_t setting);
174 /* Set clear code and span settings. */
175 int32_t ad5766_set_clr_span(struct ad5766_dev *dev,
176  enum ad5766_clr clr,
177  enum ad5766_span span);
178 /* Power down the selected channels. */
179 int32_t ad5766_set_pwr_dac(struct ad5766_dev *dev,
180  uint16_t setting);
181 /* Power down the dither block for the selected channels. */
182 int32_t ad5766_set_pwr_dither(struct ad5766_dev *dev,
183  uint16_t setting);
184 /* Enable the dither signal for the selected channels. */
185 int32_t ad5766_set_dither_signal(struct ad5766_dev *dev,
186  uint32_t setting);
187 /* Invert the dither signal for the selected channels. */
188 int32_t ad5766_set_inv_dither(struct ad5766_dev *dev,
189  uint16_t setting);
190 /* Enable the dither scaling for the selected channels. */
191 int32_t ad5766_set_dither_scale(struct ad5766_dev *dev,
192  uint32_t setting);
193 /* Do a software reset. */
194 int32_t ad5766_do_soft_reset(struct ad5766_dev *dev);
195 /* Set the input register for the selected channel. */
196 int32_t ad5766_set_in_reg(struct ad5766_dev *dev,
197  enum ad5766_dac dac,
198  uint16_t data);
199 /* Set the DAC register for the selected channel. */
200 int32_t ad5766_set_dac_reg(struct ad5766_dev *dev,
201  enum ad5766_dac dac,
202  uint16_t data);
203 /* Set the DAC register for all channels. */
204 int32_t ad5766_set_dac_reg_all(struct ad5766_dev *dev,
205  uint16_t data);
206 /* Initialize the device. */
207 int32_t ad5766_init(struct ad5766_dev **device,
209 
210 /* Free the resources allocated by ad5766_init(). */
211 int32_t ad5766_remove(struct ad5766_dev *dev);
212 #endif // AD5766_H_
AD5766_DAC_4
@ AD5766_DAC_4
Definition: ad5766.h:105
AD5766_CMD_WR_PWR_DITHER
#define AD5766_CMD_WR_PWR_DITHER
Definition: ad5766.h:54
ad5766_remove
int32_t ad5766_remove(struct ad5766_dev *dev)
Free the resources allocated by ad5766_init().
Definition: ad5766.c:334
ad5766_set_dither_scale
int32_t ad5766_set_dither_scale(struct ad5766_dev *dev, uint32_t setting)
Definition: ad5766.c:212
ad5766_init_param::dither_signal_setting
uint32_t dither_signal_setting
Definition: ad5766.h:155
AD5766_CMD_SDO_CNTRL
#define AD5766_CMD_SDO_CNTRL
Definition: ad5766.h:48
AD5766_DAC_0
@ AD5766_DAC_0
Definition: ad5766.h:101
ad5766_set_pwr_dac
int32_t ad5766_set_pwr_dac(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:147
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
ad5766_init_param::pwr_dac_setting
uint16_t pwr_dac_setting
Definition: ad5766.h:153
AD5766_DAC_13
@ AD5766_DAC_13
Definition: ad5766.h:114
ad5766_do_soft_reset
int32_t ad5766_do_soft_reset(struct ad5766_dev *dev)
Definition: ad5766.c:230
ad5766_dac
ad5766_dac
Definition: ad5766.h:100
ad5766_set_dac_reg_all
int32_t ad5766_set_dac_reg_all(struct ad5766_dev *dev, uint16_t data)
Definition: ad5766.c:272
ad5766.h
Header file of AD5766 Driver.
no_os_spi_write_and_read
int32_t no_os_spi_write_and_read(struct no_os_spi_desc *desc, uint8_t *data, uint16_t bytes_number)
Write and read data to/from SPI.
Definition: no_os_spi.c:159
ad5766_set_pwr_dither
int32_t ad5766_set_pwr_dither(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:162
ad5766_set_inv_dither
int32_t ad5766_set_inv_dither(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:197
no_os_spi.h
Header file of SPI Interface.
ad5766_init_param::clr
enum ad5766_clr clr
Definition: ad5766.h:151
ad5766_set_dither_signal
int32_t ad5766_set_dither_signal(struct ad5766_dev *dev, uint32_t setting)
Definition: ad5766.c:177
AD5766_CMD_WR_DAC_REG_ALL
#define AD5766_CMD_WR_DAC_REG_ALL
Definition: ad5766.h:55
ad5766_remove
int32_t ad5766_remove(struct ad5766_dev *dev)
Free the resources allocated by ad5766_init().
Definition: ad5766.c:334
ad5766_spi_cmd_write
int32_t ad5766_spi_cmd_write(struct ad5766_dev *dev, uint8_t cmd, uint16_t data)
Definition: ad5766.c:53
no_os_delay.h
Header file of Delay functions.
AD5766_ENABLE
@ AD5766_ENABLE
Definition: ad5766.h:96
AD5766_CMD_DITHER_SIG_1
#define AD5766_CMD_DITHER_SIG_1
Definition: ad5766.h:58
device
Definition: ad9361_util.h:69
ad5766_set_inv_dither
int32_t ad5766_set_inv_dither(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:197
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
ad5766_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5766.h:137
AD5766_CMD_INV_DITHER
#define AD5766_CMD_INV_DITHER
Definition: ad5766.h:60
ad5766_init_param
Definition: ad5766.h:144
ad5766_dev
Definition: ad5766.h:135
ad5766_span
ad5766_span
Definition: ad5766.h:119
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
AD5766_CMD_SW_LDAC
#define AD5766_CMD_SW_LDAC
Definition: ad5766.h:51
AD5766_DAC_9
@ AD5766_DAC_9
Definition: ad5766.h:110
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
ad5766_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5766.h:146
AD5766_RESET
#define AD5766_RESET
Definition: ad5766.h:78
AD5766_DAC_6
@ AD5766_DAC_6
Definition: ad5766.h:107
AD5766_DAC_7
@ AD5766_DAC_7
Definition: ad5766.h:108
no_os_error.h
Error codes definition.
AD5766_CMD_SPAN_REG
#define AD5766_CMD_SPAN_REG
Definition: ad5766.h:52
AD5766_SDO_EN
#define AD5766_SDO_EN
Definition: ad5766.h:65
AD5766_DAC_11
@ AD5766_DAC_11
Definition: ad5766.h:112
AD5766_CMD_DITHER_SCALE_2
#define AD5766_CMD_DITHER_SCALE_2
Definition: ad5766.h:62
ad5766_set_in_reg
int32_t ad5766_set_in_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint16_t data)
Definition: ad5766.c:243
AD5766_DAC_12
@ AD5766_DAC_12
Definition: ad5766.h:113
AD5766_CMD_WR_PWR_DAC
#define AD5766_CMD_WR_PWR_DAC
Definition: ad5766.h:53
ad5766_set_pwr_dac
int32_t ad5766_set_pwr_dac(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:147
AD5766_DAC_3
@ AD5766_DAC_3
Definition: ad5766.h:104
ad5766_set_dac_reg
int32_t ad5766_set_dac_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint16_t data)
Definition: ad5766.c:258
ad5766_dev::daisy_chain_en
enum ad5766_state daisy_chain_en
Definition: ad5766.h:141
AD5766_MID
@ AD5766_MID
Definition: ad5766.h:131
ad5766_set_in_reg
int32_t ad5766_set_in_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint16_t data)
Definition: ad5766.c:243
ad5766_spi_readback_reg
int32_t ad5766_spi_readback_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint32_t *data)
Definition: ad5766.c:77
AD5766_CFG_CLR
#define AD5766_CFG_CLR(x)
Definition: ad5766.h:71
ad5766_state
ad5766_state
Definition: ad5766.h:95
AD5766_M_16V_TO_0V
@ AD5766_M_16V_TO_0V
Definition: ad5766.h:121
AD5766_SPAN
#define AD5766_SPAN(x)
Definition: ad5766.h:72
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:104
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
AD5766_DAC_10
@ AD5766_DAC_10
Definition: ad5766.h:111
AD5766_M_5V_TO_P_6V
@ AD5766_M_5V_TO_P_6V
Definition: ad5766.h:125
AD5766_DAC_14
@ AD5766_DAC_14
Definition: ad5766.h:115
ad5766_init_param::gpio_reset
struct no_os_gpio_init_param gpio_reset
Definition: ad5766.h:148
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad5766_init_param::pwr_dither_setting
uint16_t pwr_dither_setting
Definition: ad5766.h:154
ad5766_spi_readback_reg
int32_t ad5766_spi_readback_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint32_t *data)
Definition: ad5766.c:77
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:49
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:43
ad5766_set_dac_reg_all
int32_t ad5766_set_dac_reg_all(struct ad5766_dev *dev, uint16_t data)
Definition: ad5766.c:272
ad5766_set_pwr_dither
int32_t ad5766_set_pwr_dither(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:162
AD5766_M_10V_TO_P_10V
@ AD5766_M_10V_TO_P_10V
Definition: ad5766.h:126
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:69
ad5766_set_clr_span
int32_t ad5766_set_clr_span(struct ad5766_dev *dev, enum ad5766_clr clr, enum ad5766_span span)
Definition: ad5766.c:131
ad5766_init
int32_t ad5766_init(struct ad5766_dev **device, struct ad5766_init_param init_param)
Definition: ad5766.c:286
AD5766_FULL
@ AD5766_FULL
Definition: ad5766.h:132
AD5766_CMD_WR_IN_REG
#define AD5766_CMD_WR_IN_REG(x)
Definition: ad5766.h:49
ad5766_init_param::daisy_chain_en
enum ad5766_state daisy_chain_en
Definition: ad5766.h:150
AD5766_DAC_1
@ AD5766_DAC_1
Definition: ad5766.h:102
AD5766_DISABLE
@ AD5766_DISABLE
Definition: ad5766.h:97
AD5766_CMD_DITHER_SCALE_1
#define AD5766_CMD_DITHER_SCALE_1
Definition: ad5766.h:61
AD5766_M_16V_TO_P_10V
@ AD5766_M_16V_TO_P_10V
Definition: ad5766.h:124
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:197
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad5766_init_param::dither_scale_setting
uint32_t dither_scale_setting
Definition: ad5766.h:157
ad5766_clr
ad5766_clr
Definition: ad5766.h:129
AD5766_M_10V_TO_0V
@ AD5766_M_10V_TO_0V
Definition: ad5766.h:122
ad5766_set_sw_ldac
int32_t ad5766_set_sw_ldac(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:106
ad5766_set_dither_scale
int32_t ad5766_set_dither_scale(struct ad5766_dev *dev, uint32_t setting)
Definition: ad5766.c:212
AD5766_CMD_READBACK_REG
#define AD5766_CMD_READBACK_REG(x)
Definition: ad5766.h:57
AD5766_CMD_DITHER_SIG_2
#define AD5766_CMD_DITHER_SIG_2
Definition: ad5766.h:59
no_os_spi_remove
int32_t no_os_spi_remove(struct no_os_spi_desc *desc)
Free the resources allocated by no_os_spi_init().
Definition: no_os_spi.c:116
ad5766_do_soft_reset
int32_t ad5766_do_soft_reset(struct ad5766_dev *dev)
Definition: ad5766.c:230
ad5766_set_sw_ldac
int32_t ad5766_set_sw_ldac(struct ad5766_dev *dev, uint16_t setting)
Definition: ad5766.c:106
no_os_gpio.h
Header file of GPIO Interface.
ad5766_set_clr_span
int32_t ad5766_set_clr_span(struct ad5766_dev *dev, enum ad5766_clr clr, enum ad5766_span span)
Definition: ad5766.c:131
AD5766_M_12V_TO_P_14V
@ AD5766_M_12V_TO_P_14V
Definition: ad5766.h:123
AD5766_CMD_SW_FULL_RESET
#define AD5766_CMD_SW_FULL_RESET
Definition: ad5766.h:56
AD5766_DAC_2
@ AD5766_DAC_2
Definition: ad5766.h:103
ad5766_set_dac_reg
int32_t ad5766_set_dac_reg(struct ad5766_dev *dev, enum ad5766_dac dac, uint16_t data)
Definition: ad5766.c:258
no_os_spi_init
int32_t no_os_spi_init(struct no_os_spi_desc **desc, const struct no_os_spi_init_param *param)
Initialize the SPI communication peripheral.
Definition: no_os_spi.c:52
ad5766_init_param::span
enum ad5766_span span
Definition: ad5766.h:152
AD5766_ZERO
@ AD5766_ZERO
Definition: ad5766.h:130
ad5766_set_dither_signal
int32_t ad5766_set_dither_signal(struct ad5766_dev *dev, uint32_t setting)
Definition: ad5766.c:177
AD5766_DAC_15
@ AD5766_DAC_15
Definition: ad5766.h:116
AD5766_M_20V_TO_0V
@ AD5766_M_20V_TO_0V
Definition: ad5766.h:120
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:147
ad5766_init
int32_t ad5766_init(struct ad5766_dev **device, struct ad5766_init_param init_param)
Definition: ad5766.c:286
AD5766_DAC_8
@ AD5766_DAC_8
Definition: ad5766.h:109
ad5766_spi_cmd_write
int32_t ad5766_spi_cmd_write(struct ad5766_dev *dev, uint8_t cmd, uint16_t data)
Definition: ad5766.c:53
AD5766_DAC_5
@ AD5766_DAC_5
Definition: ad5766.h:106
ad5766_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad5766.h:139
ad5766_init_param::inv_dither_setting
uint16_t inv_dither_setting
Definition: ad5766.h:156
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140
AD5766_CMD_WR_DAC_REG
#define AD5766_CMD_WR_DAC_REG(x)
Definition: ad5766.h:50