no-OS
ad5449.h
Go to the documentation of this file.
1 /***************************************************************************/
36 /*****************************************************************************/
37 /***************************** Include Files *********************************/
38 /*****************************************************************************/
39 #include <stdint.h>
40 #include "no_os_gpio.h"
41 #include "no_os_spi.h"
42 
43 /******************************************************************************/
44 /*************************** Types Declarations *******************************/
45 /******************************************************************************/
46 enum bool_t {
47  false,
48  true
49 };
50 
51 /* Supported devices */
60 };
61 
63  uint8_t num_channels;
64  uint8_t resolution;
66 };
67 
68 struct ad5449_dev {
69  /* SPI */
71  /* GPIO */
74  /* Device Settings */
76  uint16_t control_reg;
77 };
78 
80  /* SPI */
82  /* GPIO */
85  /* Device Settings */
87 };
88 
89 /* Control Bits */
90 #define AD5449_CTRL_NOP 0
91 #define AD5449_CTRL_LOADUPDATE(x) (1 + 3 * (x))
92 #define AD5449_CTRL_READBACK(x) (2 + 3 * (x))
93 #define AD5449_CTRL_LOAD(x) (3 + 3 * (x))
94 #define AD5449_CTRL_UPDATEALL 7
95 #define AD5449_CTRL_LOADALL 8
96 #define AD5449_CTRL_DAISY_CHAIN 9
97 #define AD5449_CTRL_CLK_EDGE 10
98 #define AD5449_CTRL_CLR_ZERO 11
99 #define AD5449_CTRL_CLR_MID 12
100 #define AD5449_CTRL_REG 13
101 
102 /* AD5449 channels */
103 #define AD5449_CH_A 0
104 #define AD5449_CH_B 1
105 
106 /* Clear target scales */
107 #define AD5449_ZERO_SCALE 0
108 #define AD5449_MID_SCALE 1
109 
110 /* Active clock edge */
111 #define AD5449_CLOCK_NEGEDGE 0
112 #define AD5449_CLOCK_POSEDGE 1
113 
114 /* Daisy-Chain Control */
115 #define AD5449_DAISY_CHAIN_DIS 0
116 #define AD5449_DAISY_CHAIN_EN 1
117 
118 /* AD5449_CTRL_REG definition */
119 #define AD5449_SDO_MASK (3 << 10)
120 #define AD5449_DSY_MASK (1 << 9)
121 #define AD5449_HCLR_MASK (1 << 8)
122 #define AD5449_SCLK_MASK (1 << 7)
123 #define AD5449_SDO_BIT 10
124 #define AD5449_DSY_BIT 9
125 #define AD5449_HCLR_BIT 8
126 #define AD5449_SCLK_BIT 7
127 
128 /* AD5449 GPIO */
129 #define AD5449_LDAC_OUT no_os_gpio_direction_output(dev->gpio_ldac, \
130  NO_OS_GPIO_HIGH)
131 #define AD5449_LDAC_LOW no_os_gpio_set_value(dev->gpio_ldac, \
132  NO_OS_GPIO_LOW)
133 #define AD5449_LDAC_HIGH no_os_gpio_set_value(dev->gpio_ldac, \
134  NO_OS_GPIO_HIGH)
135 
136 #define AD5449_CLR_OUT no_os_gpio_direction_output(dev->gpio_clr, \
137  NO_OS_GPIO_HIGH)
138 #define AD5449_CLR_LOW no_os_gpio_set_value(dev->gpio_clr, \
139  NO_OS_GPIO_LOW)
140 #define AD5449_CLR_HIGH no_os_gpio_set_value(dev->gpio_clr, \
141  NO_OS_GPIO_HIGH)
142 
143 /* SDO Control Bits */
144 #define AD5449_SDO_FULL 0
145 #define AD5449_SDO_WEAK 1
146 #define AD5449_SDO_OPEN_DRAIN 2
147 #define AD5449_SDO_DISABLE 3
148 
149 /******************************************************************************/
150 /************************ Functions Declarations ******************************/
151 /******************************************************************************/
152 
153 /* Initialize SPI and Initial Values for AD5449 Board. */
154 int8_t ad5449_init(struct ad5449_dev **device,
156 
157 /* Free the resources allocated by AD5449_Init(). */
158 int32_t ad5449_remove(struct ad5449_dev *dev);
159 
160 /* Write to shift register via SPI. */
161 uint16_t ad5449_set_input_shift_reg(struct ad5449_dev *dev,
162  uint16_t command,
163  uint16_t data);
164 
165 /* Load and updates the selected DAC with a given value. */
166 void ad5449_load_update_channel(struct ad5449_dev *dev,
167  uint8_t channel,
168  uint16_t dac_value);
169 
170 /* Load selected DAC input register with a given value. */
171 void ad5449_load_channel(struct ad5449_dev *dev,
172  uint8_t channel,
173  uint16_t dac_value);
174 
175 /* Read from the selected DAC register. */
176 uint16_t ad5449_readback_channel(struct ad5449_dev *dev,
177  uint8_t channel);
178 
179 /* Update the DAC outputs (all channels). */
180 void ad5449_update_all(struct ad5449_dev *dev);
181 
182 /* Load the DAC input registers. */
183 void ad5449_load_all(struct ad5449_dev *dev,
184  int16_t dac_value);
185 
186 /* Set up the scale where to the output will be cleared on active CLR signal */
187 void ad5449_clear_scale_setup(struct ad5449_dev *dev,
188  int8_t type);
189 
190 /* Enable/disable the Daisy-Chain mode */
191 void ad5449_daisy_chain_setup(struct ad5449_dev *dev,
192  int8_t value);
193 
194 /* Control the SDO output driver strength */
195 void ad5449_sdocontrol(struct ad5449_dev *dev,
196  int8_t control_bits);
197 
198 /* Set up the active clock edge of the SPI interface */
199 void ad5449_sclksetup(struct ad5449_dev *dev,
200  int8_t value);
ad5449_sclksetup
void ad5449_sclksetup(struct ad5449_dev *dev, int8_t value)
Set up the active clock edge of the SPI interface.
Definition: ad5449.c:448
no_os_alloc.h
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:79
ad5449_load_all
void ad5449_load_all(struct ad5449_dev *dev, int16_t dac_value)
Load the DAC input registers. This function has a physical result just with devices with two channels...
Definition: ad5449.c:320
AD5449_CLOCK_POSEDGE
#define AD5449_CLOCK_POSEDGE
Definition: ad5449.h:112
ad5449_update_all
void ad5449_update_all(struct ad5449_dev *dev)
Update the DAC outputs. This function has a physical result just with devices with two channels.
Definition: ad5449.c:302
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
ad5449_init_param::gpio_ldac
struct no_os_gpio_init_param gpio_ldac
Definition: ad5449.h:83
AD5449_CTRL_REG
#define AD5449_CTRL_REG
Definition: ad5449.h:100
AD5449_SDO_BIT
#define AD5449_SDO_BIT
Definition: ad5449.h:123
no_os_spi.h
Header file of SPI Interface.
LSB_OFFSET
#define LSB_OFFSET
Definition: ad5449.c:48
AD5449_CH_A
#define AD5449_CH_A
Definition: ad5449.h:103
ad5449_chip_info
Definition: ad5449.h:62
ad5449_daisy_chain_setup
void ad5449_daisy_chain_setup(struct ad5449_dev *dev, int8_t value)
Enable/disable the Daisy-Chain mode.
Definition: ad5449.c:381
ID_AD5415
@ ID_AD5415
Definition: ad5449.h:53
AD5449_CLR_HIGH
#define AD5449_CLR_HIGH
Definition: ad5449.h:140
ad5449_chip_info::num_channels
uint8_t num_channels
Definition: ad5449.h:63
AD5449_CTRL_DAISY_CHAIN
#define AD5449_CTRL_DAISY_CHAIN
Definition: ad5449.h:96
ad5449_daisy_chain_setup
void ad5449_daisy_chain_setup(struct ad5449_dev *dev, int8_t value)
Enable/disable the Daisy-Chain mode.
Definition: ad5449.c:381
device
Definition: ad9361_util.h:69
CMD_OFFSET
#define CMD_OFFSET
Definition: ad5449.c:44
ad5449_load_channel
void ad5449_load_channel(struct ad5449_dev *dev, uint8_t channel, uint16_t dac_value)
Load selected DAC input register with a given value.
Definition: ad5449.c:246
ad5449_set_input_shift_reg
uint16_t ad5449_set_input_shift_reg(struct ad5449_dev *dev, uint16_t command, uint16_t data)
Write to input register and read from output register via SPI.
Definition: ad5449.c:179
AD5449_LDAC_OUT
#define AD5449_LDAC_OUT
Definition: ad5449.h:129
AD5449_ZERO_SCALE
#define AD5449_ZERO_SCALE
Definition: ad5449.h:107
AD5449_DSY_BIT
#define AD5449_DSY_BIT
Definition: ad5449.h:124
ad5449_dev
Definition: ad5449.h:68
bool_t
bool_t
Definition: ad5446.h:55
DATA_MASK
#define DATA_MASK
Definition: ad5449.c:42
ad5449_load_update_channel
void ad5449_load_update_channel(struct ad5449_dev *dev, uint8_t channel, uint16_t dac_value)
Loads and updates the selected DAC with a given value.
Definition: ad5449.c:220
PKT_LENGTH
#define PKT_LENGTH
Definition: ad5449.c:49
ad5449_chip_info::has_ctrl
enum bool_t has_ctrl
Definition: ad5449.h:65
ad5449_load_channel
void ad5449_load_channel(struct ad5449_dev *dev, uint8_t channel, uint16_t dac_value)
Load selected DAC input register with a given value.
Definition: ad5449.c:246
ad5449_readback_channel
uint16_t ad5449_readback_channel(struct ad5449_dev *dev, uint8_t channel)
Read from the selected DAC register.
Definition: ad5449.c:271
MSB_OFFSET
#define MSB_OFFSET
Definition: ad5449.c:46
AD5449_LDAC_LOW
#define AD5449_LDAC_LOW
Definition: ad5449.h:131
ad5449_dev::gpio_ldac
struct no_os_gpio_desc * gpio_ldac
Definition: ad5449.h:72
ad5449.h
Header file of AD5449 Driver. This driver supporting the following devices: AD5415,...
ad5449_chip_info::resolution
uint8_t resolution
Definition: ad5449.h:64
AD5449_CTRL_LOAD
#define AD5449_CTRL_LOAD(x)
Definition: ad5449.h:93
ID_AD5443
@ ID_AD5443
Definition: ad5449.h:58
AD5449_HCLR_MASK
#define AD5449_HCLR_MASK
Definition: ad5449.h:121
ad5449_load_update_channel
void ad5449_load_update_channel(struct ad5449_dev *dev, uint8_t channel, uint16_t dac_value)
Loads and updates the selected DAC with a given value.
Definition: ad5449.c:220
ad5449_readback_channel
uint16_t ad5449_readback_channel(struct ad5449_dev *dev, uint8_t channel)
Read from the selected DAC register.
Definition: ad5449.c:271
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:171
AD5449_MID_SCALE
#define AD5449_MID_SCALE
Definition: ad5449.h:108
AD5449_CTRL_LOADALL
#define AD5449_CTRL_LOADALL
Definition: ad5449.h:95
AD5449_CTRL_CLR_ZERO
#define AD5449_CTRL_CLR_ZERO
Definition: ad5449.h:98
ad5449_sdocontrol
void ad5449_sdocontrol(struct ad5449_dev *dev, int8_t control_bits)
Control the SDO output driver strength. This function is supported by the devices : AD5415,...
Definition: ad5449.c:420
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:96
ad5449_init_param::act_device
enum ad5449_type_t act_device
Definition: ad5449.h:86
MAX_RESOLUTION
#define MAX_RESOLUTION
Definition: ad5449.c:41
ad5449_init
int8_t ad5449_init(struct ad5449_dev **device, struct ad5449_init_param init_param)
Initialize SPI and Initial Values for AD5449 Board.
Definition: ad5449.c:105
TWO_BIT_MASK
#define TWO_BIT_MASK
Definition: ad5449.c:51
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
AD5449_DSY_MASK
#define AD5449_DSY_MASK
Definition: ad5449.h:120
AD5449_CTRL_UPDATEALL
#define AD5449_CTRL_UPDATEALL
Definition: ad5449.h:94
AD5449_CTRL_CLR_MID
#define AD5449_CTRL_CLR_MID
Definition: ad5449.h:99
ID_AD5449
@ ID_AD5449
Definition: ad5449.h:59
ad5449_type_t
ad5449_type_t
Definition: ad5449.h:52
MSB_MASK
#define MSB_MASK
Definition: ad5449.c:45
ad5449_set_input_shift_reg
uint16_t ad5449_set_input_shift_reg(struct ad5449_dev *dev, uint16_t command, uint16_t data)
Write to input register and read from output register via SPI.
Definition: ad5449.c:179
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
ID_AD5426
@ ID_AD5426
Definition: ad5449.h:54
AD5449_SCLK_BIT
#define AD5449_SCLK_BIT
Definition: ad5449.h:126
ad5449_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad5449.h:70
AD5449_CTRL_LOADUPDATE
#define AD5449_CTRL_LOADUPDATE(x)
Definition: ad5449.h:91
AD5449_CLR_OUT
#define AD5449_CLR_OUT
Definition: ad5449.h:136
ad5449_clear_scale_setup
void ad5449_clear_scale_setup(struct ad5449_dev *dev, int8_t type)
Set up the scale where to the output will be cleared on active CLR signal.
Definition: ad5449.c:341
AD5449_DAISY_CHAIN_EN
#define AD5449_DAISY_CHAIN_EN
Definition: ad5449.h:116
ID_AD5432
@ ID_AD5432
Definition: ad5449.h:56
AD5449_HCLR_BIT
#define AD5449_HCLR_BIT
Definition: ad5449.h:125
ad5449_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad5449.h:81
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:113
ad5449_init
int8_t ad5449_init(struct ad5449_dev **device, struct ad5449_init_param init_param)
Initialize SPI and Initial Values for AD5449 Board.
Definition: ad5449.c:105
ad5449_sclksetup
void ad5449_sclksetup(struct ad5449_dev *dev, int8_t value)
Set up the active clock edge of the SPI interface.
Definition: ad5449.c:448
ID_AD5429
@ ID_AD5429
Definition: ad5449.h:55
ad5449_dev::act_device
enum ad5449_type_t act_device
Definition: ad5449.h:75
ad5449_load_all
void ad5449_load_all(struct ad5449_dev *dev, int16_t dac_value)
Load the DAC input registers. This function has a physical result just with devices with two channels...
Definition: ad5449.c:320
ad5449_sdocontrol
void ad5449_sdocontrol(struct ad5449_dev *dev, int8_t control_bits)
Control the SDO output driver strength. This function is supported by the devices : AD5415,...
Definition: ad5449.c:420
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
no_os_gpio.h
Header file of GPIO Interface.
ID_AD5439
@ ID_AD5439
Definition: ad5449.h:57
AD5449_SDO_FULL
#define AD5449_SDO_FULL
Definition: ad5449.h:144
ad5449_remove
int32_t ad5449_remove(struct ad5449_dev *dev)
Free the resources allocated by ad5449_init().
Definition: ad5449.c:156
ad5449_dev::control_reg
uint16_t control_reg
Definition: ad5449.h:76
ad5449_update_all
void ad5449_update_all(struct ad5449_dev *dev)
Update the DAC outputs. This function has a physical result just with devices with two channels.
Definition: ad5449.c:302
ad5449_init_param::gpio_clr
struct no_os_gpio_init_param gpio_clr
Definition: ad5449.h:84
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
ad5449_init_param
Definition: ad5449.h:79
AD5449_SCLK_MASK
#define AD5449_SCLK_MASK
Definition: ad5449.h:122
ad5449_dev::gpio_clr
struct no_os_gpio_desc * gpio_clr
Definition: ad5449.h:73
AD5449_CTRL_READBACK
#define AD5449_CTRL_READBACK(x)
Definition: ad5449.h:92
CMD_MASK
#define CMD_MASK
Definition: ad5449.c:43
ad5449_remove
int32_t ad5449_remove(struct ad5449_dev *dev)
Free the resources allocated by ad5449_init().
Definition: ad5449.c:156
AD5449_DAISY_CHAIN_DIS
#define AD5449_DAISY_CHAIN_DIS
Definition: ad5449.h:115
AD5449_CTRL_CLK_EDGE
#define AD5449_CTRL_CLK_EDGE
Definition: ad5449.h:97
AD5449_CLOCK_NEGEDGE
#define AD5449_CLOCK_NEGEDGE
Definition: ad5449.h:111
ad5449_clear_scale_setup
void ad5449_clear_scale_setup(struct ad5449_dev *dev, int8_t type)
Set up the scale where to the output will be cleared on active CLR signal.
Definition: ad5449.c:341
AD5449_CTRL_NOP
#define AD5449_CTRL_NOP
Definition: ad5449.h:90
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:125
AD5449_SDO_MASK
#define AD5449_SDO_MASK
Definition: ad5449.h:119
LSB_MASK
#define LSB_MASK
Definition: ad5449.c:47