no-OS
Functions
ad4858.c File Reference

Source file for the ad4858 drivers. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "ad4858.h"
#include "no_os_delay.h"
#include "no_os_print_log.h"
Include dependency graph for ad4858.c:

Functions

int ad4858_reg_write (struct ad4858_dev *dev, uint32_t reg_addr, uint32_t reg_val)
 Write device register. More...
 
int ad4858_reg_read (struct ad4858_dev *dev, uint32_t reg_addr, uint32_t *reg_val)
 Read device register. More...
 
int ad4858_reg_mask (struct ad4858_dev *dev, uint32_t reg_addr, uint32_t mask, uint32_t reg_val)
 Update specific register bits of an input register. More...
 
int ad4858_set_operating_mode (struct ad4858_dev *dev, enum ad4858_operating_mode mode)
 Set the device operating mode. More...
 
int ad4858_set_spi_data_mode (struct ad4858_dev *dev, enum ad4858_spi_data_mode mode)
 Set the SPI data mode. More...
 
int ad4858_set_config_interface_mode (struct ad4858_dev *dev)
 Set device config interface mode. More...
 
int ad4858_set_data_interface_mode (struct ad4858_dev *dev)
 Set device data interface mode. More...
 
int ad4858_enable_osr (struct ad4858_dev *dev, bool osr_status)
 Enable OSR. More...
 
int ad4858_set_osr_ratio (struct ad4858_dev *dev, enum ad4858_osr_ratio osr_ratio)
 Set OSR ratio. More...
 
int ad4858_set_packet_format (struct ad4858_dev *dev, enum ad4858_packet_format packet_format)
 Set packet format. More...
 
int ad4858_enable_test_pattern (struct ad4858_dev *dev, bool test_pattern)
 Enable/Disable test pattern on ADC data output. More...
 
int ad4858_enable_ch_sleep (struct ad4858_dev *dev, uint8_t chn, enum ad4858_ch_sleep_value sleep_status)
 Enable/Disable channel sleep. More...
 
int ad4858_enable_ch_seamless_hdr (struct ad4858_dev *dev, uint8_t chn, enum ad4858_ch_seamless_hdr seamless_hdr_status)
 Enable/Disable seamless hdr. More...
 
int ad4858_set_chn_softspan (struct ad4858_dev *dev, uint8_t chn, enum ad4858_chn_softspan chn_softspan)
 Set channel softspan. More...
 
int ad4858_set_chn_offset (struct ad4858_dev *dev, uint8_t chn, uint32_t offset)
 Set channel offset. More...
 
int ad4858_set_chn_gain (struct ad4858_dev *dev, uint8_t chn, uint16_t gain)
 Set channel gain. More...
 
int ad4858_set_chn_phase (struct ad4858_dev *dev, uint8_t chn, uint16_t phase)
 Set channel phase. More...
 
int ad4858_set_chn_or_limit (struct ad4858_dev *dev, uint8_t chn, uint32_t or_limit)
 Set channel overrange (OR) limit. More...
 
int ad4858_set_chn_ur_limit (struct ad4858_dev *dev, uint8_t chn, uint32_t ur_limit)
 Set channel underrange (UR) limit. More...
 
int ad4858_convst (struct ad4858_dev *dev)
 Toggle the CNV pin to start a conversion. More...
 
int ad4858_perform_conv (struct ad4858_dev *dev)
 Perform ADC conversion. More...
 
int ad4858_spi_data_read (struct ad4858_dev *dev, struct ad4858_conv_data *data)
 Read ADC conversion data over SPI. More...
 
int ad4858_read_data (struct ad4858_dev *dev, struct ad4858_conv_data *data)
 Read ADC data (for all channels). More...
 
int ad4858_soft_reset (struct ad4858_dev *dev)
 Perform an AD4858 software reset. More...
 
int ad4858_init (struct ad4858_dev **device, struct ad4858_init_param *init_param)
 Initialize an AD4858 device structure. More...
 
int ad4858_remove (struct ad4858_dev *dev)
 Remove an AD4858 device (free memory allocated by ad4858_init function). More...
 

Detailed Description

Source file for the ad4858 drivers.

Header file for the ad4858 drivers.

