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

Implementation of AD5706R Driver. More...

#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "ad5706r.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_print_log.h"
#include "no_os_alloc.h"
#include "no_os_util.h"
Include dependency graph for ad5706r.c:

Functions

int ad5706r_spi_reg_read (struct ad5706r_dev *dev, uint32_t reg_addr, uint16_t *reg_data)
 Read from device.
 
int ad5706r_spi_reg_read_multiple (struct ad5706r_dev *dev, uint32_t start_addr, uint8_t count, uint8_t *buff)
 Read multiple register's values.
 
int ad5706r_spi_reg_write (struct ad5706r_dev *dev, uint32_t reg_addr, uint16_t reg_data)
 Write to device.
 
int ad5706r_spi_reg_write_multiple (struct ad5706r_dev *dev, uint32_t start_addr, uint8_t count, uint8_t *buff)
 Write multiple register's values.
 
int ad5706r_spi_write_mask (struct ad5706r_dev *dev, uint32_t reg_addr, uint32_t mask, uint16_t data)
 SPI write to device using a mask.
 
int ad5706r_set_reference (struct ad5706r_dev *dev, enum ad5706r_vref_select reference_selector)
 Set reference configuration.
 
int ad5706r_set_operating_mode (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_output_op_mode op_mode)
 Set output operating mode of a channel.
 
int ad5706r_set_ch_output_range (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_output_range range_sel)
 Set output range for a channel.
 
int ad5706r_func_en (struct ad5706r_dev *dev, uint16_t en_mask)
 Set the function generator enable configuration.
 
int ad5706r_func_mode_select (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_function_mode func_mode_sel)
 Set function generator mode for a channel.
 
int ad5706r_set_dither_period (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_dither_period period)
 Set period for dither function generator.
 
int ad5706r_set_dither_phase (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_dither_phase phase)
 Set phase for dither function generator.
 
int ad5706r_set_hw_sw_ldac (struct ad5706r_dev *dev, uint16_t mask_hw_sw_ldac)
 Set the hardware and software ldac configuration.
 
int ad5706r_set_sync_async_ldac (struct ad5706r_dev *dev, uint16_t mask_ldac_sync_async)
 Set sync/async ldac configuration.
 
int ad5706r_set_ldac_config (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_dac_mode dac_mode, struct ad5706r_ldac_settings *ldac_settings)
 Set ldac config for single channel.
 
int ad5706r_multi_dac_sw_ldac_trigger (struct ad5706r_dev *dev)
 Trigger Multi DAC SW LDAC.
 
int ad5706r_set_multi_ldac_config (struct ad5706r_dev *dev, uint16_t ch_mask, enum ad5706r_dac_mode dac_mode, struct ad5706r_ldac_settings *ldac_settings)
 Set ldac config for multiple channels.
 
int ad5706r_set_dac_a_value (struct ad5706r_dev *dev, enum ad5706r_channels ch, uint16_t dac_value)
 Set dac value on DAC input register A.
 
int ad5706r_set_dac_b_value (struct ad5706r_dev *dev, enum ad5706r_channels ch, uint16_t dac_value)
 Set dac value on DAC input register B.
 
int ad5706r_set_multi_dac_a_value (struct ad5706r_dev *dev, uint16_t dac_value)
 Set dac value on Multi DAC input register A.
 
int ad5706r_set_mux_out_mode (struct ad5706r_dev *dev, enum ad5706r_mux_out_state mux_output_mode_sel)
 Set the multiplexer output mode.
 
int ad5706r_set_mux_out_select (struct ad5706r_dev *dev, enum ad5706r_mux_out_select mux_output_sel)
 Set the multiplexer output select register.
 
int ad5706r_hw_ldac_trigger (struct ad5706r_dev *dev)
 Trigger the LDAC using hardware.
 
int ad5706r_set_edge_trigger (struct ad5706r_dev *dev, enum ad5706r_channels ch, enum ad5706r_ldac_edge_trig trig_edge)
 Set LDAC/TGP/DCLK edge trigger.
 
