no-OS
Loading...
Searching...
No Matches
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.
 
int32_t ad463x_spi_reg_write (struct ad463x_dev *dev, uint16_t reg_addr, uint8_t reg_data)
 Write device register.
 
int32_t ad463x_enter_config_mode (struct ad463x_dev *dev)
 Enter register configuration mode.
 
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.
 
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.
 
int32_t ad463x_set_pwr_mode (struct ad463x_dev *dev, uint8_t mode)
 Set power mode.
 
int32_t ad463x_set_avg_frame_len (struct ad463x_dev *dev, uint8_t mode)
 Set average frame length.
 
int32_t ad463x_set_drive_strength (struct ad463x_dev *dev, uint8_t mode)
 Set drive strength.
 
int32_t ad463x_exit_reg_cfg_mode (struct ad463x_dev *dev)
 Exit register configuration mode.
 
int32_t ad463x_set_ch_gain (struct ad463x_dev *dev, uint8_t ch_idx, uint64_t gain)
 Set channel gain.
 
int32_t ad463x_set_ch_offset (struct ad463x_dev *dev, uint8_t ch_idx, uint32_t offset)
 Set channel offset.
 
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.
 
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.
 
int32_t ad463x_init (struct ad463x_dev **device, struct ad463x_init_param *init_param)
 Initialize the device.
 
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.
 
int32_t ad463x_set_pgia_gain (struct ad463x_dev *dev, enum ad463x_pgia_gain gain_idx)
 Set the PGIA gain.
 
int32_t ad463x_remove (struct ad463x_dev *dev)
 Free the memory allocated by ad463x_init().
 

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.

SPDX-License-Identifier: BSD-3-Clause

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

◆ 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.

◆ 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.

◆ 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.

◆ 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.