Copyright 2023(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

◆ ad4858_convst()

int ad4858_convst ( struct ad4858_dev dev)

Toggle the CNV pin to start a conversion.

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

◆ ad4858_enable_ch_seamless_hdr()

int ad4858_enable_ch_seamless_hdr ( struct ad4858_dev dev,
uint8_t  chn,
enum ad4858_ch_seamless_hdr  seamless_hdr_status 
)

Enable/Disable seamless hdr.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
seamless_hdr_status- seamless hdr status.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_enable_ch_sleep()

int ad4858_enable_ch_sleep ( struct ad4858_dev dev,
uint8_t  chn,
enum ad4858_ch_sleep_value  sleep_status 
)

Enable/Disable channel sleep.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
sleep_status- Sleep status.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_enable_osr()

int ad4858_enable_osr ( struct ad4858_dev dev,
bool  osr_status 
)

Enable OSR.

Parameters
dev- Pointer to the device structure.
osr_status- OSR enable/disable status.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_enable_test_pattern()

int ad4858_enable_test_pattern ( struct ad4858_dev dev,
bool  test_pattern 
)

Enable/Disable test pattern on ADC data output.

Parameters
dev- Pointer to the device structure.
test_pattern- Test pattern enable status.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_init()

int ad4858_init ( struct ad4858_dev **  device,
struct ad4858_init_param init_param 
)

Initialize an AD4858 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.

◆ ad4858_perform_conv()

int ad4858_perform_conv ( struct ad4858_dev dev)

Perform ADC conversion.

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

◆ ad4858_read_data()

int ad4858_read_data ( struct ad4858_dev dev,
struct ad4858_conv_data data 
)

Read ADC data (for all channels).

Parameters
dev- Pointer to the device structure.
data- Pointer to adc conversion data structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_reg_mask()

int ad4858_reg_mask ( struct ad4858_dev dev,
uint32_t  reg_addr,
uint32_t  mask,
uint32_t  reg_val 
)

Update specific register bits of an input register.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- Specific bits mask.
reg_val- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Note
Multibyte read/write with streaming mode is supported by default.
Here is the caller graph for this function:

◆ ad4858_reg_read()

int ad4858_reg_read ( struct ad4858_dev dev,
uint32_t  reg_addr,
uint32_t *  reg_val 
)

Read device register.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_val- The data read from the register.
Returns
0 in case of success, negative error code otherwise.
Note
Multibyte read with streaming mode is supported by default.
Here is the caller graph for this function:

◆ ad4858_reg_write()

int ad4858_reg_write ( struct ad4858_dev dev,
uint32_t  reg_addr,
uint32_t  reg_val 
)

Write device register.

Parameters
dev-The device structure.
reg_addr- The register address.
reg_val- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Note
Multibyte write with streaming mode is supported by default.
Here is the caller graph for this function:

◆ ad4858_remove()

int ad4858_remove ( struct ad4858_dev dev)

Remove an AD4858 device (free memory allocated by ad4858_init function).

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

◆ ad4858_set_chn_gain()

int ad4858_set_chn_gain ( struct ad4858_dev dev,
uint8_t  chn,
uint16_t  gain 
)

Set channel gain.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
gain- Gain value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_chn_offset()

int ad4858_set_chn_offset ( struct ad4858_dev dev,
uint8_t  chn,
uint32_t  offset 
)

Set channel offset.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
offset- Offset value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_chn_or_limit()

int ad4858_set_chn_or_limit ( struct ad4858_dev dev,
uint8_t  chn,
uint32_t  or_limit 
)

Set channel overrange (OR) limit.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
or_limit- Overrange limit.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_chn_phase()

int ad4858_set_chn_phase ( struct ad4858_dev dev,
uint8_t  chn,
uint16_t  phase 
)

Set channel phase.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
phase- Phase value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_chn_softspan()

int ad4858_set_chn_softspan ( struct ad4858_dev dev,
uint8_t  chn,
enum ad4858_chn_softspan  chn_softspan 
)

Set channel softspan.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
chn_softspan- Softspan value.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_chn_ur_limit()

int ad4858_set_chn_ur_limit ( struct ad4858_dev dev,
uint8_t  chn,
uint32_t  ur_limit 
)

Set channel underrange (UR) limit.

Parameters
dev- Pointer to the device structure.
chn- Input channel.
ur_limit- Underrange limit.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_config_interface_mode()

int ad4858_set_config_interface_mode ( struct ad4858_dev dev)

Set device config interface mode.

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

◆ ad4858_set_data_interface_mode()

int ad4858_set_data_interface_mode ( struct ad4858_dev dev)

Set device data interface mode.

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

◆ ad4858_set_operating_mode()

int ad4858_set_operating_mode ( struct ad4858_dev dev,
enum ad4858_operating_mode  mode 
)

Set the device operating mode.

Parameters
dev- Pointer to the device structure.
mode- Operating mode.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_osr_ratio()

int ad4858_set_osr_ratio ( struct ad4858_dev dev,
enum ad4858_osr_ratio  osr_ratio 
)

Set OSR ratio.

Parameters
dev- Pointer to the device structure.
osr_ratio- OSR ratio.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_packet_format()

int ad4858_set_packet_format ( struct ad4858_dev dev,
enum ad4858_packet_format  packet_format 
)

Set packet format.

Parameters
dev- Pointer to the device structure.
packet_format- Packet format.
Returns
0 in case of success, negative error code otherwise.

◆ ad4858_set_spi_data_mode()

int ad4858_set_spi_data_mode ( struct ad4858_dev dev,
enum ad4858_spi_data_mode  mode 
)

Set the SPI data mode.

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

◆ ad4858_soft_reset()

int ad4858_soft_reset ( struct ad4858_dev dev)

Perform an AD4858 software reset.

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

◆ ad4858_spi_data_read()

int ad4858_spi_data_read ( struct ad4858_dev dev,
struct ad4858_conv_data data 
)

Read ADC conversion data over SPI.

Parameters
dev- Pointer to the device structure.
data- Pointer to adc conversion data structure.
Returns
0 in case of success, negative error code otherwise.
Note
As this is a simultaneously sampling ADC, data for all channels is acquired/read in a single SPI read function call.
Here is the caller graph for this function: