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

Header file of AD7746 Driver. More...

#include <stdint.h>
#include <stdbool.h>
#include "no_os_util.h"
#include "no_os_i2c.h"
Include dependency graph for ad7746.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ad7746_cap
 
struct  ad7746_vt
 
struct  ad7746_exc
 
struct  ad7746_config
 
struct  ad7746_setup
 
struct  ad7746_init_param
 
struct  ad7746_dev
 

Macros

#define AD7746_ADDRESS   0x48
 
#define AD7746_RESET_CMD   0xBF
 
#define AD7746_REG_STATUS   0u
 
#define AD7746_REG_CAP_DATA_HIGH   1u
 
#define AD7746_REG_CAP_DATA_MID   2u
 
#define AD7746_REG_CAP_DATA_LOW   3u
 
#define AD7746_REG_VT_DATA_HIGH   4u
 
#define AD7746_REG_VT_DATA_MID   5u
 
#define AD7746_REG_VT_DATA_LOW   6u
 
#define AD7746_REG_CAP_SETUP   7u
 
#define AD7746_REG_VT_SETUP   8u
 
#define AD7746_REG_EXC_SETUP   9u
 
#define AD7746_REG_CFG   10u
 
#define AD7746_REG_CAPDACA   11u
 
#define AD7746_REG_CAPDACB   12u
 
#define AD7746_REG_CAP_OFFH   13u
 
#define AD7746_REG_CAP_OFFL   14u
 
#define AD7746_REG_CAP_GAINH   15u
 
#define AD7746_REG_CAP_GAINL   16u
 
#define AD7746_REG_VOLT_GAINH   17u
 
#define AD7746_REG_VOLT_GAINL   18u
 
#define AD7746_NUM_REGISTERS   (AD7746_REG_VOLT_GAINL + 1u)
 
#define AD7746_STATUS_EXCERR_MSK   NO_OS_BIT(3)
 
#define AD7746_STATUS_RDY_MSK   NO_OS_BIT(2)
 
#define AD7746_STATUS_RDYVT_MSK   NO_OS_BIT(1)
 
#define AD7746_STATUS_RDYCAP_MSK   NO_OS_BIT(0)
 
#define AD7746_CAPSETUP_CAPEN_MSK   NO_OS_BIT(7)
 
#define AD7746_CAPSETUP_CIN2_MSK   NO_OS_BIT(6)
 
#define AD7746_CAPSETUP_CAPDIFF_MSK   NO_OS_BIT(5)
 
#define AD7746_CAPSETUP_CAPCHOP_MSK   NO_OS_BIT(0)
 
#define AD7746_VTSETUP_VTEN_MSK   NO_OS_BIT(7)
 
#define AD7746_VTSETUP_VTMD_MSK   NO_OS_GENMASK(6,5)
 
#define AD7746_VTSETUP_EXTREF_MSK   NO_OS_BIT(4)
 
#define AD7746_VTSETUP_VTSHORT_MSK   NO_OS_BIT(1)
 
#define AD7746_VTSETUP_VTCHOP_MSK   NO_OS_BIT(0)
 
#define AD7746_EXCSETUP_CLKCTRL_MSK   NO_OS_BIT(7)
 
#define AD7746_EXCSETUP_EXCON_MSK   NO_OS_BIT(6)
 
#define AD7746_EXCSETUP_EXCB_MSK   NO_OS_GENMASK(5,4)
 
#define AD7746_EXCSETUP_EXCA_MSK   NO_OS_GENMASK(3,2)
 
#define AD7746_EXCSETUP_EXCLVL_MSK   NO_OS_GENMASK(1,0)
 
#define AD7746_CONF_VTF_MSK   NO_OS_GENMASK(7,6)
 
#define AD7746_CONF_CAPF_MSK   NO_OS_GENMASK(5,3)
 
#define AD7746_CONF_MD_MSK   NO_OS_GENMASK(2,0)
 
#define AD7746_CAPDAC_DACEN_MSK   NO_OS_BIT(7)
 
#define AD7746_CAPDAC_DACP_MSK   NO_OS_GENMASK(6,0)
 

Enumerations

