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 #if defined(USE_STANDARD_SPI)
49 #include "no_os_spi.h"
50 #endif
51 
52 /******************************************************************************/
53 /********************** Macros and Constants Definitions **********************/
54 /******************************************************************************/
55 
56 /*
57  * AD738X registers definition
58  */
59 #define AD738X_REG_NOP 0x00
60 #define AD738X_REG_CONFIG1 0x01
61 #define AD738X_REG_CONFIG2 0x02
62 #define AD738X_REG_ALERT 0x03
63 #define AD738X_REG_ALERT_LOW_TH 0x04
64 #define AD738X_REG_ALERT_HIGH_TH 0x05
65 
66 /*
67  * AD738X_REG_CONFIG1
68  */
69 #define AD738X_CONFIG1_OS_MODE_MSK NO_OS_BIT(9)
70 #define AD738X_CONFIG1_OS_MODE(x) (((x) & 0x1) << 9)
71 #define AD738X_CONFIG1_OSR_MSK NO_OS_GENMASK(8, 6)
72 #define AD738X_CONFIG1_OSR(x) (((x) & 0x7) << 6)
73 #define AD738X_CONFIG1_CRC_W_MSK NO_OS_BIT(5)
74 #define AD738X_CONFIG1_CRC_W(x) (((x) & 0x1) << 5)
75 #define AD738X_CONFIG1_CRC_R_MSK NO_OS_BIT(4)
76 #define AD738X_CONFIG1_CRC_R(x) (((x) & 0x1) << 4)
77 #define AD738X_CONFIG1_ALERTEN_MSK NO_OS_BIT(3)
78 #define AD738X_CONFIG1_ALERTEN(x) (((x) & 0x1) << 3)
79 #define AD738X_CONFIG1_RES_MSK NO_OS_BIT(2)
80 #define AD738X_CONFIG1_RES(x) (((x) & 0x1) << 2)
81 #define AD738X_CONFIG1_REFSEL_MSK NO_OS_BIT(1)
82 #define AD738X_CONFIG1_REFSEL(x) (((x) & 0x1) << 1)
83 #define AD738X_CONFIG1_PMODE_MSK NO_OS_BIT(0)
84 #define AD738X_CONFIG1_PMODE(x) (((x) & 0x1) << 0)
85 
86 /*
87  * AD738X_REG_CONFIG2
88  */
89 #define AD738X_CONFIG2_SDO2_MSK NO_OS_BIT(8)
90 #define AD738X_CONFIG2_SDO2(x) (((x) & 0x1) << 8)
91 #define AD738X_CONFIG2_SDO4_MSK NO_OS_GENMASK(9, 8)
92 #define AD738X_CONFIG2_SDO4(x) (((x) & 0x3) << 8)
93 #define AD738X_CONFIG2_RESET_MSK NO_OS_GENMASK(7, 0)
94 #define AD738X_CONFIG2_RESET(x) (((x) & 0xFF) << 0)
95 
96 /*
97  * AD738X_REG_ALERT_LOW_TH
98  */
99 #define AD738X_ALERT_LOW_MSK NO_OS_GENMASK(11, 0)
100 #define AD738X_ALERT_LOW(x) (((x) & 0xFFF) << 0)
101 
102 /*
103  * AD738X_REG_ALERT_HIGH_TH
104  */
105 #define AD738X_ALERT_HIGH_MSK NO_OS_GENMASK(11, 0)
106 #define AD738X_ALERT_HIGH(x) (((x) & 0xFFF) << 0)
107 
108 /* Write to register x */
109 #define AD738X_REG_WRITE(x) ((1 << 7) | ((x & 0x7) << 4))
110 /* Read from register x */
111 #define AD738X_REG_READ(x) ((x & 0x7) << 4)
112 
113 /*****************************************************************************/
114 /*************************** Types Declarations *******************************/
115 /******************************************************************************/
119 };
120 
124 };
125 
133 };
134 
138 };
139 
143 };
144 
148 };
149 
153 };
154 
155 struct ad738x_dev {
156  /* SPI */
158 #if !defined(USE_STANDARD_SPI)
159 
161 #endif
162  /* Device Settings */
165  uint32_t ref_voltage_mv;
168  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
169 };
170 
172  /* SPI */
174 #if !defined(USE_STANDARD_SPI)
175 
177 #endif
178  /* Device Settings */
181  uint32_t ref_voltage_mv;
183  void (*dcache_invalidate_range)(uint32_t address, uint32_t bytes_count);
184 };
185 
186 /******************************************************************************/
187 /************************ Functions Declarations ******************************/
188 /******************************************************************************/
190 int32_t ad738x_init(struct ad738x_dev **device,
191  struct ad738x_init_param *init_param);
193 int32_t ad738x_remove(struct ad738x_dev *dev);
195 int32_t ad738x_spi_reg_read(struct ad738x_dev *dev,
196  uint8_t reg_addr,
197  uint16_t *reg_data);
199 int32_t ad738x_spi_reg_write(struct ad738x_dev *dev,
200  uint8_t reg_addr,
201  uint16_t reg_data);
203 int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev,
204  uint16_t *adc_data);
206 int32_t ad738x_spi_write_mask(struct ad738x_dev *dev,
207  uint8_t reg_addr,
208  uint32_t mask,
209  uint16_t data);
211 int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev,
212  enum ad738x_conv_mode mode);
214 int32_t ad738x_reset(struct ad738x_dev *dev,
215  enum ad738x_reset_type reset);
217 int32_t ad738x_oversampling_config(struct ad738x_dev *dev,
218  enum ad738x_os_mode os_mode,
219  enum ad738x_os_ratio os_ratio,
220  enum ad738x_resolution res);
222 int32_t ad738x_power_down_mode(struct ad738x_dev *dev,
223  enum ad738x_pwd_mode pmode);
225 int32_t ad738x_reference_sel(struct ad738x_dev *dev,
226  enum ad738x_ref_sel ref_sel);
228 int32_t ad738x_read_data(struct ad738x_dev *dev,
229  uint32_t *buf,
230  uint16_t samples);
231 #endif /* SRC_AD738X_H_ */
ad738x_dev
Definition: ad738x.h:155
ad738x_init
int32_t ad738x_init(struct ad738x_dev **device, struct ad738x_init_param *init_param)
Definition: ad738x.c:338
adc_data
Definition: ad77681.h:496
OSR_X32
@ OSR_X32
Definition: ad738x.h:132
no_os_alloc.h
ad738x_init_param
Definition: ad738x.h:171
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:180
AD738X_CONFIG1_OSR
#define AD738X_CONFIG1_OSR(x)
Definition: ad738x.h:72
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:220
ad738x_dev::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:168
AD738X_REG_CONFIG2
#define AD738X_REG_CONFIG2
Definition: ad738x.h:61
AD738X_CONFIG1_PMODE_MSK
#define AD738X_CONFIG1_PMODE_MSK
Definition: ad738x.h:83
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:165
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:192
no_os_spi.h
Header file of SPI Interface.
FULL_PWDM
@ FULL_PWDM
Definition: ad738x.h:147
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:759
AD738X_CONFIG1_OS_MODE_MSK
#define AD738X_CONFIG1_OS_MODE_MSK
Definition: ad738x.h:69
NORMAL_OS_MODE
@ NORMAL_OS_MODE
Definition: ad738x.h:122
ad738x_os_mode
ad738x_os_mode
Definition: ad738x.h:121
AD738X_CONFIG2_RESET
#define AD738X_CONFIG2_RESET(x)
Definition: ad738x.h:94
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:274
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:116
ad738x_reset_type
ad738x_reset_type
Definition: ad738x.h:140
ad738x_dev::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:163
AD738X_CONFIG1_OS_MODE
#define AD738X_CONFIG1_OS_MODE(x)
Definition: ad738x.h:70
AD738X_REG_CONFIG1
#define AD738X_REG_CONFIG1
Definition: ad738x.h:60
ad738x_reference_sel
int32_t ad738x_reference_sel(struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
Definition: ad738x.c:274
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:118
AD738X_CONFIG1_REFSEL_MSK
#define AD738X_CONFIG1_REFSEL_MSK
Definition: ad738x.h:81
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint16_t *adc_data)
Definition: ad738x.c:140
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:65
NO_OS_ARRAY_SIZE
#define NO_OS_ARRAY_SIZE(x)
Definition: no_os_util.h:53
OSR_X16
@ OSR_X16
Definition: ad738x.h:131
ad738x_dev::ref_voltage_mv
uint32_t ref_voltage_mv
Definition: ad738x.h:165
AD738X_CONFIG1_PMODE
#define AD738X_CONFIG1_PMODE(x)
Definition: ad738x.h:84
EXT_REF
@ EXT_REF
Definition: ad738x.h:152
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:338
NORMAL_PWDM
@ NORMAL_PWDM
Definition: ad738x.h:146
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: aducm3029_delay.c:132
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:79
no_os_error.h
Error codes definition.
OSR_X4
@ OSR_X4
Definition: ad738x.h:129
SOFT_RESET
@ SOFT_RESET
Definition: ad738x.h:141
AD738X_CONFIG1_OSR_MSK
#define AD738X_CONFIG1_OSR_MSK
Definition: ad738x.h:71
RES_18_BIT
@ RES_18_BIT
Definition: ad738x.h:137
AD738X_CONFIG2_SDO2
#define AD738X_CONFIG2_SDO2(x)
Definition: ad738x.h:90
HARD_RESET
@ HARD_RESET
Definition: ad738x.h:142
ad7616_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad7616.h:211
AD738X_CONFIG1_REFSEL
#define AD738X_CONFIG1_REFSEL(x)
Definition: ad738x.h:82
spi_engine.h
ad738x_dev::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:160
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:98
INT_REF
@ INT_REF
Definition: ad738x.h:151
ad738x_init_param::ref_voltage_mv
uint32_t ref_voltage_mv
Definition: ad738x.h:181
OSR_X2
@ OSR_X2
Definition: ad738x.h:128
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:177
ad738x_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad738x.h:183
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:118
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:291
ad738x_ref_sel
ad738x_ref_sel
Definition: ad738x.h:150
ad738x_pwd_mode
ad738x_pwd_mode
Definition: ad738x.h:145
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:378
ad738x_os_ratio
ad738x_os_ratio
Definition: ad738x.h:126
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:93
AD738X_CONFIG1_RES
#define AD738X_CONFIG1_RES(x)
Definition: ad738x.h:80
ad738x_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ad738x.h:157
ad7616_init_param::dcache_invalidate_range
void(* dcache_invalidate_range)(uint32_t address, uint32_t bytes_count)
Definition: ad7616.h:236
no_os_malloc
void * no_os_malloc(size_t size)
Allocate memory and return a pointer to it.
Definition: chibios_alloc.c:49
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:98
ONE_WIRE_MODE
@ ONE_WIRE_MODE
Definition: ad738x.h:118
ad738x_dev::ref_sel
enum ad738x_ref_sel ref_sel
Definition: ad738x.h:164
no_os_free
void no_os_free(void *ptr)
Deallocate memory previously allocated by a call to no_os_calloc or no_os_malloc.
Definition: chibios_alloc.c:75
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:291
AD738X_REG_WRITE
#define AD738X_REG_WRITE(x)
Definition: ad738x.h:109
AD738X_REG_READ
#define AD738X_REG_READ(x)
Definition: ad738x.h:111
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:220
ad738x_remove
int32_t ad738x_remove(struct ad738x_dev *dev)
Free the resources allocated by ad738x_init().
Definition: ad738x.c:378
ad738x_init_param::offload_init_param
struct spi_engine_offload_init_param * offload_init_param
Definition: ad738x.h:176
AD738X_CONFIG2_SDO2_MSK
#define AD738X_CONFIG2_SDO2_MSK
Definition: ad738x.h:89
RES_16_BIT
@ RES_16_BIT
Definition: ad738x.h:136
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:119
ad738x_init_param::spi_param
struct no_os_spi_init_param * spi_param
Definition: ad738x.h:173
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:175
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:65
ad738x_init_param::conv_mode
enum ad738x_conv_mode conv_mode
Definition: ad738x.h:179
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:805
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:122
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:257
OSR_DISABLED
@ OSR_DISABLED
Definition: ad738x.h:127
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:58
OSR_X8
@ OSR_X8
Definition: ad738x.h:130
no_os_util.h
Header file of utility functions.
ROLLING_OS_MODE
@ ROLLING_OS_MODE
Definition: ad738x.h:123
ad738x_dev::resolution
enum ad738x_resolution resolution
Definition: ad738x.h:166
ad738x_set_conversion_mode
int32_t ad738x_set_conversion_mode(struct ad738x_dev *dev, enum ad738x_conv_mode mode)
Definition: ad738x.c:175
TWO_WIRE_MODE
@ TWO_WIRE_MODE
Definition: ad738x.h:117
spi_engine_offload_message::rx_addr
uint32_t rx_addr
Definition: spi_engine.h:173
ad738x_resolution
ad738x_resolution
Definition: ad738x.h:135
ad738x_spi_single_conversion
int32_t ad738x_spi_single_conversion(struct ad738x_dev *dev, uint16_t *adc_data)
Definition: ad738x.c:140
ad7616_init_param::spi_param
struct no_os_spi_init_param * spi_param
Definition: ad7616.h:210
ad738x_power_down_mode
int32_t ad738x_power_down_mode(struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
Definition: ad738x.c:257
ad738x_reset
int32_t ad738x_reset(struct ad738x_dev *dev, enum ad738x_reset_type reset)
Definition: ad738x.c:192
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:131