no-OS
ad5629r.h
Go to the documentation of this file.
1 /**************************************************************************/
35 #ifndef _AD5629R_H_
36 #define _AD5629R_H_
37 
38 /******************************************************************************/
39 /***************************** Include Files **********************************/
40 /******************************************************************************/
41 #include <stdint.h>
42 #include "no_os_gpio.h"
43 #include "no_os_spi.h"
44 #include "no_os_i2c.h"
45 
46 /******************************************************************************/
47 /******************* Macros and Constants Definitions *************************/
48 /******************************************************************************/
49 /* AD5629R Device I2C Address */
50 #define AD5629R_I2C_ADDR_0 0x54 // A1=0 and A0=0 (A0_Pin=High)
51 #define AD5629R_I2C_ADDR_1 0x56 // A1=1 and A0=0 (A0_Pin=NC)
52 #define AD5629R_I2C_ADDR_2 0x57 // A1=1 and A0=1 (A0_Pin=Low)
53 
54 #define MAX_RESOLUTION 16
55 
56 /* Commands */
57 #define AD5629R_WRITE_N 0x0
58 #define AD5629R_UPDATE_N 0x1
59 #define AD5629R_WRITE_N_UPDATE_ALL 0x2
60 #define AD5629R_WRITE_N_UPDATE_N 0x3
61 #define AD5629R_POWER 0x4
62 #define AD5629R_LOAD_CLEAR_REG 0x5
63 #define AD5629R_LOAD_LDAC_REG 0x6
64 #define AD5629R_RESET 0x7
65 #define AD5629R_REFERENCE 0x8
66 
67 /* AD5629R GPIO */
68 /* LDAC - GPIO0 */
69 #define AD5629R_LDAC_OUT no_os_gpio_direction_output(dev->gpio_ldac, \
70  NO_OS_GPIO_HIGH);
71 #define AD5629R_LDAC_LOW no_os_gpio_set_value(dev->gpio_ldac, \
72  NO_OS_GPIO_LOW)
73 #define AD5629R_LDAC_HIGH no_os_gpio_set_value(dev->gpio_ldac, \
74  NO_OS_GPIO_HIGH)
75 /* CLR - GPIO1 */
76 #define AD5629R_CLR_OUT no_os_gpio_direction_output(dev->gpio_clr, \
77  NO_OS_GPIO_HIGH);
78 #define AD5629R_CLR_LOW no_os_gpio_set_value(dev->gpio_clr, \
79  NO_OS_GPIO_LOW)
80 #define AD5629R_CLR_HIGH no_os_gpio_set_value(dev->gpio_clr, \
81  NO_OS_GPIO_HIGH)
82 
83 /* DAC Addresses */
84 #define AD5629R_DAC_A_ADDR 0x0
85 #define AD5629R_DAC_B_ADDR 0x1
86 #define AD5629R_DAC_C_ADDR 0x2
87 #define AD5629R_DAC_D_ADDR 0x3
88 #define AD5629R_DAC_E_ADDR 0x4
89 #define AD5629R_DAC_F_ADDR 0x5
90 #define AD5629R_DAC_G_ADDR 0x6
91 #define AD5629R_DAC_H_ADDR 0x7
92 #define AD5629R_DAC_ALL_ADDR 0xF
93 
94 /* DAC Selection */
95 #define DAC_A_SEL 1
96 #define DAC_B_SEL 2
97 #define DAC_C_SEL 4
98 #define DAC_D_SEL 8
99 #define DAC_E_SEL 16
100 #define DAC_F_SEL 32
101 #define DAC_G_SEL 64
102 #define DAC_H_SEL 128
103 
104 /* Power modes */
105 #define PWR_NORMAL 0
106 #define PWR_1K_TO_GND 1
107 #define PWR_100K_TO_GND 2
108 #define PWR_3_STATE 3
109 
110 /* Clear code values */
111 #define CLR_TO_ZEROSCALE 0
112 #define CLR_TO_MIDSCALE 1
113 #define CLR_TO_FULLSCALE 2
114 #define CLR_NOOP 3
115 
116 /* Internal reference status */
117 #define REF_ON 1
118 #define REF_OFF 0
119 
120 /******************************************************************************/
121 /*************************** Types Declarations *******************************/
122 /******************************************************************************/
123 /* Supported devices */
130 };
131 
135 };
136 
138  uint32_t resolution;
140 };
141 
142 struct ad5629r_dev {
143  /* I2C */
145  /* SPI */
147  /* GPIO */
150  /* Device Settings */
152 };
153 
155  /* I2C */
157  /* SPI */
159  /* GPIO */
162  /* Device Settings */
164 };
165 
166 /******************************************************************************/
167 /************************ Functions Declarations ******************************/
168 /******************************************************************************/
169 /* Initializes the communication with the device. */
170 int8_t ad5629r_init(struct ad5629r_dev **device,
172 /* Free the resources allocated by AD5629R_Init(). */
173 int32_t ad5629r_remove(struct ad5629r_dev *dev);
174 /* Writes a value to Input Register N of selected DAC channel. */
175 void ad5629r_write_reg_n(struct ad5629r_dev *dev,
176  uint8_t dac_n,
177  uint16_t dac_value);
178 /* Updates selected DAC register. */
179 void ad5629r_update_dac_n(struct ad5629r_dev *dev,
180  uint8_t dac_n);
181 /* Writes a value to Input Register N of selected DAC channel, then updates all. */
183  uint8_t dac_n,
184  uint16_t dac_value);
185 /* Writes a value to Input Register N and updates the respective DAC channel. */
187  uint8_t dac_n,
188  uint16_t dac_value);
189 /* Sets the power mode for one or more selected DAC channels. */
190 void ad5629r_set_power_mode(struct ad5629r_dev *dev,
191  uint8_t dac_sel,
192  uint8_t mode);
193 /* Loads the Clear Code Register with a certain value. */
195  uint8_t clear_value);
196 /* Loads the LDAC register with a certain value. */
197 void ad5629r_load_ldac_reg(struct ad5629r_dev *dev,
198  uint8_t dac_sel);
199 /* Makes a power-on reset. */
200 void ad5629r_reset(struct ad5629r_dev *dev);
201 /* Turns on/off the internal reference. */
202 void ad5629r_set_ref(struct ad5629r_dev *dev,
203  uint8_t status);
204 
205 
206 #endif /* AD5629_H_ */
ad5629r_dev::act_device
enum ad5629r_type act_device
Definition: ad5629r.h:151
ad5629r_init_param
Definition: ad5629r.h:154
ID_AD5668
@ ID_AD5668
Definition: ad5629r.h:127
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
ad5629r_remove
int32_t ad5629r_remove(struct ad5629r_dev *dev)
Free the resources allocated by AD5629R_Init().
Definition: ad5629r.c:123
AD5629R_LOAD_LDAC_REG
#define AD5629R_LOAD_LDAC_REG
Definition: ad5629r.h:63
ad5629r_set_ctrl
void ad5629r_set_ctrl(struct ad5629r_dev *dev, uint8_t function, uint8_t dac_n, uint32_t data)
Write to input register and read from output register via SPI.
Definition: ad5629r.c:153
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
ad5629r_write_reg_nupdate_all
void ad5629r_write_reg_nupdate_all(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N of selected DAC channel, then updates all.
Definition: ad5629r.c:274
ad5629r_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5629r.h:146
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
ad5629r_reset
void ad5629r_reset(struct ad5629r_dev *dev)
Makes a power-on reset.
Definition: ad5629r.c:395
ad5629r_write_reg_nupdate_n
void ad5629r_write_reg_nupdate_n(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N and updates the respective DAC channel.
Definition: ad5629r.c:294
no_os_spi.h
Header file of SPI Interface.
ad5629r_set_power_mode
void ad5629r_set_power_mode(struct ad5629r_dev *dev, uint8_t dac_sel, uint8_t mode)
Sets the power mode for one or more selected DAC channels.
Definition: ad5629r.c:321
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
comm_type_t
comm_type_t
Definition: ad5629r.h:132
ad5629r_chip_info::communication
enum comm_type_t communication
Definition: ad5629r.h:139
AD5629R_WRITE_N_UPDATE_ALL
#define AD5629R_WRITE_N_UPDATE_ALL
Definition: ad5629r.h:59
ad5629r_init
int8_t ad5629r_init(struct ad5629r_dev **device, struct ad5629r_init_param init_param)
Initializes the communication with the device.
Definition: ad5629r.c:85
ad5629r_init_param::i2c_init
struct no_os_i2c_init_param i2c_init
Definition: ad5629r.h:156
device
Definition: ad9361_util.h:69
ID_AD5628
@ ID_AD5628
Definition: ad5629r.h:129
ID_AD5629R
@ ID_AD5629R
Definition: ad5629r.h:125
ad5629r_dev::gpio_ldac
struct no_os_gpio_desc * gpio_ldac
Definition: ad5629r.h:148
AD5629R_LDAC_LOW
#define AD5629R_LDAC_LOW
Definition: ad5629r.h:71
com_spi
@ com_spi
Definition: ad5629r.h:133
ad5629r_type
ad5629r_type
Definition: ad5629r.h:124
ad5629r.h
Header file of AD5629R Driver for Microblaze processor.
ad5629r_init
int8_t ad5629r_init(struct ad5629r_dev **device, struct ad5629r_init_param init_param)
Initializes the communication with the device.
Definition: ad5629r.c:85
ad5629r_write_reg_n
void ad5629r_write_reg_n(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N of selected DAC channel.
Definition: ad5629r.c:237
ad5629r_init_param::act_device
enum ad5629r_type act_device
Definition: ad5629r.h:163
ad5629r_write_reg_nupdate_all
void ad5629r_write_reg_nupdate_all(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N of selected DAC channel, then updates all.
Definition: ad5629r.c:274
ad5629r_set_input_reg
void ad5629r_set_input_reg(struct ad5629r_dev *dev, uint8_t function, uint8_t dac_n, uint16_t dac_value)
Write to input register and read from output register via SPI.
Definition: ad5629r.c:195
ad5629r_update_dac_n
void ad5629r_update_dac_n(struct ad5629r_dev *dev, uint8_t dac_n)
Updates selected DAC register.
Definition: ad5629r.c:255
AD5629R_WRITE_N
#define AD5629R_WRITE_N
Definition: ad5629r.h:57
AD5629R_LDAC_OUT
#define AD5629R_LDAC_OUT
Definition: ad5629r.h:69
ad5629r_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5629r.h:158
AD5629R_CLR_HIGH
#define AD5629R_CLR_HIGH
Definition: ad5629r.h:80
ID_AD5669R
@ ID_AD5669R
Definition: ad5629r.h:126
ad5629r_load_clear_code_reg
void ad5629r_load_clear_code_reg(struct ad5629r_dev *dev, uint8_t clear_value)
Loads the Clear Code Register with a certain value.
Definition: ad5629r.c:348
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
com_i2c
@ com_i2c
Definition: ad5629r.h:134
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:192
ad5629r_load_ldac_reg
void ad5629r_load_ldac_reg(struct ad5629r_dev *dev, uint8_t dac_sel)
Loads the LDAC register with a certain value.
Definition: ad5629r.c:375
ad5629r_load_clear_code_reg
void ad5629r_load_clear_code_reg(struct ad5629r_dev *dev, uint8_t clear_value)
Loads the Clear Code Register with a certain value.
Definition: ad5629r.c:348
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad5629r_set_ref
void ad5629r_set_ref(struct ad5629r_dev *dev, uint8_t status)
Turns on/off the internal reference.
Definition: ad5629r.c:413
ad5629r_dev::gpio_clr
struct no_os_gpio_desc * gpio_clr
Definition: ad5629r.h:149
ad5629r_init_param::gpio_clr
struct no_os_gpio_init_param gpio_clr
Definition: ad5629r.h:161
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
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
no_os_i2c.h
Header file of I2C Interface.
AD5629R_LOAD_CLEAR_REG
#define AD5629R_LOAD_CLEAR_REG
Definition: ad5629r.h:62
AD5629R_REFERENCE
#define AD5629R_REFERENCE
Definition: ad5629r.h:65
ad5629r_dev
Definition: ad5629r.h:142
ID_AD5648
@ ID_AD5648
Definition: ad5629r.h:128
AD5629R_RESET
#define AD5629R_RESET
Definition: ad5629r.h:64
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
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
AD5629R_POWER
#define AD5629R_POWER
Definition: ad5629r.h:61
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
AD5629R_UPDATE_N
#define AD5629R_UPDATE_N
Definition: ad5629r.h:58
MAX_RESOLUTION
#define MAX_RESOLUTION
Definition: ad5446.c:43
ad5629r_load_ldac_reg
void ad5629r_load_ldac_reg(struct ad5629r_dev *dev, uint8_t dac_sel)
Loads the LDAC register with a certain value.
Definition: ad5629r.c:375
AD5629R_CLR_OUT
#define AD5629R_CLR_OUT
Definition: ad5629r.h:76
ad5629r_remove
int32_t ad5629r_remove(struct ad5629r_dev *dev)
Free the resources allocated by AD5629R_Init().
Definition: ad5629r.c:123
ad5629r_chip_info
Definition: ad5629r.h:137
ad5629r_set_ref
void ad5629r_set_ref(struct ad5629r_dev *dev, uint8_t status)
Turns on/off the internal reference.
Definition: ad5629r.c:413
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
AD5629R_WRITE_N_UPDATE_N
#define AD5629R_WRITE_N_UPDATE_N
Definition: ad5629r.h:60
no_os_gpio.h
Header file of GPIO Interface.
ad5629r_dev::i2c_desc
struct no_os_i2c_desc * i2c_desc
Definition: ad5629r.h:144
ad5629r_write_reg_n
void ad5629r_write_reg_n(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N of selected DAC channel.
Definition: ad5629r.c:237
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
ad5629r_init_param::gpio_ldac
struct no_os_gpio_init_param gpio_ldac
Definition: ad5629r.h:160
ad5629r_update_dac_n
void ad5629r_update_dac_n(struct ad5629r_dev *dev, uint8_t dac_n)
Updates selected DAC register.
Definition: ad5629r.c:255
ad5629r_set_power_mode
void ad5629r_set_power_mode(struct ad5629r_dev *dev, uint8_t dac_sel, uint8_t mode)
Sets the power mode for one or more selected DAC channels.
Definition: ad5629r.c:321
ad5629r_chip_info::resolution
uint32_t resolution
Definition: ad5629r.h:138
ad5629r_reset
void ad5629r_reset(struct ad5629r_dev *dev)
Makes a power-on reset.
Definition: ad5629r.c:395
ad5629r_write_reg_nupdate_n
void ad5629r_write_reg_nupdate_n(struct ad5629r_dev *dev, uint8_t dac_n, uint16_t dac_value)
Writes a value to Input Register N and updates the respective DAC channel.
Definition: ad5629r.c:294
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:140