no-OS
Classes | Macros | Functions | Variables
ad469x.c File Reference

Implementation of ad69x Driver. More...

#include <string.h>
#include "stdio.h"
#include "stdlib.h"
#include "ad469x.h"
#include "spi_engine.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_alloc.h"
Include dependency graph for ad469x.c:

Classes

struct  ad469x_device_info
 

Macros

#define AD469x_TEST_DATA   0xEA
 

Functions

int32_t ad469x_spi_reg_read (struct ad469x_dev *dev, uint16_t reg_addr, uint8_t *reg_data)
 
int32_t ad469x_spi_reg_write (struct ad469x_dev *dev, uint16_t reg_addr, uint8_t reg_data)
 
int32_t ad469x_spi_read_mask (struct ad469x_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t *data)
 
int32_t ad469x_spi_write_mask (struct ad469x_dev *dev, uint16_t reg_addr, uint8_t mask, uint8_t data)
 
int32_t ad469x_set_reg_access_mode (struct ad469x_dev *dev, enum ad469x_reg_access access)
 Configure register access mode. More...
 
int32_t ad469x_get_num_channels (struct ad469x_dev *dev, uint8_t *num_channels)
 
bool ad469x_is_temp_channel (struct ad469x_dev *dev, uint8_t channel)
 
int32_t ad469x_adv_seq_osr (struct ad469x_dev *dev, uint16_t ch, enum ad469x_osr_ratios ratio)
 Configure over sampling ratio in advanced sequencer mode. More...
 
int32_t ad469x_std_seq_osr (struct ad469x_dev *dev, enum ad469x_osr_ratios ratio)
 Configure over sampling ratio in standard sequencer mode. More...
 
int32_t ad469x_std_pin_pairing (struct ad469x_dev *dev, enum ad469x_pin_pairing pin_pair)
 Configure the pin pairing option in standard sequencer mode. More...
 
int32_t ad469x_set_channel_sequence (struct ad469x_dev *dev, enum ad469x_channel_sequencing seq)
 Set channel sequence. More...
 
int32_t ad469x_adv_sequence_set_num_slots (struct ad469x_dev *dev, uint8_t num_slots)
 Configure advanced sequencer number of slots, temp channel not included. More...
 
int32_t ad469x_adv_sequence_set_slot (struct ad469x_dev *dev, uint8_t slot, uint8_t channel)
 Advanced sequencer, assign channel to a slot. More...
 
int32_t ad469x_std_sequence_ch (struct ad469x_dev *dev, uint16_t ch_mask)
 Configure standard sequencer channels. More...
 
int32_t ad469x_sequence_enable_temp (struct ad469x_dev *dev)
 Enable temperature read at the end of the sequence, for standard and advanced sequencer. More...
 
int32_t ad469x_sequence_disable_temp (struct ad469x_dev *dev)
 Disable temperature read at the end of the sequence, for standard and advanced sequencer. More...
 
int32_t ad469x_set_busy (struct ad469x_dev *dev, enum ad469x_busy_gp_sel gp_sel)
 Configure converter busy indicator to the output of the specified port. More...
 
int32_t ad469x_enter_conversion_mode (struct ad469x_dev *dev)
 Enter conversion mode. To exit conversion mode send a 5 bit conversion mode command AD469x_CMD_REG_CONFIG_MODE. More...
 
int32_t ad469x_exit_conversion_mode (struct ad469x_dev *dev)
 Exit conversion mode. Enter register mode to read/write registers. More...
 
int32_t ad469x_seq_read_data (struct ad469x_dev *dev, uint32_t *buf, uint32_t samples)
 Read from device when converter has the channel sequencer activated. Enter register mode to read/write registers. More...
 
int32_t ad469x_read_data (struct ad469x_dev *dev, uint8_t channel, uint32_t *buf, uint16_t samples)
 Read from device. Enter register mode to read/write registers. More...
 
