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

Implementation of AD552XR Driver. More...

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

Functions

int ad552xr_spi_reg_read (struct ad552xr_dev *dev, uint32_t reg_addr, uint16_t *reg_data)
 Read from device.
 
int ad552xr_spi_reg_write (struct ad552xr_dev *dev, uint32_t reg_addr, uint16_t reg_data)
 Write to device.
 
int ad552xr_spi_write_mask (struct ad552xr_dev *dev, uint32_t reg_addr, uint32_t mask, uint16_t data)
 SPI write to device using a mask.
 
int ad552xr_set_reference (struct ad552xr_dev *dev, enum ad552xr_vref_select ref_sel)
 
int ad552xr_set_ch_output_range (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_output_range range_sel)
 
int ad552xr_channel_output_en (struct ad552xr_dev *dev, uint8_t ch, bool en)
 
int ad552xr_func_en (struct ad552xr_dev *dev, uint8_t ch, bool en)
 
int ad552xr_func_mode_select (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_function_mode func_mode_sel)
 
int ad552xr_set_dither_period (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_dither_period period)
 
int ad552xr_set_dither_phase (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_dither_phase phase)
 
int ad552xr_set_ramp_step_size (struct ad552xr_dev *dev, uint8_t ch, uint8_t step_size)
 
int ad552xr_set_hw_sw_ldac (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_hw_sw_ldac ldac_mode_sel)
 
int ad552xr_set_sync_async_ldac (struct ad552xr_dev *dev, uint8_t ch, bool is_sync)
 
int ad552xr_set_hw_edge_trigger (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_ldac_edge_trig trig_edge)
 Set LDAC/TGP edge trigger.
 
int ad552xr_set_hw_ldac_toggle_pin (struct ad552xr_dev *dev, uint8_t ch, enum ad552xr_ldac_toggle_sel ldac_hw_sel)
 Set LDAC/TGP source pin.
 
int ad552xr_set_dac_a_value (struct ad552xr_dev *dev, uint8_t ch, uint16_t dac_value)
 
int ad552xr_set_dac_b_value (struct ad552xr_dev *dev, uint8_t ch, uint16_t dac_value)
 
int ad552xr_hw_ldac_trigger (struct ad552xr_dev *dev, enum ad552xr_ldac_toggle_sel ldac_hw_sel, uint32_t delay_us)
 Trigger the LDAC using hardware.
 
int ad552xr_sw_ldac_trigger (struct ad552xr_dev *dev)
 Trigger the LDAC using software.
 
int ad552xr_set_mux_out_select (struct ad552xr_dev *dev, enum ad552xr_mux_out_select mux_output_sel)
 
int ad552xr_set_device_spi (struct ad552xr_dev *dev, struct ad552xr_device_spi_settings *spi_settings)
 Set device spi settings.
 
int ad552xr_sw_reset (struct ad552xr_dev *dev)
 Perform soft reset.
 
int ad552xr_hw_reset (struct ad552xr_dev *dev)
 Perform hard reset.
 
int ad552xr_init (struct ad552xr_dev **device, struct ad552xr_init_param *init_param)
 Initialize the device.
 
int ad552xr_remove (struct ad552xr_dev *dev)
 Free the resources allocated by ad552xr_init().
 

Detailed Description

Implementation of AD552XR Driver.

Author
Naga Himanshu Indraganti (naga..nosp@m.indr.nosp@m.agant.nosp@m.i@an.nosp@m.alog..nosp@m.com)

Copyright 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

◆ ad552xr_channel_output_en()

int ad552xr_channel_output_en ( struct ad552xr_dev * dev,
uint8_t ch,
bool en )

Set the channel output enable.

Parameters
dev- The device structure.
ch- Channel selected.
en- Enable/disable for the channel.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_func_en()

int ad552xr_func_en ( struct ad552xr_dev * dev,
uint8_t ch,
bool en )

Set the function generator enable configuration.

Parameters
dev- The device structure.
ch- Channel selected.
en- Enable/disable for the channel.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_func_mode_select()

int ad552xr_func_mode_select ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_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: AD552XR_FUNCTION_MODE_TOGGLE (default) AD552XR_FUNCTION_MODE_DITHER AD552XR_FUNCTION_MODE_TRIANGULAR AD552XR_FUNCTION_MODE_SAWTOOTH
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_hw_ldac_trigger()

int ad552xr_hw_ldac_trigger ( struct ad552xr_dev * dev,
enum ad552xr_ldac_toggle_sel ldac_hw_sel,
uint32_t delay_us )

Trigger the LDAC using hardware.

Parameters
dev- The device structure.
ldac_hw_sel- HW LDAC Toggle pin select. Accepted values: AD552XR_LDAC_TGP_0 (default) AD552XR_LDAC_TGP_1 AD552XR_LDAC_TGP_2 AD552XR_LDAC_TGP_3
delay_us- Pulse width of the HW toggle gpio trigger in microseconds.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_hw_reset()

int ad552xr_hw_reset ( struct ad552xr_dev * dev)

Perform hard reset.

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

◆ ad552xr_init()

