no-OS
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ad405x.h
Go to the documentation of this file.
1/*******************************************************************************
2 * @file ad405x.h
3 * @brief Header file of AD405X Driver.
4 * @author George Mois (george.mois@analog.com)
5 * @author Ribhu Das Purkayastha (ribhu.daspurkayastha@analog.com)
6********************************************************************************
7 * Copyright 2024(c) Analog Devices, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26 * EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*******************************************************************************/
34
35#ifndef __AD405X_H__
36#define __AD405X_H__
37
38#include <stdint.h>
39#include <string.h>
40#include "no_os_util.h"
41#include "no_os_spi.h"
42#include "no_os_gpio.h"
43
45#define AD405X_REG_INTERFACE_CONFIG_A 0x00
46#define AD405X_REG_INTERFACE_CONFIG_B 0x01
47#define AD405X_REG_DEVICE_CONFIG 0x02
48#define AD405X_REG_DEVICE_TYPE 0x03
49#define AD405X_REG_PRODUCT_ID_L 0x04
50#define AD405X_REG_PRODUCT_ID_H 0x05
51#define AD405X_REG_CHIP_GRADE 0x06
52#define AD405X_REG_SCRATCH_PAD 0x0A
53#define AD405X_REG_SPI_REVISION 0x0B
54#define AD405X_REG_VENDOR_L 0x0C
55#define AD405X_REG_VENDOR_H 0x0D
56#define AD405X_REG_STREAM_MODE 0x0E
57#define AD405X_REG_TRANSFER_CONFIG 0x0F
58#define AD405X_REG_INTERFACE_CONFIG_C 0x10
59#define AD405X_REG_INTERFACE_STATUS 0x11
60#define AD405X_REG_MODE_SET 0x20
61#define AD405X_REG_ADC_MODES 0x21
62#define AD405X_REG_ADC_CONFIG 0x22
63#define AD405X_REG_AVG_CONFIG 0x23
64#define AD405X_REG_GPIO_CONFIG 0x24
65#define AD405X_REG_INTR_CONFIG 0x25
66#define AD405X_REG_CHOP_CONFIG 0x26
67#define AD405X_REG_TIMER_CONFIG 0x27
68#define AD405X_REG_MAX_THRESH 0x28
69#define AD405X_REG_MIN_THRESH 0x2A
70#define AD405X_REG_MAX_HYST 0x2C
71#define AD405X_REG_MIN_HYST 0x2D
72#define AD405X_REG_MON_VAL 0x2E
73#define AD405X_REG_FUSE_CRC 0x40
74#define AD405X_REG_DEVICE_STATUS 0x41
75#define AD405X_REG_MAX_INTR 0x42
76#define AD405X_REG_MIN_INTR 0x44
77
79#define AD405X_SW_RESET_MSK NO_OS_BIT(7) | NO_OS_BIT(0)
80
82#define AD405X_SINGLE_INST_MSK NO_OS_BIT(7) /* Should be set to 0. */
83#define AD405X_SHORT_INST_MSK NO_OS_BIT(3)
84
86#define AD405X_STRICT_REG_ACCESS_MSK NO_OS_BIT(5)
87
89#define AD405X_ADC_DATA_FORMAT_MSK NO_OS_BIT(7)
90#define AD405X_ADC_MODES_MSK NO_OS_GENMASK(1, 0)
91#define AD405X_SAMPLE_MODE 0x00
92#define AD405X_BURST_AVERAGING_MODE NO_OS_BIT(0)
93#define AD405X_AVERAGING_MODE NO_OS_BIT(1)
94#define AD405X_AUTONOMOUS_MODE NO_OS_GENMASK(1, 0)
95
97#define AD405X_ENTER_ADC_MODE_MSK NO_OS_BIT(0)
98#define AD405X_ENTER_ADC_MODE NO_OS_BIT(0)
99
101#define AD405X_FS_BURST_AUTO_MSK NO_OS_GENMASK(7, 4)
102
104#define AD405X_AVG_WIN_LEN_MSK NO_OS_GENMASK(3, 0)
105
107#define AD405X_DEV_EN_POL_MSK NO_OS_BIT(7)
108#define AD405X_GP1_MODE_MSK NO_OS_GENMASK(6, 4)
109#define AD405X_INVERT_ON_CHOP_MSK NO_OS_BIT(3)
110#define AD405X_GP0_MODE_MSK NO_OS_GENMASK(2, 0)
111
112#define AD405X_DEV_EN_POL_LOW ~NO_OS_BIT(7)
113#define AD405X_DEV_EN_POL_HIGH NO_OS_BIT(7)
114
115#define AD405X_INVERT_ON_CHOP_OFF ~NO_OS_BIT(3)
116#define AD405X_INVERT_ON_CHOP_ON NO_OS_BIT(3)
117
119#define AD405X_SW_RESET NO_OS_BIT(7) | NO_OS_BIT(0)
120#define AD405X_SPI_READ NO_OS_BIT(7)
121#define BYTE_ADDR_H NO_OS_GENMASK(15, 8)
122#define BYTE_ADDR_L NO_OS_GENMASK(7, 0)
123#define AD405X_DEVICE_TYPE NO_OS_GENMASK(2, 0)
124
134
154
170
176
182
194
200
206
212
218
251
274
276int ad405x_write(struct ad405x_dev *dev,
277 uint8_t reg_addr,
278 uint8_t reg_val);
279
281int ad405x_read(struct ad405x_dev *dev,
282 uint8_t reg_addr,
283 uint8_t *reg_val);
284
286int ad405x_update_bits(struct ad405x_dev *dev,
287 uint8_t reg_addr,
288 uint8_t mask,
289 uint8_t reg_val);
290
292int ad405x_exit_command(struct ad405x_dev *dev);
293
296
298int ad405x_soft_reset(struct ad405x_dev *dev);
299
301int ad405x_set_adc_mode(struct ad405x_dev *dev);
302
305
307int ad405x_set_config_mode(struct ad405x_dev *dev);
308
311 enum ad405x_operation_mode mode);
312
314int ad405x_convst(struct ad405x_dev *dev);
315
317int ad405x_spi_data_read(struct ad405x_dev *dev,
318 int32_t *data);
319
321int ad405x_read_val(struct ad405x_dev *dev, int32_t *data);
322
324int ad405x_set_sample_rate(struct ad405x_dev *dev,
325 enum ad405x_sample_rate rate);
326
329 enum ad405x_avg_filter_l length);
330
333 struct ad405x_dev *dev);
334
337 enum ad405x_dev_en_polarity polarity);
338
341
344
347
350 struct ad405x_dev *dev);
351
353int ad405x_set_gp_mode(struct ad405x_dev *dev,
354 enum ad405x_gp_select gp,
355 enum ad405x_gp_mode mode);
356
359 struct ad405x_dev *dev, enum ad405x_gp_select gp);
360
362int ad405x_set_data_format(struct ad405x_dev *dev,
363 enum ad405x_out_data_format data_format);
364
366int ad405x_init(struct ad405x_dev **device,
368
370int ad405x_remove(struct ad405x_dev *dev);
371
372#endif /* __AD405X_H__ */
int ad405x_set_sample_rate(struct ad405x_dev *dev, enum ad405x_sample_rate rate)
Select sample rate for Burst and Autonomous Modes.
Definition ad405x.c:472
int ad405x_set_operation_mode(struct ad405x_dev *dev, enum ad405x_operation_mode mode)
Set operation mode.
Definition ad405x.c:336
int ad405x_init(struct ad405x_dev **device, struct ad405x_init_param init_param)
Initialize the device.
Definition ad405x.c:796
int ad405x_disable_invert_on_chop(struct ad405x_dev *dev)
Disable INVERT_ON_CHOP.
Definition ad405x.c:612
ad405x_dev_en_polarity
Definition ad405x.h:172
@ AD405X_DEV_EN_ACTIVE_LOW
Definition ad405x.h:173
@ AD405X_DEV_EN_ACTIVE_HIGH
Definition ad405x.h:174
int ad405x_remove(struct ad405x_dev *dev)
Remove the device and release resources.
Definition ad405x.c:880
ad405x_gp_select
Definition ad405x.h:196
@ AD405X_GP_0
Definition ad405x.h:197
@ AD405X_GP_1
Definition ad405x.h:198
int ad405x_soft_reset(struct ad405x_dev *dev)
Software reset the device.
Definition ad405x.c:189
int ad405x_set_burst_averaging_mode(struct ad405x_dev *dev)
Enter Burst Averaging Mode.
Definition ad405x.c:247
int ad405x_read(struct ad405x_dev *dev, uint8_t reg_addr, uint8_t *reg_val)
Read device register.
Definition ad405x.c:95
ad405x_out_data_format
Definition ad405x.h:202
@ AD405X_TWOS_COMPLEMENT
Definition ad405x.h:204
@ AD405X_STRAIGHT_BINARY
Definition ad405x.h:203
int ad405x_set_averaging_filter_length(struct ad405x_dev *dev, enum ad405x_avg_filter_l length)
Set averaging filter window length.
Definition ad405x.c:498
ad405x_sample_rate
Definition ad405x.h:136
@ AD405X_333_SPS
Definition ad405x.h:146
@ AD405X_333_KSPS
Definition ad405x.h:139
@ AD405X_10_KSPS
Definition ad405x.h:142
@ AD405X_3_KSPS
Definition ad405x.h:143
@ AD405X_1_MSPS
Definition ad405x.h:138
@ AD405X_200_SPS
Definition ad405x.h:148
@ AD405X_500_SPS
Definition ad405x.h:145
@ AD405X_125_SPS
Definition ad405x.h:151
@ AD405X_1_KSPS
Definition ad405x.h:144
@ AD405X_166_SPS
Definition ad405x.h:149
@ AD405X_250_SPS
Definition ad405x.h:147
@ AD405X_2_MSPS
Definition ad405x.h:137
@ AD405X_100_KSPS
Definition ad405x.h:140
@ AD405X_140_SPS
Definition ad405x.h:150
@ AD405X_111_SPS
Definition ad405x.h:152
@ AD405X_33_KSPS
Definition ad405x.h:141
int ad405x_write(struct ad405x_dev *dev, uint8_t reg_addr, uint8_t reg_val)
Write device register.
Definition ad405x.c:73
int ad405x_reset_pattern_command(struct ad405x_dev *dev)
Definition ad405x.c:168
enum ad405x_gp_mode ad405x_get_gp_mode(struct ad405x_dev *dev, enum ad405x_gp_select gp)
Get GP mode setting.
Definition ad405x.c:704
enum ad405x_avg_filter_l ad405x_get_averaging_filter_length(struct ad405x_dev *dev)
Get averaging filter window length.
Definition ad405x.c:535
int ad405x_update_bits(struct ad405x_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t reg_val)
Update specific register bits.
Definition ad405x.c:122
ad405x_product_id
Definition ad405x.h:214
@ PROD_ID_AD4050
Definition ad405x.h:215
@ PROD_ID_AD4052
Definition ad405x.h:216
int ad405x_exit_command(struct ad405x_dev *dev)
Send EXIT command.
Definition ad405x.c:148
int ad405x_set_config_mode(struct ad405x_dev *dev)
Enter Config Mode.
Definition ad405x.c:313
ad405x_invert_on_chop
Definition ad405x.h:178
@ AD405X_INVERT_ON_CHOP_ENABLED
Definition ad405x.h:180
@ AD405X_INVERT_ON_CHOP_DISABLED
Definition ad405x.h:179
int ad405x_set_dev_en_polarity(struct ad405x_dev *dev, enum ad405x_dev_en_polarity polarity)
Set DEV_EN signal polarity.
Definition ad405x.c:550
ad405x_avg_filter_l
Definition ad405x.h:156
@ AD405X_LENGTH_2
Definition ad405x.h:157
@ AD405X_LENGTH_1024
Definition ad405x.h:166
@ AD405X_LENGTH_8
Definition ad405x.h:159
@ AD405X_LENGTH_64
Definition ad405x.h:162
@ AD405X_LENGTH_32
Definition ad405x.h:161
@ AD405X_LENGTH_4096
Definition ad405x.h:168
@ AD405X_LENGTH_128
Definition ad405x.h:163
@ AD405X_LENGTH_512
Definition ad405x.h:165
@ AD405X_LENGTH_256
Definition ad405x.h:164
@ AD405X_LENGTH_4
Definition ad405x.h:158
@ AD405X_LENGTH_16
Definition ad405x.h:160
@ AD405X_LENGTH_2048
Definition ad405x.h:167
int ad405x_enable_invert_on_chop(struct ad405x_dev *dev)
Enable INVERT_ON_CHOP.
Definition ad405x.c:588
int ad405x_set_gp_mode(struct ad405x_dev *dev, enum ad405x_gp_select gp, enum ad405x_gp_mode mode)
Set GP mode.
Definition ad405x.c:652
ad405x_operation_mode
Definition ad405x.h:126
@ AD405X_NON_PERSISTENT_AUTO_MODE_OP
Definition ad405x.h:132
@ AD405X_PERSISTENT_AUTO_MODE_OP
Definition ad405x.h:131
@ AD405X_ADC_MODE_OP
Definition ad405x.h:128
@ AD405X_CONFIG_MODE_OP
Definition ad405x.h:127
@ AD405X_AVERAGING_MODE_OP
Definition ad405x.h:129
@ AD405X_BURST_AVERAGING_MODE_OP
Definition ad405x.h:130
enum ad405x_dev_en_polarity ad405x_get_dev_en_polarity(struct ad405x_dev *dev)
Get DEV_EN signal polarity.
Definition ad405x.c:575
ad405x_gp_mode
Definition ad405x.h:184
@ AD405X_GP_MODE_HIGH
Definition ad405x.h:191
@ AD405X_GP_MODE_LOW
Definition ad405x.h:190
@ AD405X_GP_MODE_DEV_EN
Definition ad405x.h:188
@ AD405X_GP_MODE_CHOP
Definition ad405x.h:189
@ AD405X_GP_MODE_INTR
Definition ad405x.h:186
@ AD405X_GP_MODE_DRDY
Definition ad405x.h:187
@ AD405X_GP_MODE_HIGH_Z
Definition ad405x.h:185
@ AD405X_GP_MODE_DEV_RDY
Definition ad405x.h:192
int ad405x_set_data_format(struct ad405x_dev *dev, enum ad405x_out_data_format data_format)
Set output data format.
Definition ad405x.c:727
int ad405x_convst(struct ad405x_dev *dev)
Toggle the CNV pin to start a conversion.
Definition ad405x.c:373
ad405x_device_type
Definition ad405x.h:208
@ ID_AD4052
Definition ad405x.h:210
@ ID_AD4050
Definition ad405x.h:209
int ad405x_read_val(struct ad405x_dev *dev, int32_t *data)
Trigger conversion and read data.
Definition ad405x.c:450
enum ad405x_invert_on_chop ad405x_get_invert_on_chop_state(struct ad405x_dev *dev)
Get INVERT_ON_CHOP setting.
Definition ad405x.c:636
int ad405x_set_adc_mode(struct ad405x_dev *dev)
Enter ADC Mode.
Definition ad405x.c:214
int ad405x_spi_data_read(struct ad405x_dev *dev, int32_t *data)
Read conversion data.
Definition ad405x.c:400
struct ad7616_init_param init_param
Definition ad7616_sdz.c:107
Header file of GPIO Interface.
Header file of SPI Interface.
Header file of utility functions.
AD405X Device structure.
Definition ad405x.h:223
struct no_os_gpio_desc * gpio_cnv
Definition ad405x.h:231
struct no_os_gpio_desc * gpio_gpio1
Definition ad405x.h:235
enum ad405x_avg_filter_l filter_length
Definition ad405x.h:239
enum ad405x_sample_rate rate
Definition ad405x.h:237
enum ad405x_gp_mode gp0_mode
Definition ad405x.h:247
enum ad405x_gp_mode gp1_mode
Definition ad405x.h:243
enum ad405x_device_type active_device
Definition ad405x.h:227
enum ad405x_out_data_format data_format
Definition ad405x.h:249
enum ad405x_operation_mode operation_mode
Definition ad405x.h:229
struct no_os_gpio_desc * gpio_gpio0
Definition ad405x.h:233
enum ad405x_invert_on_chop invert_on_chop_status
Definition ad405x.h:245
enum ad405x_dev_en_polarity polarity
Definition ad405x.h:241
struct no_os_spi_desc * spi_desc
Definition ad405x.h:225
Definition ad405x.h:256
enum ad405x_device_type active_device
Definition ad405x.h:260
enum ad405x_operation_mode operation_mode
Definition ad405x.h:262
enum ad405x_avg_filter_l filter_length
Definition ad405x.h:272
enum ad405x_sample_rate rate
Definition ad405x.h:270
struct no_os_spi_init_param * spi_init
Definition ad405x.h:258
struct no_os_gpio_init_param * gpio_cnv
Definition ad405x.h:264
struct no_os_gpio_init_param * gpio_gpio1
Definition ad405x.h:268
struct no_os_gpio_init_param * gpio_gpio0
Definition ad405x.h:266
Definition ad9361_util.h:63
Structure holding the GPIO descriptor.
Definition no_os_gpio.h:84
Structure holding the parameters for GPIO initialization.
Definition no_os_gpio.h:67
Structure holding SPI descriptor.
Definition no_os_spi.h:180
Structure holding the parameters for SPI initialization.
Definition no_os_spi.h:128