enum  ad7746_id {
  ID_AD7745,
  ID_AD7746,
  ID_AD7747
}
 
enum  ad7746_vtmd {
  AD7746_VTMD_INT_TEMP,
  AD7746_VTMD_EXT_TEMP,
  AD7746_VTMD_VDD_MON,
  AD7746_VIN_EXT_VIN
}
 
enum  ad7746_exc_pin {
  AD7746_EXC_PIN_DISABLED,
  AD7746_EXC_PIN_INVERTED,
  AD7746_EXC_PIN_NORMAL
}
 
enum  ad7746_exclvl {
  AD7746_EXCLVL_1_DIV_8,
  AD7746_EXCLVL_2_DIV_8,
  AD7746_EXCLVL_3_DIV_8,
  AD7746_EXCLVL_4_DIV_8
}
 
enum  ad7746_md {
  AD7746_MODE_IDLE,
  AD7746_MODE_CONT,
  AD7746_MODE_SINGLE,
  AD7746_MODE_POWERDOWN,
  AD7746_MODE_OFFSET_CALIB = 5,
  AD7746_MODE_GAIN_CALIB
}
 

Functions

int32_t ad7746_init (struct ad7746_dev **device, struct ad7746_init_param *init_param)
 Initialize the ad7606 device structure. More...
 
int32_t ad7746_reg_write (struct ad7746_dev *dev, uint8_t reg, uint8_t *data, uint16_t bytes_number)
 Writes data into AD7746 registers, starting from the selected register address pointer. More...
 
int32_t ad7746_reg_read (struct ad7746_dev *dev, uint8_t reg, uint8_t *data, uint16_t bytes_number)
 Reads data from AD7746 registers, starting from the selected register address pointer. More...
 
int32_t ad7746_reset (struct ad7746_dev *dev)
 Resets the AD7746. More...
 
int32_t ad7746_remove (struct ad7746_dev *dev)
 Deinitialize the ad7746 driver and free all allocated resources. More...
 
int32_t ad7746_set_cap (struct ad7746_dev *dev, struct ad7746_cap cap)
 Configure the capacitive setup register. More...
 
int32_t ad7746_set_vt (struct ad7746_dev *dev, struct ad7746_vt vt)
 Configure the voltage/temperature setup register. More...
 
int32_t ad7746_set_exc (struct ad7746_dev *dev, struct ad7746_exc exc)
 Configure the excitation setup register. More...
 
int32_t ad7746_set_config (struct ad7746_dev *dev, struct ad7746_config config)
 Set the configuration register. More...
 
int32_t ad7746_set_cap_dac_a (struct ad7746_dev *dev, bool enable, uint8_t code)
 Set the DAC code and enable state for EXCA. More...
 
int32_t ad7746_set_cap_dac_b (struct ad7746_dev *dev, bool enable, uint8_t code)
 Set the DAC code and enable state for EXCB. More...
 
int32_t ad7746_set_cap_offset (struct ad7746_dev *dev, uint16_t offset)
 Set the capacitive offset. More...
 
int32_t ad7746_set_cap_gain (struct ad7746_dev *dev, uint16_t gain)
 Set the capacitive gain. More...
 
int32_t ad7746_set_volt_gain (struct ad7746_dev *dev, uint16_t gain)
 Set the voltage gain. More...
 
int32_t ad7746_get_vt_data (struct ad7746_dev *dev, uint32_t *vt_data)
 Waits until a conversion on a voltage/temperature channel has been finished and returns the output data. More...
 
int32_t ad7746_get_cap_data (struct ad7746_dev *dev, uint32_t *cap_data)
 Waits until a conversion on the capacitive channel has been finished and returns the output data. More...
 
int32_t ad7746_calibrate (struct ad7746_dev *dev, enum ad7746_md md)
 Perform offset/gain calibration. More...
 

Detailed Description

Header file of AD7746 Driver.

