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

Implementation of AD4110 Driver. More...

#include <stdio.h>
#include <stdlib.h>
#include "ad4110.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
#include "no_os_error.h"
#include "no_os_irq.h"
#include "no_os_print_log.h"
#include <string.h>
Include dependency graph for ad4110.c:

Functions

uint8_t ad4110_compute_crc8 (uint8_t *data, uint8_t data_size)
 
uint8_t ad4110_compute_xor (uint8_t *data, uint8_t data_size)
 
int32_t ad4110_spi_int_reg_write_msk (struct ad4110_dev *dev, uint8_t reg_map, uint8_t reg_addr, uint32_t data, uint16_t mask)
 
int32_t ad4110_set_adc_mode (struct ad4110_dev *dev, enum ad4110_adc_mode mode)
 
int32_t ad4110_set_gain (struct ad4110_dev *dev, enum ad4110_gain gain)
 
int32_t ad4110_set_adc_clk (struct ad4110_dev *dev, enum ad4110_adc_clk_sel clk)
 
int32_t ad4110_set_afe_clk (struct ad4110_dev *dev, enum ad4110_afe_clk_cfg clk)
 
int32_t ad4110_set_reference (struct ad4110_dev *dev, enum ad4110_voltage_reference ref)
 
int32_t ad4110_set_op_mode (struct ad4110_dev *dev, enum ad4110_op_mode mode)
 
int32_t ad4110_spi_do_soft_reset (struct ad4110_dev *dev)
 
uint8_t ad4110_get_data_size (struct ad4110_dev *dev, uint8_t reg_map, uint8_t reg_addr)
 
int32_t ad4110_spi_int_reg_write (struct ad4110_dev *dev, uint8_t reg_map, uint8_t reg_addr, uint32_t reg_data)
 
int32_t ad4110_spi_int_data_reg_read (struct ad4110_dev *dev, uint32_t *reg_data)
 
int32_t ad4110_spi_int_reg_read (struct ad4110_dev *dev, uint8_t reg_map, uint8_t reg_addr, uint32_t *reg_data)
 
int ad4110_set_channel_status (struct ad4110_dev *dev, uint8_t chan_id, bool status)
 Enable/Disable channel.
 
int ad4110_set_analog_input_buffer (struct ad4110_dev *dev, enum ad4110_ain_buffer buffer)
 Assign analog input buffer.
 
int ad4110_set_bipolar (struct ad4110_dev *dev, bool bipolar)
 Set polarity.
 
int ad4110_set_odr (struct ad4110_dev *dev, enum ad4110_odr odr)
 Set Output Data Rate.
 
int ad4110_set_order (struct ad4110_dev *dev, enum ad4110_order order)
 Set Order of Filter.
 
int ad4110_wait_for_rdy_low (struct ad4110_dev *dev, uint32_t timeout)
 Wait for RDY bit to go low indicating conversion completion.
 
int ad4110_do_single_read (struct ad4110_dev *dev, uint32_t *buffer)
 ADC data read in single conversion mode.
 
int32_t ad4110_setup (struct ad4110_dev **device, struct ad4110_init_param init_param)
 
int32_t ad4110_continuous_read (struct ad4110_dev *dev, uint32_t *buffer, uint32_t buffer_size)
 
int32_t ad4110_remove (struct ad4110_dev *dev)
 Free the resources allocated by ad4110_setup().
 

Detailed Description

Implementation of AD4110 Driver.

Author
Stefan Popa (stefa.nosp@m.n.po.nosp@m.pa@an.nosp@m.alog.nosp@m..com) Andrei Porumb (andre.nosp@m.i.po.nosp@m.rumb@.nosp@m.anal.nosp@m.og.co.nosp@m.m) Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

