no-OS
Classes | Functions
ad7606.c File Reference

Implementation of ad7606 Driver. More...

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include "ad7606.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_crc.h"
#include "no_os_alloc.h"
Include dependency graph for ad7606.c:

Classes

struct  ad7606_chip_info
 

Functions

 NO_OS_DECLARE_CRC8_TABLE (ad7606_crc8)
 
 NO_OS_DECLARE_CRC16_TABLE (ad7606_crc16)
 
int32_t ad7606_spi_reg_read (struct ad7606_dev *dev, uint8_t reg_addr, uint8_t *reg_data)
 Read a device register via SPI. More...
 
int32_t ad7606_spi_reg_write (struct ad7606_dev *dev, uint8_t reg_addr, uint8_t reg_data)
 Write a device register via SPI. More...
 
int32_t ad7606_spi_write_mask (struct ad7606_dev *dev, uint32_t addr, uint32_t mask, uint32_t val)
 Write a device register via SPI with masking. More...
 
int32_t ad7606_convst (struct ad7606_dev *dev)
 Toggle the CONVST pin to start a conversion. More...
 
int32_t ad7606_spi_data_read (struct ad7606_dev *dev, uint32_t *data)
 Read conversion data. More...
 
int32_t ad7606_read (struct ad7606_dev *dev, uint32_t *data)
 Blocking conversion start and data read. More...
 
int32_t ad7606_reset (struct ad7606_dev *dev)
 Reset the device by toggling the reset GPIO. More...
 
int32_t ad7606_set_oversampling (struct ad7606_dev *dev, struct ad7606_oversampling oversampling)
 Set the oversampling ratio. More...
 
int32_t ad7606_set_ch_range (struct ad7606_dev *dev, uint8_t ch, struct ad7606_range range)
 Set the channel operation range. More...
 
int32_t ad7606_set_ch_offset (struct ad7606_dev *dev, uint8_t ch, int8_t offset)
 Set the channel offset. More...
 
int32_t ad7606_set_ch_phase (struct ad7606_dev *dev, uint8_t ch, uint8_t phase)
 Set the channel phase. More...
 
int32_t ad7606_set_ch_gain (struct ad7606_dev *dev, uint8_t ch, uint8_t gain)
 Set the channel gain. More...
 
int32_t ad7606_set_config (struct ad7606_dev *dev, struct ad7606_config config)
 Set the device config register. More...
 
int32_t ad7606_set_digital_diag (struct ad7606_dev *dev, struct ad7606_digital_diag diag)
 Set the device digital diagnostics configuration. More...
 
int32_t ad7606_init (struct ad7606_dev **device, struct ad7606_init_param *init_param)
 Initialize the ad7606 device structure. More...
 
int32_t ad7606_remove (struct ad7606_dev *dev)
 Free any resource used by the driver. More...
 

Detailed Description

Implementation of ad7606 Driver.

Author
Stefan Popa (stefa.nosp@m.n.po.nosp@m.pa@an.nosp@m.alog.nosp@m..com)
Darius Berghe (dariu.nosp@m.s.be.nosp@m.rghe@.nosp@m.anal.nosp@m.og.co.nosp@m.m)

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

Function Documentation

◆ ad7606_convst()

int32_t ad7606_convst ( struct ad7606_dev dev)

Toggle the CONVST pin to start a conversion.

If needed, this function also puts the device in ADC reading mode by a write at address zero.

Parameters
dev- The device structure.
Returns
ret - return code. Example: -EIO - SPI communication error. -EIO - CONVST GPIO not available. 0 - No errors encountered.

◆ ad7606_init()

int32_t ad7606_init ( struct ad7606_dev **  device,
struct ad7606_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 configuration of the driver.
Returns
ret - return code. Example: -ENOMEM - Memory allocation error. -EIO - SPI communication error. -EIO - GPIO initialization error. -ENODEV - Unexpected device id. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_read()

int32_t ad7606_read ( struct ad7606_dev dev,
uint32_t *  data 
)

Blocking conversion start and data read.

This function performs a conversion start and then proceeds to reading the conversion data.

Parameters
dev- The device structure.
data- Pointer to location of buffer where to store the data.
Returns
ret - return code. Example: -EIO - SPI communication error. -ETIME - Timeout while waiting for the BUSY signal. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_remove()

int32_t ad7606_remove ( struct ad7606_dev dev)

Free any resource used by the driver.

Parameters
dev- The device structure.
Returns
ret - return code. Example: -EIO - SPI communication error. 0 - No errors encountered.

◆ ad7606_reset()

int32_t ad7606_reset ( struct ad7606_dev dev)

Reset the device by toggling the reset GPIO.

Parameters
dev- The device structure.
Returns
ret - return code. Example: -EIO - Reset GPIO not available. 0 - No errors encountered.

◆ ad7606_set_ch_gain()

int32_t ad7606_set_ch_gain ( struct ad7606_dev dev,
uint8_t  ch,
uint8_t  gain 
)

Set the channel gain.

Parameters
dev- The device structure.
ch- Channel number (0-7).
gain- Gain calibration amount.
Returns
ret - return code. Example: -EIO - SPI communication error. -EINVAL - Invalid input. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_ch_offset()

int32_t ad7606_set_ch_offset ( struct ad7606_dev dev,
uint8_t  ch,
int8_t  offset 
)

Set the channel offset.

The offset parameter is a signed 8-bit integer ranging from -128 to 127 to make it intuitive and user-friendly.

This offset gets converted to the register representation where 0x80 is calibration offset 0, 0x0 is calibration offset -128 and 0xFF is calibration offset 127, etc.

Parameters
dev- The device structure.
ch- Channel number (0-7).
offset- Offset calibration amount (-128...127).
Returns
ret - return code. Example: -EIO - SPI communication error. -EINVAL - Invalid input. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_ch_phase()

int32_t ad7606_set_ch_phase ( struct ad7606_dev dev,
uint8_t  ch,
uint8_t  phase 
)

Set the channel phase.

Parameters
dev- The device structure.
ch- Channel number (0-7).
phase- Phase calibration amount.
Returns
ret - return code. Example: -EIO - SPI communication error. -EINVAL - Invalid input. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_ch_range()

int32_t ad7606_set_ch_range ( struct ad7606_dev dev,
uint8_t  ch,
struct ad7606_range  range 
)

Set the channel operation range.

Parameters
dev- The device structure.
ch- Channel number (0-7).
range- Operation range.
Returns
ret - return code. Example: -EIO - SPI communication error. -EINVAL - Invalid input. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_config()

int32_t ad7606_set_config ( struct ad7606_dev dev,
struct ad7606_config  config 
)

Set the device config register.

Configuration structure affects the CONFIG register of the device.

Parameters
dev- The device structure.
config- Configuration structure.
Returns
ret - return code. Example: -EIO - SPI communication error. -EIO - GPIO not available. -EINVAL - Invalid input. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_digital_diag()

int32_t ad7606_set_digital_diag ( struct ad7606_dev dev,
struct ad7606_digital_diag  diag 
)

Set the device digital diagnostics configuration.

Digital diagnostics structure affects the DIGITAL_DIAG register of the device.

Parameters
dev- The device structure.
diag- Configuration structure.
Returns
ret - return code. Example: -EIO - SPI communication error. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_set_oversampling()

int32_t ad7606_set_oversampling ( struct ad7606_dev dev,
struct ad7606_oversampling  oversampling 
)

Set the oversampling ratio.

In hardware mode, it silently sets AD7606_OSR_64 if higher oversampling is provided.

Parameters
dev- The device structure.
oversampling- Oversampling settings.
Returns
ret - return code. Example: -EIO - SPI communication error. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ ad7606_spi_data_read()

int32_t ad7606_spi_data_read ( struct ad7606_dev dev,
uint32_t *  data 
)

Read conversion data.

This function performs CRC16 computation and checking if enabled in the device. If the status is enabled in device settings, each sample of data will contain status information in the lowest 8 bits.

The output buffer provided by the user should be as wide as to be able to contain 1 sample from each channel since this function reads conversion data across all channels.

Parameters
dev- The device structure.
data- Pointer to location of buffer where to store the data.
Returns
ret - return code. Example: -EIO - SPI communication error. -EBADMSG - CRC computation mismatch. -ENOTSUP - Device bits per sample not supported. 0 - No errors encountered.

◆ ad7606_spi_reg_read()

int32_t ad7606_spi_reg_read ( struct ad7606_dev dev,
uint8_t  reg_addr,
uint8_t *  reg_data 
)

Read a device register via SPI.

This function performs CRC8 computation and checking if enabled in the device.

Parameters
dev- The device structure.
reg_addr- Register address in device memory.
reg_data- Pointer to the location where to store the register value.
Returns
ret - return code. Example: -EIO - SPI communication error. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7606_spi_reg_write()

int32_t ad7606_spi_reg_write ( struct ad7606_dev dev,
uint8_t  reg_addr,
uint8_t  reg_data 
)

Write a device register via SPI.

This function performs CRC8 computation and checking if enabled in the device.

Parameters
dev- The device structure.
reg_addr- Register address in device memory.
reg_data- Value to write to register.
Returns
ret - return code. Example: -EIO - SPI communication error. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.
Here is the caller graph for this function:

◆ ad7606_spi_write_mask()

int32_t ad7606_spi_write_mask ( struct ad7606_dev dev,
uint32_t  addr,
uint32_t  mask,
uint32_t  val 
)

Write a device register via SPI with masking.

Parameters
dev- The device structure.
addr- Register address in device memory.
mask- Only bits set to 1 in mask will be modified.
val- Value to write to register.
Returns
ret - return code. Example: -EIO - SPI communication error. -ENOTSUP - Device not in software mode. -EBADMSG - CRC computation mismatch. 0 - No errors encountered.

◆ NO_OS_DECLARE_CRC16_TABLE()

NO_OS_DECLARE_CRC16_TABLE ( ad7606_crc16  )

◆ NO_OS_DECLARE_CRC8_TABLE()

NO_OS_DECLARE_CRC8_TABLE ( ad7606_crc8  )