Author
Dragos Bogdan (drago.nosp@m.s.bo.nosp@m.gdan@.nosp@m.anal.nosp@m.og.co.nosp@m.m)
Darius Berghe (dariu.nosp@m.s.be.nosp@m.rghe@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

Copyright 2021(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

◆ AD7746_ADDRESS

#define AD7746_ADDRESS   0x48

◆ AD7746_CAPDAC_DACEN_MSK

#define AD7746_CAPDAC_DACEN_MSK   NO_OS_BIT(7)

◆ AD7746_CAPDAC_DACP_MSK

#define AD7746_CAPDAC_DACP_MSK   NO_OS_GENMASK(6,0)

◆ AD7746_CAPSETUP_CAPCHOP_MSK

#define AD7746_CAPSETUP_CAPCHOP_MSK   NO_OS_BIT(0)

◆ AD7746_CAPSETUP_CAPDIFF_MSK

#define AD7746_CAPSETUP_CAPDIFF_MSK   NO_OS_BIT(5)

◆ AD7746_CAPSETUP_CAPEN_MSK

#define AD7746_CAPSETUP_CAPEN_MSK   NO_OS_BIT(7)

◆ AD7746_CAPSETUP_CIN2_MSK

#define AD7746_CAPSETUP_CIN2_MSK   NO_OS_BIT(6)

◆ AD7746_CONF_CAPF_MSK

#define AD7746_CONF_CAPF_MSK   NO_OS_GENMASK(5,3)

◆ AD7746_CONF_MD_MSK

#define AD7746_CONF_MD_MSK   NO_OS_GENMASK(2,0)

◆ AD7746_CONF_VTF_MSK

#define AD7746_CONF_VTF_MSK   NO_OS_GENMASK(7,6)

◆ AD7746_EXCSETUP_CLKCTRL_MSK

#define AD7746_EXCSETUP_CLKCTRL_MSK   NO_OS_BIT(7)

◆ AD7746_EXCSETUP_EXCA_MSK

#define AD7746_EXCSETUP_EXCA_MSK   NO_OS_GENMASK(3,2)

◆ AD7746_EXCSETUP_EXCB_MSK

#define AD7746_EXCSETUP_EXCB_MSK   NO_OS_GENMASK(5,4)

◆ AD7746_EXCSETUP_EXCLVL_MSK

#define AD7746_EXCSETUP_EXCLVL_MSK   NO_OS_GENMASK(1,0)

◆ AD7746_EXCSETUP_EXCON_MSK

#define AD7746_EXCSETUP_EXCON_MSK   NO_OS_BIT(6)

◆ AD7746_NUM_REGISTERS

#define AD7746_NUM_REGISTERS   (AD7746_REG_VOLT_GAINL + 1u)

◆ AD7746_REG_CAP_DATA_HIGH

#define AD7746_REG_CAP_DATA_HIGH   1u

◆ AD7746_REG_CAP_DATA_LOW

#define AD7746_REG_CAP_DATA_LOW   3u

◆ AD7746_REG_CAP_DATA_MID

#define AD7746_REG_CAP_DATA_MID   2u

◆ AD7746_REG_CAP_GAINH

#define AD7746_REG_CAP_GAINH   15u

◆ AD7746_REG_CAP_GAINL

#define AD7746_REG_CAP_GAINL   16u

◆ AD7746_REG_CAP_OFFH

#define AD7746_REG_CAP_OFFH   13u

◆ AD7746_REG_CAP_OFFL

#define AD7746_REG_CAP_OFFL   14u

◆ AD7746_REG_CAP_SETUP

#define AD7746_REG_CAP_SETUP   7u

◆ AD7746_REG_CAPDACA

#define AD7746_REG_CAPDACA   11u

◆ AD7746_REG_CAPDACB

#define AD7746_REG_CAPDACB   12u

◆ AD7746_REG_CFG

#define AD7746_REG_CFG   10u

◆ AD7746_REG_EXC_SETUP

#define AD7746_REG_EXC_SETUP   9u

◆ AD7746_REG_STATUS

#define AD7746_REG_STATUS   0u

◆ AD7746_REG_VOLT_GAINH

#define AD7746_REG_VOLT_GAINH   17u

◆ AD7746_REG_VOLT_GAINL

#define AD7746_REG_VOLT_GAINL   18u

◆ AD7746_REG_VT_DATA_HIGH

#define AD7746_REG_VT_DATA_HIGH   4u

◆ AD7746_REG_VT_DATA_LOW

#define AD7746_REG_VT_DATA_LOW   6u

◆ AD7746_REG_VT_DATA_MID

#define AD7746_REG_VT_DATA_MID   5u

◆ AD7746_REG_VT_SETUP

#define AD7746_REG_VT_SETUP   8u

◆ AD7746_RESET_CMD

#define AD7746_RESET_CMD   0xBF

◆ AD7746_STATUS_EXCERR_MSK

#define AD7746_STATUS_EXCERR_MSK   NO_OS_BIT(3)

◆ AD7746_STATUS_RDY_MSK

#define AD7746_STATUS_RDY_MSK   NO_OS_BIT(2)

◆ AD7746_STATUS_RDYCAP_MSK

#define AD7746_STATUS_RDYCAP_MSK   NO_OS_BIT(0)

◆ AD7746_STATUS_RDYVT_MSK

#define AD7746_STATUS_RDYVT_MSK   NO_OS_BIT(1)

◆ AD7746_VTSETUP_EXTREF_MSK

#define AD7746_VTSETUP_EXTREF_MSK   NO_OS_BIT(4)

◆ AD7746_VTSETUP_VTCHOP_MSK

#define AD7746_VTSETUP_VTCHOP_MSK   NO_OS_BIT(0)

◆ AD7746_VTSETUP_VTEN_MSK

#define AD7746_VTSETUP_VTEN_MSK   NO_OS_BIT(7)

◆ AD7746_VTSETUP_VTMD_MSK

#define AD7746_VTSETUP_VTMD_MSK   NO_OS_GENMASK(6,5)

◆ AD7746_VTSETUP_VTSHORT_MSK

#define AD7746_VTSETUP_VTSHORT_MSK   NO_OS_BIT(1)

Enumeration Type Documentation

◆ ad7746_exc_pin

Enumerator
AD7746_EXC_PIN_DISABLED 
AD7746_EXC_PIN_INVERTED 
AD7746_EXC_PIN_NORMAL 

◆ ad7746_exclvl

Enumerator
AD7746_EXCLVL_1_DIV_8 
AD7746_EXCLVL_2_DIV_8 
AD7746_EXCLVL_3_DIV_8 
AD7746_EXCLVL_4_DIV_8 

◆ ad7746_id

enum ad7746_id
Enumerator
ID_AD7745 
ID_AD7746 
ID_AD7747 

◆ ad7746_md

enum ad7746_md
Enumerator
AD7746_MODE_IDLE 
AD7746_MODE_CONT 
AD7746_MODE_SINGLE 
AD7746_MODE_POWERDOWN 
AD7746_MODE_OFFSET_CALIB 
AD7746_MODE_GAIN_CALIB 

◆ ad7746_vtmd

Enumerator
AD7746_VTMD_INT_TEMP 
AD7746_VTMD_EXT_TEMP 
AD7746_VTMD_VDD_MON 
AD7746_VIN_EXT_VIN 

Function Documentation

◆ ad7746_calibrate()

int32_t ad7746_calibrate ( struct ad7746_dev dev,
enum ad7746_md  md 
)

Perform offset/gain calibration.

Parameters
dev- Device descriptor pointer.
md- AD7746 calibration mode specifier.
Returns
return code. Example: -EINVAL - Wrong input values. -EIO - I2C Communication error. 0 - No errors encountered.

◆ ad7746_get_cap_data()

int32_t ad7746_get_cap_data ( struct ad7746_dev dev,
uint32_t *  cap_data 
)

Waits until a conversion on the capacitive channel has been finished and returns the output data.

Parameters
dev- Device descriptor pointer.
cap_data- The content of the Capacitive Data register.
Returns
return code. Example: -EINVAL - Wrong input values. -EIO - I2C Communication error. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_get_vt_data()

int32_t ad7746_get_vt_data ( struct ad7746_dev dev,
uint32_t *  vt_data 
)

Waits until a conversion on a voltage/temperature channel has been finished and returns the output data.

Parameters
dev- Device descriptor pointer.
vt_data- The content of the VT Data register.
Returns
return code. Example: -EINVAL - Wrong input values. -EIO - I2C Communication error. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_init()

int32_t ad7746_init ( struct ad7746_dev **  device,
struct ad7746_init_param init_param 
)

Initialize the ad7606 device structure.

Performs memory allocation of the device structure.

Parameters
device- Pointer to location of device structure to write.
init_param- Pointer to the configuration of the driver.
Returns
ret - return code. Example: -ENOMEM - Memory allocation error. -EIO - I2C communication error. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_reg_read()

int32_t ad7746_reg_read ( struct ad7746_dev dev,
uint8_t  reg,
uint8_t *  data,
uint16_t  bytes_number 
)

Reads data from AD7746 registers, starting from the selected register address pointer.

Parameters
dev- Device descriptor pointer.
reg- The selected register address pointer.
data- Pointer to a buffer that will store the received data.
bytes_number- Number of bytes to read (typically 1, other values when using the address auto-increment).
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_reg_write()

int32_t ad7746_reg_write ( struct ad7746_dev dev,
uint8_t  reg,
uint8_t *  data,
uint16_t  bytes_number 
)

Writes data into AD7746 registers, starting from the selected register address pointer.

Parameters
dev- Device descriptor pointer.
reg- The selected register address.
data- Pointer to data to transmit.
bytes_number- Number of bytes to send (typically 1, other values when using the address auto-increment).
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_remove()

int32_t ad7746_remove ( struct ad7746_dev dev)

Deinitialize the ad7746 driver and free all allocated resources.

Parameters
dev- Device descriptor pointer.
Returns
0
Here is the caller graph for this function:

◆ ad7746_reset()

int32_t ad7746_reset ( struct ad7746_dev dev)

Resets the AD7746.

Parameters
dev- Device descriptor pointer.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_set_cap()

int32_t ad7746_set_cap ( struct ad7746_dev dev,
struct ad7746_cap  cap 
)

Configure the capacitive setup register.

Parameters
dev- Device descriptor pointer.
cap- Capacitive setup settings.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_set_cap_dac_a()

int32_t ad7746_set_cap_dac_a ( struct ad7746_dev dev,
bool  enable,
uint8_t  code 
)

Set the DAC code and enable state for EXCA.

Parameters
dev- Device descriptor pointer.
enable- DAC_A Enable.
code- DAC_A register code.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_set_cap_dac_b()

int32_t ad7746_set_cap_dac_b ( struct ad7746_dev dev,
bool  enable,
uint8_t  code 
)

Set the DAC code and enable state for EXCB.

Parameters
dev- Device descriptor pointer.
enable- DAC_B Enable.
code- DAC_B register code.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.

◆ ad7746_set_cap_gain()

int32_t ad7746_set_cap_gain ( struct ad7746_dev dev,
uint16_t  gain 
)

Set the capacitive gain.

Parameters
dev- Device descriptor pointer.
gain- Gain as raw code.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.

◆ ad7746_set_cap_offset()

int32_t ad7746_set_cap_offset ( struct ad7746_dev dev,
uint16_t  offset 
)

Set the capacitive offset.

Parameters
dev- Device descriptor pointer.
offset- Offset as raw code.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.

◆ ad7746_set_config()

int32_t ad7746_set_config ( struct ad7746_dev dev,
struct ad7746_config  config 
)

Set the configuration register.

Parameters
dev- Device descriptor pointer.
config- Configuration register settings.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_set_exc()

int32_t ad7746_set_exc ( struct ad7746_dev dev,
struct ad7746_exc  exc 
)

Configure the excitation setup register.

Parameters
dev- Device descriptor pointer.
exc- Excitation setup settings.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7746_set_volt_gain()

int32_t ad7746_set_volt_gain ( struct ad7746_dev dev,
uint16_t  gain 
)

Set the voltage gain.

Parameters
dev- Device descriptor pointer.
gain- Gain as raw code.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.

◆ ad7746_set_vt()

int32_t ad7746_set_vt ( struct ad7746_dev dev,
struct ad7746_vt  vt 
)

Configure the voltage/temperature setup register.

Parameters
dev- Device descriptor pointer.
vt- Voltage/Temperature setup settings.
Returns
return code. Example: -EINVAL - Wrong input values. 0 - No errors encountered.
Here is the caller graph for this function: