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