no-OS
ad738x.h
Go to the documentation of this file.
1 /***************************************************************************/
41 #ifndef SRC_AD738X_H_
42 #define SRC_AD738X_H_
43 
44 /******************************************************************************/
45 /***************************** Include Files **********************************/
46 /******************************************************************************/
47 #include "no_os_util.h"
48 
49 /******************************************************************************/
50 /********************** Macros and Constants Definitions **********************/
51 /******************************************************************************/
52 
53 /*
54  * AD738X registers definition
55  */
56 #define AD738X_REG_NOP 0x00
57 #define AD738X_REG_CONFIG1 0x01
58 #define AD738X_REG_CONFIG2 0x02
59 #define AD738X_REG_ALERT 0x03
60 #define AD738X_REG_ALERT_LOW_TH 0x04
61 #define AD738X_REG_ALERT_HIGH_TH 0x05
62 
63 /*
64  * AD738X_REG_CONFIG1
65  */
66 #define AD738X_CONFIG1_OS_MODE_MSK NO_OS_BIT(9)
67 #define AD738X_CONFIG1_OS_MODE(x) (((x) & 0x1) << 9)
68 #define AD738X_CONFIG1_OSR_MSK NO_OS_GENMASK(8, 6)
69 #define AD738X_CONFIG1_OSR(x) (((x) & 0x7) << 6)
70 #define AD738X_CONFIG1_CRC_W_MSK NO_OS_BIT(5)
71 #define AD738X_CONFIG1_CRC_W(x) (((x) & 0x1) << 5)
72 #define AD738X_CONFIG1_CRC_R_MSK NO_OS_BIT(4)
73 #define AD738X_CONFIG1_CRC_R(x) (((x) & 0x1) << 4)
74 #define AD738X_CONFIG1_ALERTEN_MSK NO_OS_BIT(3)
75 #define AD738X_CONFIG1_ALERTEN(x) (((x) & 0x1) << 3)
76 #define AD738X_CONFIG1_RES_MSK NO_OS_BIT(2)
77 #define AD738X_CONFIG1_RES(x) (((x) & 0x1) << 2)
78 #define AD738X_CONFIG1_REFSEL_MSK NO_OS_BIT(1)
79 #define AD738X_CONFIG1_REFSEL(x) (((x) & 0x1) << 1)
80 #define AD738X_CONFIG1_PMODE_MSK NO_OS_BIT(0)
81 #define AD738X_CONFIG1_PMODE(x) (((x) & 0x1) << 0)
82 
83 /*
84  * AD738X_REG_CONFIG2
85  */
86 #define AD738X_CONFIG2_SDO2_MSK NO_OS_BIT(8)
87 #define AD738X_CONFIG2_SDO2(x) (((x) & 0x1) << 8)
88 #define AD738X_CONFIG2_SDO4_MSK NO_OS_GENMASK(9, 8)
89 #define AD738X_CONFIG2_SDO4(x) (((x) & 0x3) << 8)
90 #define AD738X_CONFIG2_RESET_MSK NO_OS_GENMASK(7, 0)
91 #define AD738X_CONFIG2_RESET(x) (((x) & 0xFF) << 0)
92 
93 /*
94  * AD738X_REG_ALERT_LOW_TH
95  */
96 #define AD738X_ALERT_LOW_MSK NO_OS_GENMASK(11, 0)
97 #define AD738X_ALERT_LOW(x) (((x) & 0xFFF) << 0)
98 
99 /*
100  * AD738X_REG_ALERT_HIGH_TH
101  */
102 #define AD738X_ALERT_HIGH_MSK NO_OS_GENMASK(11, 0)
103 #define AD738X_ALERT_HIGH(x) (((x) & 0xFFF) << 0)
104 
105 /* Write to register x */
106 #define AD738X_REG_WRITE(x) ((1 << 7) | ((x & 0x7) << 4))
107 /* Read from register x */
108 #define AD738X_REG_READ(x) ((x & 0x7) << 4)
109 
110 /*****************************************************************************/
111 /*************************** Types Declarations *******************************/
112 /******************************************************************************/
116 };
117 
121 };
122 
130 };
131 
135 };
136 
140 };
141 
145 };
146 
150 };
151 
152 struct ad738x_dev {
153  /* SPI */
157  /* Device Settings */
162  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
163 };
164 
166  /* SPI */
170  /* Device Settings */
174  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
175 };
176 
177 /******************************************************************************/
178 /************************ Functions Declarations ******************************/
179 /******************************************************************************/
181 int32_t ad738x_init(struct ad738x_dev **device,
182  struct ad738x_init_param *init_param);
184 int32_t ad738x_remove(struct ad738x_dev *dev);
186 int32_t ad738x_spi_reg_read(struct ad738x_dev *dev,
187  uint8_t reg_addr,
188  uint16_t *reg_data);
190 int32_t ad738x_spi_reg_write(struct ad738x_dev *dev,
191  uint8_t reg_addr,
192  uint16_t reg_data);
194 int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev,
195  uint16_t *adc_data);
197 int32_t ad738x_spi_write_mask(struct ad738x_dev *dev,
198  uint8_t reg_addr,
199  uint32_t mask,
200  uint16_t data);
202 int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev,
203  enum ad738x_conv_mode mode);
205 int32_t ad738x_reset(struct ad738x_dev *dev,
206  enum ad738x_reset_type reset);
208 int32_t ad738x_oversampling_config(struct ad738x_dev *dev,
209  enum ad738x_os_mode os_mode,
210  enum ad738x_os_ratio os_ratio,
211  enum ad738x_resolution res);
213 int32_t ad738x_power_down_mode(struct ad738x_dev *dev,
214  enum ad738x_pwd_mode pmode);
216 int32_t ad738x_reference_sel(struct ad738x_dev *dev,
217  enum ad738x_ref_sel ref_sel);
219 int32_t ad738x_read_data(struct ad738x_dev *dev,
220  uint32_t *buf,
221  uint16_t samples);
222 #endif /* SRC_AD738X_H_ */
ad738x_dev
Definition: ad738x.h:152
ad738x_init
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition: ad738x.c:318
adc_data
Definition: ad77681.h:496
OSR_X32
@ OSR_X32
Definition: ad738x.h:129
ad738x_init_param
Definition: ad738x.h:165
spi_engine_offload_message::no_commands
uint32_t no_commands
Definition: spi_engine.h:167
ad738x_init_param::ref_sel
enum ad738x_ref_sel ref_sel
Definition: ad738x.h:172
AD738X_CONFIG1_OSR
#define AD738X_CONFIG1_OSR(x)
Definition: ad738x.h:69
ad738x_oversampling_config
int32_t ad738x_oversampling_config(struct ad738x_dev *dev, enum ad738x_os_mode os_mode, enum ad738x_os_ratio os_ratio, enum ad738x_resolution res)
Definition: ad738x.c:207
ad738x_dev::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:162
AD738X_REG_CONFIG2
#define AD738X_REG_CONFIG2
Definition: ad738x.h:58
AD738X_CONFIG1_PMODE_MSK
#define AD738X_CONFIG1_PMODE_MSK
Definition: ad738x.h:80
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
CS_LOW
#define CS_LOW
Definition: spi_engine.h:79
ad738x_reset
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition: ad738x.c:179
FULL_PWDM
@ FULL_PWDM
Definition: ad738x.h:144
spi_engine_offload_init
int32_t spi_engine_offload_init(struct no_os_spi_desc *desc, const struct spi_engine_offload_init_param *param)
Initialize the SPI engine's offload module.
Definition: spi_engine.c:757
AD738X_CONFIG1_OS_MODE_MSK
#define AD738X_CONFIG1_OS_MODE_MSK
Definition: ad738x.h:66
NORMAL_OS_MODE
@ NORMAL_OS_MODE
Definition: ad738x.h:119
ad738x_os_mode
ad738x_os_mode
Definition: ad738x.h:118
AD738X_CONFIG2_RESET
#define AD738X_CONFIG2_RESET(x)
Definition: ad738x.h:91
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:261
spi_engine_offload_message::commands_data
uint32_t * commands_data
Definition: spi_engine.h:169
no_os_delay.h
Header file of Delay functions.
ad738x_conv_mode
ad738x_conv_mode
Definition: ad738x.h:113
ad738x_reset_type
ad738x_reset_type
Definition: ad738x.h:137
ad738x_dev::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:158
ad738x_dev::spi_desc
no_os_spi_desc * spi_desc
Definition: ad738x.h:154
AD738X_CONFIG1_OS_MODE
#define AD738X_CONFIG1_OS_MODE(x)
Definition: ad738x.h:67
AD738X_REG_CONFIG1
#define AD738X_REG_CONFIG1
Definition: ad738x.h:57
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:261
spi_engine_offload_message
Structure representing an offload message.
Definition: spi_engine.h:160
device
Definition: ad9361_util.h:75
ad738x_spi_write_mask
int32_t ad738x_spi_write_mask(struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
Definition: ad738x.c:105
AD738X_CONFIG1_REFSEL_MSK
#define AD738X_CONFIG1_REFSEL_MSK
Definition: ad738x.h:78
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint16_t *adc_data)
Definition: ad738x.c:127
ad738x_spi_reg_read
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad738x.c:62
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:53
OSR_X16
@ OSR_X16
Definition: ad738x.h:128
AD738X_CONFIG1_PMODE
#define AD738X_CONFIG1_PMODE(x)
Definition: ad738x.h:81
EXT_REF
@ EXT_REF
Definition: ad738x.h:149
WRITE_READ
#define WRITE_READ(no_bytes)
Definition: spi_engine.h:71
ad738x_init
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition: ad738x.c:318
NORMAL_PWDM
@ NORMAL_PWDM
Definition: ad738x.h:143
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
ad738x.h
Header file for AD738x Driver.
CS_HIGH
#define CS_HIGH
Definition: spi_engine.h:78
AD738X_CONFIG1_RES_MSK
#define AD738X_CONFIG1_RES_MSK
Definition: ad738x.h:76
no_os_error.h
Error codes definition.
OSR_X4
@ OSR_X4
Definition: ad738x.h:126
SOFT_RESET
@ SOFT_RESET
Definition: ad738x.h:138
AD738X_CONFIG1_OSR_MSK
#define AD738X_CONFIG1_OSR_MSK
Definition: ad738x.h:68
ad738x_init_param::spi_param
no_os_spi_init_param * spi_param
Definition: ad738x.h:167
RES_18_BIT
@ RES_18_BIT
Definition: ad738x.h:134
AD738X_CONFIG2_SDO2
#define AD738X_CONFIG2_SDO2(x)
Definition: ad738x.h:87
HARD_RESET
@ HARD_RESET
Definition: ad738x.h:139
ad7616_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad7616.h:168
AD738X_CONFIG1_REFSEL
#define AD738X_CONFIG1_REFSEL(x)
Definition: ad738x.h:79
spi_engine.h
ad738x_dev::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:156
ad738x_spi_reg_write
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad738x.c:85
INT_REF
@ INT_REF
Definition: ad738x.h:148
OSR_X2
@ OSR_X2
Definition: ad738x.h:125
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
ad738x_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:174
ad738x_spi_write_mask
int32_t ad738x_spi_write_mask(struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
Definition: ad738x.c:105
ad738x_read_data
int32_t ad738x_read_data(struct ad738x_dev *dev, uint32_t *buf, uint16_t samples)
Read from device. Enter register mode to read/write registers.
Definition: ad738x.c:278
ad738x_ref_sel
ad738x_ref_sel
Definition: ad738x.h:147
ad738x_pwd_mode
ad738x_pwd_mode
Definition: ad738x.h:142
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:355
ad738x_os_ratio
ad738x_os_ratio
Definition: ad738x.h:123
spi_engine_offload_message::commands
uint32_t * commands
Definition: spi_engine.h:165
AD738X_CONFIG2_RESET_MSK
#define AD738X_CONFIG2_RESET_MSK
Definition: ad738x.h:90
AD738X_CONFIG1_RES
#define AD738X_CONFIG1_RES(x)
Definition: ad738x.h:77
ad7616_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad7616.h:184
ad738x_spi_reg_write
int32_t ad738x_spi_reg_write(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
Definition: ad738x.c:85
ONE_WIRE_MODE
@ ONE_WIRE_MODE
Definition: ad738x.h:115
ad738x_dev::ref_sel
enum ad738x_ref_sel ref_sel
Definition: ad738x.h:159
ad738x_read_data
int32_t ad738x_read_data(struct ad738x_dev *dev, uint32_t *buf, uint16_t samples)
Read from device. Enter register mode to read/write registers.
Definition: ad738x.c:278
AD738X_REG_WRITE
#define AD738X_REG_WRITE(x)
Definition: ad738x.h:106
AD738X_REG_READ
#define AD738X_REG_READ(x)
Definition: ad738x.h:108
ad738x_oversampling_config
int32_t ad738x_oversampling_config(struct ad738x_dev *dev, enum ad738x_os_mode os_mode, enum ad738x_os_ratio os_ratio, enum ad738x_resolution res)
Definition: ad738x.c:207
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:355
ad738x_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:169
AD738X_CONFIG2_SDO2_MSK
#define AD738X_CONFIG2_SDO2_MSK
Definition: ad738x.h:86
RES_16_BIT
@ RES_16_BIT
Definition: ad738x.h:133
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:162
ad738x_spi_reg_read
int32_t ad738x_spi_reg_read(struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
Definition: ad738x.c:62
ad738x_init_param::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:171
spi_engine_offload_transfer
int32_t spi_engine_offload_transfer(struct no_os_spi_desc *desc, struct spi_engine_offload_message msg, uint32_t no_samples)
Initiate a SPI transfer in offload mode.
Definition: spi_engine.c:803
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:70
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:244
OSR_DISABLED
@ OSR_DISABLED
Definition: ad738x.h:124
spi_engine_offload_init_param
Structure containing the init parameters needed by the offload module.
Definition: spi_engine.h:145
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
OSR_X8
@ OSR_X8
Definition: ad738x.h:127
no_os_util.h
Implementation of utility functions.
ROLLING_OS_MODE
@ ROLLING_OS_MODE
Definition: ad738x.h:120
ad738x_dev::resolution
enum ad738x_resolution resolution
Definition: ad738x.h:160
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:162
TWO_WIRE_MODE
@ TWO_WIRE_MODE
Definition: ad738x.h:114
spi_engine_offload_message::rx_addr
uint32_t rx_addr
Definition: spi_engine.h:173
ad738x_resolution
ad738x_resolution
Definition: ad738x.h:132
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint16_t *adc_data)
Definition: ad738x.c:127
ad7616_init_param::spi_param
struct no_os_spi_init_param * spi_param
Definition: ad7616.h:167
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:244
ad738x_reset
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition: ad738x.c:179
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112