no-OS
Macros | Functions
ad5460.c File Reference

Source file of AD5460 Driver. More...

#include "ad5460.h"
#include "no_os_crc8.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
Include dependency graph for ad5460.c:

Macros

#define AD5460_CRC_POLYNOMIAL   0x7
 
#define AD5460_DIN_DEBOUNCE_LEN   NO_OS_BIT(5)
 
#define AD77416H_DEV_ADDRESS_MSK   NO_OS_GENMASK(5, 4)
 

Functions

 NO_OS_DECLARE_CRC8_TABLE (_crc_table)
 
int ad5460_dac_voltage_to_code (struct ad5460_desc *desc, int32_t mvolts, uint16_t *code, uint32_t ch)
 Converts a millivolt value in the corresponding DAC 16 bit code. More...
 
int ad5460_dac_current_to_code (struct ad5460_desc *desc, uint32_t uamps, uint16_t *code, uint32_t ch)
 Convers a microamp value in the corresponding DAC 16 bit code. More...
 
int ad5460_reg_read_raw (struct ad5460_desc *desc, uint32_t addr, uint8_t *val)
 Read a raw communication frame. More...
 
int ad5460_reg_write (struct ad5460_desc *desc, uint32_t addr, uint16_t val)
 Write a register's value. More...
 
int ad5460_reg_read (struct ad5460_desc *desc, uint32_t addr, uint16_t *val)
 Read a register's value. More...
 
int ad5460_reg_update (struct ad5460_desc *desc, uint32_t addr, uint16_t mask, uint16_t val)
 Update a register's field. More...
 
int ad5460_set_channel_function (struct ad5460_desc *desc, uint32_t ch, enum ad5460_op_mode ch_func)
 Set the operation mode for a specific channel. More...
 
int ad5460_set_channel_vout_range (struct ad5460_desc *desc, uint32_t ch, enum ad5460_vout_range vout_range)
 Set the voltage range for a specific channel. More...
 
int ad5460_set_channel_iout_range (struct ad5460_desc *desc, uint32_t ch, enum ad5460_iout_range iout_range)
 Set the current range for a specific channel. More...
 
int ad5460_set_channel_i_limit (struct ad5460_desc *desc, uint32_t ch, enum ad5460_i_limit i_limit)
 Set the current limit for a specific DAC channel in vout mode. More...
 
int ad5460_set_channel_dac_code (struct ad5460_desc *desc, uint32_t ch, uint16_t dac_code)
 Set and load a code for the DAC on a specific channel. More...
 
int ad5460_set_diag (struct ad5460_desc *desc, uint32_t ch, enum ad5460_diag_mode diag_code)
 Set which diagnostic value to be loaded in the DIAG_RESULT register. More...
 
int ad5460_set_gpio_config (struct ad5460_desc *desc, uint32_t ch, enum ad5460_gpio_select config)
 Set the GPIO operation mode. More...
 
int ad5460_gpio_set (struct ad5460_desc *desc, uint32_t ch, uint8_t val)
 Set the logic value of a GPO pin. More...
 
int ad5460_gpio_get (struct ad5460_desc *desc, uint32_t ch, uint8_t *val)
 Get the GPO value for a specific channel. More...
 
int ad5460_get_live (struct ad5460_desc *desc, union ad5460_live_status *status)
 Read the live status bits. More...
 
int ad5460_dac_slew_enable (struct ad5460_desc *desc, uint32_t ch, enum ad5460_slew_lin_step step, enum ad5460_lin_rate rate)
 Configure and enable slew rate control for a DAC on a specific channel. More...
 
int ad5460_dac_slew_disable (struct ad5460_desc *desc, uint32_t ch)
 Disable the slew rate control. More...
 
int ad5460_set_therm_rst (struct ad5460_desc *desc, bool enable)
 Enable or disable the higher thermal reset. More...
 
int ad5460_reset (struct ad5460_desc *desc)
 Perform software or hardware reset and wait for device reset time. More...
 
int ad5460_init (struct ad5460_desc **desc, struct ad5460_init_param *init_param)
 Initialize the device structure. More...
 
int ad5460_remove (struct ad5460_desc *desc)
 Free the device descriptor. More...
 

Detailed Description

Source file of AD5460 Driver.

Author
Antoniu Miclaus (anton.nosp@m.iu.m.nosp@m.iclau.nosp@m.s@an.nosp@m.alog..nosp@m.com)

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

Macro Definition Documentation

◆ AD5460_CRC_POLYNOMIAL

#define AD5460_CRC_POLYNOMIAL   0x7

◆ AD5460_DIN_DEBOUNCE_LEN

#define AD5460_DIN_DEBOUNCE_LEN   NO_OS_BIT(5)

◆ AD77416H_DEV_ADDRESS_MSK

#define AD77416H_DEV_ADDRESS_MSK   NO_OS_GENMASK(5, 4)

Function Documentation

◆ ad5460_dac_current_to_code()

int ad5460_dac_current_to_code ( struct ad5460_desc desc,
uint32_t  uamps,
uint16_t *  code,
uint32_t  ch 
)

Convers a microamp value in the corresponding DAC 16 bit code.

Parameters
desc- The device structure.
uamps- The microamps value
code- The resulting DAC code
ch- Channel Number
Returns
0 in case of success, -EINVAL otherwise
Here is the caller graph for this function:

◆ ad5460_dac_slew_disable()

int ad5460_dac_slew_disable ( struct ad5460_desc desc,
uint32_t  ch 
)

Disable the slew rate control.

