no-OS
Classes | Macros | Enumerations | Functions
ad5791.h File Reference

Header file of AD5791 Driver. More...

#include <stdint.h>
#include "no-os/delay.h"
#include "no-os/gpio.h"
#include "no-os/spi.h"
Include dependency graph for ad5791.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ad5791_chip_info
 
struct  ad5791_dev
 
struct  ad5791_init_param
 

Macros

#define AD5791_RESET_OUT
 
#define AD5791_RESET_LOW
 
#define AD5791_RESET_HIGH
 
#define AD5791_CLR_OUT
 
#define AD5791_CLR_LOW
 
#define AD5791_CLR_HIGH
 
#define AD5791_LDAC_OUT
 
#define AD5791_LDAC_LOW
 
#define AD5791_LDAC_HIGH
 
#define MAX_RESOLUTION   20
 
#define AD5791_NOP   0
 
#define AD5791_REG_DAC   1
 
#define AD5791_REG_CTRL   2
 
#define AD5791_REG_CLR_CODE   3
 
#define AD5791_CMD_WR_SOFT_CTRL   4
 
#define AD5791_READ   (1ul << 23)
 
#define AD5791_WRITE   (0ul << 23)
 
#define AD5791_ADDR_REG(x)   (((uint32_t)(x) & 0x7) << 20)
 
#define AD5791_CTRL_LINCOMP(x)   (((x) & 0xF) << 6)
 
#define AD5791_CTRL_SDODIS   (1 << 5)
 
#define AD5791_CTRL_BIN2SC   (1 << 4)
 
#define AD5791_CTRL_DACTRI   (1 << 3)
 
#define AD5791_CTRL_OPGND   (1 << 2)
 
#define AD5791_CTRL_RBUF   (1 << 1)
 
#define AD5791_SOFT_CTRL_RESET   (1 << 2)
 
#define AD5791_SOFT_CTRL_CLR   (1 << 1)
 
#define AD5791_SOFT_CTRL_LDAC   (1 << 0)
 
#define AD5791_OUT_NORMAL   0x0
 
#define AD5791_OUT_CLAMPED_6K   0x1
 
#define AD5791_OUT_TRISTATE   0x2
 

Enumerations

enum  ad5791_type {
  ID_AD5760,
  ID_AD5780,
  ID_AD5781,
  ID_AD5790,
  ID_AD5791
}
 

Functions

int32_t ad5791_init (struct ad5791_dev **device, struct ad5791_init_param init_param)
 Initializes the communication with the device. More...
 
int32_t ad5791_remove (struct ad5791_dev *dev)
 Free the resources allocated by ad5791_init(). More...
 
int32_t ad5791_set_register_value (struct ad5791_dev *dev, uint8_t register_address, uint32_t register_value)
 Writes data into a register. More...
 
int32_t ad5791_get_register_value (struct ad5791_dev *dev, uint8_t register_address, uint32_t *value)
 Reads the value of a register. More...
 
int32_t ad5791_dac_ouput_state (struct ad5791_dev *dev, uint8_t state)
 Sets the DAC output in one of the three states. More...
 
int32_t ad5791_set_dac_value (struct ad5791_dev *dev, uint32_t value)
 Writes to the DAC register. More...
 
int32_t ad5791_soft_instruction (struct ad5791_dev *dev, uint8_t instruction_bit)
 Asserts RESET, CLR or LDAC in a software manner. More...
 
int32_t ad5791_setup (struct ad5791_dev *dev, uint32_t setup_word)
 Configures the output amplifier, DAC coding, SDO state and the linearity error compensation. More...
 

Detailed Description

Header file of AD5791 Driver.

Author
DNechita (Dan.N.nosp@m.echi.nosp@m.ta@an.nosp@m.alog.nosp@m..com)

