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

Source file for the AD4170, AD4190 driver. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_crc8.h"
#include "ad4170.h"
Include dependency graph for ad4170.c:

Functions

 NO_OS_DECLARE_CRC8_TABLE (ad4170_crc8)
 
int ad4170_spi_reg_read (struct ad4170_dev *dev, uint32_t reg_addr, uint32_t *reg_data)
 Read device register.
 
int ad4170_spi_reg_write (struct ad4170_dev *dev, uint32_t reg_addr, uint32_t reg_data)
 Write device register.
 
int ad4170_spi_reg_write_mask (struct ad4170_dev *dev, uint32_t reg_addr, uint8_t mask, uint32_t reg_data)
 SPI write device register using a mask.
 
int ad4170_reset_spi_interface (struct ad4170_dev *dev)
 Reset the SPI interface by sending reset sequence to device.
 
int ad4170_get_data16 (struct ad4170_dev *dev, uint16_t *data)
 Get data from register Data_16b.
 
int ad4170_get_data16s (struct ad4170_dev *dev, uint16_t *data, uint8_t *status)
 Get data and status from register Data_16b_Status.
 
int ad4170_get_data24 (struct ad4170_dev *dev, uint32_t *data)
 Get data from register Data_24b.
 
int ad4170_get_data24s (struct ad4170_dev *dev, uint32_t *data, uint8_t *status)
 Get data and status from register Data_24b_Status.
 
int ad4170_get_data32 (struct ad4170_dev *dev, uint32_t *data)
 Get data from register Data_32b.
 
int ad4170_get_ch_data (struct ad4170_dev *dev, uint8_t ch, uint32_t *data)
 Get data from register Data_Per_Channel[n].
 
int ad4170_get_status (struct ad4170_dev *dev, uint16_t *status)
 Get status from register Data_Status.
 
int ad4170_read16 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples)
 Read multiple samples using direct register access from Data_16b.
 
int ad4170_read16s (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples)
 Read multiple samples using direct register access from Data_16b_Status.
 
int ad4170_read24 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples)
 Read multiple samples using direct register access from Data_24.
 
int ad4170_read24s (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples)
 Read multiple samples using direct register access from Data_24_Status.
 
int ad4170_read32 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples)
 Read multiple samples using direct register access from Data_32b.
 
int ad4170_continuous_read (struct ad4170_dev *dev, uint32_t *data_out, uint8_t *status_out, uint16_t nb_samples)
 Read multiple samples in continuous read mode.
 
int ad4170_continuous_read_exit (struct ad4170_dev *dev)
 Exit continuous read mode.
 
int ad4170_continuous_transmit_exit (struct ad4170_dev *dev)
 Exit continuous transmit mode.
 
int ad4170_reset (struct ad4170_dev *dev)
 Perform a software reset.
 
int ad4170_set_spi_settings (struct ad4170_dev *dev, const struct ad4170_spi_settings *spi_settings)
 Set the AD4170 SPI settings.
 
int ad4170_set_pin_muxing (struct ad4170_dev *dev, struct ad4170_pin_muxing pin_muxing)
 Set the AD4170 Pin Muxing settings.
 
int ad4170_set_dclk_div (struct ad4170_dev *dev, enum ad4170_dclk_div div)
 Set the AD4170 DCLK configuration.
 
int ad4170_set_mclk_div (struct ad4170_dev *dev, enum ad4170_mclk_div div)
 Set the AD4170 MCLK configuration.
 
int ad4170_set_clocksel (struct ad4170_dev *dev, enum ad4170_clocksel sel)
 Set the AD4170 clock selection configuration.
 
int ad4170_set_standby_ctrl (struct ad4170_dev *dev, uint16_t standby_ctrl)
 Set the AD4170 Standby control settings.
 
int ad4170_set_powerdown_sw (struct ad4170_dev *dev, uint16_t powerdown_sw)
 Set the AD4170 Powerdown switches settings.
 
int ad4170_set_error_en (struct ad4170_dev *dev, uint16_t error_en)
 Set the AD4170 Error enable settings.
 
int ad4170_set_error (struct ad4170_dev *dev, uint16_t error)
 Set the Error register with a value to clear specific errors.
 
int ad4170_get_error (struct ad4170_dev *dev, uint16_t *error)
 Get the Error register.
 
int ad4170_set_adc_ctrl (struct ad4170_dev *dev, struct ad4170_adc_ctrl adc_ctrl)
 Set the AD4170 ADC Control.
 
int ad4170_set_channel_en (struct ad4170_dev *dev, uint16_t channel_en)
 Enable AD4170 channels.
 
int ad4170_set_channel_setup (struct ad4170_dev *dev, uint8_t ch, struct ad4170_channel_setup setup)
 Set the AD4170 Channel specific setup.
 
int ad4170_set_channel_map (struct ad4170_dev *dev, uint8_t ch, struct ad4170_channel_map map)
 Set the AD4170 Channel specific map.
 
int ad4170_set_setup (struct ad4170_dev *dev, uint8_t n, struct ad4170_setup setup)
 Configure an ADC setup.
 
int ad4170_set_ref_control (struct ad4170_dev *dev, bool enable)
 Set the AD4170 Ref Control.
 
int ad4170_set_v_bias (struct ad4170_dev *dev, uint16_t ch_mask)
 Set the AD4170 Voltage bias.
 
int ad4170_set_i_pullup (struct ad4170_dev *dev, uint16_t ch_mask)
 Set the AD4170 Input pullup.
 
int ad4170_set_current_source (struct ad4170_dev *dev, uint8_t n, struct ad4170_current_source current_source)
 Set the AD4170 Excitation Current.
 
int ad4170_set_fir_control (struct ad4170_dev *dev, struct ad4170_fir_control fir_control)
 Set the AD4170 FIR control settings.
 
int ad4170_set_dac_config (struct ad4170_dev *dev, struct ad4170_dac_config config)
 Set the AD4170 DAC settings.
 
int ad4170_set_dac_data (struct ad4170_dev *dev, uint16_t code)
 Set the AD4170 DAC data by directly writing the DAT_DATA register.
 
int ad4170_set_dac_inputa (struct ad4170_dev *dev, uint16_t code)
 Set the AD4170 DAC data by writing the INPUTA register to be loaded separately by LDAC or Toggle operations.
 
int ad4170_set_dac_inputb (struct ad4170_dev *dev, uint16_t code)
 Set the AD4170 DAC data by writing the INPUTB register to be loaded separately by LDAC or Toggle operations.
 
int ad4170_dac_sw_ldac (struct ad4170_dev *dev, bool polarity)
 Perform a software LDAC.
 
int ad4170_dac_sw_toggle (struct ad4170_dev *dev, bool polarity)
 Perform a software toggle.
 
int ad4170_dac_hw_toggle (struct ad4170_dev *dev, bool polarity)
 Perform a hardware toggle using the DIG_AUX2 pin, assumed to be pre-configured for this.
 
int ad4170_init (struct ad4170_dev **device, struct ad4170_init_param *init_param)
 Initialize an AD4170 device structure.
 
int ad4170_remove (struct ad4170_dev *dev)
 Remove the device and free al the resources.
 
int ad4170_regmap (struct ad4170_dev *dev)
 Debugging function to print the register map to console.
 

Variables

struct ad4170_config ad4170_config_reset
 

Detailed Description

Source file for the AD4170, AD4190 driver.

