no-OS
ad5791.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef __AD5791_H__
41 #define __AD5791_H__
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 #include <stdint.h>
47 #include "no_os_delay.h"
48 #include "no_os_gpio.h"
49 #include "no_os_spi.h"
50 
51 /******************************************************************************/
52 /*************************** Types Declarations *******************************/
53 /******************************************************************************/
54 /* Supported devices */
61 };
62 
64  uint32_t resolution;
65 };
66 
67 struct ad5791_dev {
68  /* SPI */
70  /* GPIO */
74  /* Device Settings */
76 };
77 
79  /* SPI */
81  /* GPIO */
85  /* Device Settings */
87 };
88 
89 /******************************************************************************/
90 /*********************************** GPIO *************************************/
91 /******************************************************************************/
92 #define AD5791_RESET_OUT no_os_gpio_direction_output(dev->gpio_reset, \
93  NO_OS_GPIO_HIGH);
94 #define AD5791_RESET_LOW no_os_gpio_set_value(dev->gpio_reset, \
95  NO_OS_GPIO_LOW)
96 #define AD5791_RESET_HIGH no_os_gpio_set_value(dev->gpio_reset, \
97  NO_OS_GPIO_HIGH)
98 
99 #define AD5791_CLR_OUT no_os_gpio_direction_output(dev->gpio_clr, \
100  NO_OS_GPIO_HIGH);
101 #define AD5791_CLR_LOW no_os_gpio_set_value(dev->gpio_clr, \
102  NO_OS_GPIO_LOW)
103 #define AD5791_CLR_HIGH no_os_gpio_set_value(dev->gpio_clr, \
104  NO_OS_GPIO_HIGH)
105 
106 #define AD5791_LDAC_OUT no_os_gpio_direction_output(dev->gpio_ldac, \
107  NO_OS_GPIO_HIGH);
108 #define AD5791_LDAC_LOW no_os_gpio_set_value(dev->gpio_ldac, \
109  NO_OS_GPIO_LOW)
110 #define AD5791_LDAC_HIGH no_os_gpio_set_value(dev->gpio_ldac, \
111  NO_OS_GPIO_HIGH)
112 
113 /******************************************************************************/
114 /********************************** AD5791 ************************************/
115 /******************************************************************************/
116 
117 /* Maximum resolution */
118 #define MAX_RESOLUTION 20
119 
120 /* Register Map */
121 #define AD5791_NOP 0 // No operation (NOP).
122 #define AD5791_REG_DAC 1 // DAC register.
123 #define AD5791_REG_CTRL 2 // Control register.
124 #define AD5791_REG_CLR_CODE 3 // Clearcode register.
125 #define AD5791_CMD_WR_SOFT_CTRL 4 // Software control register(Write only).
126 
127 /* Input Shift Register bit definition. */
128 #define AD5791_READ (1ul << 23)
129 #define AD5791_WRITE (0ul << 23)
130 #define AD5791_ADDR_REG(x) (((uint32_t)(x) & 0x7) << 20)
131 
132 /* Control Register bit Definition */
133 #define AD5791_CTRL_LINCOMP(x) (((x) & 0xF) << 6) // Linearity error compensation.
134 #define AD5791_CTRL_SDODIS (1 << 5) // SDO pin enable/disable control.
135 #define AD5791_CTRL_BIN2SC (1 << 4) // DAC register coding selection.
136 #define AD5791_CTRL_DACTRI (1 << 3) // DAC tristate control.
137 #define AD5791_CTRL_OPGND (1 << 2) // Output ground clamp control.
138 #define AD5791_CTRL_RBUF (1 << 1) // Output amplifier configuration control.
139 
140 /* Software Control Register bit definition */
141 #define AD5791_SOFT_CTRL_RESET (1 << 2) // RESET function.
142 #define AD5791_SOFT_CTRL_CLR (1 << 1) // CLR function.
143 #define AD5791_SOFT_CTRL_LDAC (1 << 0) // LDAC function.
144 
145 /* DAC OUTPUT STATES */
146 #define AD5791_OUT_NORMAL 0x0
147 #define AD5791_OUT_CLAMPED_6K 0x1
148 #define AD5791_OUT_TRISTATE 0x2
149 
150 /******************************************************************************/
151 /************************ Functions Declarations ******************************/
152 /******************************************************************************/
153 
155 int32_t ad5791_init(struct ad5791_dev **device,
157 
159 int32_t ad5791_remove(struct ad5791_dev *dev);
160 
162 int32_t ad5791_set_register_value(struct ad5791_dev *dev,
163  uint8_t register_address,
164  uint32_t register_value);
165 
167 int32_t ad5791_get_register_value(struct ad5791_dev *dev,
168  uint8_t register_address,
169  uint32_t *value);
170 
172 int32_t ad5791_dac_ouput_state(struct ad5791_dev *dev,
173  uint8_t state);
174 
176 int32_t ad5791_set_dac_value(struct ad5791_dev *dev,
177  uint32_t value);
178 
180 int32_t ad5791_soft_instruction(struct ad5791_dev *dev,
181  uint8_t instruction_bit);
182 
185 int32_t ad5791_setup(struct ad5791_dev *dev,
186  uint32_t setup_word);
187 
188 #endif /* __AD5791_H__ */
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
AD5791_REG_DAC
#define AD5791_REG_DAC
Definition: ad5791.h:122
AD5791_LDAC_HIGH
#define AD5791_LDAC_HIGH
Definition: ad5791.h:110
ad5791_soft_instruction
int32_t ad5791_soft_instruction(struct ad5791_dev *dev, uint8_t instruction_bit)
Asserts RESET, CLR or LDAC in a software manner.
Definition: ad5791.c:287
ad5791_dev::gpio_clr
struct no_os_gpio_desc * gpio_clr
Definition: ad5791.h:72
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:95
ad5791_init_param
Definition: ad5791.h:78
no_os_spi.h
Header file of SPI Interface.
ID_AD5760
@ ID_AD5760
Definition: ad5791.h:56
ad5791_soft_instruction
int32_t ad5791_soft_instruction(struct ad5791_dev *dev, uint8_t instruction_bit)
Asserts RESET, CLR or LDAC in a software manner.
Definition: ad5791.c:287
AD5791_LDAC_LOW
#define AD5791_LDAC_LOW
Definition: ad5791.h:108
ad5791.h
Header file of AD5791 Driver.
ad5791_set_dac_value
int32_t ad5791_set_dac_value(struct ad5791_dev *dev, uint32_t value)
Writes to the DAC register.
Definition: ad5791.c:260
ad5791_type
ad5791_type
Definition: ad5791.h:55
no_os_delay.h
Header file of Delay functions.
ad5791_set_dac_value
int32_t ad5791_set_dac_value(struct ad5791_dev *dev, uint32_t value)
Writes to the DAC register.
Definition: ad5791.c:260
AD5791_CTRL_DACTRI
#define AD5791_CTRL_DACTRI
Definition: ad5791.h:136
AD5791_WRITE
#define AD5791_WRITE
Definition: ad5791.h:129
ad5791_init
int32_t ad5791_init(struct ad5791_dev **device, struct ad5791_init_param init_param)
Initializes the communication with the device.
Definition: ad5791.c:80
device
Definition: ad9361_util.h:75
ad5791_init_param::act_device
enum ad5791_type act_device
Definition: ad5791.h:86
AD5791_CTRL_BIN2SC
#define AD5791_CTRL_BIN2SC
Definition: ad5791.h:135
AD5791_CTRL_OPGND
#define AD5791_CTRL_OPGND
Definition: ad5791.h:137
ID_AD5791
@ ID_AD5791
Definition: ad5791.h:60
ad5791_get_register_value
int32_t ad5791_get_register_value(struct ad5791_dev *dev, uint8_t register_address, uint32_t *value)
Reads the value of a register.
Definition: ad5791.c:185
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:132
ad5791_remove
int32_t ad5791_remove(struct ad5791_dev *dev)
Free the resources allocated by ad5791_init().
Definition: ad5791.c:118
ad5791_init_param::gpio_ldac
struct no_os_gpio_init_param gpio_ldac
Definition: ad5791.h:84
ad5791_get_register_value
int32_t ad5791_get_register_value(struct ad5791_dev *dev, uint8_t register_address, uint32_t *value)
Reads the value of a register.
Definition: ad5791.c:185
AD5791_CMD_WR_SOFT_CTRL
#define AD5791_CMD_WR_SOFT_CTRL
Definition: ad5791.h:125
ad5791_init
int32_t ad5791_init(struct ad5791_dev **device, struct ad5791_init_param init_param)
Initializes the communication with the device.
Definition: ad5791.c:80
ad5791_setup
int32_t ad5791_setup(struct ad5791_dev *dev, uint32_t setup_word)
Configures the output amplifier, DAC coding, SDO state and the linearity error compensation.
Definition: ad5791.c:319
AD5791_CTRL_RBUF
#define AD5791_CTRL_RBUF
Definition: ad5791.h:138
ad5791_dac_ouput_state
int32_t ad5791_dac_ouput_state(struct ad5791_dev *dev, uint8_t state)
Sets the DAC output in one of the three states.
Definition: ad5791.c:227
AD5791_CLR_HIGH
#define AD5791_CLR_HIGH
Definition: ad5791.h:103
ad5791_dev::act_device
enum ad5791_type act_device
Definition: ad5791.h:75
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:143
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
AD5791_CTRL_LINCOMP
#define AD5791_CTRL_LINCOMP(x)
Definition: ad5791.h:133
ad5791_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5791.h:69
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)
AD5791_ADDR_REG
#define AD5791_ADDR_REG(x)
Definition: ad5791.h:130
ad5791_chip_info::resolution
uint32_t resolution
Definition: ad5791.h:64
ID_AD5790
@ ID_AD5790
Definition: ad5791.h:59
ad5791_dev
Definition: ad5791.h:67
no_os_free
void no_os_free(void *ptr)
ad5791_set_register_value
int32_t ad5791_set_register_value(struct ad5791_dev *dev, uint8_t register_address, uint32_t register_value)
Writes data into a register.
Definition: ad5791.c:147
ad5791_setup
int32_t ad5791_setup(struct ad5791_dev *dev, uint32_t setup_word)
Configures the output amplifier, DAC coding, SDO state and the linearity error compensation.
Definition: ad5791.c:319
ad5791_set_register_value
int32_t ad5791_set_register_value(struct ad5791_dev *dev, uint8_t register_address, uint32_t register_value)
Writes data into a register.
Definition: ad5791.c:147
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
AD5791_CTRL_SDODIS
#define AD5791_CTRL_SDODIS
Definition: ad5791.h:134
AD5791_RESET_HIGH
#define AD5791_RESET_HIGH
Definition: ad5791.h:96
ID_AD5780
@ ID_AD5780
Definition: ad5791.h:57
ad5791_remove
int32_t ad5791_remove(struct ad5791_dev *dev)
Free the resources allocated by ad5791_init().
Definition: ad5791.c:118
ad5791_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad5791.h:71
MAX_RESOLUTION
#define MAX_RESOLUTION
Definition: ad5446.c:51
AD5791_READ
#define AD5791_READ
Definition: ad5791.h:128
AD5791_CLR_OUT
#define AD5791_CLR_OUT
Definition: ad5791.h:99
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:77
ad5791_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5791.h:80
no_os_gpio.h
Header file of GPIO Interface.
ad5791_dev::gpio_ldac
struct no_os_gpio_desc * gpio_ldac
Definition: ad5791.h:73
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:51
AD5791_RESET_OUT
#define AD5791_RESET_OUT
Definition: ad5791.h:92
ad5791_chip_info
Definition: ad5791.h:63
ad5791_dac_ouput_state
int32_t ad5791_dac_ouput_state(struct ad5791_dev *dev, uint8_t state)
Sets the DAC output in one of the three states.
Definition: ad5791.c:227
ID_AD5781
@ ID_AD5781
Definition: ad5791.h:58
AD5791_REG_CTRL
#define AD5791_REG_CTRL
Definition: ad5791.h:123
AD5791_LDAC_OUT
#define AD5791_LDAC_OUT
Definition: ad5791.h:106
ad5791_init_param::gpio_reset
struct no_os_gpio_init_param gpio_reset
Definition: ad5791.h:82
ad5791_init_param::gpio_clr
struct no_os_gpio_init_param gpio_clr
Definition: ad5791.h:83
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:121