no-OS
Functions | Variables
ad413x.c File Reference

Implementation of AD413X Driver. More...

#include <stdio.h>
#include <stdlib.h>
#include "ad413x.h"
#include "no_os_error.h"
#include "no_os_irq.h"
#include "no_os_print_log.h"
#include "no_os_delay.h"
#include "no_os_crc8.h"
#include "no_os_spi.h"
#include "no_os_alloc.h"
Include dependency graph for ad413x.c:

Functions

 NO_OS_DECLARE_CRC8_TABLE (ad413x_crc8)
 
int32_t ad413x_reg_write_msk (struct ad413x_dev *dev, uint32_t reg_addr, uint32_t data, uint32_t mask)
 
int32_t ad413x_set_adc_mode (struct ad413x_dev *dev, enum ad413x_adc_mode mode)
 
int32_t ad413x_set_int_ref (struct ad413x_dev *dev, enum ad413x_int_ref int_ref)
 
int32_t ad413x_data_stat_en (struct ad413x_dev *dev, uint8_t enable)
 
int32_t ad413x_set_gain (struct ad413x_dev *dev, enum ad413x_gain gain, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_ref (struct ad413x_dev *dev, enum ad413x_ref_sel ref, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_ref_buf (struct ad413x_dev *dev, struct ad413x_ref_buf ref_buf, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_filter (struct ad413x_dev *dev, enum ad413x_filter filter, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_settle_time (struct ad413x_dev *dev, enum ad413x_settle_time s_time, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_exc_current (struct ad413x_dev *dev, enum ad413x_exc_current iout0_exc, enum ad413x_exc_current iout1_exc, enum ad413x_preset_nb reg_nb)
 
int32_t ad413x_set_ch_preset (struct ad413x_dev *dev, uint8_t ch_nb, enum ad413x_preset_nb preset_nb)
 
int32_t ad413x_ch_exc_input (struct ad413x_dev *dev, uint8_t ch_nb, enum ad413x_input iout0_exc_inp, enum ad413x_input iout1_exc_inp)
 
int32_t ad413x_ch_en (struct ad413x_dev *dev, uint8_t ch_nb, uint8_t enable)
 
int32_t ad413x_pdsw_en (struct ad413x_dev *dev, uint8_t ch_nb, bool pdsw_en)
 
int32_t ad413x_adc_bipolar (struct ad413x_dev *dev, uint8_t enable)
 
int32_t ad413x_set_v_bias (struct ad413x_dev *dev, uint16_t v_bias_val)
 
int32_t ad413x_set_standby_ctrl (struct ad413x_dev *dev, struct ad413x_standby_ctrl standby_ctrl)
 
int32_t ad413x_set_mclk (struct ad413x_dev *dev, enum ad413x_mclk_sel clk)
 
int32_t ad413x_do_soft_reset (struct ad413x_dev *dev)
 
int32_t ad413x_reg_write (struct ad413x_dev *dev, uint32_t reg_addr, uint32_t reg_data)
 
int32_t ad413x_reg_read (struct ad413x_dev *dev, uint32_t reg_addr, uint32_t *reg_data)
 
int32_t ad413x_single_conv (struct ad413x_dev *dev, uint32_t *buffer, uint8_t ch_nb)
 
int32_t ad413x_continuous_conv (struct ad413x_dev *dev, uint32_t *buffer, uint8_t ch_nb, uint32_t sample_nb)
 
int32_t ad413x_preset_store (struct ad413x_dev *dev, struct ad413x_preset preset, enum ad413x_preset_nb preset_nb)
 
int32_t ad413x_init (struct ad413x_dev **device, struct ad413x_init_param init_param)
 
int32_t ad413x_remove (struct ad413x_dev *dev)
 Free the resources allocated by ad413x_init(). More...
 

Variables

uint32_t timeout = 0xFFFFFF
 

Detailed Description

Implementation of AD413X Driver.

Author
Andrei Porumb (andre.nosp@m.i.po.nosp@m.rumb@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2022(c) Analog Devices, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ ad413x_adc_bipolar()

int32_t ad413x_adc_bipolar ( struct ad413x_dev dev,
uint8_t  enable 
)

Enable/disable bipolar data coding.

Parameters
dev- The device structure.
enable- 1 - Bipolar 0 - Unipolar
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_ch_en()

int32_t ad413x_ch_en ( struct ad413x_dev dev,
uint8_t  ch_nb,
uint8_t  enable 
)

Enable/disable channel.

Parameters
dev- The device structure.
ch_nb- The channel number.
enable- Channel status.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_ch_exc_input()

int32_t ad413x_ch_exc_input ( struct ad413x_dev dev,
uint8_t  ch_nb,
enum ad413x_input  iout0_exc_inp,
enum ad413x_input  iout1_exc_inp 
)

Select the excitation source pins.

Parameters
dev- The device structure.
ch_nb- The channel number.
iout0_exc_inp- IOUT0 excitation input pin.
iout1_exc_inp- IOUT1 excitation input pin.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_continuous_conv()

int32_t ad413x_continuous_conv ( struct ad413x_dev dev,
uint32_t *  buffer,
uint8_t  ch_nb,
uint32_t  sample_nb 
)

Continuous conversion of each adc active channel.

Parameters
dev- The device structure.
buffer- Buffer to store read data. Buffer size needs to be at least equal to the number of active channels * samples number. Results will be stored in consecutive order of the active channels.
ch_nb- Number of active channels.
sample_nb- Samples number.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_data_stat_en()

int32_t ad413x_data_stat_en ( struct ad413x_dev dev,
uint8_t  enable 
)

Enable/disable DATA_STAT field.

Parameters
dev- The device structure.
enable- 0 DISABLE 1 ENABLE
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_do_soft_reset()

int32_t ad413x_do_soft_reset ( struct ad413x_dev dev)

Do a SPI software reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_init()

int32_t ad413x_init ( struct ad413x_dev **  device,
struct ad413x_init_param  init_param 
)

Initialize the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_pdsw_en()

int32_t ad413x_pdsw_en ( struct ad413x_dev dev,
uint8_t  ch_nb,
bool  pdsw_en 
)

Enable/disable Power-Down Switch (PDSW).

Parameters
dev- The device structure.
ch_nb- The channel number.
pdsw_en- PDSW status.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_preset_store()

int32_t ad413x_preset_store ( struct ad413x_dev dev,
struct ad413x_preset  preset,
enum ad413x_preset_nb  preset_nb 
)

Store adc channel presets.

Parameters
dev- The device structure.
preset- The structure to be saved as preset.
preset_nb- Preset's number.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_reg_read()

int32_t ad413x_reg_read ( struct ad413x_dev dev,
uint32_t  reg_addr,
uint32_t *  reg_data 
)

SPI internal register read from device.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_reg_write()

int32_t ad413x_reg_write ( struct ad413x_dev dev,
uint32_t  reg_addr,
uint32_t  reg_data 
)

SPI internal register write to device.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_reg_write_msk()

int32_t ad413x_reg_write_msk ( struct ad413x_dev dev,
uint32_t  reg_addr,
uint32_t  data,
uint32_t  mask 
)

SPI internal register write to device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
data- The register data.
mask- The mask.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_remove()

int32_t ad413x_remove ( struct ad413x_dev dev)

Free the resources allocated by ad413x_init().

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_adc_mode()

int32_t ad413x_set_adc_mode ( struct ad413x_dev dev,
enum ad413x_adc_mode  mode 
)

Set the mode of the ADC.

Parameters
dev- The device structure.
mode- The ADC mode Accepted values: AD4110_CONTINOUS_CONV_MODE AD4110_SINGLE_CONV_MODE AD4110_STANDBY_MODE AD4110_PW_DOWN_MODE AD4110_SYS_OFFSET_CAL AD4110_SYS_GAIN_CAL
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_ch_preset()

int32_t ad413x_set_ch_preset ( struct ad413x_dev dev,
uint8_t  ch_nb,
enum ad413x_preset_nb  preset_nb 
)

Select preset for adc channel.

Parameters
dev- The device structure.
ch_nb- The channel number.
preset_nb- The preset number.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_exc_current()

int32_t ad413x_set_exc_current ( struct ad413x_dev dev,
enum ad413x_exc_current  iout0_exc,
enum ad413x_exc_current  iout1_exc,
enum ad413x_preset_nb  reg_nb 
)

Select excitation current value from config register.

Parameters
dev- The device structure.
iout0_exc- The Iout0 excitation current value.
iout1_exc- The Iout1 excitation current value. Accepted values: AD413X_EXC_OFF AD413X_EXC_10UA AD413X_EXC_20UA AD413X_EXC_50UA AD413X_EXC_100UA AD413X_EXC_150UA AD413X_EXC_200UA AD413X_EXC_100NA
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_filter()

int32_t ad413x_set_filter ( struct ad413x_dev dev,
enum ad413x_filter  filter,
enum ad413x_preset_nb  reg_nb 
)

Select filter from filter register.

Parameters
dev- The device structure.
filter- The filter type. Accepted values: AD413X_SYNC4_STANDALONE AD413X_SYNC4_SYNC1 AD413X_SYNC3_STANDALONE AD413X_SYNC3_REJ60 AD413X_SYNC3_SYNC1 AD413X_SYNC3_PF1 AD413X_SYNC3_PF2 AD413X_SYNC3_PF3 AD413X_SYNC3_PF4
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_gain()

int32_t ad413x_set_gain ( struct ad413x_dev dev,
enum ad413x_gain  gain,
enum ad413x_preset_nb  reg_nb 
)

Set the gain from configuration register.

Parameters
dev- The device structure.
gain- The gain value. Accepted values: AD413X_GAIN_1 AD413X_GAIN_2 AD413X_GAIN_4 AD413X_GAIN_8 AD413X_GAIN_16 AD413X_GAIN_32 AD413X_GAIN_64 AD413X_GAIN_128
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_int_ref()

int32_t ad413x_set_int_ref ( struct ad413x_dev dev,
enum ad413x_int_ref  int_ref 
)

Set the internal reference.

Parameters
dev- The device structure.
int_ref- The internal reference option. Accepted values: AD413X_INTREF_DISABLED AD413X_INTREF_2_5V, AD413X_INTREF_1_25V
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_mclk()

int32_t ad413x_set_mclk ( struct ad413x_dev dev,
enum ad413x_mclk_sel  clk 
)

Set ADC master clock mode.

Parameters
dev- The device structure.
clk- The clock mode. Accepted values: AD413X_INT_76_8_KHZ_OUT_OFF AD413X_INT_76_8_KHZ_OUT_ON AD413X_EXT_76_8KHZ AD413X_EXT_153_6_KHZ_DIV_2
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_ref()

int32_t ad413x_set_ref ( struct ad413x_dev dev,
enum ad413x_ref_sel  ref,
enum ad413x_preset_nb  reg_nb 
)

Select reference from configuration register.

Parameters
dev- The device structure.
ref- The reference value. Accepted values: AD413X_REFIN1 AD413X_REFIN2 AD413X_REFOUT_AVSS AD413X_AVDD_AVSS
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_ref_buf()

int32_t ad413x_set_ref_buf ( struct ad413x_dev dev,
struct ad413x_ref_buf  ref_buf,
enum ad413x_preset_nb  reg_nb 
)

Select the reference buffers.

Parameters
dev- The device structure.
ref_buf- The reference buffer status.
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_settle_time()

int32_t ad413x_set_settle_time ( struct ad413x_dev dev,
enum ad413x_settle_time  s_time,
enum ad413x_preset_nb  reg_nb 
)

Select settle time from filter register.

Parameters
dev- The device structure.
s_time- The settle time value. Accepted values: AD413X_32_MCLK AD413X_64_MCLK AD413X_128_MCLK AD413X_256_MCLK AD413X_512_MCLK AD413X_1024_MCLK AD413X_2048_MCLK AD413X_4096_MCLK
reg_nb- Number of Configuration Register
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_standby_ctrl()

int32_t ad413x_set_standby_ctrl ( struct ad413x_dev dev,
struct ad413x_standby_ctrl  standby_ctrl 
)

Set standby control flags.

Parameters
dev- The device structure.
standby_ctrl- Standby control value
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_set_v_bias()

int32_t ad413x_set_v_bias ( struct ad413x_dev dev,
uint16_t  v_bias_val 
)

Set output VBIAS on analog inputs.

Parameters
dev- The device structure.
v_bias_val- V_BIAS control register value
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad413x_single_conv()

int32_t ad413x_single_conv ( struct ad413x_dev dev,
uint32_t *  buffer,
uint8_t  ch_nb 
)

Single conversion of each adc active channel.

Parameters
dev- The device structure.
buffer- Buffer to store read data. Buffer size needs to be at least equal to the number of active channels. Results will be stored in consecutive order of the active channels.
ch_nb- Number of active channels.
Returns
0 in case of success, negative error code otherwise.

◆ NO_OS_DECLARE_CRC8_TABLE()

NO_OS_DECLARE_CRC8_TABLE ( ad413x_crc8  )

Variable Documentation

◆ timeout

uint32_t timeout = 0xFFFFFF