no-OS
ad5592r-base.h
Go to the documentation of this file.
1 /***************************************************************************/
39 #ifndef AD5592R_BASE_H_
40 #define AD5592R_BASE_H_
41 
42 #include "stdint.h"
43 #include "no_os_delay.h"
44 #include "no_os_spi.h"
45 #include "no_os_i2c.h"
46 #include "no_os_util.h"
47 #include <stdbool.h>
48 
49 #define CH_MODE_UNUSED 0
50 #define CH_MODE_ADC 1
51 #define CH_MODE_DAC 2
52 #define CH_MODE_DAC_AND_ADC 3
53 #define CH_MODE_GPI 4
54 #define CH_MODE_GPO 5
55 
56 #define CH_OFFSTATE_PULLDOWN 0
57 #define CH_OFFSTATE_OUT_LOW 1
58 #define CH_OFFSTATE_OUT_HIGH 2
59 #define CH_OFFSTATE_OUT_TRISTATE 3
60 
77 };
78 
79 #define AD5592R_REG_PD_PD_ALL NO_OS_BIT(10)
80 #define AD5592R_REG_PD_EN_REF NO_OS_BIT(9)
81 
82 #define AD5592R_REG_CTRL_ADC_PC_BUFF NO_OS_BIT(9)
83 #define AD5592R_REG_CTRL_ADC_BUFF_EN NO_OS_BIT(8)
84 #define AD5592R_REG_CTRL_CONFIG_LOCK NO_OS_BIT(7)
85 #define AD5592R_REG_CTRL_W_ALL_DACS NO_OS_BIT(6)
86 #define AD5592R_REG_CTRL_ADC_RANGE NO_OS_BIT(5)
87 #define AD5592R_REG_CTRL_DAC_RANGE NO_OS_BIT(4)
88 
89 #define AD5592R_REG_ADC_SEQ_REP NO_OS_BIT(9)
90 #define AD5592R_REG_ADC_SEQ_TEMP_READBACK NO_OS_BIT(8)
91 #define AD5592R_REG_ADC_SEQ_CODE_MSK(x) ((x) & 0x0FFF)
92 
93 #define AD5592R_REG_GPIO_OUT_EN_ADC_NOT_BUSY NO_OS_BIT(8)
94 
95 #define AD5592R_REG_LDAC_IMMEDIATE_OUT 0x00
96 #define AD5592R_REG_LDAC_INPUT_REG_ONLY 0x01
97 #define AD5592R_REG_LDAC_INPUT_REG_OUT 0x02
98 
99 #define INTERNAL_VREF_VOLTAGE 2.5
100 
101 struct ad5592r_dev;
102 
104  int32_t (*write_dac)(struct ad5592r_dev *dev, uint8_t chan,
105  uint16_t value);
106  int32_t (*read_adc)(struct ad5592r_dev *dev, uint8_t chan,
107  uint16_t *value);
108  int32_t(*multi_read_adc)(struct ad5592r_dev *dev,
109  uint16_t chans, uint16_t *value);
110  int32_t (*reg_write)(struct ad5592r_dev *dev, uint8_t reg,
111  uint16_t value);
112  int32_t (*reg_read)(struct ad5592r_dev *dev, uint8_t reg,
113  uint16_t *value);
114  int32_t (*gpio_read)(struct ad5592r_dev *dev, uint8_t *value);
115 };
116 
118  bool int_ref;
119 };
120 
121 struct ad5592r_dev {
122  const struct ad5592r_rw_ops *ops;
125  uint16_t spi_msg;
126  uint8_t num_channels;
127  uint16_t cached_dac[8];
128  uint16_t cached_gp_ctrl;
129  uint8_t channel_modes[8];
130  uint8_t channel_offstate[8];
131  uint8_t gpio_out;
132  uint8_t gpio_in;
133  uint8_t gpio_val;
134  uint8_t ldac_mode;
135 };
136 
137 int32_t ad5592r_base_reg_write(struct ad5592r_dev *dev, uint8_t reg,
138  uint16_t value);
139 int32_t ad5592r_base_reg_read(struct ad5592r_dev *dev, uint8_t reg,
140  uint16_t *value);
141 int32_t ad5592r_gpio_get(struct ad5592r_dev *dev, uint8_t offset);
142 int32_t ad5592r_gpio_set(struct ad5592r_dev *dev, uint8_t offset,
143  int32_t value);
144 int32_t ad5592r_gpio_direction_input(struct ad5592r_dev *dev, uint8_t offset);
145 int32_t ad5592r_gpio_direction_output(struct ad5592r_dev *dev,
146  uint8_t offset, int32_t value);
147 int32_t ad5592r_software_reset(struct ad5592r_dev *dev);
148 int32_t ad5592r_set_channel_modes(struct ad5592r_dev *dev);
149 int32_t ad5592r_reset_channel_modes(struct ad5592r_dev *dev);
150 
151 #endif /* AD5592R_BASE_H_ */
ad5592r_reset_channel_modes
int32_t ad5592r_reset_channel_modes(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:317
AD5592R_REG_GPIO_IN_EN
@ AD5592R_REG_GPIO_IN_EN
Definition: ad5592r-base.h:72
ad5592r_dev::cached_dac
uint16_t cached_dac[8]
Definition: ad5592r-base.h:127
ad5592r_dev::num_channels
uint8_t num_channels
Definition: ad5592r-base.h:126
adxl372_spi_reg_read_multiple
int32_t adxl372_spi_reg_read_multiple(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
Definition: adxl372_spi.c:100
ad5592r_rw_ops::reg_read
int32_t(* reg_read)(struct ad5592r_dev *dev, uint8_t reg, uint16_t *value)
Definition: ad5592r-base.h:112
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:85
ad5592r_gpio_get
int32_t ad5592r_gpio_get(struct ad5592r_dev *dev, uint8_t offset)
Definition: ad5592r-base.c:77
ad5592r_dev::gpio_in
uint8_t gpio_in
Definition: ad5592r-base.h:132
AD5592R_REG_NOOP
@ AD5592R_REG_NOOP
Definition: ad5592r-base.h:62
ad5592r_rw_ops::read_adc
int32_t(* read_adc)(struct ad5592r_dev *dev, uint8_t chan, uint16_t *value)
Definition: ad5592r-base.h:106
adxl372_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: adxl372.h:370
ad5592r_gpio_set
int32_t ad5592r_gpio_set(struct ad5592r_dev *dev, uint8_t offset, int32_t value)
Definition: ad5592r-base.c:103
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:82
ad5592r_dev::ldac_mode
uint8_t ldac_mode
Definition: ad5592r-base.h:134
no_os_spi.h
Header file of SPI Interface.
AD5592R_REG_DAC_READBACK
@ AD5592R_REG_DAC_READBACK
Definition: ad5592r-base.h:63
ad5592r_software_reset
int32_t ad5592r_software_reset(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:188
AD5592R_REG_GPIO_OUT_EN
@ AD5592R_REG_GPIO_OUT_EN
Definition: ad5592r-base.h:70
CH_OFFSTATE_OUT_HIGH
#define CH_OFFSTATE_OUT_HIGH
Definition: ad5592r-base.h:58
adxl372_dev::i2c_desc
no_os_i2c_desc * i2c_desc
Definition: adxl372.h:372
AD5592R_REG_GPIO_SET
@ AD5592R_REG_GPIO_SET
Definition: ad5592r-base.h:71
AD5592R_REG_ADC_SEQ
@ AD5592R_REG_ADC_SEQ
Definition: ad5592r-base.h:64
ad5592r_software_reset
int32_t ad5592r_software_reset(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:188
no_os_delay.h
Header file of Delay functions.
CH_OFFSTATE_PULLDOWN
#define CH_OFFSTATE_PULLDOWN
Definition: ad5592r-base.h:56
ad5592r_dev::cached_gp_ctrl
uint16_t cached_gp_ctrl
Definition: ad5592r-base.h:128
AD5592R_REG_CTRL
@ AD5592R_REG_CTRL
Definition: ad5592r-base.h:65
adxl372.h
Header file for adxl372 Driver.
AD5592R_REG_PULLDOWN
@ AD5592R_REG_PULLDOWN
Definition: ad5592r-base.h:68
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:53
ad5592r_dev::channel_offstate
uint8_t channel_offstate[8]
Definition: ad5592r-base.h:130
ad5592r_gpio_set
int32_t ad5592r_gpio_set(struct ad5592r_dev *dev, uint8_t offset, int32_t value)
Definition: ad5592r-base.c:103
AD5592R_REG_DAC_EN
@ AD5592R_REG_DAC_EN
Definition: ad5592r-base.h:67
CH_MODE_ADC
#define CH_MODE_ADC
Definition: ad5592r-base.h:50
ad5592r_dev::gpio_val
uint8_t gpio_val
Definition: ad5592r-base.h:133
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
ad5592r_rw_ops::write_dac
int32_t(* write_dac)(struct ad5592r_dev *dev, uint8_t chan, uint16_t value)
Definition: ad5592r-base.h:104
no_os_error.h
Error codes definition.
ad5592r_dev::channel_modes
uint8_t channel_modes[8]
Definition: ad5592r-base.h:129
ad5592r_gpio_direction_output
int32_t ad5592r_gpio_direction_output(struct ad5592r_dev *dev, uint8_t offset, int32_t value)
Definition: ad5592r-base.c:151
ADXL372_REG_WRITE
#define ADXL372_REG_WRITE(x)
Definition: adxl372.h:122
ad5592r_base_reg_write
int32_t ad5592r_base_reg_write(struct ad5592r_dev *dev, uint8_t reg, uint16_t value)
Definition: ad5592r-base.c:50
adxl372_i2c_reg_read
int32_t adxl372_i2c_reg_read(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Definition: adxl372_i2c.c:53
AD5592R_REG_TRISTATE
@ AD5592R_REG_TRISTATE
Definition: ad5592r-base.h:75
adxl372_spi_reg_read
int32_t adxl372_spi_reg_read(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
Definition: adxl372_spi.c:53
adxl372_dev
Definition: adxl372.h:368
ad5592r_base_reg_write
int32_t ad5592r_base_reg_write(struct ad5592r_dev *dev, uint8_t reg, uint16_t value)
Definition: ad5592r-base.c:50
CH_MODE_UNUSED
#define CH_MODE_UNUSED
Definition: ad5592r-base.h:49
AD5592R_REG_LDAC
@ AD5592R_REG_LDAC
Definition: ad5592r-base.h:69
CH_OFFSTATE_OUT_LOW
#define CH_OFFSTATE_OUT_LOW
Definition: ad5592r-base.h:57
ad5592r_dev::i2c
no_os_i2c_desc * i2c
Definition: ad5592r-base.h:123
ad5592r_rw_ops::multi_read_adc
int32_t(* multi_read_adc)(struct ad5592r_dev *dev, uint16_t chans, uint16_t *value)
Definition: ad5592r-base.h:108
CH_OFFSTATE_OUT_TRISTATE
#define CH_OFFSTATE_OUT_TRISTATE
Definition: ad5592r-base.h:59
ad5592r_base_reg_read
int32_t ad5592r_base_reg_read(struct ad5592r_dev *dev, uint8_t reg, uint16_t *value)
Definition: ad5592r-base.c:64
ad5592r-base.h
Header file of AD5592R Base Driver.
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
ad5592r_rw_ops::reg_write
int32_t(* reg_write)(struct ad5592r_dev *dev, uint8_t reg, uint16_t value)
Definition: ad5592r-base.h:110
ad5592r_dev::spi
no_os_spi_desc * spi
Definition: ad5592r-base.h:124
adxl372_i2c_reg_write
int32_t adxl372_i2c_reg_write(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Definition: adxl372_i2c.c:82
ad5592r_registers
ad5592r_registers
Definition: ad5592r-base.h:61
ad5592r_init_param
Definition: ad5592r-base.h:117
ad5592r_init_param::int_ref
bool int_ref
Definition: ad5592r-base.h:118
ad5592r_gpio_direction_output
int32_t ad5592r_gpio_direction_output(struct ad5592r_dev *dev, uint8_t offset, int32_t value)
Definition: ad5592r-base.c:151
no_os_i2c_desc
Structure holding I2C descriptor.
Definition: no_os_i2c.h:81
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:104
ad5592r_gpio_get
int32_t ad5592r_gpio_get(struct ad5592r_dev *dev, uint8_t offset)
Definition: ad5592r-base.c:77
no_os_i2c.h
Header file of I2C Interface.
ad5592r_set_channel_modes
int32_t ad5592r_set_channel_modes(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:209
ad5592r_rw_ops::gpio_read
int32_t(* gpio_read)(struct ad5592r_dev *dev, uint8_t *value)
Definition: ad5592r-base.h:114
AD5592R_REG_PD
@ AD5592R_REG_PD
Definition: ad5592r-base.h:73
NO_OS_BIT
#define NO_OS_BIT(x)
Definition: no_os_util.h:51
ad5592r_rw_ops
Definition: ad5592r-base.h:103
ad5592r_gpio_direction_input
int32_t ad5592r_gpio_direction_input(struct ad5592r_dev *dev, uint8_t offset)
Definition: ad5592r-base.c:124
ad5592r_dev::spi_msg
uint16_t spi_msg
Definition: ad5592r-base.h:125
ad5592r_dev::gpio_out
uint8_t gpio_out
Definition: ad5592r-base.h:131
CH_MODE_GPO
#define CH_MODE_GPO
Definition: ad5592r-base.h:54
adxl372_spi_reg_write
int32_t adxl372_spi_reg_write(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t reg_data)
Definition: adxl372_spi.c:79
ad5592r_set_channel_modes
int32_t ad5592r_set_channel_modes(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:209
AD5592R_REG_RESET
@ AD5592R_REG_RESET
Definition: ad5592r-base.h:76
AD5592R_REG_ADC_EN
@ AD5592R_REG_ADC_EN
Definition: ad5592r-base.h:66
adxl372_i2c_reg_read_multiple
int32_t adxl372_i2c_reg_read_multiple(struct adxl372_dev *dev, uint8_t reg_addr, uint8_t *reg_data, uint16_t count)
Definition: adxl372_i2c.c:103
AD5592R_REG_OPEN_DRAIN
@ AD5592R_REG_OPEN_DRAIN
Definition: ad5592r-base.h:74
CH_MODE_DAC
#define CH_MODE_DAC
Definition: ad5592r-base.h:51
ad5592r_reset_channel_modes
int32_t ad5592r_reset_channel_modes(struct ad5592r_dev *dev)
Definition: ad5592r-base.c:317
ad5592r_gpio_direction_input
int32_t ad5592r_gpio_direction_input(struct ad5592r_dev *dev, uint8_t offset)
Definition: ad5592r-base.c:124
no_os_util.h
Implementation of utility functions.
ad5592r_dev
Definition: ad5592r-base.h:121
CH_MODE_GPI
#define CH_MODE_GPI
Definition: ad5592r-base.h:53
ad5592r_base_reg_read
int32_t ad5592r_base_reg_read(struct ad5592r_dev *dev, uint8_t reg, uint16_t *value)
Definition: ad5592r-base.c:64
ad5592r_dev::ops
const struct ad5592r_rw_ops * ops
Definition: ad5592r-base.h:122
CH_MODE_DAC_AND_ADC
#define CH_MODE_DAC_AND_ADC
Definition: ad5592r-base.h:52
ADXL372_REG_READ
#define ADXL372_REG_READ(x)
Definition: adxl372.h:121