Copyright 2013(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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

◆ AD5791_ADDR_REG

#define AD5791_ADDR_REG (   x)    (((uint32_t)(x) & 0x7) << 20)

◆ AD5791_CLR_HIGH

#define AD5791_CLR_HIGH
Value:
gpio_set_value(dev->gpio_clr, \

◆ AD5791_CLR_LOW

#define AD5791_CLR_LOW
Value:
gpio_set_value(dev->gpio_clr, \

◆ AD5791_CLR_OUT

#define AD5791_CLR_OUT
Value:

◆ AD5791_CMD_WR_SOFT_CTRL

#define AD5791_CMD_WR_SOFT_CTRL   4

◆ AD5791_CTRL_BIN2SC

#define AD5791_CTRL_BIN2SC   (1 << 4)

◆ AD5791_CTRL_DACTRI

#define AD5791_CTRL_DACTRI   (1 << 3)

◆ AD5791_CTRL_LINCOMP

#define AD5791_CTRL_LINCOMP (   x)    (((x) & 0xF) << 6)

◆ AD5791_CTRL_OPGND

#define AD5791_CTRL_OPGND   (1 << 2)

◆ AD5791_CTRL_RBUF

#define AD5791_CTRL_RBUF   (1 << 1)

◆ AD5791_CTRL_SDODIS

#define AD5791_CTRL_SDODIS   (1 << 5)

◆ AD5791_LDAC_HIGH

#define AD5791_LDAC_HIGH
Value:
gpio_set_value(dev->gpio_ldac, \

◆ AD5791_LDAC_LOW

#define AD5791_LDAC_LOW
Value:
gpio_set_value(dev->gpio_ldac, \

◆ AD5791_LDAC_OUT

#define AD5791_LDAC_OUT
Value:

◆ AD5791_NOP

#define AD5791_NOP   0

◆ AD5791_OUT_CLAMPED_6K

#define AD5791_OUT_CLAMPED_6K   0x1

◆ AD5791_OUT_NORMAL

#define AD5791_OUT_NORMAL   0x0

◆ AD5791_OUT_TRISTATE

#define AD5791_OUT_TRISTATE   0x2

◆ AD5791_READ

#define AD5791_READ   (1ul << 23)

◆ AD5791_REG_CLR_CODE

#define AD5791_REG_CLR_CODE   3

◆ AD5791_REG_CTRL

#define AD5791_REG_CTRL   2

◆ AD5791_REG_DAC

#define AD5791_REG_DAC   1

◆ AD5791_RESET_HIGH

#define AD5791_RESET_HIGH
Value:
gpio_set_value(dev->gpio_reset, \

◆ AD5791_RESET_LOW

#define AD5791_RESET_LOW
Value:
gpio_set_value(dev->gpio_reset, \

◆ AD5791_RESET_OUT

#define AD5791_RESET_OUT
Value:

◆ AD5791_SOFT_CTRL_CLR

#define AD5791_SOFT_CTRL_CLR   (1 << 1)

◆ AD5791_SOFT_CTRL_LDAC

#define AD5791_SOFT_CTRL_LDAC   (1 << 0)

◆ AD5791_SOFT_CTRL_RESET

#define AD5791_SOFT_CTRL_RESET   (1 << 2)

◆ AD5791_WRITE

#define AD5791_WRITE   (0ul << 23)

◆ MAX_RESOLUTION

#define MAX_RESOLUTION   20

Enumeration Type Documentation

◆ ad5791_type

Enumerator
ID_AD5760 
ID_AD5780 
ID_AD5781 
ID_AD5790 
ID_AD5791 

Function Documentation

◆ ad5791_dac_ouput_state()

int32_t ad5791_dac_ouput_state ( struct ad5791_dev dev,
uint8_t  state 
)

Sets the DAC output in one of the three states.

Sets the DAC output in one of the three states.

Parameters
dev- The device structure.
state- The output state. Example: AD5791_OUT_NORMAL - normal operation mode AD5791_OUT_CLAMPED_6K - output is clamped via ~6KOhm to AGND AD5791_OUT_TRISTATE - output is in tristate
Returns
Negative error code or 0 in case of success.

◆ ad5791_get_register_value()

int32_t ad5791_get_register_value ( struct ad5791_dev dev,
uint8_t  register_address,
uint32_t *  value 
)

Reads the value of a register.

Reads the value of a register.

Parameters
dev- The device structure.
register_address- Address of the register. Example: AD5791_REG_DAC - DAC register AD5791_REG_CTRL - Control register AD5791_REG_CLR_CODE - Clearcode register AD5791_CMD_WR_SOFT_CTRL - Software control register
value- Pointer to the register data.
Returns
dataRead - The register's value or negative error code.
Here is the caller graph for this function:

◆ ad5791_init()

int32_t ad5791_init ( struct ad5791_dev **  device,
struct ad5791_init_param  init_param 
)

Initializes the communication with the device.

Initializes the communication with the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
status - Result of the initialization procedure. Example: 0 - if initialization was successful; -1 - if initialization was unsuccessful.
Here is the caller graph for this function:

◆ ad5791_remove()

int32_t ad5791_remove ( struct ad5791_dev dev)

Free the resources allocated by ad5791_init().

Free the resources allocated by ad5791_init().

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

◆ ad5791_set_dac_value()

int32_t ad5791_set_dac_value ( struct ad5791_dev dev,
uint32_t  value 
)

Writes to the DAC register.

Writes to the DAC register.

Parameters
dev- The device structure.
value- The value to be written to DAC.
Returns
Negative error code or 0 in case of success.
Here is the caller graph for this function:

◆ ad5791_set_register_value()

int32_t ad5791_set_register_value ( struct ad5791_dev dev,
uint8_t  register_address,
uint32_t  register_value 
)

Writes data into a register.

Writes data into a register.

Parameters
dev- The device structure.
register_address- Address of the register. Example: AD5791_REG_DAC - DAC register AD5791_REG_CTRL - Control register AD5791_REG_CLR_CODE - Clearcode register AD5791_CMD_WR_SOFT_CTRL - Software control register
register_value- Value of the register.
Returns
Returns 0 in case of success or negative error code.
Here is the caller graph for this function:

◆ ad5791_setup()

int32_t ad5791_setup ( struct ad5791_dev dev,
uint32_t  setup_word 
)

Configures the output amplifier, DAC coding, SDO state and the linearity error compensation.

Configures the output amplifier, DAC coding, SDO state and the linearity error compensation.

Parameters
dev- The device structure.
setup_word- Is a 24-bit value that sets or clears the Control Register bits : RBUF bit(AD5791_CTRL_RBUF), BIN/2sC bit(AD5791_CTRL_BIN2SC), SDODIS bit(AD5791_CTRL_SDODIS) and LINCOMP bits(AD5791_CTRL_LINCOMP(x)). Example: AD5791_CTRL_BIN2SC | AD5791_CTRL_RBUF - sets the DAC register to use offset binary coding and powers down the internal output amplifier.
Returns
Negative error code or 0 in case of success.

◆ ad5791_soft_instruction()

int32_t ad5791_soft_instruction ( struct ad5791_dev dev,
uint8_t  instruction_bit 
)

Asserts RESET, CLR or LDAC in a software manner.

Asserts RESET, CLR or LDAC in a software manner.

Parameters
dev- The device structure.
instruction_bit- A Software Control Register bit. Example: AD5791_SOFT_CTRL_LDAC - Load DAC AD5791_SOFT_CTRL_CLR - Clear AD5791_SOFT_CTRL_RESET - Reset
Returns
Negative error code or 0 in case of success.
gpio_direction_output
int32_t gpio_direction_output(struct gpio_desc *desc, uint8_t value)
Enable the output direction of the specified GPIO.
Definition: gpio.c:124
GPIO_LOW
@ GPIO_LOW
Definition: gpio.h:99
gpio_set_value
int32_t gpio_set_value(struct gpio_desc *desc, uint8_t value)
Set the value of the specified GPIO.
Definition: gpio.c:160
GPIO_HIGH
@ GPIO_HIGH
Definition: gpio.h:101
iio_app_device::dev
void * dev
Definition: iio_app.h:60