no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ad525x.h
Go to the documentation of this file.
1/**************************************************************************/
35#ifndef __AD525X_H__
36#define __AD525X_H__
37
38#include <stdint.h>
39#include "no_os_delay.h"
40#include "no_os_gpio.h"
41#include "no_os_spi.h"
42#include "no_os_i2c.h"
43
44/* GPIOs */
45#define AD525X_RESET_OUT no_os_gpio_direction_output(dev->gpio_reset, \
46 NO_OS_GPIO_HIGH)
47#define AD525X_RESET_LOW no_os_gpio_set_value(dev->gpio_reset, \
48 NO_OS_GPIO_LOW)
49#define AD525X_RESET_HIGH no_os_gpio_set_value(dev->gpio_reset, \
50 NO_OS_GPIO_HIGH)
51#define AD525X_SHUTDOWN_OUT no_os_gpio_direction_output(dev->gpio_shutdown, \
52 NO_OS_GPIO_HIGH)
53#define AD525X_SHUTDOWN_LOW no_os_gpio_set_value(dev->gpio_shutdown, \
54 NO_OS_GPIO_LOW)
55#define AD525X_SHUTDOWN_HIGH no_os_gpio_set_value(dev->gpio_shutdown, \
56 NO_OS_GPIO_HIGH)
57#define AD525X_READY_IN no_os_gpio_direction_input(dev->gpio_ready)
58#define AD525X_READY_LOW no_os_gpio_set_value(dev->gpio_ready, \
59 NO_OS_GPIO_LOW)
60#define AD525X_READY_HIGH no_os_gpio_set_value(dev->gpio_ready, \
61 NO_OS_GPIO_HIGH)
62#define AD525X_WP_BF_OUT no_os_gpio_direction_output(dev->gpio_wpbf, \
63 NO_OS_GPIO_HIGH)
64#define AD525X_WP_BF_LOW no_os_gpio_set_value(dev->gpio_wpbf, \
65 NO_OS_GPIO_LOW)
66#define AD525X_WP_BF_HIGH no_os_gpio_set_value(dev->gpio_wpbf, \
67 NO_OS_GPIO_HIGH)
68
69/* Data word masks */
70#define AD525X_MEM_ADDR_MASK 0xF
71#define AD525X_RDAC_ADDR_MASK_1BIT 0x1
72#define AD525X_RDAC_ADDR_MASK_3BIT 0x7
73#define AD525X_DATA8_MASK 0xFF
74#define AD525X_DATA10_MASK 0x3FF
75
76/*********************** Command definitions *********************************/
77#define AD525X_CMD_NOP 0x0
78#define AD525X_CMD_MEM2RDAC 0x1
79#define AD525X_CMD_RDAC2MEM 0x2
80#define AD525X_CMD_DECRDAC_6DB 0x3
81#define AD525X_CMD_DECALLRDAC_6DB 0x4
82#define AD525X_CMD_DECRDAC_ONE 0x5
83#define AD525X_CMD_DECALLRDAC_ONE 0x6
84#define AD525X_CMD_RESET 0x7
85#define AD525X_CMD_INCRDAC_6DB 0x8
86#define AD525X_CMD_INCALLRDAC_6DB 0x9
87#define AD525X_CMD_INCRDAC_ONE 0xA
88#define AD525X_CMD_INCALLRDAC_ONE 0xB
89/*****************************************************************************/
90
91/**************************** SPI specific macros ****************************/
92#define AD525X_CMD_SPI_OFFSET 0x4
93#define AD525X_CMD_MASK 0xF
94/* SPI Read/Write commands */
95#define AD525X_CMD_SPI_SREG2MEM 0x3
96#define AD525X_CMD_SPI_MEM2SREG 0x9 // Result in the next frame
97#define AD525X_CMD_SPI_RDAC2SREG 0xA // Result in the next frame
98#define AD525X_CMD_SPI_SREG2RDAC 0xB
99
100/*************************** I2C specific macros *****************************/
101/* I2C device address */
102#define AD525X_I2C_HARD_ADDR 0x2C
103/* Package pin-programmable address bits */
104#define AD525X_I2C_PIN_ADDR_MASK 0x03
105/* Mask for I2C Control Bits */
106#define AD525X_I2C_CNTR_MASK 0xBF
107/* Access Types */
108#define AD525X_I2C_CMD_OR_REG 0x80
109#define AD525X_I2C_EE_OR_RDAC 0x20
110/* Address mask for EEMEM addresses, one bit wider than at devices with SPI */
111#define AD525X_I2C_MEM_ADDR_MASK 0x1F
112/* The offset of the Command in the I2C word */
113#define AD525X_CMD_I2C_OFFSET 0x3
114
115/*************************** Reading tolerance addresses *********************/
116/* Note: The valid tolerance addresses varies on different devices. Check the data sheet for further information */
117#define AD525x_RDAC_TOLERANCE 0x0F
118#define AD525X_RDAC0_SIGN_TOL 0x18
119#define AD525X_RDAC0_DECIMAL_TOL 0x19
120#define AD525X_RDAC1_SIGN_TOL 0x1A
121#define AD525X_RDAC1_DECIMAL_TOL 0x1B
122#define AD525X_RDAC2_SIGN_TOL 0x1C
123#define AD525X_RDAC2_DECIMAL_TOL 0x1D
124#define AD525X_RDAC3_SIGN_TOL 0x1E
125#define AD525X_RDAC4_DECIMAL_TOL 0x1F
126
127/* Custom boolean type */
128enum bool_t {
129 false,
130 true
131};
132
133/* Supported devices */
143
144/* Communication types */
149
155
157 /* I2C */
159 /* SPI */
161 /* GPIO */
166 /* Device Settings */
168};
169
183
184/* Initialize the communication with the device */
185int8_t ad525x_init(struct ad525x_dev **device,
187
188/* Free the resources allocated by ad525x_init(). */
189int32_t ad525x_remove(struct ad525x_dev *dev);
190
191/* Read data from the EEMEM */
192uint16_t ad525x_read_mem(struct ad525x_dev *dev,
193 uint8_t address);
194
195/* Write data to EEMEM */
196void ad525x_write_mem(struct ad525x_dev *dev,
197 uint8_t address,
198 uint16_t data);
199
200/* Read the value of the RDAC register */
201uint16_t ad525x_read_rdac(struct ad525x_dev *dev,
202 uint8_t address);
203
204/* Write the value of the RDAC register */
205void ad525x_write_rdac(struct ad525x_dev *dev,
206 uint8_t address,
207 uint16_t data);
208
209/* Write quick commands to the device */
210void ad525x_write_command(struct ad525x_dev *dev,
211 uint8_t command,
212 uint8_t address);
213
214#endif // __AD525X_H__
int32_t ad525x_remove(struct ad525x_dev *dev)
Free the resources allocated by ad525x_init().
Definition ad525x.c:137
uint16_t ad525x_read_rdac(struct ad525x_dev *dev, uint8_t address)
Read data from the RDAC register.
Definition ad525x.c:271
ad525_x_type_t
Definition ad525x.h:134
@ ID_AD5254
Definition ad525x.h:140
@ ID_AD5232
Definition ad525x.h:135
@ ID_ADN2850
Definition ad525x.h:137
@ ID_AD5252
Definition ad525x.h:138
@ ID_AD5253
Definition ad525x.h:141
@ ID_AD5235
Definition ad525x.h:136
@ ID_AD5251
Definition ad525x.h:139
comm_type_t
Definition ad525x.h:145
uint16_t ad525x_read_mem(struct ad525x_dev *dev, uint8_t address)
Read data from the EEMEM.
Definition ad525x.c:172
void ad525x_write_rdac(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to RDAC register.
Definition ad525x.c:332
void ad525x_write_mem(struct ad525x_dev *dev, uint8_t address, uint16_t data)
Write data to EEMEM.
Definition ad525x.c:226
int8_t ad525x_init(struct ad525x_dev **device, struct ad525x_init_param init_param)
Initialize SPI and Initial Values for AD5172 Board.
Definition ad525x.c:89
void ad525x_write_command(struct ad525x_dev *dev, uint8_t command, uint8_t address)
Write quick commands to the device.
Definition ad525x.c:377
bool_t
Definition ad5446.h:48
comm_type_t
Definition ad5629r.h:123
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
@ I2C
Definition adxl372.h:311
@ SPI
Definition adxl372.h:310
Header file of Delay functions.
Header file of GPIO Interface.
Header file of I2C Interface.
Header file of SPI Interface.
Definition ad525x.h:150
uint8_t num_channels
Definition ad525x.h:151
uint16_t num_position
Definition ad525x.h:153
enum comm_type_t comm_type
Definition ad525x.h:152
Definition ad525x.h:156
struct no_os_gpio_desc * gpio_wpbf
Definition ad525x.h:165
struct no_os_i2c_desc * i2c_desc
Definition ad525x.h:158
struct no_os_gpio_desc * gpio_ready
Definition ad525x.h:164
enum ad525_x_type_t this_device
Definition ad525x.h:167
struct no_os_gpio_desc * gpio_reset
Definition ad525x.h:162
struct no_os_spi_desc * spi_desc
Definition ad525x.h:160
struct no_os_gpio_desc * gpio_shutdown
Definition ad525x.h:163
Definition ad525x.h:170
struct no_os_spi_init_param spi_init
Definition ad525x.h:174
struct no_os_i2c_init_param i2c_init
Definition ad525x.h:172
struct no_os_gpio_init_param gpio_wpbf
Definition ad525x.h:179
struct no_os_gpio_init_param gpio_shutdown
Definition ad525x.h:177
struct no_os_gpio_init_param gpio_reset
Definition ad525x.h:176
enum ad525_x_type_t this_device
Definition ad525x.h:181
struct no_os_gpio_init_param gpio_ready
Definition ad525x.h:178
Definition ad9361_util.h:63
Structure holding the GPIO descriptor.
Definition no_os_gpio.h:84
Structure holding the parameters for GPIO initialization.
Definition no_os_gpio.h:67
Structure holding I2C address descriptor.
Definition no_os_i2c.h:89
Structure holding the parameters for I2C initialization.
Definition no_os_i2c.h:52
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128