no-OS
Macros | Functions
ad463x.c File Reference

Implementation of AD463x Driver. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_units.h"
#include "ad463x.h"
#include "no_os_print_log.h"
#include "no_os_alloc.h"
#include "no_os_spi.h"
Include dependency graph for ad463x.c:

Macros

#define AD463x_TEST_DATA   0xAA
 
#define ADAQ4224_GAIN_MAX_NANO   6670000000ULL
 

Functions

int32_t ad463x_spi_reg_read (struct ad463x_dev *dev, uint16_t reg_addr, uint8_t *reg_data)
 Read device register. More...
 
int32_t ad463x_spi_reg_write (struct ad463x_dev *dev, uint16_t reg_addr, uint8_t reg_data)
 Write device register. More...
 
int32_t ad463x_enter_config_mode (struct ad463x_dev *dev)
 Enter register configuration mode. More...
 
int32_t ad463x_spi_reg_read_masked (struct ad463x_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t *data)
 SPI read device register using a mask. More...
 
int32_t ad463x_spi_reg_write_masked (struct ad463x_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t data)
 SPI write device register using a mask. More...
 
int32_t ad463x_set_pwr_mode (struct ad463x_dev *dev, uint8_t mode)
 Set power mode. More...
 
int32_t ad463x_set_avg_frame_len (struct ad463x_dev *dev, uint8_t mode)
 Set average frame length. More...
 
int32_t ad463x_set_drive_strength (struct ad463x_dev *dev, uint8_t mode)
 Set drive strength. More...
 
int32_t ad463x_exit_reg_cfg_mode (struct ad463x_dev *dev)
 Exit register configuration mode. More...
 
int32_t ad463x_set_ch_gain (struct ad463x_dev *dev, uint8_t ch_idx, uint64_t gain)
 Set channel gain. More...
 
int32_t ad463x_set_ch_offset (struct ad463x_dev *dev, uint8_t ch_idx, uint32_t offset)
 Set channel offset. More...
 
int32_t ad463x_read_data_offload (struct ad463x_dev *dev, uint32_t *buf, uint16_t samples)
 Read from device. Enter register mode to read/write registers. More...
 
int32_t ad463x_read_data (struct ad463x_dev *dev, uint32_t *buf, uint16_t samples)
 Read from device. Enter register mode to read/write registers. More...
 
int32_t ad463x_init (struct ad463x_dev **device, struct ad463x_init_param *init_param)
 Initialize the device. More...
 
int32_t ad463x_calc_pgia_gain (int32_t gain_int, int32_t gain_fract, int32_t vref, int32_t precision, enum ad463x_pgia_gain *gain_idx)
 Calculate the PGIA gain. More...
 
int32_t ad463x_set_pgia_gain (struct ad463x_dev *dev, enum ad463x_pgia_gain gain_idx)
 Set the PGIA gain. More...
 
int32_t ad463x_remove (struct ad463x_dev *dev)
 Free the memory allocated by ad463x_init(). More...
 

Detailed Description

Implementation of AD463x Driver.

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

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

◆ AD463x_TEST_DATA

#define AD463x_TEST_DATA   0xAA

◆ ADAQ4224_GAIN_MAX_NANO

#define ADAQ4224_GAIN_MAX_NANO   6670000000ULL

Function Documentation

◆ ad463x_calc_pgia_gain()

int32_t ad463x_calc_pgia_gain ( int32_t  gain_int,
int32_t  gain_fract,
int32_t  vref,
int32_t  precision,
enum ad463x_pgia_gain gain_idx 
)

Calculate the PGIA gain.

Parameters
gain_int- Interger part of the gain.
gain_fract- Fractional part of the gain.
vref- Reference Voltage.
precision- Precision value shifter.
gain_idx- Index of gain resulting from the calculation.
Returns
Zero in case of success, negative number otherwise

◆ ad463x_enter_config_mode()

int32_t ad463x_enter_config_mode ( struct ad463x_dev dev)

Enter register configuration mode.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_exit_reg_cfg_mode()

int32_t ad463x_exit_reg_cfg_mode ( struct ad463x_dev dev)

