Skip to content

Commit

Permalink
drivers:adc-dac:ad5592r: Driver Enhancement
Browse files Browse the repository at this point in the history
1. Added driver apis for adc range, dac range, power down,set internal
reference and set adc buffer to the base driver.
2. Added API to enable busy indicator on AD5592r
3. Removed static for spi nop API for visibilty.
4. Moved some macros from ad5593.c to header file for visibility.
5. Renamed start and stop macros.

Signed-off-by: Disha D <[email protected]>
  • Loading branch information
D-Disha committed Jan 20, 2025
1 parent 764a2a8 commit 7867222
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 53 deletions.
166 changes: 164 additions & 2 deletions drivers/adc-dac/ad5592r/ad5592r-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Implementation of AD5592R Base Driver.
* @author Mircea Caprioru ([email protected])
********************************************************************************
* Copyright 2018, 2020(c) Analog Devices, Inc.
* Copyright 2018, 2020, 2025(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:
Expand All @@ -19,7 +19,7 @@
* 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
* 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,
Expand Down Expand Up @@ -320,3 +320,165 @@ int32_t ad5592r_reset_channel_modes(struct ad5592r_dev *dev)

return ad5592r_set_channel_modes(dev);
}

/**
* Set ADC Range of the device
*
* @param dev - The device structure.
* @param adc_range - ADC Range
* @return 0 in case of success, negative error code otherwise
*/
int32_t ad5592r_set_adc_range(struct ad5592r_dev *dev,
enum ad559xr_range adc_range)
{
int32_t ret;
uint16_t temp_reg_val;

if (!dev)
return -1;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_CTRL, &temp_reg_val);
if (ret < 0)
return ret;

if (adc_range)
temp_reg_val |= AD5592R_REG_CTRL_ADC_RANGE;
else
temp_reg_val &= ~AD5592R_REG_CTRL_ADC_RANGE;

ret = ad5592r_base_reg_write(dev, AD5592R_REG_CTRL, temp_reg_val);
if (ret < 0)
return ret;

dev->adc_range = adc_range;

return 0;
}

/**
* Set DAC Range of the device
*
* @param dev - The device structure.
* @param dac_range - DAC Range
* @return 0 in case of success, negative error code otherwise
*/
int32_t ad5592r_set_dac_range(struct ad5592r_dev *dev,
enum ad559xr_range dac_range)
{
int32_t ret;
uint16_t temp_reg_val;

if (!dev)
return -1;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_CTRL, &temp_reg_val);
if (ret < 0)
return ret;

if (dac_range)
temp_reg_val |= AD5592R_REG_CTRL_DAC_RANGE;
else
temp_reg_val &= ~AD5592R_REG_CTRL_DAC_RANGE;

ret = ad5592r_base_reg_write(dev, AD5592R_REG_CTRL, temp_reg_val);
if (ret < 0)
return ret;

dev->dac_range = dac_range;

return 0;
}

/**
* Set Power Down DAC Channel of the device
*
* @param dev - The device structure.
* @param chan - The channel number.
* @param status - Status to enable/disable power down.
* @return 0 in case of success, negative error code otherwise
*/
int32_t ad5592r_power_down(struct ad5592r_dev *dev, uint8_t chan, bool status)
{
int ret;
uint16_t temp_reg_val;

if (!dev)
return -1;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_PD, &temp_reg_val);
if (ret < 0)
return ret;

if (status)
temp_reg_val |= NO_OS_BIT(chan);
else
temp_reg_val &= ~NO_OS_BIT(chan);

ret = ad5592r_base_reg_write(dev, AD5592R_REG_PD, temp_reg_val);
if (ret < 0)
return ret;

dev->power_down[chan] = status;

return 0;
}

/**
* Set Reference Select option for the device
*
* @param dev - The device structure.
* @param status - Status to enable/disable internal reference.
* @return 0 in case of success, negative error code otherwise
*/
int32_t ad5592r_set_int_ref(struct ad5592r_dev *dev, bool status)
{
uint16_t temp_reg_val;
int ret;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_PD, &temp_reg_val);
if (ret < 0)
return ret;