int ad5706r_sw_ldac_trigger (struct ad5706r_dev *dev)
 Trigger the LDAC using software.
 
int ad5706r_sw_reset (struct ad5706r_dev *dev)
 Perform soft reset.
 
int ad5706r_hw_reset (struct ad5706r_dev *dev)
 Perform hard reset.
 
int ad5706r_device_config (struct ad5706r_dev *dev, struct ad5706r_init_param *init_param)
 Configures the device.
 
int ad5706r_set_device_spi (struct ad5706r_dev *dev, struct ad5706r_device_spi_settings *spi_settings)
 Set device spi settings.
 
int ad5706r_crc_enable (struct ad5706r_dev *dev, bool crc_enable)
 Configures the CRC selection bit .
 
int ad5706r_shdn_trigger (struct ad5706r_dev *dev, bool shdn_state)
 Set SHDN pin state.
 
int ad5706r_init (struct ad5706r_dev **device, struct ad5706r_init_param *init_param)
 Initialize the device.
 
int ad5706r_remove (struct ad5706r_dev *dev)
 Free the device descriptor.
 

Detailed Description

Implementation of AD5706R Driver.

Author
NAlteza (natha.nosp@m.niel.nosp@m..alte.nosp@m.za@a.nosp@m.nalog.nosp@m..com)

Copyright 2024-2026(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

◆ ad5706r_crc_enable()

int ad5706r_crc_enable ( struct ad5706r_dev * dev,
bool crc_enable )

Configures the CRC selection bit .

Parameters
dev- The device structure.
crc_enable- boolean selection for crc bit.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_device_config()

int ad5706r_device_config ( struct ad5706r_dev * dev,
struct ad5706r_init_param * init_param )

Configures the device.

Parameters
dev- The device structure to be initialized.
init_param- Configuration parameters for the device.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_func_en()

int ad5706r_func_en ( struct ad5706r_dev * dev,
uint16_t en_mask )

Set the function generator enable configuration.

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

◆ ad5706r_func_mode_select()

int ad5706r_func_mode_select ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_function_mode func_mode_sel )

Set function generator mode for a channel.

Parameters
dev- The device structure.
ch- Channel selected.
func_mode_sel- Function generator mode to be selected. Accepted values: AD5706R_TOGGLE (default) AD5706R_DITHER
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_hw_ldac_trigger()

int ad5706r_hw_ldac_trigger ( struct ad5706r_dev * dev)

Trigger the LDAC using hardware.

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

◆ ad5706r_hw_reset()

int ad5706r_hw_reset ( struct ad5706r_dev * dev)

Perform hard reset.

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

◆ ad5706r_init()

int ad5706r_init ( struct ad5706r_dev ** device,
struct ad5706r_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.

◆ ad5706r_multi_dac_sw_ldac_trigger()

int ad5706r_multi_dac_sw_ldac_trigger ( struct ad5706r_dev * dev)

Trigger Multi DAC SW LDAC.

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

◆ ad5706r_remove()

int ad5706r_remove ( struct ad5706r_dev * dev)

Free the device descriptor.

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

◆ ad5706r_set_ch_output_range()

int ad5706r_set_ch_output_range ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_output_range range_sel )

Set output range for a channel.

Parameters
dev- The device structure.
ch- Channel selected.
range_sel- Output range to be selected. Accepted values: AD5706R_50mA (default) AD5706R_150mA AD5706R_200mA AD5706R_300mA
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_dac_a_value()

int ad5706r_set_dac_a_value ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
uint16_t dac_value )

Set dac value on DAC input register A.

Parameters
dev- The device structure.
ch- Channel selected.
dac_value- value that will be set in DAC input register A.
Returns
0 in case of success, negative error code otherwise.

◆ ad5706r_set_dac_b_value()

int ad5706r_set_dac_b_value ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
uint16_t dac_value )

Set dac value on DAC input register B.