Copyright 2021(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad4110_compute_crc8()

uint8_t ad4110_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.

◆ ad4110_compute_xor()

uint8_t ad4110_compute_xor ( uint8_t * data,
uint8_t data_size )

Compute XOR checksum.

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

◆ ad4110_continuous_read()

int32_t ad4110_continuous_read ( struct ad4110_dev * dev,
uint32_t * buffer,
uint32_t buffer_size )

ADC continuous read fills buffer with buffer_size number of samples.

Parameters
dev- The device structure.
buffer- The buffer.
buffer_size- The buffer size = number of samples.
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_do_single_read()

int ad4110_do_single_read ( struct ad4110_dev * dev,
uint32_t * buffer )

ADC data read in single conversion mode.

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

◆ ad4110_get_data_size()

uint8_t ad4110_get_data_size ( struct ad4110_dev * dev,
uint8_t reg_map,
uint8_t reg_addr )

Get the data size of a specified register.

Parameters
dev- The device structure.
reg_map- The register map. Accepted values: A4110_ADC A4110_AFE
reg_addr- The register address.
Returns
the data size in bytes

◆ ad4110_remove()

int32_t ad4110_remove ( struct ad4110_dev * dev)

Free the resources allocated by ad4110_setup().

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

◆ ad4110_set_adc_clk()

int32_t ad4110_set_adc_clk ( struct ad4110_dev * dev,
enum ad4110_adc_clk_sel clk )

Set ADC clock.

Parameters
dev- The device structure.
clk- The clock mode. Accepted values: AD4110_ADC_INT_CLK AD4110_ADC_INT_CLK_CLKIO AD4110_ADC_EXT_CLK
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_adc_mode()

int32_t ad4110_set_adc_mode ( struct ad4110_dev * dev,
enum ad4110_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.

◆ ad4110_set_afe_clk()

int32_t ad4110_set_afe_clk ( struct ad4110_dev * dev,
enum ad4110_afe_clk_cfg clk )

Set AFE clock.

Parameters
dev- The device structure.
clk- The clock mode. Accepted values: AD4110_AFE_INT_CLOCK AD4110_AFE_ADC_CLOCKED
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_analog_input_buffer()

int ad4110_set_analog_input_buffer ( struct ad4110_dev * dev,
enum ad4110_ain_buffer buffer )

Assign analog input buffer.

Parameters
dev- The device structure.
buffer- Choice of analog input buffer to be set
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_bipolar()

int ad4110_set_bipolar ( struct ad4110_dev * dev,
bool bipolar )

Set polarity.

Parameters
dev- The device structure.
bipolar- True in case of Bipolar/ False in case of Unipolar
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_channel_status()

int ad4110_set_channel_status ( struct ad4110_dev * dev,
uint8_t chan_id,
bool status )

Enable/Disable channel.

Parameters
dev- The device structure.
chan_id- Channel ID (number)
status- Channel Status (True for Enable and False for Disable)
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_gain()

int32_t ad4110_set_gain ( struct ad4110_dev * dev,
enum ad4110_gain gain )

Set the gain.

Parameters
dev- The device structure.
gain- The gain value. Accepted values: AD4110_GAIN_0_2 AD4110_GAIN_0_25 AD4110_GAIN_0_3 AD4110_GAIN_0_375 AD4110_GAIN_0_5 AD4110_GAIN_0_75 AD4110_GAIN_1 AD4110_GAIN_1_5 AD4110_GAIN_2 AD4110_GAIN_3 AD4110_GAIN_4 AD4110_GAIN_6 AD4110_GAIN_8 AD4110_GAIN_12 AD4110_GAIN_16 AD4110_GAIN_24
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_odr()

int ad4110_set_odr ( struct ad4110_dev * dev,
enum ad4110_odr odr )

Set Output Data Rate.

Parameters
dev- The device structure.
odr- Choice of ODR to be set
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_op_mode()

int32_t ad4110_set_op_mode ( struct ad4110_dev * dev,
enum ad4110_op_mode mode )

Set the operation mode.

Parameters
dev- The device structure.
mode- The operation mode type. Accepted values: AD4110_VOLTAGE_MODE AD4110_CURRENT_MODE AD4110_CURRENT_MODE_EXT_R_SEL AD4110_THERMOCOUPLE AD4110_FLD_POWER_MODE AD4110_RTD_2W_MODE AD4110_RTD_3W_MODE AD4110_RTD_4W_MODE
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_order()

int ad4110_set_order ( struct ad4110_dev * dev,
enum ad4110_order order )

Set Order of Filter.

Parameters
dev- The device structure.
order- Choice of order to be set
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_set_reference()

int32_t ad4110_set_reference ( struct ad4110_dev * dev,
enum ad4110_voltage_reference ref )

Set the voltage reference.

Parameters
dev- The device structure.
ref- The voltage reference. Accepted values: AD4110_EXT_REF AD4110_INT_2_5V_REF AD4110_AVDD5_REF
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_setup()

int32_t ad4110_setup ( struct ad4110_dev ** device,
struct ad4110_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.

◆ ad4110_spi_do_soft_reset()

int32_t ad4110_spi_do_soft_reset ( struct ad4110_dev * dev)

Do a SPI software reset.

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

◆ ad4110_spi_int_data_reg_read()

int32_t ad4110_spi_int_data_reg_read ( struct ad4110_dev * dev,
uint32_t * reg_data )

SPI internal DATA register read from device.

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

◆ ad4110_spi_int_reg_read()

int32_t ad4110_spi_int_reg_read ( struct ad4110_dev * dev,
uint8_t reg_map,
uint8_t reg_addr,
uint32_t * reg_data )

SPI internal register read from device.

Parameters
dev- The device structure.
reg_map- The register map. Accepted values: A4110_ADC A4110_AFE
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_spi_int_reg_write()

int32_t ad4110_spi_int_reg_write ( struct ad4110_dev * dev,
uint8_t reg_map,
uint8_t reg_addr,
uint32_t reg_data )

SPI internal register write to device.

Parameters
dev- The device structure.
reg_map- The register map. Accepted values: A4110_ADC A4110_AFE
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_spi_int_reg_write_msk()

int32_t ad4110_spi_int_reg_write_msk ( struct ad4110_dev * dev,
uint8_t reg_map,
uint8_t reg_addr,
uint32_t data,
uint16_t mask )

SPI internal register write to device using a mask.

Parameters
dev- The device structure.
reg_map- The register map. Accepted values: A4110_ADC A4110_AFE
reg_addr- The register address.
data- The register data.
mask- The mask.
Returns
0 in case of success, negative error code otherwise.

◆ ad4110_wait_for_rdy_low()

int ad4110_wait_for_rdy_low ( struct ad4110_dev * dev,
uint32_t timeout )

Wait for RDY bit to go low indicating conversion completion.

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