int ad552xr_init ( struct ad552xr_dev ** device,
struct ad552xr_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 value otherwise.

◆ ad552xr_remove()

int ad552xr_remove ( struct ad552xr_dev * dev)

Free the resources allocated by ad552xr_init().

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

◆ ad552xr_set_ch_output_range()

int ad552xr_set_ch_output_range ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_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: AD552XR_UNIPOLAR_5V (default) AD552XR_UNIPOLAR_10V AD552XR_UNIPOLAR_20V AD552XR_UNIPOLAR_40V AD552XR_BIPOLAR_5V AD552XR_BIPOLAR_10V AD552XR_BIPOLAR_15V AD552XR_BIPOLAR_20V
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_dac_a_value()

int ad552xr_set_dac_a_value ( struct ad552xr_dev * dev,
uint8_t ch,
uint16_t dac_value )

Set dac value on DAC input register A.

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

◆ ad552xr_set_dac_b_value()

int ad552xr_set_dac_b_value ( struct ad552xr_dev * dev,
uint8_t ch,
uint16_t dac_value )

Set dac value on DAC input register B.

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

◆ ad552xr_set_device_spi()

int ad552xr_set_device_spi ( struct ad552xr_dev * dev,
struct ad552xr_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.

◆ ad552xr_set_dither_period()

int ad552xr_set_dither_period ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_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: SAMPLES_128 (default) SAMPLES_64 SAMPLES_32 SAMPLES_16 SAMPLES_8 SAMPLES_4 SAMPLES_2
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_dither_phase()

int ad552xr_set_dither_phase ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_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: DEGREES_0 (default) DEGREES_90 DEGREES_180 DEGREES_270
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_hw_edge_trigger()

int ad552xr_set_hw_edge_trigger ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_ldac_edge_trig trig_edge )

Set LDAC/TGP edge trigger.

Parameters
dev- The device structure.
ch- Channel selected.
trig_edge- Trigger edge select. Accepted values: RISING_EDGE_TRIG (default) FALLING_EDGE_TRIG ANY_EDGE_TRIG
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_hw_ldac_toggle_pin()

int ad552xr_set_hw_ldac_toggle_pin ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_ldac_toggle_sel ldac_hw_sel )

Set LDAC/TGP source pin.

Parameters
dev- The device structure.
ch- Channel selected.
ldac_hw_sel- HW LDAC Toggle pin select. Accepted values: AD552XR_LDAC_TGP_0 (default) AD552XR_LDAC_TGP_1 AD552XR_LDAC_TGP_2 AD552XR_LDAC_TGP_3
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_hw_sw_ldac()

int ad552xr_set_hw_sw_ldac ( struct ad552xr_dev * dev,
uint8_t ch,
enum ad552xr_hw_sw_ldac ldac_mode_sel )

Set the hardware and software ldac configuration.

Parameters
dev- The device structure.
ch- Channel selected.
ldac_mode_sel- LDAC mode to be selected. Accepted values: AD552XR_HW_LDAC (default) AD552XR_SW_LDAC
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_mux_out_select()

int ad552xr_set_mux_out_select ( struct ad552xr_dev * dev,
enum ad552xr_mux_out_select mux_output_sel )

Set the multiplexer output select register.

Parameters
dev- The device structure.
mux_output_sel- signal to be monitored on the mux_out pin.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_ramp_step_size()

int ad552xr_set_ramp_step_size ( struct ad552xr_dev * dev,
uint8_t ch,
uint8_t step_size )

Set ramp step size.

Parameters
dev- The device structure.
ch- Channel selected.
step_size- Step size for ramp waveform.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_reference()

int ad552xr_set_reference ( struct ad552xr_dev * dev,
enum ad552xr_vref_select ref_sel )

Set reference configuration.

Parameters
dev- The device structure.
ref_sel- The reference to be selected. Accepted values: AD552XR_INTERNAL_VREF_4P096V (default) AD552XR_EXTERNAL_VREF
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_set_sync_async_ldac()

int ad552xr_set_sync_async_ldac ( struct ad552xr_dev * dev,
uint8_t ch,
bool is_sync )

Set sync/async ldac configuration.

Parameters
dev- The device structure.
ch- Channel selected.
is_sync- To set to synchronous LDAC.
Returns
0 in case of success, negative error code otherwise.

◆ ad552xr_spi_reg_read()

int ad552xr_spi_reg_read ( struct ad552xr_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 value otherwise.
Here is the caller graph for this function:

◆ ad552xr_spi_reg_write()

int ad552xr_spi_reg_write ( struct ad552xr_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 value otherwise.
Here is the caller graph for this function:

◆ ad552xr_spi_write_mask()

int ad552xr_spi_write_mask ( struct ad552xr_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 value otherwise.
Here is the caller graph for this function:

◆ ad552xr_sw_ldac_trigger()

int ad552xr_sw_ldac_trigger ( struct ad552xr_dev * dev)

Trigger the LDAC using software.

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

◆ ad552xr_sw_reset()

int ad552xr_sw_reset ( struct ad552xr_dev * dev)

Perform soft reset.

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