no-OS
Loading...
Searching...
No Matches
ad7779.c File Reference

Implementation of AD7779 Driver. More...

#include <stdio.h>
#include <stdlib.h>
#include "ad7779.h"
#include "no_os_util.h"
#include "no_os_error.h"
#include "no_os_alloc.h"
Include dependency graph for ad7779.c:

Functions

uint8_t ad7779_compute_crc8 (uint8_t *data, uint8_t data_size)
 
int32_t ad7779_spi_int_reg_read (ad7779_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 
int32_t ad7779_spi_int_reg_write (ad7779_dev *dev, uint8_t reg_addr, uint8_t reg_data)
 
int32_t ad7779_spi_int_reg_read_mask (ad7779_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t *data)
 
int32_t ad7779_spi_int_reg_write_mask (ad7779_dev *dev, uint8_t reg_addr, uint8_t mask, uint8_t data)
 
int32_t ad7779_spi_sar_read_code (ad7779_dev *dev, ad7779_sar_mux mux_next_conv, uint16_t *sar_code)
 
int32_t ad7779_set_spi_op_mode (ad7779_dev *dev, ad7779_spi_op_mode mode)
 
int32_t ad7779_get_spi_op_mode (ad7779_dev *dev, ad7779_spi_op_mode *mode)
 
int32_t ad7779_do_update_mode_pins (ad7779_dev *dev)
 
int32_t ad7779_set_state (ad7779_dev *dev, ad7779_ch ch, ad7779_state state)
 
int32_t ad7779_get_state (ad7779_dev *dev, ad7779_ch ch, ad7779_state *state)
 
int32_t ad7779_set_gain (ad7779_dev *dev, ad7779_ch ch, ad7779_gain gain)
 
int32_t ad7779_get_gain (ad7779_dev *dev, ad7779_ch ch, ad7779_gain *gain)
 
int32_t ad7779_set_dec_rate (ad7779_dev *dev, uint16_t int_val, uint16_t dec_val)
 
int32_t ad7779_get_dec_rate (ad7779_dev *dev, uint16_t *int_val, uint16_t *dec_val)
 
int32_t ad7779_set_power_mode (ad7779_dev *dev, ad7779_pwr_mode pwr_mode)
 
int32_t ad7779_get_power_mode (ad7779_dev *dev, ad7779_pwr_mode *pwr_mode)
 
int32_t ad7779_set_reference_type (ad7779_dev *dev, ad7779_ref_type ref_type)
 
int32_t ad7779_get_reference_type (ad7779_dev *dev, ad7779_ref_type *ref_type)
 
int32_t ad7779_set_dclk_div (ad7779_dev *dev, ad7779_dclk_div div)
 
int32_t ad7779_get_dclk_div (ad7779_dev *dev, ad7779_dclk_div *div)
 
int32_t ad7779_set_sync_offset (ad7779_dev *dev, ad7779_ch ch, uint8_t sync_offset)
 
int32_t ad7779_get_sync_offset (ad7779_dev *dev, ad7779_ch ch, uint8_t *sync_offset)
 
int32_t ad7779_set_offset_corr (ad7779_dev *dev, ad7779_ch ch, uint32_t offset)
 
int32_t ad7779_get_offset_corr (ad7779_dev *dev, ad7779_ch ch, uint32_t *offset)
 
int32_t ad7779_set_gain_corr (ad7779_dev *dev, ad7779_ch ch, uint32_t gain)
 
int32_t ad7779_get_gain_corr (ad7779_dev *dev, ad7779_ch ch, uint32_t *gain)
 
int32_t ad7779_set_ref_buf_op_mode (ad7779_dev *dev, ad7779_refx_pin refx_pin, ad7779_ref_buf_op_mode mode)
 
int32_t ad7779_get_ref_buf_op_mode (ad7779_dev *dev, ad7779_refx_pin refx_pin, ad7779_ref_buf_op_mode *mode)
 
int32_t ad7779_set_sar_cfg (ad7779_dev *dev, ad7779_state state, ad7779_sar_mux mux)
 
int32_t ad7779_get_sar_cfg (ad7779_dev *dev, ad7779_state *state, ad7779_sar_mux *mux)
 
int32_t ad7779_do_single_sar_conv (ad7779_dev *dev, ad7779_sar_mux mux, uint16_t *sar_code)
 
int32_t ad7779_do_spi_soft_reset (ad7779_dev *dev)
 
int32_t ad7771_set_sinc5_filter_state (ad7779_dev *dev, ad7779_state state)
 
int32_t ad7771_get_sinc5_filter_state (ad7779_dev *dev, ad7779_state *state)
 
int32_t ad7779_init (ad7779_dev **device, ad7779_init_param init_param)
 
int32_t ad7779_remove (ad7779_dev *dev)
 Free the resources allocated by ad7779_init().
 

Variables

const uint8_t pin_mode_options [16][4]
 

Detailed Description

Implementation of AD7779 Driver.

Author
DBogdan (drago.nosp@m.s.bo.nosp@m.gdan@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2016(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad7771_get_sinc5_filter_state()

int32_t ad7771_get_sinc5_filter_state ( ad7779_dev * dev,
ad7779_state * state )

Get the state (enable, disable) of the SINC5 filter.

Parameters
dev- The device structure.
state- The SINC5 filter state.
Returns
0 in case of success, negative error code otherwise.

◆ ad7771_set_sinc5_filter_state()

int32_t ad7771_set_sinc5_filter_state ( ad7779_dev * dev,
ad7779_state state )

Set the state (enable, disable) of the SINC5 filter.

Parameters
dev- The device structure.
state- The SINC5 filter state. Accepted values: AD7779_ENABLE AD7779_DISABLE
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_compute_crc8()

uint8_t ad7779_compute_crc8 ( uint8_t * data,
uint8_t data_size )

Compute CRC8 checksum.

Parameters
data- The data buffer.
data_size- The size of the data buffer.
Returns
CRC8 checksum.

◆ ad7779_do_single_sar_conv()

int32_t ad7779_do_single_sar_conv ( ad7779_dev * dev,
ad7779_sar_mux mux,
uint16_t * sar_code )

Do a single SAR conversion.

Parameters
dev- The device structure.
mux- The SAR mux input configuration. Accepted values: AD7779_AUXAINP_AUXAINN AD7779_DVBE_AVSSX AD7779_REF1P_REF1N AD7779_REF2P_REF2N AD7779_REF_OUT_AVSSX AD7779_VCM_AVSSX AD7779_AREG1CAP_AVSSX_ATT AD7779_AREG2CAP_AVSSX_ATT AD7779_DREGCAP_DGND_ATT AD7779_AVDD1A_AVSSX_ATT AD7779_AVDD1B_AVSSX_ATT AD7779_AVDD2A_AVSSX_ATT AD7779_AVDD2B_AVSSX_ATT AD7779_IOVDD_DGND_ATT AD7779_AVDD4_AVSSX AD7779_DGND_AVSS1A_ATT AD7779_DGND_AVSS1B_ATT AD7779_DGND_AVSSX_ATT AD7779_AVDD4_AVSSX_ATT AD7779_REF1P_AVSSX AD7779_REF2P_AVSSX AD7779_AVSSX_AVDD4_ATT
sar_code- SAR conversion code.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_do_spi_soft_reset()

int32_t ad7779_do_spi_soft_reset ( ad7779_dev * dev)

Do a SPI software reset.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_do_update_mode_pins()

int32_t ad7779_do_update_mode_pins ( ad7779_dev * dev)

Update the state of the MODEx pins according to the settings specified in the device structure.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_dclk_div()

int32_t ad7779_get_dclk_div ( ad7779_dev * dev,
ad7779_dclk_div * div )

Get the DCLK divider.

Parameters
dev- The device structure.
div- The DCLK divider.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_dec_rate()

int32_t ad7779_get_dec_rate ( ad7779_dev * dev,
uint16_t * int_val,
uint16_t * dec_val )

Get the decimation rate.

Parameters
dev- The device structure.
int_val- The integer value.
dec_val- The decimal value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_gain()

int32_t ad7779_get_gain ( ad7779_dev * dev,
ad7779_ch ch,
ad7779_gain * gain )

Get the gain of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
gain- The gain value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_gain_corr()

int32_t ad7779_get_gain_corr ( ad7779_dev * dev,
ad7779_ch ch,
uint32_t * gain )

Get the gain correction of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
gain- The gain value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_offset_corr()

int32_t ad7779_get_offset_corr ( ad7779_dev * dev,
ad7779_ch ch,
uint32_t * offset )

Get the offset correction of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
offset- The offset value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_power_mode()

int32_t ad7779_get_power_mode ( ad7779_dev * dev,
ad7779_pwr_mode * pwr_mode )

Get the power mode.

Parameters
dev- The device structure.
pwr_mode- The power mode.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_ref_buf_op_mode()

int32_t ad7779_get_ref_buf_op_mode ( ad7779_dev * dev,
ad7779_refx_pin refx_pin,
ad7779_ref_buf_op_mode * mode )

Get the reference buffer operation mode of the selected pin.

Parameters
dev- The device structure.
refx_pin- The selected pin. Accepted values: AD7779_REFX_P AD7779_REFX_N
mode- The reference buffer operation mode. Accepted values: AD7779_REF_BUF_ENABLED AD7779_REF_BUF_PRECHARGED AD7779_REF_BUF_DISABLED
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_reference_type()

int32_t ad7779_get_reference_type ( ad7779_dev * dev,
ad7779_ref_type * ref_type )

Get the reference type.

Parameters
dev- The device structure.
ref_type- The reference type.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_sar_cfg()

int32_t ad7779_get_sar_cfg ( ad7779_dev * dev,
ad7779_state * state,
ad7779_sar_mux * mux )

Get the SAR ADC configuration.

Parameters
dev- The device structure.
state- The SAR ADC state.
mux- The SAR mux input configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_spi_op_mode()

int32_t ad7779_get_spi_op_mode ( ad7779_dev * dev,
ad7779_spi_op_mode * mode )

Get SPI operation mode.

Parameters
dev- The device structure.
mode- The SPI operation mode.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_state()

int32_t ad7779_get_state ( ad7779_dev * dev,
ad7779_ch ch,
ad7779_state * state )

Get the state (enable, disable) of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
state- The channel state.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_get_sync_offset()

int32_t ad7779_get_sync_offset ( ad7779_dev * dev,
ad7779_ch ch,
uint8_t * sync_offset )

Get the synchronization offset of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
sync_offset- The synchronization offset value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_init()

int32_t ad7779_init ( ad7779_dev ** device,
ad7779_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.

◆ ad7779_remove()

int32_t ad7779_remove ( ad7779_dev * dev)

Free the resources allocated by ad7779_init().

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_dclk_div()

int32_t ad7779_set_dclk_div ( ad7779_dev * dev,
ad7779_dclk_div div )

Set the DCLK divider.

Parameters
dev- The device structure.
div- The DCLK divider. Accepted values: AD7779_DCLK_DIV_1 AD7779_DCLK_DIV_2 AD7779_DCLK_DIV_4 AD7779_DCLK_DIV_8 AD7779_DCLK_DIV_16 AD7779_DCLK_DIV_32 AD7779_DCLK_DIV_64 AD7779_DCLK_DIV_128
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_dec_rate()

int32_t ad7779_set_dec_rate ( ad7779_dev * dev,
uint16_t int_val,
uint16_t dec_val )

Set the decimation rate.

Parameters
dev- The device structure.
int_val- The integer value.
dec_val- The decimal value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_gain()

int32_t ad7779_set_gain ( ad7779_dev * dev,
ad7779_ch ch,
ad7779_gain gain )

Set the gain of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
gain- The gain value. Accepted values: AD7779_GAIN_1 AD7779_GAIN_2 AD7779_GAIN_4 AD7779_GAIN_8
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_gain_corr()

int32_t ad7779_set_gain_corr ( ad7779_dev * dev,
ad7779_ch ch,
uint32_t gain )

Set the gain correction of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
gain- The gain value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_offset_corr()

int32_t ad7779_set_offset_corr ( ad7779_dev * dev,
ad7779_ch ch,
uint32_t offset )

Set the offset correction of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
offset- The offset value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_power_mode()

int32_t ad7779_set_power_mode ( ad7779_dev * dev,
ad7779_pwr_mode pwr_mode )

Set the power mode.

Parameters
dev- The device structure.
pwr_mode- The power mode. Accepted values: AD7779_HIGH_RES AD7779_LOW_PWR
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_ref_buf_op_mode()

int32_t ad7779_set_ref_buf_op_mode ( ad7779_dev * dev,
ad7779_refx_pin refx_pin,
ad7779_ref_buf_op_mode mode )

Set the reference buffer operation mode of the selected pin.

Parameters
dev- The device structure.
refx_pin- The selected pin. Accepted values: AD7779_REFX_P AD7779_REFX_N
mode- The reference buffer operation mode. Accepted values: AD7779_REF_BUF_ENABLED AD7779_REF_BUF_PRECHARGED AD7779_REF_BUF_DISABLED
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_reference_type()

int32_t ad7779_set_reference_type ( ad7779_dev * dev,
ad7779_ref_type ref_type )

Set the reference type.

Parameters
dev- The device structure.
ref_type- The reference type. Accepted values: AD7779_EXT_REF AD7779_INT_REF AD7779_EXT_SUPPLY AD7779_EXT_REF_INV
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_sar_cfg()

int32_t ad7779_set_sar_cfg ( ad7779_dev * dev,
ad7779_state state,
ad7779_sar_mux mux )

Set the SAR ADC configuration.

Parameters
dev- The device structure.
state- The SAR ADC state. Accepted values: AD7779_ENABLE AD7779_DISABLE
mux- The SAR mux input configuration. Accepted values: AD7779_AUXAINP_AUXAINN AD7779_DVBE_AVSSX AD7779_REF1P_REF1N AD7779_REF2P_REF2N AD7779_REF_OUT_AVSSX AD7779_VCM_AVSSX AD7779_AREG1CAP_AVSSX_ATT AD7779_AREG2CAP_AVSSX_ATT AD7779_DREGCAP_DGND_ATT AD7779_AVDD1A_AVSSX_ATT AD7779_AVDD1B_AVSSX_ATT AD7779_AVDD2A_AVSSX_ATT AD7779_AVDD2B_AVSSX_ATT AD7779_IOVDD_DGND_ATT AD7779_AVDD4_AVSSX AD7779_DGND_AVSS1A_ATT AD7779_DGND_AVSS1B_ATT AD7779_DGND_AVSSX_ATT AD7779_AVDD4_AVSSX_ATT AD7779_REF1P_AVSSX AD7779_REF2P_AVSSX AD7779_AVSSX_AVDD4_ATT
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_spi_op_mode()

int32_t ad7779_set_spi_op_mode ( ad7779_dev * dev,
ad7779_spi_op_mode mode )

Set SPI operation mode.

Parameters
dev- The device structure.
mode- The SPI operation mode. Accepted values: AD7779_INT_REG AD7779_SD_CONV AD7779_SAR_CONV
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_state()

int32_t ad7779_set_state ( ad7779_dev * dev,
ad7779_ch ch,
ad7779_state state )

Set the state (enable, disable) of the channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
state- The channel state. Accepted values: AD7779_ENABLE AD7779_DISABLE
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_set_sync_offset()

int32_t ad7779_set_sync_offset ( ad7779_dev * dev,
ad7779_ch ch,
uint8_t sync_offset )

Set the synchronization offset of the selected channel.

Parameters
dev- The device structure.
ch- The channel number. Accepted values: AD7779_CH0 AD7779_CH1 AD7779_CH2 AD7779_CH3 AD7779_CH4 AD7779_CH5 AD7779_CH6 AD7779_CH7
sync_offset- The synchronization offset value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_spi_int_reg_read()

int32_t ad7779_spi_int_reg_read ( ad7779_dev * dev,
uint8_t reg_addr,
uint8_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.

◆ ad7779_spi_int_reg_read_mask()

int32_t ad7779_spi_int_reg_read_mask ( ad7779_dev * dev,
uint8_t reg_addr,
uint8_t mask,
uint8_t * data )

SPI internal register read from device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_spi_int_reg_write()

int32_t ad7779_spi_int_reg_write ( ad7779_dev * dev,
uint8_t reg_addr,
uint8_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.

◆ ad7779_spi_int_reg_write_mask()

int32_t ad7779_spi_int_reg_write_mask ( ad7779_dev * dev,
uint8_t reg_addr,
uint8_t mask,
uint8_t data )

SPI internal register write to device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ ad7779_spi_sar_read_code()

int32_t ad7779_spi_sar_read_code ( ad7779_dev * dev,
ad7779_sar_mux mux_next_conv,
uint16_t * sar_code )

SPI SAR conversion code read.

Parameters
dev- The device structure.
mux_next_conv- The SAR mux input configuration for the next conversion. Accepted values: AD7779_AUXAINP_AUXAINN AD7779_DVBE_AVSSX AD7779_REF1P_REF1N AD7779_REF2P_REF2N AD7779_REF_OUT_AVSSX AD7779_VCM_AVSSX AD7779_AREG1CAP_AVSSX_ATT AD7779_AREG2CAP_AVSSX_ATT AD7779_DREGCAP_DGND_ATT AD7779_AVDD1A_AVSSX_ATT AD7779_AVDD1B_AVSSX_ATT AD7779_AVDD2A_AVSSX_ATT AD7779_AVDD2B_AVSSX_ATT AD7779_IOVDD_DGND_ATT AD7779_AVDD4_AVSSX AD7779_DGND_AVSS1A_ATT AD7779_DGND_AVSS1B_ATT AD7779_DGND_AVSSX_ATT AD7779_AVDD4_AVSSX_ATT AD7779_REF1P_AVSSX AD7779_REF2P_AVSSX AD7779_AVSSX_AVDD4_ATT
sar_code- SAR conversion code.
Returns
0 in case of success, negative error code otherwise.

Variable Documentation

◆ pin_mode_options

const uint8_t pin_mode_options[16][4]
Initial value:
= {
{0x03, 0xFF, 0x07, 0xFF},
{0x0A, 0xFF, 0xFF, 0xFF},
{0x0D, 0xFF, 0xFF, 0xFF},
{0x0E, 0xFF, 0xFF, 0xFF},
{0x02, 0x04, 0x06, 0xFF},
{0x09, 0xFF, 0xFF, 0xFF},
{0x0C, 0xFF, 0xFF, 0xFF},
{0x0F, 0xFF, 0xFF, 0xFF},
{0x01, 0xFF, 0x05, 0xFF},
{0x08, 0xFF, 0xFF, 0xFF},
{0x08, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0x00, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF},
}