Parameters
desc- The device structure.
ch- The channel index.
Returns
0 in case of success, negative error code otherwise.

◆ ad5460_dac_slew_enable()

int ad5460_dac_slew_enable ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_slew_lin_step  step,
enum ad5460_lin_rate  rate 
)

Configure and enable slew rate control for a DAC on a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
step- Number of codes per increment.
rate- Number of increments per second.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_dac_voltage_to_code()

int ad5460_dac_voltage_to_code ( struct ad5460_desc desc,
int32_t  mvolts,
uint16_t *  code,
uint32_t  ch 
)

Converts a millivolt value in the corresponding DAC 16 bit code.

Parameters
desc- The device structure.
mvolts- The millivolts value.
code- The resulting DAC code.
ch- The channel index.
Returns
0 in case of success, -EINVAL otherwise
Here is the caller graph for this function:

◆ ad5460_get_live()

int ad5460_get_live ( struct ad5460_desc desc,
union ad5460_live_status status 
)

Read the live status bits.

Parameters
desc- The device structure.
status- The register's value.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_gpio_get()

int ad5460_gpio_get ( struct ad5460_desc desc,
uint32_t  ch,
uint8_t *  val 
)

Get the GPO value for a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
val- The debounce time.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_gpio_set()

int ad5460_gpio_set ( struct ad5460_desc desc,
uint32_t  ch,
uint8_t  val 
)

Set the logic value of a GPO pin.

Parameters
desc- The device structure.
ch- The channel index.
val- The output logic state.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_init()

int ad5460_init ( struct ad5460_desc **  desc,
struct ad5460_init_param init_param 
)

Initialize the device structure.

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

◆ ad5460_reg_read()

int ad5460_reg_read ( struct ad5460_desc desc,
uint32_t  addr,
uint16_t *  val 
)

Read a register's value.

Parameters
desc- The device structure.
addr- The register's address.
val- The register's read value.
Returns
0 in case of success, negative error otherwise
Here is the caller graph for this function:

◆ ad5460_reg_read_raw()

int ad5460_reg_read_raw ( struct ad5460_desc desc,
uint32_t  addr,
uint8_t *  val 
)

Read a raw communication frame.

Parameters
desc- The device structure.
addr- The register's address.
val- A raw comm frame.
Returns
0 in case of success, negative error otherwise.

Reading a register on AD5460 requires writing the address to the READ_SELECT register first and then doing another spi read, which will contain the requested register value.

Here is the caller graph for this function:

◆ ad5460_reg_update()

int ad5460_reg_update ( struct ad5460_desc desc,
uint32_t  addr,
uint16_t  mask,
uint16_t  val 
)

Update a register's field.

Parameters
desc- The device structure.
addr- The register's address.
val- The register's value.
mask- The mask for a specific register field.
Returns
0 in case of success, negative error otherwise.
Here is the caller graph for this function:

◆ ad5460_reg_write()

int ad5460_reg_write ( struct ad5460_desc desc,
uint32_t  addr,
uint16_t  val 
)

Write a register's value.

Parameters
desc- The device structure.
addr- The register's address.
val- The register's value.
Returns
0 in case of success, negative error otherwise
Here is the caller graph for this function:

◆ ad5460_remove()

int ad5460_remove ( struct ad5460_desc desc)

Free the device descriptor.

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

◆ ad5460_reset()

int ad5460_reset ( struct ad5460_desc desc)

Perform software or hardware reset and wait for device reset time.

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

◆ ad5460_set_channel_dac_code()

int ad5460_set_channel_dac_code ( struct ad5460_desc desc,
uint32_t  ch,
uint16_t  dac_code 
)

Set and load a code for the DAC on a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
dac_code- The code for the DAC.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_channel_function()

int ad5460_set_channel_function ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_op_mode  ch_func 
)

Set the operation mode for a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
ch_func- The operation mode.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_channel_i_limit()

int ad5460_set_channel_i_limit ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_i_limit  i_limit 
)

Set the current limit for a specific DAC channel in vout mode.

Parameters
desc- The devices structure
ch- The channel index
i_limit- The current limit
Returns
0 in case of success, negative error otherwise

◆ ad5460_set_channel_iout_range()

int ad5460_set_channel_iout_range ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_iout_range  iout_range 
)

Set the current range for a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
iout_range- The current range.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_channel_vout_range()

int ad5460_set_channel_vout_range ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_vout_range  vout_range 
)

Set the voltage range for a specific channel.

Parameters
desc- The device structure.
ch- The channel index.
vout_range- The voltage range.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_diag()

int ad5460_set_diag ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_diag_mode  diag_code 
)

Set which diagnostic value to be loaded in the DIAG_RESULT register.

Parameters
desc- The device structure.
ch- The channel index.
diag_code- The diagnostic setting.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_gpio_config()

int ad5460_set_gpio_config ( struct ad5460_desc desc,
uint32_t  ch,
enum ad5460_gpio_select  config 
)

Set the GPIO operation mode.

Parameters
desc- The device structure.
ch- The channel index.
config- The configuration setting.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad5460_set_therm_rst()

int ad5460_set_therm_rst ( struct ad5460_desc desc,
bool  enable 
)

Enable or disable the higher thermal reset.

Parameters
desc- The device structure.
enable- The thermal reset status. false: reset at 110 deg. Celsius. true: reset at 140 deg. Celsius.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ NO_OS_DECLARE_CRC8_TABLE()

NO_OS_DECLARE_CRC8_TABLE ( _crc_table  )