Author
Darius Berghe (dariu.nosp@m.s.be.nosp@m.rghe@.nosp@m.anal.nosp@m.og.co.nosp@m.m)
Janani Sunil (janan.nosp@m.i.su.nosp@m.nil@a.nosp@m.nalo.nosp@m.g.com)
Mahesh Phalke (mahes.nosp@m.h.ph.nosp@m.alke@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2020, 2023(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad4170_continuous_read()

int ad4170_continuous_read ( struct ad4170_dev * dev,
uint32_t * data_out,
uint8_t * status_out,
uint16_t nb_samples )

Read multiple samples in continuous read mode.

Parameters
dev- The device structure.
data_out- Output pointer where to store the data values.
status_out- Output pointer where to store the status values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_continuous_read_exit()

int ad4170_continuous_read_exit ( struct ad4170_dev * dev)

Exit continuous read mode.

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

◆ ad4170_continuous_transmit_exit()

int ad4170_continuous_transmit_exit ( struct ad4170_dev * dev)

Exit continuous transmit mode.

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

◆ ad4170_dac_hw_toggle()

int ad4170_dac_hw_toggle ( struct ad4170_dev * dev,
bool polarity )

Perform a hardware toggle using the DIG_AUX2 pin, assumed to be pre-configured for this.

Parameters
dev- The device structure.
polarity- Polarity of the toggle operation.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_dac_sw_ldac()

int ad4170_dac_sw_ldac ( struct ad4170_dev * dev,
bool polarity )

Perform a software LDAC.

Parameters
dev- The device structure.
polarity- Polarity of the LDAC operation.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_dac_sw_toggle()

int ad4170_dac_sw_toggle ( struct ad4170_dev * dev,
bool polarity )

Perform a software toggle.

Parameters
dev- The device structure.
polarity- Polarity of the toggle operation.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_ch_data()

int ad4170_get_ch_data ( struct ad4170_dev * dev,
uint8_t ch,
uint32_t * data )

Get data from register Data_Per_Channel[n].

This function assumes Per-Channel ADC Data is enabled, otherwise the output data may contain zeroes.

Parameters
dev- The device structure.
ch- The channel number (0 to 15)
data- Output pointer where to store the data value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_data16()

int ad4170_get_data16 ( struct ad4170_dev * dev,
uint16_t * data )

Get data from register Data_16b.

Parameters
dev- The device structure.
data- Output pointer where to store the data value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_data16s()

int ad4170_get_data16s ( struct ad4170_dev * dev,
uint16_t * data,
uint8_t * status )

Get data and status from register Data_16b_Status.

Parameters
dev- The device structure.
data- Output pointer where to store the data value.
status- Output pointer where to store the status value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_data24()

int ad4170_get_data24 ( struct ad4170_dev * dev,
uint32_t * data )

Get data from register Data_24b.

Parameters
dev- The device structure.
data- Output pointer where to store the data value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_data24s()

int ad4170_get_data24s ( struct ad4170_dev * dev,
uint32_t * data,
uint8_t * status )

Get data and status from register Data_24b_Status.

Parameters
dev- The device structure.
data- Output pointer where to store the data value.
status- Output pointer where to store the status value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_data32()

int ad4170_get_data32 ( struct ad4170_dev * dev,
uint32_t * data )

Get data from register Data_32b.

Parameters
dev- The device structure.
data- Output pointer where to store the data value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_error()

int ad4170_get_error ( struct ad4170_dev * dev,
uint16_t * error )

Get the Error register.

Parameters
dev- The device structure.
error- Pointer to where Error register content should be stored.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_get_status()

int ad4170_get_status ( struct ad4170_dev * dev,
uint16_t * status )

Get status from register Data_Status.

Parameters
dev- The device structure.
status- Output pointer where to store the status value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_init()

int ad4170_init ( struct ad4170_dev ** device,
struct ad4170_init_param * init_param )

Initialize an AD4170 device structure.

Parameters
device- Pointer to the device structure (memory is allocated within this function).
init_param- Pointer to the initialization parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_read16()

int ad4170_read16 ( struct ad4170_dev * dev,
uint32_t * pbuf,
uint16_t nb_samples )

Read multiple samples using direct register access from Data_16b.

Parameters
dev- The device structure.
pbuf- Output pointer where to store the data values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_read16s()

int ad4170_read16s ( struct ad4170_dev * dev,
uint32_t * pbuf,
uint16_t nb_samples )

Read multiple samples using direct register access from Data_16b_Status.

Parameters
dev- The device structure.
pbuf- Output pointer where to store the data values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_read24()

int ad4170_read24 ( struct ad4170_dev * dev,
uint32_t * pbuf,
uint16_t nb_samples )

Read multiple samples using direct register access from Data_24.

Parameters
dev- The device structure.
pbuf- Output pointer where to store the data values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_read24s()

int ad4170_read24s ( struct ad4170_dev * dev,
uint32_t * pbuf,
uint16_t nb_samples )

Read multiple samples using direct register access from Data_24_Status.

Parameters
dev- The device structure.
pbuf- Output pointer where to store the data values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_read32()

int ad4170_read32 ( struct ad4170_dev * dev,
uint32_t * pbuf,
uint16_t nb_samples )

Read multiple samples using direct register access from Data_32b.

Parameters
dev- The device structure.
pbuf- Output pointer where to store the data values.
nb_samples- The number of samples to read.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_regmap()

int ad4170_regmap ( struct ad4170_dev * dev)

Debugging function to print the register map to console.

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

◆ ad4170_remove()

int ad4170_remove ( struct ad4170_dev * dev)

Remove the device and free al the resources.

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

◆ ad4170_reset()

int ad4170_reset ( struct ad4170_dev * dev)

Perform a software reset.

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

◆ ad4170_reset_spi_interface()

int ad4170_reset_spi_interface ( struct ad4170_dev * dev)

Reset the SPI interface by sending reset sequence to device.

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

◆ ad4170_set_adc_ctrl()

int ad4170_set_adc_ctrl ( struct ad4170_dev * dev,
struct ad4170_adc_ctrl adc_ctrl )

Set the AD4170 ADC Control.

Parameters
dev- The device structure.
adc_ctrl- AD4170 ADC Control configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_channel_en()

int ad4170_set_channel_en ( struct ad4170_dev * dev,
uint16_t channel_en )

Enable AD4170 channels.

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

◆ ad4170_set_channel_map()

int ad4170_set_channel_map ( struct ad4170_dev * dev,
uint8_t ch,
struct ad4170_channel_map map )

Set the AD4170 Channel specific map.

Parameters
dev- The device structure.
ch- The channel number (0 to 15).
map- AD4170 Channel specific map configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_channel_setup()

int ad4170_set_channel_setup ( struct ad4170_dev * dev,
uint8_t ch,
struct ad4170_channel_setup setup )

Set the AD4170 Channel specific setup.

Parameters
dev- The device structure.
ch- The channel number (0 to 15).
setup- AD4170 Channel specific setup configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_clocksel()

int ad4170_set_clocksel ( struct ad4170_dev * dev,
enum ad4170_clocksel sel )

Set the AD4170 clock selection configuration.

Parameters
dev- The device structure.
sel- AD4170 clock selection configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_current_source()

int ad4170_set_current_source ( struct ad4170_dev * dev,
uint8_t n,
struct ad4170_current_source current_source )

Set the AD4170 Excitation Current.

Parameters
dev- The device structure.
n- Current source number (0 to 3).
current_source- Excitation current confguration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_dac_config()

int ad4170_set_dac_config ( struct ad4170_dev * dev,
struct ad4170_dac_config config )

Set the AD4170 DAC settings.

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

◆ ad4170_set_dac_data()

int ad4170_set_dac_data ( struct ad4170_dev * dev,
uint16_t code )

Set the AD4170 DAC data by directly writing the DAT_DATA register.

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

◆ ad4170_set_dac_inputa()

int ad4170_set_dac_inputa ( struct ad4170_dev * dev,
uint16_t code )

Set the AD4170 DAC data by writing the INPUTA register to be loaded separately by LDAC or Toggle operations.

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

◆ ad4170_set_dac_inputb()

int ad4170_set_dac_inputb ( struct ad4170_dev * dev,
uint16_t code )

Set the AD4170 DAC data by writing the INPUTB register to be loaded separately by LDAC or Toggle operations.

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

◆ ad4170_set_dclk_div()

int ad4170_set_dclk_div ( struct ad4170_dev * dev,
enum ad4170_dclk_div div )

Set the AD4170 DCLK configuration.

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

◆ ad4170_set_error()

int ad4170_set_error ( struct ad4170_dev * dev,
uint16_t error )

Set the Error register with a value to clear specific errors.

Parameters
dev- The device structure.
error- Error mask (set bits will be cleared from the Error register).
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_error_en()

int ad4170_set_error_en ( struct ad4170_dev * dev,
uint16_t error_en )

Set the AD4170 Error enable settings.

Parameters
dev- The device structure.
error_en- AD4170 Error enable configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_fir_control()

int ad4170_set_fir_control ( struct ad4170_dev * dev,
struct ad4170_fir_control fir_control )

Set the AD4170 FIR control settings.

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

◆ ad4170_set_i_pullup()

int ad4170_set_i_pullup ( struct ad4170_dev * dev,
uint16_t ch_mask )

Set the AD4170 Input pullup.

Parameters
dev- The device structure.
ch_mask- Input pullup enable mask.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_mclk_div()

int ad4170_set_mclk_div ( struct ad4170_dev * dev,
enum ad4170_mclk_div div )

Set the AD4170 MCLK configuration.

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

◆ ad4170_set_pin_muxing()

int ad4170_set_pin_muxing ( struct ad4170_dev * dev,
struct ad4170_pin_muxing pin_muxing )

Set the AD4170 Pin Muxing settings.

Parameters
dev- The device structure.
pin_muxing- AD4170 Pin Muxing configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_powerdown_sw()

int ad4170_set_powerdown_sw ( struct ad4170_dev * dev,
uint16_t powerdown_sw )

Set the AD4170 Powerdown switches settings.

Parameters
dev- The device structure.
powerdown_sw- AD4170 Powerdown switches configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_ref_control()

int ad4170_set_ref_control ( struct ad4170_dev * dev,
bool enable )

Set the AD4170 Ref Control.

Parameters
dev- The device structure.
enable- Enable/Disable Ref Control.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_setup()

int ad4170_set_setup ( struct ad4170_dev * dev,
uint8_t n,
struct ad4170_setup setup )

Configure an ADC setup.

Parameters
dev- The device structure.
n- The setup number (0 to 8).
setup- AD4170 setup configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_spi_settings()

int ad4170_set_spi_settings ( struct ad4170_dev * dev,
const struct ad4170_spi_settings * spi_settings )

Set the AD4170 SPI settings.

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

◆ ad4170_set_standby_ctrl()

int ad4170_set_standby_ctrl ( struct ad4170_dev * dev,
uint16_t standby_ctrl )

Set the AD4170 Standby control settings.

Parameters
dev- The device structure.
standby_ctrl- AD4170 Standby control configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_set_v_bias()

int ad4170_set_v_bias ( struct ad4170_dev * dev,
uint16_t ch_mask )

Set the AD4170 Voltage bias.

Parameters
dev- The device structure.
ch_mask- Voltage bias enable mask.
Returns
0 in case of success, negative error code otherwise.

◆ ad4170_spi_reg_read()

int ad4170_spi_reg_read ( struct ad4170_dev * dev,
uint32_t reg_addr,
uint32_t * reg_data )

Read device register.

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

◆ ad4170_spi_reg_write()

int ad4170_spi_reg_write ( struct ad4170_dev * dev,
uint32_t reg_addr,
uint32_t reg_data )

Write device register.

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.

◆ ad4170_spi_reg_write_mask()

int ad4170_spi_reg_write_mask ( struct ad4170_dev * dev,
uint32_t reg_addr,
uint8_t mask,
uint32_t reg_data )

SPI write device register using a mask.

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

◆ NO_OS_DECLARE_CRC8_TABLE()

NO_OS_DECLARE_CRC8_TABLE ( ad4170_crc8 )

Variable Documentation

◆ ad4170_config_reset

struct ad4170_config ad4170_config_reset

ad4170_config default state when the chip is hardware/software reset.