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