no-OS
ad5791.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef __AD5791_H__
35 #define __AD5791_H__
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 #include <stdint.h>
41 #include "no_os_delay.h"
42 #include "no_os_gpio.h"
43 #include "no_os_spi.h"
44 #include "no_os_util.h"
45 #include "no_os_error.h"
46 
47 /******************************************************************************/
48 /*************************** Types Declarations *******************************/
49 /******************************************************************************/
50 /* Supported devices */
57 };
58 
59 /* Possible voltage spans for linearity error compensation */
67 };
68 
70  uint32_t resolution;
71 };
72 
73 struct ad5791_dev {
74  /* SPI */
76  /* GPIO */
80  /* Device Settings */
82  bool rbuf_gain2;
83 };
84 
86  /* SPI */
88  /* GPIO */
92  /* Device Settings */
94  bool rbuf_gain2;
95 };
96 
97 /******************************************************************************/
98 /*********************************** GPIO *************************************/
99 /******************************************************************************/
100 #define AD5791_RESET_OUT no_os_gpio_direction_output(dev->gpio_reset, \
101  NO_OS_GPIO_HIGH);
102 #define AD5791_RESET_LOW no_os_gpio_set_value(dev->gpio_reset, \
103  NO_OS_GPIO_LOW)
104 #define AD5791_RESET_HIGH no_os_gpio_set_value(dev->gpio_reset, \
105  NO_OS_GPIO_HIGH)
106 
107 #define AD5791_CLR_OUT no_os_gpio_direction_output(dev->gpio_clr, \
108  NO_OS_GPIO_HIGH);
109 #define AD5791_CLR_LOW no_os_gpio_set_value(dev->gpio_clr, \
110  NO_OS_GPIO_LOW)
111 #define AD5791_CLR_HIGH no_os_gpio_set_value(dev->gpio_clr, \
112  NO_OS_GPIO_HIGH)
113 
114 #define AD5791_LDAC_OUT no_os_gpio_direction_output(dev->gpio_ldac, \
115  NO_OS_GPIO_HIGH);
116 #define AD5791_LDAC_LOW no_os_gpio_set_value(dev->gpio_ldac, \
117  NO_OS_GPIO_LOW)
118 #define AD5791_LDAC_HIGH no_os_gpio_set_value(dev->gpio_ldac, \
119  NO_OS_GPIO_HIGH)
120 
121 /******************************************************************************/
122 /********************************** AD5791 ************************************/
123 /******************************************************************************/
124 
125 /* Maximum resolution */
126 #define MAX_RESOLUTION 20
127 
128 /* Register Map */
129 #define AD5791_NOP 0 // No operation (NOP).
130 #define AD5791_REG_DAC 1 // DAC register.
131 #define AD5791_REG_CTRL 2 // Control register.
132 #define AD5791_REG_CLR_CODE 3 // Clearcode register.
133 #define AD5791_CMD_WR_SOFT_CTRL 4 // Software control register(Write only).
134 
135 /* Input Shift Register bit definition. */
136 #define AD5791_READ (1ul << 23)
137 #define AD5791_WRITE (0ul << 23)
138 #define AD5791_ADDR_REG(x) (((uint32_t)(x) & 0x7) << 20)
139 
140 /* Control Register bit Definition */
141 #define AD5791_CTRL_LINCOMP_MASK NO_OS_GENMASK(9,6) // Linearity error compensation.
142 #define AD5791_CTRL_LINCOMP(x) (((x) & 0xF) << 6)
143 #define AD5791_CTRL_SDODIS_MASK NO_OS_BIT(5) // SDO pin enable/disable control.
144 #define AD5791_CTRL_SDODIS(x) ((x & 0x01) << 5)
145 #define AD5791_CTRL_BIN2SC_MASK NO_OS_BIT(4) // DAC register coding selection.
146 #define AD5791_CTRL_BIN2SC(x) ((x & 0x01) << 4)
147 #define AD5791_CTRL_DACTRI NO_OS_BIT(3) // DAC tristate control.
148 #define AD5791_CTRL_OPGND NO_OS_BIT(2) // Output ground clamp control.
149 #define AD5791_CTRL_RBUF_MASK NO_OS_BIT(1) // Output amplifier configuration control.
150 #define AD5791_CTRL_RBUF(x) ((x & 0x01) << 1)
151 
152 /* Software Control Register bit definition */
153 #define AD5791_SOFT_CTRL_RESET (1 << 2) // RESET function.
154 #define AD5791_SOFT_CTRL_CLR (1 << 1) // CLR function.
155 #define AD5791_SOFT_CTRL_LDAC (1 << 0) // LDAC function.
156 
157 /* DAC OUTPUT STATES */
158 #define AD5791_OUT_NORMAL 0x0
159 #define AD5791_OUT_CLAMPED_6K 0x1
160 #define AD5791_OUT_TRISTATE 0x2
161 
162 /******************************************************************************/
163 /************************ Functions Declarations ******************************/
164 /******************************************************************************/
165 
167 int32_t ad5791_init(struct ad5791_dev **device,
169 
171 int32_t ad5791_remove(struct ad5791_dev *dev);
172 
174 int32_t ad5791_set_register_value(struct ad5791_dev *dev,
175  uint8_t register_address,
176  uint32_t register_value);
177 
179 int32_t ad5791_get_register_value(struct ad5791_dev *dev,
180  uint8_t register_address,
181  uint32_t *value);
182 
184 int32_t ad5791_dac_ouput_state(struct ad5791_dev *dev,
185  uint8_t state);
186 
188 int32_t ad5791_set_dac_value(struct ad5791_dev *dev,
189  uint32_t value);
190 
192 int32_t ad5791_soft_instruction(struct ad5791_dev *dev,
193  uint8_t instruction_bit);
194 
197 int32_t ad5791_setup(struct ad5791_dev *dev,
198  uint32_t setup_word);
199 
201 int ad5791_spi_write_mask(struct ad5791_dev *dev,
202  uint8_t register_address,
203  uint32_t mask,
204  uint32_t value);
205 
207 int ad5791_set_lin_comp(struct ad5791_dev *dev,
208  enum ad5791_lin_comp_select v_span);
209 
211 int ad5791_ldac_trigger(struct ad5791_dev *dev);
212 
214 int ad5791_clear_async(struct ad5791_dev *dev);
215 
216 #endif /* __AD5791_H__ */
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
AD5791_REG_DAC
#define AD5791_REG_DAC
Definition: ad5791.h:130
AD5791_LDAC_HIGH
#define AD5791_LDAC_HIGH
Definition: ad5791.h:118
AD5791_SPAN_19V_TO_20V
@ AD5791_SPAN_19V_TO_20V
Definition: ad5791.h:66
AD5781_SPAN_10V_TO_20V
@ AD5781_SPAN_10V_TO_20V
Definition: ad5791.h:62
AD5791_CTRL_RBUF_MASK
#define AD5791_CTRL_RBUF_MASK
Definition: ad5791.h:149
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:282
ad5791_dev::gpio_clr
struct no_os_gpio_desc * gpio_clr
Definition: ad5791.h:78
ad5791_spi_write_mask
int ad5791_spi_write_mask(struct ad5791_dev *dev, uint8_t register_address, uint32_t mask, uint32_t value)
SPI write to device using a mask.
Definition: ad5791.c:363
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
ad5791_init_param
Definition: ad5791.h:85
ad5791_dev::rbuf_gain2
bool rbuf_gain2
Definition: ad5791.h:82
no_os_spi.h
Header file of SPI Interface.
ID_AD5760
@ ID_AD5760
Definition: ad5791.h:52
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:282
AD5791_LDAC_LOW
#define AD5791_LDAC_LOW
Definition: ad5791.h:116
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:255
ad5791_type
ad5791_type
Definition: ad5791.h:51
no_os_delay.h
Header file of Delay functions.
ad5791_clear_async
int ad5791_clear_async(struct ad5791_dev *dev)
Clear DAC channel output with the clearcode.
Definition: ad5791.c:454
AD5791_SPAN_16V_TO_19V
@ AD5791_SPAN_16V_TO_19V
Definition: ad5791.h:65
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:255
AD5791_CTRL_DACTRI
#define AD5791_CTRL_DACTRI
Definition: ad5791.h:147
AD5791_WRITE
#define AD5791_WRITE
Definition: ad5791.h:137
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:74
AD5791_SPAN_12V_TO_16V
@ AD5791_SPAN_12V_TO_16V
Definition: ad5791.h:64
device
Definition: ad9361_util.h:69
ad5791_init_param::act_device
enum ad5791_type act_device
Definition: ad5791.h:93
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:117
ad5791_ldac_trigger
int ad5791_ldac_trigger(struct ad5791_dev *dev)
Trigger LDAC.
Definition: ad5791.c:426
AD5791_CTRL_OPGND
#define AD5791_CTRL_OPGND
Definition: ad5791.h:148
ID_AD5791
@ ID_AD5791
Definition: ad5791.h:56
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:115
AD5791_CTRL_LINCOMP_MASK
#define AD5791_CTRL_LINCOMP_MASK
Definition: ad5791.h:141
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:180
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:126
ad5791_remove
int32_t ad5791_remove(struct ad5791_dev *dev)
Free the resources allocated by ad5791_init().
Definition: ad5791.c:113
no_os_error.h
Error codes definition.
ad5791_init_param::gpio_ldac
struct no_os_gpio_init_param gpio_ldac
Definition: ad5791.h:91
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:180
AD5791_CMD_WR_SOFT_CTRL
#define AD5791_CMD_WR_SOFT_CTRL
Definition: ad5791.h:133
ad5791_ldac_trigger
int ad5791_ldac_trigger(struct ad5791_dev *dev)
Trigger LDAC.
Definition: ad5791.c:426
AD5791_SOFT_CTRL_CLR
#define AD5791_SOFT_CTRL_CLR
Definition: ad5791.h:154
ad5791_init_param::rbuf_gain2
bool rbuf_gain2
Definition: ad5791.h:94
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:74
AD5791_CTRL_BIN2SC_MASK
#define AD5791_CTRL_BIN2SC_MASK
Definition: ad5791.h:145
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:314
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:222
AD5791_CLR_HIGH
#define AD5791_CLR_HIGH
Definition: ad5791.h:111
ad5791_dev::act_device
enum ad5791_type act_device
Definition: ad5791.h:81
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
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
AD5781_SPAN_UPTO_10V
@ AD5781_SPAN_UPTO_10V
Definition: ad5791.h:61
AD5791_CTRL_LINCOMP
#define AD5791_CTRL_LINCOMP(x)
Definition: ad5791.h:142
ad5791_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5791.h:75
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
ad5791_lin_comp_select
ad5791_lin_comp_select
Definition: ad5791.h:60
AD5791_ADDR_REG
#define AD5791_ADDR_REG(x)
Definition: ad5791.h:138
ad5791_spi_write_mask
int ad5791_spi_write_mask(struct ad5791_dev *dev, uint8_t register_address, uint32_t mask, uint32_t value)
SPI write to device using a mask.
Definition: ad5791.c:363
AD5791_SOFT_CTRL_LDAC
#define AD5791_SOFT_CTRL_LDAC
Definition: ad5791.h:155
ad5791_chip_info::resolution
uint32_t resolution
Definition: ad5791.h:70
ID_AD5790
@ ID_AD5790
Definition: ad5791.h:55
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:45
ad5791_dev
Definition: ad5791.h:73
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
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:142
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:314
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: aducm3029_delay.c:114
ad5791_set_lin_comp
int ad5791_set_lin_comp(struct ad5791_dev *dev, enum ad5791_lin_comp_select v_span)
Set Linearity error compensation based on the reference voltage span.
Definition: ad5791.c:391
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:142
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
AD5791_RESET_HIGH
#define AD5791_RESET_HIGH
Definition: ad5791.h:104
ID_AD5780
@ ID_AD5780
Definition: ad5791.h:53
ad5791_remove
int32_t ad5791_remove(struct ad5791_dev *dev)
Free the resources allocated by ad5791_init().
Definition: ad5791.c:113
ad5791_dev::gpio_reset
struct no_os_gpio_desc * gpio_reset
Definition: ad5791.h:77
MAX_RESOLUTION
#define MAX_RESOLUTION
Definition: ad5446.c:43
AD5791_CTRL_SDODIS_MASK
#define AD5791_CTRL_SDODIS_MASK
Definition: ad5791.h:143
ad5791_clear_async
int ad5791_clear_async(struct ad5791_dev *dev)
Clear DAC channel output with the clearcode.
Definition: ad5791.c:454
AD5791_READ
#define AD5791_READ
Definition: ad5791.h:136
AD5791_CLR_OUT
#define AD5791_CLR_OUT
Definition: ad5791.h:107
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
ad5791_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5791.h:87
AD5791_SPAN_10V_TO_12V
@ AD5791_SPAN_10V_TO_12V
Definition: ad5791.h:63
no_os_gpio.h
Header file of GPIO Interface.
ad5791_dev::gpio_ldac
struct no_os_gpio_desc * gpio_ldac
Definition: ad5791.h:79
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
ad5791_set_lin_comp
int ad5791_set_lin_comp(struct ad5791_dev *dev, enum ad5791_lin_comp_select v_span)
Set Linearity error compensation based on the reference voltage span.
Definition: ad5791.c:391
no_os_util.h
Header file of utility functions.
AD5791_RESET_OUT
#define AD5791_RESET_OUT
Definition: ad5791.h:100
ad5791_chip_info
Definition: ad5791.h:69
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:222
ID_AD5781
@ ID_AD5781
Definition: ad5791.h:54
AD5791_REG_CTRL
#define AD5791_REG_CTRL
Definition: ad5791.h:131
AD5791_LDAC_OUT
#define AD5791_LDAC_OUT
Definition: ad5791.h:114
ad5791_init_param::gpio_reset
struct no_os_gpio_init_param gpio_reset
Definition: ad5791.h:89
ad5791_init_param::gpio_clr
struct no_os_gpio_init_param gpio_clr
Definition: ad5791.h:90
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140