Exit register configuration mode.

Parameters
dev- The device structure.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_init()

int32_t ad463x_init ( struct ad463x_dev **  device,
struct ad463x_init_param init_param 
)

Initialize the device.

Parameters
[out]device- The device structure.
[in]init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, -1 otherwise.

Perform Hardware Reset and configure pins

Here is the caller graph for this function:

◆ ad463x_read_data()

int32_t ad463x_read_data ( struct ad463x_dev dev,
uint32_t *  buf,
uint16_t  samples 
)

Read from device. Enter register mode to read/write registers.

Parameters
dev- ad469x_dev device handler.
buf- data buffer.
samples- sample number.
Returns
0 in case of success, negative otherwise.

◆ ad463x_read_data_offload()

int32_t ad463x_read_data_offload ( struct ad463x_dev dev,
uint32_t *  buf,
uint16_t  samples 
)

Read from device. Enter register mode to read/write registers.

Parameters
[in]dev- ad469x_dev device handler.
[out]buf- data buffer.
[in]samples- sample number.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad463x_remove()

int32_t ad463x_remove ( struct ad463x_dev dev)

Free the memory allocated by ad463x_init().

Parameters
[in]dev- Pointer to the device handler.
Returns
0 in case of success, -1 otherwise

◆ ad463x_set_avg_frame_len()

int32_t ad463x_set_avg_frame_len ( struct ad463x_dev dev,
uint8_t  mode 
)

Set average frame length.

Parameters
dev- The device structure.
mode- Average filter frame length mode.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_set_ch_gain()

int32_t ad463x_set_ch_gain ( struct ad463x_dev dev,
uint8_t  ch_idx,
uint64_t  gain 
)

Set channel gain.

Parameters
dev- The device structure.
ch_idx- The channel index.
gain- The gain value scaled by 10000. Example: to set gain 1.5, use 150000
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_set_ch_offset()

int32_t ad463x_set_ch_offset ( struct ad463x_dev dev,
uint8_t  ch_idx,
uint32_t  offset 
)

Set channel offset.

Parameters
dev- The device structure.
ch_idx- The channel index.
offset- The channel offset.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_set_drive_strength()

int32_t ad463x_set_drive_strength ( struct ad463x_dev dev,
uint8_t  mode 
)

Set drive strength.

Parameters
dev- The device structure.
mode- The register data.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_set_pgia_gain()

int32_t ad463x_set_pgia_gain ( struct ad463x_dev dev,
enum ad463x_pgia_gain  gain_idx 
)

Set the PGIA gain.

Parameters
dev- Pointer to the device handler.
gain_idx- Gain control index.
Returns
0 in case of success, -1 otherwise

Check if gain available in the ADC

Check if gain gain_idx is in the valid range

update gain index value in the device handler

Set A0 and A1 pins according to gain index value

◆ ad463x_set_pwr_mode()

int32_t ad463x_set_pwr_mode ( struct ad463x_dev dev,
uint8_t  mode 
)

Set power mode.

Parameters
dev- The device structure.
mode- The power mode.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_spi_reg_read()

int32_t ad463x_spi_reg_read ( struct ad463x_dev dev,
uint16_t  reg_addr,
uint8_t *  reg_data 
)

Read device register.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The data read from the register.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad463x_spi_reg_read_masked()

int32_t ad463x_spi_reg_read_masked ( struct ad463x_dev dev,
uint16_t  reg_addr,
uint8_t  mask,
uint8_t *  data 
)

SPI read device register using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The data read from the register.
Returns
0 in case of success, negative error code otherwise.

◆ ad463x_spi_reg_write()

int32_t ad463x_spi_reg_write ( struct ad463x_dev dev,
uint16_t  reg_addr,
uint8_t  reg_data 
)

Write device register.

Parameters
dev- The device structure.
reg_addr- The register address.
reg_data- The register data.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad463x_spi_reg_write_masked()

int32_t ad463x_spi_reg_write_masked ( struct ad463x_dev dev,
uint16_t  reg_addr,
uint8_t  mask,
uint8_t  data 
)

SPI write device register using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
mask- The mask.
data- The register data.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function: