no-OS
Loading...
Searching...
No Matches
ad738x.c File Reference

Implementation of AD738x Driver. More...

#include "stdio.h"
#include "stdlib.h"
#include "stdbool.h"
#include "spi_engine.h"
#include "ad738x.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_alloc.h"
#include "no_os_pwm.h"
Include dependency graph for ad738x.c:

Functions

int32_t ad738x_spi_reg_read (struct ad738x_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
 
int32_t ad738x_spi_reg_write (struct ad738x_dev *dev, uint8_t reg_addr, uint16_t reg_data)
 
int32_t ad738x_spi_write_mask (struct ad738x_dev *dev, uint8_t reg_addr, uint32_t mask, uint16_t data)
 
int32_t ad738x_set_conversion_mode (struct ad738x_dev *dev, enum ad738x_conv_mode mode)
 
int32_t ad738x_ch_seq_sel (struct ad738x_dev *dev, enum ad738x_ch_seq_sel ch)
 
int32_t ad738x_reset (struct ad738x_dev *dev, enum ad738x_reset_type reset)
 
int32_t ad738x_oversampling_config (struct ad738x_dev *dev, enum ad738x_os_mode os_mode, enum ad738x_os_ratio os_ratio, enum ad738x_resolution res)
 
int32_t ad738x_power_down_mode (struct ad738x_dev *dev, enum ad738x_pwd_mode pmode)
 
int32_t ad738x_reference_sel (struct ad738x_dev *dev, enum ad738x_ref_sel ref_sel)
 
int32_t ad738x_spi_single_conversion (struct ad738x_dev *dev, uint32_t *adc_data)
 
int32_t ad738x_read_data (struct ad738x_dev *dev, uint32_t *buf, uint16_t samples)
 Read from device. Enter register mode to read/write registers.
 
int32_t ad738x_init (struct ad738x_dev **device, struct ad738x_init_param *init_param)
 
int32_t ad738x_remove (struct ad738x_dev *dev)
 Free the resources allocated by ad738x_init().
 

Detailed Description

Implementation of AD738x Driver.

Author
SPopa (stefa.nosp@m.n.po.nosp@m.pa@an.nosp@m.alog.nosp@m..com)
Antoniu Miclaus (anton.nosp@m.iu.m.nosp@m.iclau.nosp@m.s@an.nosp@m.alog..nosp@m.com)
Vilmos-Csaba Jozsa (vilmo.nosp@m.scsa.nosp@m.ba.jo.nosp@m.zsa@.nosp@m.analo.nosp@m.g.co.nosp@m.m)

Copyright 2020-2026(c) Analog Devices, Inc.

SPDX-License-Identifier: BSD-3-Clause

Function Documentation

◆ ad738x_ch_seq_sel()

int32_t ad738x_ch_seq_sel ( struct ad738x_dev * dev,
enum ad738x_ch_seq_sel ch )

Mapping (enum ad738x_ch_seq_sel): FIRST_FOUR -> 0b00 (CH=0, SEQ=0): Channel 0 pair (AINA0/AINB0) ALL -> 0b01 (CH=0, SEQ=1): sequencer enabled, cycles AINx0, AINx1 SECOND_FOUR -> 0b10 (CH=1, SEQ=0): Channel 1 pair (AINA1/AINB1)

Parameters
dev- The device structure.
ch- Channel/sequencer select configuration.
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_init()

int32_t ad738x_init ( struct ad738x_dev ** device,
struct ad738x_init_param * init_param )

Initialize the device.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_oversampling_config()

int32_t ad738x_oversampling_config ( struct ad738x_dev * dev,
enum ad738x_os_mode os_mode,
enum ad738x_os_ratio os_ratio,
enum ad738x_resolution res )

Sets the oversampling mode in the device (os_mode) Sets the oversampling ratio (osr) Sets the size of the conversion result data (res)

Parameters
dev- The device structure.
os_mode- accepted values: NORMAL_OS_MODE ROLLING_OS_MODE
os_ratio- accepted values: OSR_DISABLED OSR_X2 OSR_X4 OSR_X8 OSR_X16 OSR_X32
res- accepted values: RES_16_BIT RES_18_BIT
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_power_down_mode()

int32_t ad738x_power_down_mode ( struct ad738x_dev * dev,
enum ad738x_pwd_mode pmode )

Device power down.

Parameters
dev- The device structure.
pmode- Type of power mode Accepted values: NORMAL_PWDM FULL_PWDM
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_read_data()

int32_t ad738x_read_data ( struct ad738x_dev * dev,
uint32_t * buf,
uint16_t samples )

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

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

◆ ad738x_reference_sel()

int32_t ad738x_reference_sel ( struct ad738x_dev * dev,
enum ad738x_ref_sel ref_sel )

Enable internal or external reference

Parameters
dev- The device structure.
ref_sel- Type of reference Accepted values: INT_REF EXT_REF
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_remove()

int32_t ad738x_remove ( struct ad738x_dev * dev)

Free the resources allocated by ad738x_init().

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

◆ ad738x_reset()

int32_t ad738x_reset ( struct ad738x_dev * dev,
enum ad738x_reset_type reset )

Device reset over SPI.

Parameters
dev- The device structure.
reset- Type of reset. Accepted values: SOFT_RESET HARD_RESET
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_set_conversion_mode()

int32_t ad738x_set_conversion_mode ( struct ad738x_dev * dev,
enum ad738x_conv_mode mode )

Select if ADC A and ADC B output on both SDOA and SDOB lines (two wire mode) or only on on the SDOA line

Parameters
dev- The device structure.
mode- The conversion output mode. Accepted values: TWO_WIRE_MODE ONE_WIRE_MODE
Returns
0 in case of success, negative error code otherwise.

◆ ad738x_spi_reg_read()

int32_t ad738x_spi_reg_read ( struct ad738x_dev * dev,
uint8_t reg_addr,
uint16_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.

◆ ad738x_spi_reg_write()

int32_t ad738x_spi_reg_write ( struct ad738x_dev * dev,
uint8_t reg_addr,
uint16_t reg_data )

Write to 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.

◆ ad738x_spi_single_conversion()

int32_t ad738x_spi_single_conversion ( struct ad738x_dev * dev,
uint32_t * adc_data )

Read conversion result from device.

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

◆ ad738x_spi_write_mask()

int32_t ad738x_spi_write_mask ( struct ad738x_dev * dev,
uint8_t reg_addr,
uint32_t mask,
uint16_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.