Parameters
dev- The device structure.
ch- Channel selected.
dac_value- value that will be set in DAC input register B.
Returns
0 in case of success, negative error code otherwise.

◆ ad5706r_set_device_spi()

int ad5706r_set_device_spi ( struct ad5706r_dev * dev,
struct ad5706r_device_spi_settings * spi_settings )

Set device spi settings.

Parameters
dev- The device structure.
spi_settings- The structure that contains the device spi parameters.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_dither_period()

int ad5706r_set_dither_period ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_dither_period period )

Set period for dither function generator.

Parameters
dev- The device structure.
ch- Channel selected.
period- Dither period to be selected. Accepted values: AD5706R_SAMPLES_4 (default) AD5706R_SAMPLES_8 AD5706R_SAMPLES_16 AD5706R_SAMPLES_32 AD5706R_SAMPLES_64
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_dither_phase()

int ad5706r_set_dither_phase ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_dither_phase phase )

Set phase for dither function generator.

Parameters
dev- The device structure.
ch- Channel selected.
phase- Dither phase to be selected. Accepted values: AD5706R_DEGREES_0 (default) AD5706R_DEGREES_90 AD5706R_DEGREES_180 AD5706R_DEGREES_270
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_edge_trigger()

int ad5706r_set_edge_trigger ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_ldac_edge_trig trig_edge )

Set LDAC/TGP/DCLK edge trigger.

Parameters
dev- The device structure.
ch- Channel selected.
trig_edge- Edge trigger to be selected. Accepted values: AD5706R_RISING_EDGE_TRIG (default) AD5706R_FALLING_EDGE_TRIG AD5706R_ANY_EDGE_TRIG
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_hw_sw_ldac()

int ad5706r_set_hw_sw_ldac ( struct ad5706r_dev * dev,
uint16_t mask_hw_sw_ldac )

Set the hardware and software ldac configuration.

Parameters
dev- The device structure.
mask_hw_sw_ldac- The array contains HW/SW LDAC channel masks.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_ldac_config()

int ad5706r_set_ldac_config ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_dac_mode dac_mode,
struct ad5706r_ldac_settings * ldac_settings )

Set ldac config for single channel.

Parameters
dev- The device structure.
ch- Channel selected.
dac_mode- DAC Controller Mode to be configured for selected channel. Accepted values: AD5706R_DIRECT_WRITE_REG (default) AD5706R_SW_LDAC AD5706R_HW_LDAC AD5706R_SW_TOGGLE AD5706R_HW_TOGGLE AD5706R_SW_DITHER AD5706R_HW_DITHER
ldac_settings- LDAC mode config Structure.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_multi_dac_a_value()

int ad5706r_set_multi_dac_a_value ( struct ad5706r_dev * dev,
uint16_t dac_value )

Set dac value on Multi DAC input register A.

Parameters
dev- The device structure.
dac_value- value that will be set in MULTI DAC input register A.
Returns
0 in case of success, negative error code otherwise.

◆ ad5706r_set_multi_ldac_config()

int ad5706r_set_multi_ldac_config ( struct ad5706r_dev * dev,
uint16_t ch_mask,
enum ad5706r_dac_mode dac_mode,
struct ad5706r_ldac_settings * ldac_settings )

Set ldac config for multiple channels.

Parameters
dev- The device structure.
ch_mask- Selected channels mask.
dac_mode- DAC Controller Mode to be configured for selected channel. Accepted values: AD5706R_DIRECT_WRITE_REG (default) AD5706R_SW_LDAC AD5706R_HW_LDAC AD5706R_SW_TOGGLE AD5706R_HW_TOGGLE AD5706R_SW_DITHER AD5706R_HW_DITHER
ldac_settings- LDAC mode config Structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad5706r_set_mux_out_mode()

int ad5706r_set_mux_out_mode ( struct ad5706r_dev * dev,
enum ad5706r_mux_out_state mux_output_mode_sel )

Set the multiplexer output mode.

