no-OS
Functions | Variables
ad5754r.c File Reference

Implementation of AD5754R Driver. More...

#include <stdlib.h>
#include "ad5754r.h"
#include "no_os_alloc.h"
#include "no_os_delay.h"
Include dependency graph for ad5754r.c:

Functions

int ad5754r_write (struct ad5754r_dev *dev, uint8_t instr_addr, uint16_t reg_val)
 Write device register. More...
 
int ad5754r_read (struct ad5754r_dev *dev, uint8_t instr_addr, uint16_t *reg_val)
 Read device register. More...
 
int ad5754r_update_bits (struct ad5754r_dev *dev, uint8_t instr_addr, uint16_t mask, uint16_t reg_val)
 Update specific register bits. More...
 
int ad5754r_update_dac_ch_register (struct ad5754r_dev *dev, uint8_t chn, uint16_t value)
 Update DAC register value for specific channel. More...
 
int ad5754r_update_dac_all_ch_registers (struct ad5754r_dev *dev, uint16_t value)
 Update DAC register value for all channels. More...
 
int ad5754r_ldac_trigger (struct ad5754r_dev *dev)
 Trigger LDAC. More...
 
int ad5754r_clear_async (struct ad5754r_dev *dev)
 Clear DAC output for all channels. More...
 
int ad5754r_read_dac_ch_register (struct ad5754r_dev *dev, uint8_t chn, uint16_t *value)
 Read DAC register value for specific channel. More...
 
int ad5754r_dac_code_to_mvolts (struct ad5754r_dev *dev, uint8_t chn, uint16_t code, uint16_t *value)
 Convert DAC code to millivolts for specific channel. More...
 
int ad5754r_dac_mvolts_to_code (struct ad5754r_dev *dev, uint8_t chn, uint16_t mvolts, uint16_t *code)
 Convert DAC millivolts to code for specific channel. More...
 
int ad5754r_set_ch_range (struct ad5754r_dev *dev, uint8_t chn, enum ad5754r_dac_ch_range ch_range)
 Set output range for specific channel. More...
 
int ad5754r_set_ch_pwrup (struct ad5754r_dev *dev, uint8_t chn, enum ad5754r_pwr_dac_ch_pwrup ch_pwrup)
 Set power-up state for specific channel. More...
 
int ad5754r_set_current_clamp_en (struct ad5754r_dev *dev, enum ad5754r_ctrl_current_clamp_en clamp_en)
 Apply current clamp setting for device. More...
 
int ad5754r_set_tsd_en (struct ad5754r_dev *dev, enum ad5754r_ctrl_tsd_en tsd_en)
 Apply TSD setting for device. More...
 
int ad5754r_set_clear_mode (struct ad5754r_dev *dev, enum ad5754r_ctrl_clear_sel clear_sel)
 Set clear mode setting for device. More...
 
int ad5754r_set_sdo_disable (struct ad5754r_dev *dev, enum ad5754r_ctrl_sdo_dis sdo_dis)
 Set SDO Enable/Disable state for device. More...
 
int ad5754r_set_int_ref_pwrup (struct ad5754r_dev *dev, enum ad5754r_pwr_int_ref_pwrup int_ref_pwrup)
 Set Internal Reference Enable/Disable state for device. More...
 
int ad5754r_get_oc_ch_alert (struct ad5754r_dev *dev, uint8_t chn, enum ad5754r_pwr_oc_ch_alert *oc_ch_alert)
 Get Over-current status bit for specific channel. More...
 
int ad5754r_get_tsd_alert (struct ad5754r_dev *dev, enum ad5754r_pwr_tsd_alert *tsd_alert)
 Get Thermal Shutdown status bit. More...
 
int ad5754r_spi_verify (struct ad5754r_dev *dev)
 Write to and read back a register to verify SPI. More...
 
int ad5754r_gpio_init (struct ad5754r_dev *dev, struct ad5754r_init_param *init_param)
 Do GPIO initialization and config for AD5754R. More...
 
int ad5754r_reg_init (struct ad5754r_dev *dev, struct ad5754r_init_param *init_param)
 Initialize registers based on init parameters. More...
 
int ad5754r_init (struct ad5754r_dev **device, struct ad5754r_init_param *init_param)
 Initialize the device. More...
 
int ad5754r_remove_gpios (struct ad5754r_dev *dev)
 Remove GPIOs and free resources. More...
 
int ad5754r_remove (struct ad5754r_dev *dev)
 Remove the device and release resources. More...
 

Variables

const unsigned int ad5754r_gain_values_scaled [AD5754R_SPAN_M10V8_TO_10V8+1]
 

Detailed Description

Implementation of AD5754R Driver.

Author
Ribhu DasPurkayastha (Ribhu.nosp@m..Das.nosp@m.Purka.nosp@m.yast.nosp@m.ha@an.nosp@m.alog.nosp@m..com)

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

◆ ad5754r_clear_async()

int ad5754r_clear_async ( struct ad5754r_dev dev)

Clear DAC output for all channels.

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

◆ ad5754r_dac_code_to_mvolts()

int ad5754r_dac_code_to_mvolts ( struct ad5754r_dev dev,
uint8_t  chn,
uint16_t  code,
uint16_t *  value 
)

Convert DAC code to millivolts for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
code- DAC code
value- Millivolts output calculated using DAC code.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_dac_mvolts_to_code()

int ad5754r_dac_mvolts_to_code ( struct ad5754r_dev dev,
uint8_t  chn,
uint16_t  mvolts,
uint16_t *  code 
)

Convert DAC millivolts to code for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
mvolts- Desired millivolts ouput for specific channel
code- DAC code for desired output voltage
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_get_oc_ch_alert()

