no-OS
|
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"
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... | |
Implementation of AD463x Driver.
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:
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.
#define AD463x_TEST_DATA 0xAA |
#define ADAQ4224_GAIN_MAX_NANO 6670000000ULL |
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.
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. |
int32_t ad463x_enter_config_mode | ( | struct ad463x_dev * | dev | ) |
Enter register configuration mode.
dev | - The device structure. |
int32_t ad463x_exit_reg_cfg_mode | ( | struct ad463x_dev * | dev | ) |
Exit register configuration mode.
dev | - The device structure. |
int32_t ad463x_init | ( | struct ad463x_dev ** | device, |
struct ad463x_init_param * | init_param | ||
) |
Initialize the device.
[out] | device | - The device structure. |
[in] | init_param | - The structure that contains the device initial parameters. |
Perform Hardware Reset and configure pins
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.
dev | - ad469x_dev device handler. |
buf | - data buffer. |
samples | - sample number. |
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.
[in] | dev | - ad469x_dev device handler. |
[out] | buf | - data buffer. |
[in] | samples | - sample number. |
int32_t ad463x_remove | ( | struct ad463x_dev * | dev | ) |
Free the memory allocated by ad463x_init().
[in] | dev | - Pointer to the device handler. |
int32_t ad463x_set_avg_frame_len | ( | struct ad463x_dev * | dev, |
uint8_t | mode | ||
) |
Set average frame length.
dev | - The device structure. |
mode | - Average filter frame length mode. |
int32_t ad463x_set_ch_gain | ( | struct ad463x_dev * | dev, |
uint8_t | ch_idx, | ||
uint64_t | gain | ||
) |
Set channel gain.
dev | - The device structure. |
ch_idx | - The channel index. |
gain | - The gain value scaled by 10000. Example: to set gain 1.5, use 150000 |
int32_t ad463x_set_ch_offset | ( | struct ad463x_dev * | dev, |
uint8_t | ch_idx, | ||
uint32_t | offset | ||
) |
Set channel offset.
dev | - The device structure. |
ch_idx | - The channel index. |
offset | - The channel offset. |
int32_t ad463x_set_drive_strength | ( | struct ad463x_dev * | dev, |
uint8_t | mode | ||
) |
Set drive strength.
dev | - The device structure. |
mode | - The register data. |
int32_t ad463x_set_pgia_gain | ( | struct ad463x_dev * | dev, |
enum ad463x_pgia_gain | gain_idx | ||
) |
Set the PGIA gain.
dev | - Pointer to the device handler. |
gain_idx | - Gain control index. |
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
int32_t ad463x_set_pwr_mode | ( | struct ad463x_dev * | dev, |
uint8_t | mode | ||
) |
Set power mode.
dev | - The device structure. |
mode | - The power mode. |
int32_t ad463x_spi_reg_read | ( | struct ad463x_dev * | dev, |
uint16_t | reg_addr, | ||
uint8_t * | reg_data | ||
) |
Read device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The data read from the register. |
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.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
data | - The data read from the register. |
int32_t ad463x_spi_reg_write | ( | struct ad463x_dev * | dev, |
uint16_t | reg_addr, | ||
uint8_t | reg_data | ||
) |
Write device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
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.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
data | - The register data. |