no-OS
ada4250.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef ADA4250_H_
41 #define ADA4250_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 #include <stdint.h>
47 #include <math.h>
48 #include <stdbool.h>
49 #include "no_os_spi.h"
50 #include "no_os_gpio.h"
51 #include "no_os_util.h"
52 
53 /******************************************************************************/
54 /********************** Macros and Constants Definitions **********************/
55 /******************************************************************************/
56 
57 /* ADA4250 Register Map */
58 #define ADA4250_REG_GAIN_MUX 0x00
59 #define ADA4250_REG_REFBUF_EN 0x01
60 #define ADA4250_REG_RESET 0x02
61 #define ADA4250_REG_SNSR_CAL_VAL 0x04
62 #define ADA4250_REG_SNSR_CAL_CNFG 0x05
63 #define ADA4250_REG_DIE_REV 0x18
64 #define ADA4250_REG_CHIP_ID1 0x19
65 #define ADA4250_REG_CHIP_ID2 0x1a
66 
67 /* ADA4250_REG_GAIN_MUX Map */
68 #define ADA4250_GAIN_MUX_MSK NO_OS_GENMASK(2, 0)
69 #define ADA4250_GAIN_MUX(x) no_os_field_prep(ADA4250_GAIN_MUX_MSK, x)
70 
71 /* ADA4250_REG_REFBUF Map */
72 #define ADA4250_REFBUF_MSK NO_OS_BIT(0)
73 #define ADA4250_REFBUF(x) no_os_field_prep(ADA4250_REFBUF_MSK, x)
74 
75 /* ADA4250_REG_REFBUFF_EN Bit Definition */
76 #define ADA4250_BUF_ENABLE 0x01
77 #define ADA4250_BUF_DISABLE 0x00
78 
79 /* ADA4250_REG_RESET Map */
80 #define ADA4250_RESET_MSK NO_OS_BIT(0)
81 #define ADA4250_RESET(x) no_os_field_prep(ADA4250_RESET_MSK, x)
82 
83 /* ADA4250_REG_RESET Bit Definition */
84 #define ADA4250_RESET_ENABLE 0x01
85 #define ADA4250_RESET_DISABLE 0x00
86 
87 /* ADA4250_REG_SNSR_CAL_VAL Map */
88 #define ADA4250_SNSR_CAL_VAL_MSK NO_OS_GENMASK(7, 0)
89 #define ADA4250_SNSR_CAL_VAL(x) no_os_field_prep(ADA4250_SNSR_CAL_VAL_MSK, x)
90 
91 /* ADA4250_REG_SNSR_CAL_CNFG Bit Definition */
92 #define ADA4250_BIAS_SET_MSK NO_OS_GENMASK(3, 2)
93 #define ADA4250_BIAS_SET(x) no_os_field_prep(ADA4250_BIAS_SET_MSK, x)
94 #define ADA4250_RANGE_SET_MSK NO_OS_GENMASK(1, 0)
95 #define ADA4250_RANGE_SET(x) no_os_field_prep(ADA4250_RANGE_SET_MSK, x)
96 
97 /* Specifications */
98 #define ADA4250_SPI_WRITE_CMD 0x0
99 #define ADA4250_BUFF_SIZE_BYTES 2
100 #define ADA4250_SPI_READ_CMD NO_OS_BIT(7)
101 #define ADA4250_DIE_REV 0x0
102 #define ADA4250_CHIP_ID 0x4250
103 
104 /* ADA4250 Extra Definitions */
105 #define ADA4250_SPI_DUMMY_DATA 0x00
106 
107 /******************************************************************************/
108 /*************************** Types Declarations *******************************/
109 /******************************************************************************/
110 
118 };
119 
128 };
129 
139 };
140 
154 };
155 
163 };
164 
173 };
174 
180  /* Device ID */
182  /* SPI Initialization parameters */
184  /* GPIO Initialization parameters */
192  /* AVDD value in milliVolts */
193  int32_t avdd_v;
194  /* Reference Buffer Enable */
195  bool refbuf_en;
196  /* Gain Value */
198  /* Bias Set */
200  /* Bandwidth Value */
202  /* Offset Calibration Value */
203  int32_t offset_nv;
204 };
205 
210 struct ada4250_dev {
211  /* Device ID */
213  /* SPI Initialization parameters */
215  /* GPIO Descriptors */
223  /* AVDD value in milliVolts */
224  int32_t avdd_v;
225  /* Reference Buffer Enable */
226  bool refbuf_en;
227  /* Gain Value */
229  /* Offset Range */
231  /* Bias Set */
233  /* Bandwidth Value */
235  /* Power Mode */
237  /* Offset Calibration Value in nV*/
238  int32_t offset_nv;
239 };
240 
241 /******************************************************************************/
242 /************************ Functions Declarations ******************************/
243 /******************************************************************************/
244 
246 int32_t ada4250_write(struct ada4250_dev *dev, uint8_t reg_addr,
247  uint8_t data);
248 
250 int32_t ada4250_read(struct ada4250_dev *dev, uint8_t reg_addr,
251  uint8_t *data);
252 
253 /* ADA4250 Register Update */
254 int32_t ada4250_update(struct ada4250_dev *dev, uint8_t reg_addr,
255  uint8_t mask, uint8_t data);
256 
257 /* ADA4250 Device Descriptor Update */
258 int32_t ada4250_update_desc(struct ada4250_dev *dev);
259 
260 /* Software Reset */
261 int32_t ada4250_soft_reset(struct ada4250_dev *dev);
262 
263 /* Set Reference Buffer */
264 int32_t ada4250_en_refbuf(struct ada4250_dev *dev, bool refbuf);
265 
266 /* Set Current Bias */
267 int32_t ada4250_set_bias(struct ada4250_dev *dev, enum ada4250_bias bias);
268 
269 /* Set gain */
270 int32_t ada4250_set_gain(struct ada4250_dev *dev, enum ada4250_gain gain);
271 
272 /* Set offset value */
273 int32_t ada4250_set_offset(struct ada4250_dev *dev, int64_t offset);
274 
275 /* Set bandwidth mode */
276 int32_t ada4250_set_bandwidth(struct ada4250_dev *dev,
277  enum ada4250_bandwidth bw);
278 
279 /* Set sleep/shutdown mode */
280 int32_t ada4250_set_slp_shtdwn_mode(struct ada4250_dev *dev,
281  enum ada4250_power_mode pwrmode);
282 
283 /* Set normal mode */
284 int32_t ada4250_set_normal_mode(struct ada4250_dev *dev, bool reconfig);
285 
286 /* ADA4250 Initialization */
287 int32_t ada4250_init(struct ada4250_dev **device,
289 
291 int32_t ada4250_remove(struct ada4250_dev *dev);
292 
293 #endif /* ADA4250_H_ */
ada4250_init_param::gpio_g2_param
struct no_os_gpio_init_param * gpio_g2_param
Definition: ada4250.h:185
ADA4250_RESET_MSK
#define ADA4250_RESET_MSK
Definition: ada4250.h:80
ada4250_set_bias
int32_t ada4250_set_bias(struct ada4250_dev *dev, enum ada4250_bias bias)
Set current bias for ADA4250.
Definition: ada4250.c:232
ADA4250_GAIN_128
@ ADA4250_GAIN_128
Definition: ada4250.h:153
no_os_gpio_init_param
Structure holding the parameters for GPIO initialization.
Definition: no_os_gpio.h:85
ADA4250
@ ADA4250
Definition: ada4250.h:117
ada4250_read
int32_t ada4250_read(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t *data)
Reads data from ada4250 over SPI.
Definition: ada4250.c:81
ada4250_remove
int32_t ada4250_remove(struct ada4250_dev *dev)
Free resoulces allocated for ADA4250.
Definition: ada4250.c:662
ada4250_dev::gpio_slp
struct no_os_gpio_desc * gpio_slp
Definition: ada4250.h:221
ADA4250_BIAS_BANDGAP_REF
@ ADA4250_BIAS_BANDGAP_REF
Definition: ada4250.h:126
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
ada4250_init_param
ADA4250 Initialization Parameters structure.
Definition: ada4250.h:179
ADA4250_RANGE2
@ ADA4250_RANGE2
Definition: ada4250.h:136
no_os_spi.h
Header file of SPI Interface.
ADA4250_POWER_SHUTDOWN
@ ADA4250_POWER_SHUTDOWN
Definition: ada4250.h:172
ADA4250_REFBUF
#define ADA4250_REFBUF(x)
Definition: ada4250.h:73
ADA4250_GAIN_MUX_MSK
#define ADA4250_GAIN_MUX_MSK
Definition: ada4250.h:68
ada4250_dev::power_mode
enum ada4250_power_mode power_mode
Definition: ada4250.h:236
ADA4250_BIAS_AVDD
@ ADA4250_BIAS_AVDD
Definition: ada4250.h:127
ada4250_dev::spi_desc
struct no_os_spi_desc * spi_desc
Definition: ada4250.h:214
ada4250_set_offset
int32_t ada4250_set_offset(struct ada4250_dev *dev, int64_t offset)
Set offset value for ADA4250.
Definition: ada4250.c:309
ada4250_set_slp_shtdwn_mode
int32_t ada4250_set_slp_shtdwn_mode(struct ada4250_dev *dev, enum ada4250_power_mode pwrmode)
Set the ADA4250 into sleep or shutdown mode.
Definition: ada4250.c:440
ada4250_update
int32_t ada4250_update(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
Update ADA4250 register.
Definition: ada4250.c:110
ADA4250_BUFF_SIZE_BYTES
#define ADA4250_BUFF_SIZE_BYTES
Definition: ada4250.h:99
ada4250_dev::refbuf_en
bool refbuf_en
Definition: ada4250.h:226
ADA4250_RESET
#define ADA4250_RESET(x)
Definition: ada4250.h:81
ada4250_id
ada4250_id
Current bias settings.
Definition: ada4250.h:115
ada4250_dev::gpio_g2
struct no_os_gpio_desc * gpio_g2
Definition: ada4250.h:216
no_os_delay.h
Header file of Delay functions.
ada4250_dev::bias
enum ada4250_bias bias
Definition: ada4250.h:232
ada4250_init_param::offset_nv
int32_t offset_nv
Definition: ada4250.h:203
ada4250_init
int32_t ada4250_init(struct ada4250_dev **device, struct ada4250_init_param *init_param)
Initialize the ADA4250 device.
Definition: ada4250.c:520
ada4250_set_offset
int32_t ada4250_set_offset(struct ada4250_dev *dev, int64_t offset)
Set offset value for ADA4250.
Definition: ada4250.c:309
ADA4250_REG_RESET
#define ADA4250_REG_RESET
Definition: ada4250.h:60
ada4250_init_param::spi_init
struct no_os_spi_init_param * spi_init
Definition: ada4250.h:183
ADA4250_POWER_SLEEP
@ ADA4250_POWER_SLEEP
Definition: ada4250.h:171
ada4250_write
int32_t ada4250_write(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t data)
Writes data to ada4250 over SPI.
Definition: ada4250.c:59
device
Definition: ad9361_util.h:75
NO_OS_GPIO_HIGH
@ NO_OS_GPIO_HIGH
Definition: no_os_gpio.h:123
ADA4250_SPI_DUMMY_DATA
#define ADA4250_SPI_DUMMY_DATA
Definition: ada4250.h:105
ada4250_power_mode
ada4250_power_mode
Power Modes.
Definition: ada4250.h:169
ada4250_set_bandwidth
int32_t ada4250_set_bandwidth(struct ada4250_dev *dev, enum ada4250_bandwidth bw)
Set the bandwidth value for ADA4250.
Definition: ada4250.c:367
ADA4250_RANGE4
@ ADA4250_RANGE4
Definition: ada4250.h:138
ada4250_update
int32_t ada4250_update(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
Update ADA4250 register.
Definition: ada4250.c:110
ada4250_dev::gpio_g1
struct no_os_gpio_desc * gpio_g1
Definition: ada4250.h:217
ada4250_soft_reset
int32_t ada4250_soft_reset(struct ada4250_dev *dev)
Software reset.
Definition: ada4250.c:165
ADA4250_REG_SNSR_CAL_VAL
#define ADA4250_REG_SNSR_CAL_VAL
Definition: ada4250.h:61
ADA4250_GAIN_MUX
#define ADA4250_GAIN_MUX(x)
Definition: ada4250.h:69
NO_OS_GPIO_LOW
@ NO_OS_GPIO_LOW
Definition: no_os_gpio.h:121
ada4250_write
int32_t ada4250_write(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t data)
Writes data to ada4250 over SPI.
Definition: ada4250.c:59
ADA4250_BIAS_SET
#define ADA4250_BIAS_SET(x)
Definition: ada4250.h:93
no_os_mdelay
void no_os_mdelay(uint32_t msecs)
Wait until msecs milliseconds passed.
Definition: delay.c:130
ada4250_bandwidth
ada4250_bandwidth
Bandwidth modes.
Definition: ada4250.h:160
ADA4250_BIAS_SET_MSK
#define ADA4250_BIAS_SET_MSK
Definition: ada4250.h:92
no_os_error.h
Error codes definition.
ada4250_dev::avdd_v
int32_t avdd_v
Definition: ada4250.h:224
ADA4250_BANDWIDTH_LOW
@ ADA4250_BANDWIDTH_LOW
Definition: ada4250.h:161
ada4250_init
int32_t ada4250_init(struct ada4250_dev **device, struct ada4250_init_param *init_param)
Initialize the ADA4250 device.
Definition: ada4250.c:520
ada4250_update_desc
int32_t ada4250_update_desc(struct ada4250_dev *dev)
Update ADA4250 device descriptor.
Definition: ada4250.c:136
ADA4250_GAIN_32
@ ADA4250_GAIN_32
Definition: ada4250.h:151
ADA4250_GAIN_4
@ ADA4250_GAIN_4
Definition: ada4250.h:148
ada4250_init_param::bias
enum ada4250_bias bias
Definition: ada4250.h:199
ADA4250_REG_GAIN_MUX
#define ADA4250_REG_GAIN_MUX
Definition: ada4250.h:58
ada4250_init_param::gpio_g0_param
struct no_os_gpio_init_param * gpio_g0_param
Definition: ada4250.h:187
ada4250_dev::device_id
enum ada4250_id device_id
Definition: ada4250.h:212
ADA4250_SPI_READ_CMD
#define ADA4250_SPI_READ_CMD
Definition: ada4250.h:100
ada4250_set_bias
int32_t ada4250_set_bias(struct ada4250_dev *dev, enum ada4250_bias bias)
Set current bias for ADA4250.
Definition: ada4250.c:232
ada4250_init_param::refbuf_en
bool refbuf_en
Definition: ada4250.h:195
ada4250_init_param::gpio_bufen_param
struct no_os_gpio_init_param * gpio_bufen_param
Definition: ada4250.h:189
ada4250_set_gain
int32_t ada4250_set_gain(struct ada4250_dev *dev, enum ada4250_gain gain)
Set gain for ADA4250.
Definition: ada4250.c:277
no_os_gpio_remove
int32_t no_os_gpio_remove(struct no_os_gpio_desc *desc)
Free the resources allocated by no_os_gpio_get().
Definition: no_os_gpio.c:95
no_os_spi_desc
Structure holding SPI descriptor.
Definition: no_os_spi.h:132
ADA4250_BANDWIDTH_HIGH
@ ADA4250_BANDWIDTH_HIGH
Definition: ada4250.h:162
ADA4250_SPI_WRITE_CMD
#define ADA4250_SPI_WRITE_CMD
Definition: ada4250.h:98
ADA4250_RANGE3
@ ADA4250_RANGE3
Definition: ada4250.h:137
ada4250_set_bandwidth
int32_t ada4250_set_bandwidth(struct ada4250_dev *dev, enum ada4250_bandwidth bw)
Set the bandwidth value for ADA4250.
Definition: ada4250.c:367
ada4250_offset_range
ada4250_offset_range
Sensor offset trim range.
Definition: ada4250.h:134
ad4110_dev::gain
enum ad4110_gain gain
Definition: ad4110.h:318
ada4250_init_param::gpio_slp
struct no_os_gpio_init_param * gpio_slp
Definition: ada4250.h:190
ada4250_dev::gain
enum ada4250_gain gain
Definition: ada4250.h:228
ada4250_init_param::gpio_bw_param
struct no_os_gpio_init_param * gpio_bw_param
Definition: ada4250.h:188
no_os_gpio_desc
Structure holding the GPIO descriptor.
Definition: no_os_gpio.h:102
ADA4250_GAIN_16
@ ADA4250_GAIN_16
Definition: ada4250.h:150
ada4250_init_param::gain
enum ada4250_gain gain
Definition: ada4250.h:197
no_os_gpio_get
int32_t no_os_gpio_get(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Obtain the GPIO decriptor.
Definition: no_os_gpio.c:55
ada4250_read
int32_t ada4250_read(struct ada4250_dev *dev, uint8_t reg_addr, uint8_t *data)
Reads data from ada4250 over SPI.
Definition: ada4250.c:81
ADA4250_GAIN_8
@ ADA4250_GAIN_8
Definition: ada4250.h:149
ada4250_dev
ADA4250 Device Descriptor.
Definition: ada4250.h:210
ada4250.h
Header file for ada4250 Driver.
ada4250_set_normal_mode
int32_t ada4250_set_normal_mode(struct ada4250_dev *dev, bool reconfig)
Sets the ADA4250 into normal mode and reconfigures it according to the user input.
Definition: ada4250.c:473
ada4250_dev::gpio_shtdwn
struct no_os_gpio_desc * gpio_shtdwn
Definition: ada4250.h:222
ADA4250_RESET_ENABLE
#define ADA4250_RESET_ENABLE
Definition: ada4250.h:84
ADA4250_RANGE_SET
#define ADA4250_RANGE_SET(x)
Definition: ada4250.h:95
ADA4250_GAIN_2
@ ADA4250_GAIN_2
Definition: ada4250.h:147
ada4250_bias
ada4250_bias
Current bias settings.
Definition: ada4250.h:124
ada4250_dev::offset_range
enum ada4250_offset_range offset_range
Definition: ada4250.h:230
ADA4230
@ ADA4230
Definition: ada4250.h:116
no_os_udelay
void no_os_udelay(uint32_t usecs)
Wait until usecs microseconds passed.
Definition: delay.c:118
ada4250_init_param::bandwidth
enum ada4250_bandwidth bandwidth
Definition: ada4250.h:201
ada4250_set_gain
int32_t ada4250_set_gain(struct ada4250_dev *dev, enum ada4250_gain gain)
Set gain for ADA4250.
Definition: ada4250.c:277
no_os_gpio_set_value
int32_t no_os_gpio_set_value(struct no_os_gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: no_os_gpio.c:160
ADA4250_REG_REFBUF_EN
#define ADA4250_REG_REFBUF_EN
Definition: ada4250.h:59
init_param
struct ad7616_init_param init_param
Definition: ad7616_sdz.c:96
ada4250_init_param::gpio_shtdwn
struct no_os_gpio_init_param * gpio_shtdwn
Definition: ada4250.h:191
ada4250_init_param::avdd_v
int32_t avdd_v
Definition: ada4250.h:193
ada4250_set_normal_mode
int32_t ada4250_set_normal_mode(struct ada4250_dev *dev, bool reconfig)
Sets the ADA4250 into normal mode and reconfigures it according to the user input.
Definition: ada4250.c:473
ada4250_en_refbuf
int32_t ada4250_en_refbuf(struct ada4250_dev *dev, bool refbuf)
Enable/Disable Reference Buffer.
Definition: ada4250.c:203
ADA4250_CHIP_ID
#define ADA4250_CHIP_ID
Definition: ada4250.h:102
ADA4250_BIAS_DISABLE
@ ADA4250_BIAS_DISABLE
Definition: ada4250.h:125
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
ADA4250_RANGE1
@ ADA4250_RANGE1
Definition: ada4250.h:135
ada4250_soft_reset
int32_t ada4250_soft_reset(struct ada4250_dev *dev)
Software reset.
Definition: ada4250.c:165
ADA4250_REG_SNSR_CAL_CNFG
#define ADA4250_REG_SNSR_CAL_CNFG
Definition: ada4250.h:62
no_os_gpio.h
Header file of GPIO Interface.
ada4250_init_param::device_id
enum ada4250_id device_id
Definition: ada4250.h:181
ada4250_init_param::gpio_g1_param
struct no_os_gpio_init_param * gpio_g1_param
Definition: ada4250.h:186
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
ada4250_dev::gpio_bw
struct no_os_gpio_desc * gpio_bw
Definition: ada4250.h:219
ada4250_remove
int32_t ada4250_remove(struct ada4250_dev *dev)
Free resoulces allocated for ADA4250.
Definition: ada4250.c:662
no_os_util.h
Implementation of utility functions.
ada4250_set_slp_shtdwn_mode
int32_t ada4250_set_slp_shtdwn_mode(struct ada4250_dev *dev, enum ada4250_power_mode pwrmode)
Set the ADA4250 into sleep or shutdown mode.
Definition: ada4250.c:440
ADA4250_GAIN_64
@ ADA4250_GAIN_64
Definition: ada4250.h:152
ADA4250_REG_CHIP_ID1
#define ADA4250_REG_CHIP_ID1
Definition: ada4250.h:64
ada4250_dev::gpio_bufen
struct no_os_gpio_desc * gpio_bufen
Definition: ada4250.h:220
no_os_gpio_direction_output
int32_t no_os_gpio_direction_output(struct no_os_gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: no_os_gpio.c:124
ada4250_dev::gpio_g0
struct no_os_gpio_desc * gpio_g0
Definition: ada4250.h:218
ada4250_dev::bandwidth
enum ada4250_bandwidth bandwidth
Definition: ada4250.h:234
ada4250_gain
ada4250_gain
Gain value.
Definition: ada4250.h:145
ADA4250_GAIN_1
@ ADA4250_GAIN_1
Definition: ada4250.h:146
ada4250_en_refbuf
int32_t ada4250_en_refbuf(struct ada4250_dev *dev, bool refbuf)
Enable/Disable Reference Buffer.
Definition: ada4250.c:203
ADA4250_REG_CHIP_ID2
#define ADA4250_REG_CHIP_ID2
Definition: ada4250.h:65
ada4250_update_desc
int32_t ada4250_update_desc(struct ada4250_dev *dev)
Update ADA4250 device descriptor.
Definition: ada4250.c:136
ada4250_dev::offset_nv
int32_t offset_nv
Definition: ada4250.h:238
ADA4250_POWER_NORMAL
@ ADA4250_POWER_NORMAL
Definition: ada4250.h:170
chip_id
chip_id
Definition: ad9172.h:57
ADA4250_RANGE_SET_MSK
#define ADA4250_RANGE_SET_MSK
Definition: ada4250.h:94
no_os_spi_init_param
Structure holding the parameters for SPI initialization.
Definition: no_os_spi.h:112
ADA4250_REFBUF_MSK
#define ADA4250_REFBUF_MSK
Definition: ada4250.h:72
no_os_gpio_get_optional
int32_t no_os_gpio_get_optional(struct no_os_gpio_desc **desc, const struct no_os_gpio_init_param *param)
Get the value of an optional GPIO.
Definition: no_os_gpio.c:75