if (status)
temp_reg_val |= AD5592R_REG_PD_EN_REF;
else
temp_reg_val &= ~AD5592R_REG_PD_EN_REF;

ret = ad5592r_base_reg_write(dev, AD5592R_REG_PD, temp_reg_val);
if (ret < 0)
return ret;

dev->int_ref = status;

return 0;
}

/**
* Set ADC Buffer for the device
*
* @param dev - The device structure.
* @param status - Status to enable/disable adc buffer.
* @return 0 in case of success, negative error code otherwise
*/
int32_t ad5592r_set_adc_buffer(struct ad5592r_dev *dev, bool status)
{
uint16_t temp_reg_val;
int ret;

ret = ad5592r_base_reg_read(dev, AD5592R_REG_CTRL, &temp_reg_val);
if (ret < 0)
return ret;

if (status)
temp_reg_val |= AD5592R_REG_CTRL_ADC_BUFF_EN;
else
temp_reg_val &= ~AD5592R_REG_CTRL_ADC_BUFF_EN;

ret = ad5592r_base_reg_write(dev, AD5592R_REG_CTRL, temp_reg_val);
if (ret < 0)
return ret;

dev->adc_buf = status;

return 0;
}
32 changes: 30 additions & 2 deletions drivers/adc-dac/ad5592r/ad5592r-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Header file of AD5592R Base Driver.
* @author Mircea Caprioru ([email protected])
********************************************************************************
* Copyright 2018, 2020(c) Analog Devices, Inc.
* Copyright 2018, 2020, 2025(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:
Expand All @@ -19,7 +19,7 @@
* 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
* 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,
Expand Down Expand Up @@ -92,6 +92,8 @@ enum ad5592r_registers {

#define INTERNAL_VREF_VOLTAGE 2.5

#define NUM_OF_CHANNELS 8

struct ad5592r_dev;

struct ad5592r_rw_ops {
Expand All @@ -108,8 +110,22 @@ struct ad5592r_rw_ops {
int32_t (*gpio_read)(struct ad5592r_dev *dev, uint8_t *value);
};

enum ad559xr_range {
ZERO_TO_VREF,
ZERO_TO_2VREF
};

struct ad5592r_init_param {
bool int_ref;
struct no_os_spi_init_param *spi_init;
struct no_os_i2c_init_param *i2c_init;
uint8_t channel_modes[8];
uint8_t channel_offstate[8];
enum ad559xr_range adc_range;
enum ad559xr_range dac_range;
bool adc_buf;
uint16_t cached_dac[8];
uint8_t power_down[8];
};

struct ad5592r_dev {
Expand All @@ -126,6 +142,11 @@ struct ad5592r_dev {
uint8_t gpio_in;
uint8_t gpio_val;
uint8_t ldac_mode;
enum ad559xr_range adc_range;
enum ad559xr_range dac_range;
bool int_ref;
uint8_t power_down[8];
bool adc_buf;
};

int32_t ad5592r_base_reg_write(struct ad5592r_dev *dev, uint8_t reg,
Expand All @@ -141,5 +162,12 @@ int32_t ad5592r_gpio_direction_output(struct ad5592r_dev *dev,
int32_t ad5592r_software_reset(struct ad5592r_dev *dev);
int32_t ad5592r_set_channel_modes(struct ad5592r_dev *dev);
int32_t ad5592r_reset_channel_modes(struct ad5592r_dev *dev);
int32_t ad5592r_set_adc_range(struct ad5592r_dev *dev,
enum ad559xr_range adc_range);
int32_t ad5592r_set_dac_range(struct ad5592r_dev *dev,
enum ad559xr_range dac_range);
int32_t ad5592r_power_down(struct ad5592r_dev *dev, uint8_t chan, bool status);
int32_t ad5592r_set_int_ref(struct ad5592r_dev *dev, bool status);
int32_t ad5592r_set_adc_buffer(struct ad5592r_dev *dev, bool status);

#endif /* AD5592R_BASE_H_ */
Loading

0 comments on commit 7867222

Please sign in to comment.