int ad5754r_get_oc_ch_alert ( struct ad5754r_dev dev,
uint8_t  chn,
enum ad5754r_pwr_oc_ch_alert oc_ch_alert 
)

Get Over-current status bit for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
oc_ch_alert- Store channel overcurrent alert status.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_get_tsd_alert()

int ad5754r_get_tsd_alert ( struct ad5754r_dev dev,
enum ad5754r_pwr_tsd_alert tsd_alert 
)

Get Thermal Shutdown status bit.

Parameters
dev- The device structure.
tsd_alert- Store TSD alert status.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_gpio_init()

int ad5754r_gpio_init ( struct ad5754r_dev dev,
struct ad5754r_init_param init_param 
)

Do GPIO initialization and config for AD5754R.

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

◆ ad5754r_init()

int ad5754r_init ( struct ad5754r_dev **  device,
struct ad5754r_init_param init_param 
)

Initialize the device.

Parameters
device- The device structure.
init_param- Pointer to structure containing the device initial parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_ldac_trigger()

int ad5754r_ldac_trigger ( struct ad5754r_dev dev)

Trigger LDAC.

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

◆ ad5754r_read()

int ad5754r_read ( struct ad5754r_dev dev,
uint8_t  instr_addr,
uint16_t *  reg_val 
)

Read device register.

Parameters
dev- The device structure.
instr_addr- The instruction address comprising register and dac channel address.
reg_val- The data read from the register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5754r_read_dac_ch_register()

int ad5754r_read_dac_ch_register ( struct ad5754r_dev dev,
uint8_t  chn,
uint16_t *  value 
)

Read DAC register value for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
value- The data read from dac channel register.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_reg_init()

int ad5754r_reg_init ( struct ad5754r_dev dev,
struct ad5754r_init_param init_param 
)

Initialize registers based on init parameters.

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

◆ ad5754r_remove()

int ad5754r_remove ( struct ad5754r_dev dev)

Remove the device and release resources.

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

◆ ad5754r_remove_gpios()

int ad5754r_remove_gpios ( struct ad5754r_dev dev)

Remove GPIOs and free resources.

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

◆ ad5754r_set_ch_pwrup()

int ad5754r_set_ch_pwrup ( struct ad5754r_dev dev,
uint8_t  chn,
enum ad5754r_pwr_dac_ch_pwrup  ch_pwrup 
)

Set power-up state for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
ch_pwrup- Powerup setting for specified channel.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5754r_set_ch_range()

int ad5754r_set_ch_range ( struct ad5754r_dev dev,
uint8_t  chn,
enum ad5754r_dac_ch_range  ch_range 
)

Set output range for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
ch_range- Range option to be set for specified channel.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5754r_set_clear_mode()

int ad5754r_set_clear_mode ( struct ad5754r_dev dev,
enum ad5754r_ctrl_clear_sel  clear_sel 
)

Set clear mode setting for device.

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

◆ ad5754r_set_current_clamp_en()

int ad5754r_set_current_clamp_en ( struct ad5754r_dev dev,
enum ad5754r_ctrl_current_clamp_en  clamp_en 
)

Apply current clamp setting for device.

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

◆ ad5754r_set_int_ref_pwrup()

int ad5754r_set_int_ref_pwrup ( struct ad5754r_dev dev,
enum ad5754r_pwr_int_ref_pwrup  int_ref_pwrup 
)

Set Internal Reference Enable/Disable state for device.

Parameters
dev- The device structure.
int_ref_pwrup- Internal Reference Enable/Disable state for device.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5754r_set_sdo_disable()

int ad5754r_set_sdo_disable ( struct ad5754r_dev dev,
enum ad5754r_ctrl_sdo_dis  sdo_dis 
)

Set SDO Enable/Disable state for device.

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

◆ ad5754r_set_tsd_en()

int ad5754r_set_tsd_en ( struct ad5754r_dev dev,
enum ad5754r_ctrl_tsd_en  tsd_en 
)

Apply TSD setting for device.

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

◆ ad5754r_spi_verify()

int ad5754r_spi_verify ( struct ad5754r_dev dev)

Write to and read back a register to verify SPI.

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

◆ ad5754r_update_bits()

int ad5754r_update_bits ( struct ad5754r_dev dev,
uint8_t  instr_addr,
uint16_t  mask,
uint16_t  reg_val 
)

Update specific register bits.

Parameters
dev- The device structure.
instr_addr- The instruction address comprising register and dac channel address.
mask- Specific bits mask.
reg_val- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5754r_update_dac_all_ch_registers()

int ad5754r_update_dac_all_ch_registers ( struct ad5754r_dev dev,
uint16_t  value 
)

Update DAC register value for all channels.

Parameters
dev- The device structure.
value- The data to be written to the dac channel registers.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_update_dac_ch_register()

int ad5754r_update_dac_ch_register ( struct ad5754r_dev dev,
uint8_t  chn,
uint16_t  value 
)

Update DAC register value for specific channel.

Parameters
dev- The device structure.
chn- The index of channel being addressed.
value- The data to be written to the dac channel.
Returns
0 in case of success, negative error code otherwise.

◆ ad5754r_write()

int ad5754r_write ( struct ad5754r_dev dev,
uint8_t  instr_addr,
uint16_t  reg_val 
)

Write device register.

Parameters
dev-The device structure.
instr_addr- The instruction address comprising register and dac channel address.
reg_val- The data to be written.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

Variable Documentation

◆ ad5754r_gain_values_scaled

const unsigned int ad5754r_gain_values_scaled[AD5754R_SPAN_M10V8_TO_10V8+1]
Initial value:
=
{
2000,
4000,
4320,
4000,
8000,
8640
}