int32_t ad469x_reset_dev (struct ad469x_dev *dev)
 Resets the ad469x device. More...
 
int32_t ad469x_get_reference (struct ad469x_dev *device, enum ad469x_ref_set *ref_set)
 Get the value of reference. More...
 
int32_t ad469x_set_reference (struct ad469x_dev *device, enum ad469x_ref_set ref_set)
 Set the value of reference. More...
 
int32_t ad469x_config (struct ad469x_dev *dev, struct ad469x_init_param *config_desc)
 
int32_t ad469x_config_extended (struct ad469x_dev *dev, struct ad469x_init_param *config_desc)
 
int32_t ad469x_configure_ain_high_z (struct ad469x_dev *dev, uint8_t ch, enum ad469x_ain_high_z status)
 Configure analog input high Z mode. More...
 
int32_t ad469x_get_ain_high_z_status (struct ad469x_dev *dev, uint8_t ch, enum ad469x_ain_high_z *status)
 Get the status of analog input high Z mode. More...
 
int32_t ad469x_init (struct ad469x_dev **device, struct ad469x_init_param *init_param)
 
int32_t ad469x_remove (struct ad469x_dev *dev)
 Free the memory allocated by ad469x_init(). More...
 

Variables

const uint8_t ad469x_device_resol []
 Device resolution. More...
 
struct ad469x_device_info dev_info []
 

Detailed Description

Implementation of ad69x Driver.

Author
Cristian Pop (crist.nosp@m.ian..nosp@m.pop@a.nosp@m.nalo.nosp@m.g.com)