Parameters
dev- The device structure.
mux_output_mode_sel- Select mux output state. Accepted values: AD5706R_HIGH_Z (default) AD5706R_BYPASS AD5706R_BUFFER
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_mux_out_select()

int ad5706r_set_mux_out_select ( struct ad5706r_dev * dev,
enum ad5706r_mux_out_select mux_output_sel )

Set the multiplexer output select register.

Parameters
dev- The device structure.
mux_output_sel- Select signal to be monitored on the mux_out pin.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_operating_mode()

int ad5706r_set_operating_mode ( struct ad5706r_dev * dev,
enum ad5706r_channels ch,
enum ad5706r_output_op_mode op_mode )

Set output operating mode of a channel.

Parameters
dev- The device structure.
ch- Channel selected.
op_mode- Output operating mode to be selected. Accepted values: AD5706R_SHUTDOWN_SW (default) AD5706R_SHUTDOWN_SW_W_GND AD5706R_NORMAL_SW AD5706R_SHUTDOWN_HW AD5706R_SHUTDOWN_HW_W_GND AD5706R_NORMAL_HW
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_reference()

int ad5706r_set_reference ( struct ad5706r_dev * dev,
enum ad5706r_vref_select reference_selector )

Set reference configuration.

Parameters
dev- The device structure.
reference_selector- The reference to be selected. Accepted values: AD5706R_EXTERNAL_VREF_PIN_INPUT (default) AD5706R_INTERNAL_VREF_PIN_2P5V
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_set_sync_async_ldac()

int ad5706r_set_sync_async_ldac ( struct ad5706r_dev * dev,
uint16_t mask_ldac_sync_async )

Set sync/async ldac configuration.

Parameters
dev- The device structure.
mask_ldac_sync_async- The array contains SYNC/ASYNC mode channel masks.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5706r_shdn_trigger()

int ad5706r_shdn_trigger ( struct ad5706r_dev * dev,
bool shdn_state )

Set SHDN pin state.

Parameters
dev- The device structure.
shdn_state- Boolean selection for SHDN state.
Returns
0 in case of success, negative error code otherwise.

◆ ad5706r_spi_reg_read()

int ad5706r_spi_reg_read ( struct ad5706r_dev * dev,
uint32_t reg_addr,
uint16_t * reg_data )

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.
Here is the caller graph for this function:

◆ ad5706r_spi_reg_read_multiple()

int ad5706r_spi_reg_read_multiple ( struct ad5706r_dev * dev,
uint32_t start_addr,
uint8_t count,
uint8_t * buff )

Read multiple register's values.

Parameters
dev- The device structure.
start_addr- Starting register address to read from.
count- Number of bytes to read.
buff- Buffer to store data.
Returns
0 in case of success, negative error code otherwise.

Offset register address when in descending address mode with respect to register length.

◆ ad5706r_spi_reg_write()

int ad5706r_spi_reg_write ( struct ad5706r_dev * dev,
uint32_t reg_addr,
uint16_t reg_data )

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.
Here is the caller graph for this function:

◆ ad5706r_spi_reg_write_multiple()

int ad5706r_spi_reg_write_multiple ( struct ad5706r_dev * dev,
uint32_t start_addr,
uint8_t count,
uint8_t * buff )

Write multiple register's values.

Parameters
dev- The device structure.
start_addr- Starting register address to write into.
count- Number of bytes to write.
buff- Buffer to write data from.
Returns
0 in case of success, negative error code otherwise.

Offset register address when in descending address mode with respect to register length.

◆ ad5706r_spi_write_mask()

int ad5706r_spi_write_mask ( struct ad5706r_dev * dev,
uint32_t reg_addr,
uint32_t mask,
uint16_t data )

SPI 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.
Here is the caller graph for this function:

◆ ad5706r_sw_ldac_trigger()

int ad5706r_sw_ldac_trigger ( struct ad5706r_dev * dev)

Trigger the LDAC using software.

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

◆ ad5706r_sw_reset()

int ad5706r_sw_reset ( struct ad5706r_dev * dev)

Perform soft reset.

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