no-OS
ad7799.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef AD7799_H_
40 #define AD7799_H_
41 
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include <stdint.h>
46 #include <stdbool.h>
47 #include "no_os_spi.h"
48 
49 /******************************************************************************/
50 /********************** Macros and Types Declarations *************************/
51 /******************************************************************************/
52 
53 /*AD7799 Registers*/
54 #define AD7799_REG_COMM 0x0 /* Communications Register(WO, 8-bit) */
55 #define AD7799_REG_STAT 0x0 /* Status Register (RO, 8-bit) */
56 #define AD7799_REG_MODE 0x1 /* Mode Register (RW, 16-bit) */
57 #define AD7799_REG_CONF 0x2 /* Configuration Register (RW, 16-bit)*/
58 #define AD7799_REG_DATA 0x3 /* Data Register (RO, 16-/24-bit) */
59 #define AD7799_REG_ID 0x4 /* ID Register (RO, 8-bit) */
60 #define AD7799_REG_IO 0x5 /* IO Register (RO, 8-bit) */
61 #define AD7799_REG_OFFSET 0x6 /* Offset Register (RW, 24-bit) */
62 #define AD7799_REG_FULLSCALE 0x7 /* Full-Scale Register (RW, 24-bit) */
63 
64 /* AD7799 Polarity */
65 #define AD7799_BIPOLAR 0x0 /* Bipolar bit */
66 #define AD7799_UNIPOLAR 0x1 /* Unipolar bit */
67 
68 /* Communications Register Bit Designations (AD7799_REG_COMM) */
69 #define AD7799_COMM_WEN 0x80 /* Write Enable */
70 #define AD7799_COMM_WRITE 0x00 /* Write Operation */
71 #define AD7799_COMM_READ 0x40 /* Read Operation */
72 #define AD7799_COMM_ADDR(x) (((x) & 0x7) << 3) /* Register Address */
73 #define AD7799_COMM_CREAD 0x04 /* Continuous Read */
74 
75 /* Status Register Bit Designations (AD7799_REG_STAT) */
76 #define AD7799_STAT_RDY 0x80 /* Ready */
77 #define AD7799_STAT_ERR 0x40 /* Error (Overrange, Underrange) */
78 #define AD7799_STAT_CH3 0x04 /* Channel 3 */
79 #define AD7799_STAT_CH2 (1 << 1) /* Channel 2 */
80 #define AD7799_STAT_CH1 (1 << 0) /* Channel 1 */
81 
82 /* Mode Register Bit Designations (AD7799_REG_MODE) */
83 #define AD7799_MODE_SEL(x) (((x) & 0x7) << 13) /* Operation Mode Select */
84 #define AD7799_MODE_PSW(x) 0x1000 /* Power Switch Control Bit */
85 #define AD7799_MODE_RATE(x) ((x) & 0xF) /* Filter Update Rate */
86 
87 /* AD7799_MODE_SEL(x) options */
88 #define AD7799_MODE_CONT 0x0 /* Continuous Conversion Mode */
89 #define AD7799_MODE_SINGLE 0x1 /* Single Conversion Mode */
90 #define AD7799_MODE_IDLE 0x2 /* Idle Mode */
91 #define AD7799_MODE_PWRDN 0x3 /* Power-Down Mode */
92 #define AD7799_MODE_CAL_INT_ZERO 0x4 /* Internal Zero-Scale Calibration */
93 #define AD7799_MODE_CAL_INT_FULL 0x5 /* Internal Full-Scale Calibration */
94 #define AD7799_MODE_CAL_SYS_ZERO 0x6 /* System Zero-Scale Calibration */
95 #define AD7799_MODE_CAL_SYS_FULL 0x7 /* System Full-Scale Calibration */
96 
97 /* Configuration Register Bit Designations (AD7799_REG_CONF) */
98 #define AD7799_CONF_BO_EN 0x2000 /* Burnout Current */
99 #define AD7799_CONF_POLARITY(x) (((x) & 0x1) << 12) /* Unipolar/Bipolar */
100 #define AD7799_CONF_GAIN(x) (((x) & 0x7) << 8) /* Gain Select */
101 #define AD7799_CONF_REFDET(x) (((x) & 0x1) << 5) /* Reference detect */
102 #define AD7799_CONF_BUF 0x10 /* Buffered Mode Enable */
103 #define AD7799_CONF_CHAN(x) ((x) & 0x7) /* Channel select */
104 
105 /* AD7799_CONF_GAIN(x) options */
106 #define AD7799_GAIN_1 0x0
107 #define AD7799_GAIN_2 0x1
108 #define AD7799_GAIN_4 0x2
109 #define AD7799_GAIN_8 0x3
110 #define AD7799_GAIN_16 0x4
111 #define AD7799_GAIN_32 0x5
112 #define AD7799_GAIN_64 0x6
113 #define AD7799_GAIN_128 0x7
114 
115 /* AD7799 Register size */
116 #define AD7799_REG_SIZE_1B 0x1
117 #define AD7799_REG_SIZE_2B 0x2
118 #define AD7799_REG_SIZE_3B 0x3
119 
120 /* AD7799_CONF_REFDET(x) options */
121 #define AD7799_REFDET_ENA 0x1
122 #define AD7799_REFDET_DIS 0x0
123 
124 /* AD7799_CONF_CHAN(x) options */
125 #define AD7799_CH_AIN1P_AIN1M 0x0 /* AIN1(+) - AIN1(-) */
126 #define AD7799_CH_AIN2P_AIN2M 0x1 /* AIN2(+) - AIN2(-) */
127 #define AD7799_CH_AIN3P_AIN3M 0x2 /* AIN3(+) - AIN3(-) */
128 #define AD7799_CH_AIN1M_AIN1M 0x3 /* AIN1(-) - AIN1(-) */
129 #define AD7799_CH_AVDD_MONITOR 0x7 /* AVDD Monitor */
130 
131 /* ID Register Bit Designations (AD7799_REG_ID) */
132 #define AD7799_ID_MASK 0xF
133 
134 /* AD7799 Configuration Mask */
135 #define AD7799_REG_MASK 0xF
136 
137 /* IO (Excitation Current Sources) Register Bit Designations (AD7799_REG_IO) */
138 #define AD7799_IOEN 0x40
139 #define AD7799_IO1(x) (((x) & 0x1) << 4)
140 #define AD7799_IO2(x) (((x) & 0x1) << 5)
141 
142 /* AD7799 Timeout */
143 #define AD7799_TIMEOUT 0xFFFF
144 
145 /* AD7799 Reset Sequence */
146 #define AD7799_RESET_DATA 0xFF
147 
154  ID_AD7798 = 0x8,
156  ID_AD7799 = 0x9
157 };
158 
164 };
165 
170 struct ad7799_dev {
174  uint8_t chip_type;
176  const uint8_t *reg_size;
178  uint8_t gain;
180  bool polarity;
182  uint32_t vref_mv;
185 };
186 
197  uint8_t gain;
199  bool polarity;
201  uint32_t vref_mv;
204 };
205 
206 /******************************************************************************/
207 /************************ Functions Declarations ******************************/
208 /******************************************************************************/
209 
210 /* Read device register. */
211 int32_t ad7799_read(struct ad7799_dev *device, uint8_t reg_addr,
212  uint32_t *reg_data);
213 
214 /* Write device register */
215 int32_t ad7799_write(struct ad7799_dev *device, uint8_t reg_addr,
216  uint32_t reg_data);
217 
218 /* Software reset of the device. */
219 int32_t ad7799_reset(struct ad7799_dev *device);
220 
221 /* Set the device mode. */
222 int32_t ad7799_set_mode(struct ad7799_dev *device, uint8_t mode);
223 
224 /* Select the ADC channel. */
225 int32_t ad7799_set_channel(struct ad7799_dev *device, uint8_t ch);
226 
227 /* Read specific ADC channel. */
228 int32_t ad7799_get_channel(struct ad7799_dev *device, uint8_t ch,
229  uint32_t *reg_data);
230 
231 /* Read specific ADC channel data with the specified precision. */
232 int32_t ad7799_read_channel(struct ad7799_dev *device, uint8_t ch,
233  int32_t *data_scaled);
234 
235 /* Set the ADC gain. */
236 int32_t ad7799_set_gain(struct ad7799_dev *device, uint8_t gain);
237 
238 /* Get the ADC gain. */
239 int32_t ad7799_get_gain(struct ad7799_dev *device, uint8_t *gain);
240 
241 /* Enable or disable the reference detect function. */
242 int32_t ad7799_set_refdet(struct ad7799_dev *device, uint8_t ref_en);
243 
244 /* Set ADC polarity. */
245 int32_t ad7799_set_polarity(struct ad7799_dev *device, uint8_t polarity);
246 
247 /* Check the status of the device. */
248 int32_t ad7799_dev_ready(struct ad7799_dev *device);
249 
250 /* Initialize the device. */
251 int32_t ad7799_init(struct ad7799_dev **device,
252  const struct ad7799_init_param *init_param);
253 
254 /* Remove the device and release resources. */
255 int32_t ad7799_remove(struct ad7799_dev *device);
256 
257 #endif /* AD7799_H_ */
ad7799_set_gain
int32_t ad7799_set_gain(struct ad7799_dev *device, uint8_t gain)
Set the ADC gain.
Definition: ad7799.c:282
ad7799_precision
ad7799_precision
Definition: ad7799.h:159
AD7799_COMM_ADDR
#define AD7799_COMM_ADDR(x)
Definition: ad7799.h:72
timeout
uint32_t timeout
Definition: ad413x.c:54
ad7799_init
int32_t ad7799_init(struct ad7799_dev **device, const struct ad7799_init_param *init_param)
Initialize the device.
Definition: ad7799.c:396
ad7799_dev::chip_type
uint8_t chip_type
Definition: ad7799.h:174
ad7799_set_mode
int32_t ad7799_set_mode(struct ad7799_dev *device, uint8_t mode)
Set the device mode.
Definition: ad7799.c:162
ad7799_dev
AD7798/AD7799 Device description.
Definition: ad7799.h:170
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:83
AD7799_REG_DATA
#define AD7799_REG_DATA
Definition: ad7799.h:58
no_os_spi.h
Header file of SPI Interface.
ad7799_read_channel
int32_t ad7799_read_channel(struct ad7799_dev *device, uint8_t ch, int32_t *data_scaled)
Read data from specific ADC channel with specified precision.
Definition: ad7799.c:244
AD7799_RESET_DATA
#define AD7799_RESET_DATA
Definition: ad7799.h:146
AD7799_REG_FULLSCALE
#define AD7799_REG_FULLSCALE
Definition: ad7799.h:62
ad7799_get_channel
int32_t ad7799_get_channel(struct ad7799_dev *device, uint8_t ch, uint32_t *reg_data)
Read specific ADC channel.
Definition: ad7799.c:213
ad7799_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad7799.h:172
no_os_spi_init_param::mode
enum no_os_spi_mode mode
Definition: no_os_spi.h:129
device
Definition: ad9361_util.h:75
ID_AD7798
@ ID_AD7798
Definition: ad7799.h:154
ad7799_dev::reg_size
const uint8_t * reg_size
Definition: ad7799.h:176
ad7799_get_gain
int32_t ad7799_get_gain(struct ad7799_dev *device, uint8_t *gain)
Get the ADC gain.
Definition: ad7799.c:303
ad7799_remove
int32_t ad7799_remove(struct ad7799_dev *device)
Remove the device and release resources.
Definition: ad7799.c:479
AD7799_REG_SIZE_1B
#define AD7799_REG_SIZE_1B
Definition: ad7799.h:116
AD7799_CONF_GAIN
#define AD7799_CONF_GAIN(x)
Definition: ad7799.h:100
ad7799_set_polarity
int32_t ad7799_set_polarity(struct ad7799_dev *device, uint8_t polarity)
Set ADC polarity.
Definition: ad7799.c:348
ad7799_init_param::precision
enum ad7799_precision precision
Definition: ad7799.h:203
ad7799_init_param::vref_mv
uint32_t vref_mv
Definition: ad7799.h:201
ad7799_set_mode
int32_t ad7799_set_mode(struct ad7799_dev *device, uint8_t mode)
Set the device mode.
Definition: ad7799.c:162
no_os_error.h
Error codes definition.
ad7799_dev::vref_mv
uint32_t vref_mv
Definition: ad7799.h:182
ad7799_init_param::gain
uint8_t gain
Definition: ad7799.h:197
AD7799_REG_COMM
#define AD7799_REG_COMM
Definition: ad7799.h:54
ad7799_set_polarity
int32_t ad7799_set_polarity(struct ad7799_dev *device, uint8_t polarity)
Set ADC polarity.
Definition: ad7799.c:348
ad7799_read
int32_t ad7799_read(struct ad7799_dev *device, uint8_t reg_addr, uint32_t *reg_data)
Read device register.
Definition: ad7799.c:85
AD7799_REG_OFFSET
#define AD7799_REG_OFFSET
Definition: ad7799.h:61
ad7799_set_channel
int32_t ad7799_set_channel(struct ad7799_dev *device, uint8_t ch)
Select the ADC channel.
Definition: ad7799.c:191
AD7799_STAT_RDY
#define AD7799_STAT_RDY
Definition: ad7799.h:76
ad7799_write
int32_t ad7799_write(struct ad7799_dev *device, uint8_t reg_addr, uint32_t reg_data)
Write device register.
Definition: ad7799.c:118
AD7799_COMM_READ
#define AD7799_COMM_READ
Definition: ad7799.h:71
ad7799.h
Header file of AD7798/AD7799 Driver.
ad7799_write
int32_t ad7799_write(struct ad7799_dev *device, uint8_t reg_addr, uint32_t reg_data)
Write device register.
Definition: ad7799.c:118
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:143
ad7799_dev_ready
int32_t ad7799_dev_ready(struct ad7799_dev *device)
Read the /RDY bit of status register and check the status of the device.
Definition: ad7799.c:369
ad7799_init
int32_t ad7799_init(struct ad7799_dev **device, const struct ad7799_init_param *init_param)
Initialize the device.
Definition: ad7799.c:396
AD7799_PRECISION_UV
@ AD7799_PRECISION_UV
Definition: ad7799.h:163
AD7799_MODE_SINGLE
#define AD7799_MODE_SINGLE
Definition: ad7799.h:89
ad7799_init_param::polarity
bool polarity
Definition: ad7799.h:199
AD7799_ID_MASK
#define AD7799_ID_MASK
Definition: ad7799.h:132
AD7799_COMM_WRITE
#define AD7799_COMM_WRITE
Definition: ad7799.h:70
ad7799_set_refdet
int32_t ad7799_set_refdet(struct ad7799_dev *device, uint8_t ref_en)
Enable or disable the reference detect function.
Definition: ad7799.c:325
AD7799_REG_IO
#define AD7799_REG_IO
Definition: ad7799.h:60
ad7799_read_channel
int32_t ad7799_read_channel(struct ad7799_dev *device, uint8_t ch, int32_t *data_scaled)
Read data from specific ADC channel with specified precision.
Definition: ad7799.c:244
AD7799_CONF_POLARITY
#define AD7799_CONF_POLARITY(x)
Definition: ad7799.h:99
AD7799_REG_CONF
#define AD7799_REG_CONF
Definition: ad7799.h:57
AD7799_REG_SIZE_2B
#define AD7799_REG_SIZE_2B
Definition: ad7799.h:117
ad7799_dev::precision
enum ad7799_precision precision
Definition: ad7799.h:184
ad7799_get_channel
int32_t ad7799_get_channel(struct ad7799_dev *device, uint8_t ch, uint32_t *reg_data)
Read specific ADC channel.
Definition: ad7799.c:213
ad7799_init_param::spi_init
struct no_os_spi_init_param spi_init
Definition: ad7799.h:193
AD7799_REG_MASK
#define AD7799_REG_MASK
Definition: ad7799.h:135
ad7799_dev::gain
uint8_t gain
Definition: ad7799.h:178
ad7799_get_gain
int32_t ad7799_get_gain(struct ad7799_dev *device, uint8_t *gain)
Get the ADC gain.
Definition: ad7799.c:303
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad7799_set_refdet
int32_t ad7799_set_refdet(struct ad7799_dev *device, uint8_t ref_en)
Enable or disable the reference detect function.
Definition: ad7799.c:325
ad7799_dev::polarity
bool polarity
Definition: ad7799.h:180
ad7799_reset
int32_t ad7799_reset(struct ad7799_dev *device)
Software reset of the device.
Definition: ad7799.c:144
ad7799_remove
int32_t ad7799_remove(struct ad7799_dev *device)
Remove the device and release resources.
Definition: ad7799.c:479
AD7799_REG_SIZE_3B
#define AD7799_REG_SIZE_3B
Definition: ad7799.h:118
AD7799_TIMEOUT
#define AD7799_TIMEOUT
Definition: ad7799.h:143
AD7799_MODE_SEL
#define AD7799_MODE_SEL(x)
Definition: ad7799.h:83
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:71
ad7799_type
ad7799_type
Device type (AD7798/AD7799)
Definition: ad7799.h:152
ad7799_init_param::chip_type
enum ad7799_type chip_type
Definition: ad7799.h:195
AD7799_REG_ID
#define AD7799_REG_ID
Definition: ad7799.h:59
AD7799_CONF_REFDET
#define AD7799_CONF_REFDET(x)
Definition: ad7799.h:101
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
ad7799_dev_ready
int32_t ad7799_dev_ready(struct ad7799_dev *device)
Read the /RDY bit of status register and check the status of the device.
Definition: ad7799.c:369
AD7799_REG_STAT
#define AD7799_REG_STAT
Definition: ad7799.h:55
AD7799_CONF_CHAN
#define AD7799_CONF_CHAN(x)
Definition: ad7799.h:103
ad7799_init_param
AD7798/AD7799 Device initialization parameters.
Definition: ad7799.h:191
ad7799_reset
int32_t ad7799_reset(struct ad7799_dev *device)
Software reset of the device.
Definition: ad7799.c:144
AD7799_PRECISION_MV
@ AD7799_PRECISION_MV
Definition: ad7799.h:161
AD7799_REG_MODE
#define AD7799_REG_MODE
Definition: ad7799.h:56
ad7799_set_gain
int32_t ad7799_set_gain(struct ad7799_dev *device, uint8_t gain)
Set the ADC gain.
Definition: ad7799.c:282
ad7799_read
int32_t ad7799_read(struct ad7799_dev *device, uint8_t reg_addr, uint32_t *reg_data)
Read device register.
Definition: ad7799.c:85
ad7799_set_channel
int32_t ad7799_set_channel(struct ad7799_dev *device, uint8_t ch)
Select the ADC channel.
Definition: ad7799.c:191
chip_id
chip_id
Definition: ad9172.h:57
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:121
ID_AD7799
@ ID_AD7799
Definition: ad7799.h:156