Copyright 2020-22(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

◆ AD469x_TEST_DATA

#define AD469x_TEST_DATA   0xEA

Function Documentation

◆ ad469x_adv_seq_osr()

int32_t ad469x_adv_seq_osr ( struct ad469x_dev dev,
uint16_t  ch,
enum ad469x_osr_ratios  ratio 
)

Configure over sampling ratio in advanced sequencer mode.

Parameters
[in]dev- ad469x_dev device handler.
[in]ch- Channel to configure.
[in]ratio- OSR ratio.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_adv_sequence_set_num_slots()

int32_t ad469x_adv_sequence_set_num_slots ( struct ad469x_dev dev,
uint8_t  num_slots 
)

Configure advanced sequencer number of slots, temp channel not included.

Parameters
[in]dev- ad469x_dev device handler.
[in]num_slots- Number of slots, max value = 0x7f
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_adv_sequence_set_slot()

int32_t ad469x_adv_sequence_set_slot ( struct ad469x_dev dev,
uint8_t  slot,
uint8_t  channel 
)

Advanced sequencer, assign channel to a slot.

Parameters
[in]dev- ad469x_dev device handler.
[in]slot- Slot number [0x00, 0x7f]
[in]channel- Assigned channel [0x00, 0x0f].
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_config()

int32_t ad469x_config ( struct ad469x_dev dev,
struct ad469x_init_param config_desc 
)

Configure the device with initial parameters.

Parameters
[in,out]dev- The device structure.
[in]config_desc- Pointer to structure containing configuration parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad469x_config_extended()

int32_t ad469x_config_extended ( struct ad469x_dev dev,
struct ad469x_init_param config_desc 
)

Configure the device with default parameters and enter conversion mode this adds default ch/slot assigments based on sequece mode.

Parameters
[in,out]dev- The device structure.
[in]config_desc- Pointer to structure containing configuration parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad469x_configure_ain_high_z()

int32_t ad469x_configure_ain_high_z ( struct ad469x_dev dev,
uint8_t  ch,
enum ad469x_ain_high_z  status 
)

Configure analog input high Z mode.

Parameters
devThe device structure
chChannel ID
statusStatus of analog input high Z bit
Returns
0 in case of success, negative error code otherwise

◆ ad469x_enter_conversion_mode()

int32_t ad469x_enter_conversion_mode ( struct ad469x_dev dev)

Enter conversion mode. To exit conversion mode send a 5 bit conversion mode command AD469x_CMD_REG_CONFIG_MODE.

Parameters
[in]dev- ad469x_dev device handler.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_exit_conversion_mode()

int32_t ad469x_exit_conversion_mode ( struct ad469x_dev dev)

Exit conversion mode. Enter register mode to read/write registers.

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

◆ ad469x_get_ain_high_z_status()

int32_t ad469x_get_ain_high_z_status ( struct ad469x_dev dev,
uint8_t  ch,
enum ad469x_ain_high_z status 
)

Get the status of analog input high Z mode.

Parameters
devThe device structure
chChannel ID
statusStatus of analog input high Z bit
Returns
0 in case of success, negative error code otherwise

◆ ad469x_get_num_channels()

int32_t ad469x_get_num_channels ( struct ad469x_dev dev,
uint8_t *  num_channels 
)
Here is the caller graph for this function:

◆ ad469x_get_reference()

int32_t ad469x_get_reference ( struct ad469x_dev device,
enum ad469x_ref_set ref_set 
)

Get the value of reference.

Parameters
deviceAD469x Device instance.
ref_setValue of VREF_SET
Returns
0 in case of success, negative error code otherwise.

◆ ad469x_init()

int32_t ad469x_init ( struct ad469x_dev **  device,
struct ad469x_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.
Here is the caller graph for this function:

◆ ad469x_is_temp_channel()

bool ad469x_is_temp_channel ( struct ad469x_dev dev,
uint8_t  channel 
)
Here is the caller graph for this function:

◆ ad469x_read_data()

int32_t ad469x_read_data ( struct ad469x_dev dev,
uint8_t  channel,
uint32_t *  buf,
uint16_t  samples 
)

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

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

◆ ad469x_remove()

int32_t ad469x_remove ( struct ad469x_dev dev)

Free the memory allocated by ad469x_init().

Parameters
[in]dev- Pointer to the device handler.
Returns
0 in case of success, -1 otherwise
Here is the caller graph for this function:

◆ ad469x_reset_dev()

int32_t ad469x_reset_dev ( struct ad469x_dev dev)

Resets the ad469x device.

Parameters
[in]dev- ad469x_dev device handler.
Returns
0 in case of success, negative error code otherwise.

◆ ad469x_seq_read_data()

int32_t ad469x_seq_read_data ( struct ad469x_dev dev,
uint32_t *  buf,
uint32_t  samples 
)

Read from device when converter has the channel sequencer activated. Enter register mode to read/write registers.

Parameters
[in]dev- ad469x_dev device handler.
[out]buf- data buffer.
[in]samples- Number of samples per channel. For example, if with ad469x_std_sequence_ch 2 channel where activated, buf will be filled with 10 samples for each of them. If temp is enable, the there will be an other 10 samples for temperature
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_sequence_disable_temp()

int32_t ad469x_sequence_disable_temp ( struct ad469x_dev dev)

Disable temperature read at the end of the sequence, for standard and advanced sequencer.

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

◆ ad469x_sequence_enable_temp()

int32_t ad469x_sequence_enable_temp ( struct ad469x_dev dev)

Enable temperature read at the end of the sequence, for standard and advanced sequencer.

Parameters
[in]dev- ad469x_dev device handler.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_set_busy()

int32_t ad469x_set_busy ( struct ad469x_dev dev,
enum ad469x_busy_gp_sel  gp_sel 
)

Configure converter busy indicator to the output of the specified port.

Parameters
[in]dev- ad469x_dev device handler.
[in]gp_sel- Port.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_set_channel_sequence()

int32_t ad469x_set_channel_sequence ( struct ad469x_dev dev,
enum ad469x_channel_sequencing  seq 
)

Set channel sequence.

Parameters
[in]dev- ad469x_dev device handler.
[in]seq- Channel sequence.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_set_reference()

int32_t ad469x_set_reference ( struct ad469x_dev device,
enum ad469x_ref_set  ref_set 
)

Set the value of reference.

Parameters
deviceAD469x Device instance.
ref_setValue of VREF_SET
Returns
0 in case of success, negative error code otherwise.

◆ ad469x_set_reg_access_mode()

int32_t ad469x_set_reg_access_mode ( struct ad469x_dev dev,
enum ad469x_reg_access  access 
)

Configure register access mode.

Parameters
[in]dev- ad469x_dev device handler.
[in]access- Access mode
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_spi_read_mask()

int32_t ad469x_spi_read_mask ( struct ad469x_dev dev,
uint16_t  reg_addr,
uint8_t  mask,
uint8_t *  data 
)

SPI read from device 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.

◆ ad469x_spi_reg_read()

int32_t ad469x_spi_reg_read ( struct ad469x_dev dev,
uint16_t  reg_addr,
uint8_t *  reg_data 
)

Read from device.

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:

◆ ad469x_spi_reg_write()

int32_t ad469x_spi_reg_write ( struct ad469x_dev dev,
uint16_t  reg_addr,
uint8_t  reg_data 
)

Write to device.

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

◆ ad469x_spi_write_mask()

int32_t ad469x_spi_write_mask ( struct ad469x_dev dev,
uint16_t  reg_addr,
uint8_t  mask,
uint8_t  data 
)

SPI write to device 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:

◆ ad469x_std_pin_pairing()

int32_t ad469x_std_pin_pairing ( struct ad469x_dev dev,
enum ad469x_pin_pairing  pin_pair 
)

Configure the pin pairing option in standard sequencer mode.

Parameters
[in]dev- ad469x_dev device handler.
[in]pin_pair- Pin pairing selection.
Returns
0 in case of success, negative error code otherwise.
Note
In standard sequencer the pin pair option is common for all channels.
Here is the caller graph for this function:

◆ ad469x_std_seq_osr()

int32_t ad469x_std_seq_osr ( struct ad469x_dev dev,
enum ad469x_osr_ratios  ratio 
)

Configure over sampling ratio in standard sequencer mode.

Parameters
[in]dev- ad469x_dev device handler.
[in]ratio- OSR ratio.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

◆ ad469x_std_sequence_ch()

int32_t ad469x_std_sequence_ch ( struct ad469x_dev dev,
uint16_t  ch_mask 
)

Configure standard sequencer channels.

Parameters
[in]dev- ad469x_dev device handler.
[in]ch_mask- Extra channels to activate.
Returns
0 in case of success, -1 otherwise.
Here is the caller graph for this function:

Variable Documentation

◆ ad469x_device_resol

const uint8_t ad469x_device_resol[]
Initial value:
= {
[AD469x_OSR_1] = 16,
[AD469x_OSR_4] = 17,
[AD469x_OSR_16] = 18,
}

Device resolution.

◆ dev_info

struct ad469x_device_info dev_info[]
Initial value:
= {
[ID_AD4695] = {.max_data_ch = 16, .max_rate_ksps = 500},
[ID_AD4696] = {.max_data_ch = 16, .max_rate_ksps = 1000},
[ID_AD4697] = {.max_data_ch = 8, .max_rate_ksps = 500},
[ID_AD4698] = {.max_data_ch = 8, .max_rate_ksps = 1000},
}
ID_AD4696
@ ID_AD4696
Definition: ad469x.h:203
ID_AD4697
@ ID_AD4697
Definition: ad469x.h:204
ID_AD4698
@ ID_AD4698
Definition: ad469x.h:205
ID_AD4695
@ ID_AD4695
Definition: ad469x.h:202
AD469x_OSR_64
@ AD469x_OSR_64
Definition: ad469x.h:216
AD469x_OSR_16
@ AD469x_OSR_16
Definition: ad469x.h:215
AD469x_OSR_4
@ AD469x_OSR_4
Definition: ad469x.h:214
AD469x_OSR_1
@ AD469x_OSR_1
Definition: ad469x.h:213