no-OS
Loading...
Searching...
No Matches
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.
 
int ad4858_reg_read (struct ad4858_dev *dev, uint32_t reg_addr, uint32_t *reg_val)
 Read device register.
 
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.
 
int ad4858_set_operating_mode (struct ad4858_dev *dev, enum ad4858_operating_mode mode)
 Set the device operating mode.
 
int ad4858_set_spi_data_mode (struct ad4858_dev *dev, enum ad4858_spi_data_mode mode)
 Set the SPI data mode.
 
int ad4858_set_config_interface_mode (struct ad4858_dev *dev)
 Set device config interface mode.
 
int ad4858_set_data_interface_mode (struct ad4858_dev *dev)
 Set device data interface mode.
 
int ad4858_enable_osr (struct ad4858_dev *dev, bool osr_status)
 Enable OSR.
 
int ad4858_set_osr_ratio (struct ad4858_dev *dev, enum ad4858_osr_ratio osr_ratio)
 Set OSR ratio.
 
int ad4858_set_packet_format (struct ad4858_dev *dev, enum ad4858_packet_format packet_format)
 Set packet format.
 
int ad4858_enable_test_pattern (struct ad4858_dev *dev, bool test_pattern)
 Enable/Disable test pattern on ADC data output.
 
int ad4858_enable_ch_sleep (struct ad4858_dev *dev, uint8_t chn, enum ad4858_ch_sleep_value sleep_status)
 Enable/Disable channel sleep.
 
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.
 
int ad4858_set_chn_softspan (struct ad4858_dev *dev, uint8_t chn, enum ad4858_chn_softspan chn_softspan)
 Set channel softspan.
 
int ad4858_set_chn_offset (struct ad4858_dev *dev, uint8_t chn, uint32_t offset)
 Set channel offset.
 
int ad4858_set_chn_gain (struct ad4858_dev *dev, uint8_t chn, uint16_t gain)
 Set channel gain.
 
int ad4858_set_chn_phase (struct ad4858_dev *dev, uint8_t chn, uint16_t phase)
 Set channel phase.
 
int ad4858_set_chn_or_limit (struct ad4858_dev *dev, uint8_t chn, uint32_t or_limit)
 Set channel overrange (OR) limit.
 
int ad4858_set_chn_ur_limit (struct ad4858_dev *dev, uint8_t chn, uint32_t ur_limit)
 Set channel underrange (UR) limit.
 
int ad4858_convst (struct ad4858_dev *dev)
 Toggle the CNV pin to start a conversion.
 
int ad4858_perform_conv (struct ad4858_dev *dev)
 Perform ADC conversion.
 
int ad4858_spi_data_read (struct ad4858_dev *dev, struct ad4858_conv_data *data)
 Read ADC conversion data over SPI.
 
int ad4858_read_data (struct ad4858_dev *dev, struct ad4858_conv_data *data)
 Read ADC data (for all channels).
 
int ad4858_soft_reset (struct ad4858_dev *dev)
 Perform an AD4858 software reset.
 
int ad4858_init (struct ad4858_dev **device, struct ad4858_init_param *init_param)
 Initialize an AD4858 device structure.
 
int ad4858_remove (struct ad4858_dev *dev)
 Remove an AD4858 device (free memory allocated by ad4858_init function).
 

Detailed Description

Source file for the ad4858 drivers.

Header file for the ad4858 drivers.

Copyright 2023(c) Analog Devices, Inc. SPDX-License-Identifier: BSD-3-Clause

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.