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

Header file for AD738x Driver. More...

#include "no_os_util.h"
#include "no_os_spi.h"
Include dependency graph for ad738x.h:

Classes

struct  ad738x_dev
 
struct  ad738x_init_param
 

Macros

#define AD738X_REG_NOP   0x00
 
#define AD738X_REG_CONFIG1   0x01
 
#define AD738X_REG_CONFIG2   0x02
 
#define AD738X_REG_ALERT   0x03
 
#define AD738X_REG_ALERT_LOW_TH   0x04
 
#define AD738X_REG_ALERT_HIGH_TH   0x05
 
#define AD738X_CONFIG1_CH_SEQ_MSK   NO_OS_GENMASK(11, 10)
 
#define AD738X_CONFIG1_CH_SEQ(x)
 
#define AD738X_CONFIG1_OS_MODE_MSK   NO_OS_BIT(9)
 
#define AD738X_CONFIG1_OS_MODE(x)
 
#define AD738X_CONFIG1_OSR_MSK   NO_OS_GENMASK(8, 6)
 
#define AD738X_CONFIG1_OSR(x)
 
#define AD738X_CONFIG1_CRC_W_MSK   NO_OS_BIT(5)
 
#define AD738X_CONFIG1_CRC_W(x)
 
#define AD738X_CONFIG1_CRC_R_MSK   NO_OS_BIT(4)
 
#define AD738X_CONFIG1_CRC_R(x)
 
#define AD738X_CONFIG1_ALERTEN_MSK   NO_OS_BIT(3)
 
#define AD738X_CONFIG1_ALERTEN(x)
 
#define AD738X_CONFIG1_RES_MSK   NO_OS_BIT(2)
 
#define AD738X_CONFIG1_RES(x)
 
#define AD738X_CONFIG1_REFSEL_MSK   NO_OS_BIT(1)
 
#define AD738X_CONFIG1_REFSEL(x)
 
#define AD738X_CONFIG1_PMODE_MSK   NO_OS_BIT(0)
 
#define AD738X_CONFIG1_PMODE(x)
 
#define AD738X_CONFIG2_SDO2_MSK   NO_OS_BIT(8)
 
#define AD738X_CONFIG2_SDO2(x)
 
#define AD738X_CONFIG2_SDO4_MSK   NO_OS_GENMASK(9, 8)
 
#define AD738X_CONFIG2_SDO4(x)
 
#define AD738X_CONFIG2_RESET_MSK   NO_OS_GENMASK(7, 0)
 
#define AD738X_CONFIG2_RESET(x)
 
#define AD738X_ALERT_LOW_MSK   NO_OS_GENMASK(11, 0)
 
#define AD738X_ALERT_LOW(x)
 
#define AD738X_ALERT_HIGH_MSK   NO_OS_GENMASK(11, 0)
 
#define AD738X_ALERT_HIGH(x)
 
#define AD738X_REG_WRITE(x)
 
#define AD738X_REG_READ(x)
 
#define AD738X_FLAG_STANDARD_SPI_DMA   NO_OS_BIT(0)
 
#define AD738X_FLAG_OFFLOAD   NO_OS_BIT(1)
 
#define AD738X_FLAG_NO_PWM   NO_OS_BIT(2)
 

Enumerations

enum  ad738x_conv_mode {
  TWO_WIRE_MODE ,
  ONE_WIRE_MODE ,
  FOUR_WIRE_MODE
}
 
enum  ad738x_ch_seq_sel {
  FIRST_FOUR ,
  ALL ,
  SECOND_FOUR
}
 
enum  ad738x_os_mode {
  NORMAL_OS_MODE ,
  ROLLING_OS_MODE
}
 
enum  ad738x_os_ratio {
  OSR_DISABLED ,
  OSR_X2 ,
  OSR_X4 ,
  OSR_X8 ,
  OSR_X16 ,
  OSR_X32
}
 
enum  ad738x_resolution {
  RES_16_BIT ,
  RES_18_BIT
}
 
enum  ad738x_reset_type {
  SOFT_RESET ,
  HARD_RESET
}
 
enum  ad738x_pwd_mode {
  NORMAL_PWDM ,
  FULL_PWDM
}
 
enum  ad738x_ref_sel {
  INT_REF ,
  EXT_REF
}
 

Functions

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().
 
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_single_conversion (struct ad738x_dev *dev, uint32_t *adc_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_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_ch_seq_sel (struct ad738x_dev *dev, enum ad738x_ch_seq_sel ch_seq_sel)
 
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.
 

Detailed Description

Header file for 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

Macro Definition Documentation

◆ AD738X_ALERT_HIGH

#define AD738X_ALERT_HIGH ( x)
Value:
(((x) & 0xFFF) << 0)

◆ AD738X_ALERT_HIGH_MSK

#define AD738X_ALERT_HIGH_MSK   NO_OS_GENMASK(11, 0)

◆ AD738X_ALERT_LOW

#define AD738X_ALERT_LOW ( x)
Value:
(((x) & 0xFFF) << 0)

◆ AD738X_ALERT_LOW_MSK

#define AD738X_ALERT_LOW_MSK   NO_OS_GENMASK(11, 0)

◆ AD738X_CONFIG1_ALERTEN

#define AD738X_CONFIG1_ALERTEN ( x)
Value:
(((x) & 0x1) << 3)

◆ AD738X_CONFIG1_ALERTEN_MSK

#define AD738X_CONFIG1_ALERTEN_MSK   NO_OS_BIT(3)

◆ AD738X_CONFIG1_CH_SEQ

#define AD738X_CONFIG1_CH_SEQ ( x)
Value:
(((x) & 0x3) << 10)

◆ AD738X_CONFIG1_CH_SEQ_MSK

#define AD738X_CONFIG1_CH_SEQ_MSK   NO_OS_GENMASK(11, 10)

◆ AD738X_CONFIG1_CRC_R

#define AD738X_CONFIG1_CRC_R ( x)
Value:
(((x) & 0x1) << 4)

◆ AD738X_CONFIG1_CRC_R_MSK

#define AD738X_CONFIG1_CRC_R_MSK   NO_OS_BIT(4)

◆ AD738X_CONFIG1_CRC_W

#define AD738X_CONFIG1_CRC_W ( x)
Value:
(((x) & 0x1) << 5)

◆ AD738X_CONFIG1_CRC_W_MSK

#define AD738X_CONFIG1_CRC_W_MSK   NO_OS_BIT(5)

◆ AD738X_CONFIG1_OS_MODE

#define AD738X_CONFIG1_OS_MODE ( x)
Value:
(((x) & 0x1) << 9)

◆ AD738X_CONFIG1_OS_MODE_MSK

#define AD738X_CONFIG1_OS_MODE_MSK   NO_OS_BIT(9)

◆ AD738X_CONFIG1_OSR

#define AD738X_CONFIG1_OSR ( x)
Value:
(((x) & 0x7) << 6)

◆ AD738X_CONFIG1_OSR_MSK

#define AD738X_CONFIG1_OSR_MSK   NO_OS_GENMASK(8, 6)

◆ AD738X_CONFIG1_PMODE

#define AD738X_CONFIG1_PMODE ( x)
Value:
(((x) & 0x1) << 0)

◆ AD738X_CONFIG1_PMODE_MSK

#define AD738X_CONFIG1_PMODE_MSK   NO_OS_BIT(0)

◆ AD738X_CONFIG1_REFSEL

#define AD738X_CONFIG1_REFSEL ( x)
Value:
(((x) & 0x1) << 1)

◆ AD738X_CONFIG1_REFSEL_MSK

#define AD738X_CONFIG1_REFSEL_MSK   NO_OS_BIT(1)

◆ AD738X_CONFIG1_RES

#define AD738X_CONFIG1_RES ( x)
Value:
(((x) & 0x1) << 2)

◆ AD738X_CONFIG1_RES_MSK

#define AD738X_CONFIG1_RES_MSK   NO_OS_BIT(2)

◆ AD738X_CONFIG2_RESET

#define AD738X_CONFIG2_RESET ( x)
Value:
(((x) & 0xFF) << 0)

◆ AD738X_CONFIG2_RESET_MSK

#define AD738X_CONFIG2_RESET_MSK   NO_OS_GENMASK(7, 0)

◆ AD738X_CONFIG2_SDO2

#define AD738X_CONFIG2_SDO2 ( x)
Value:
(((x) & 0x1) << 8)

◆ AD738X_CONFIG2_SDO2_MSK

#define AD738X_CONFIG2_SDO2_MSK   NO_OS_BIT(8)

◆ AD738X_CONFIG2_SDO4

#define AD738X_CONFIG2_SDO4 ( x)
Value:
(((x) & 0x3) << 8)

◆ AD738X_CONFIG2_SDO4_MSK

#define AD738X_CONFIG2_SDO4_MSK   NO_OS_GENMASK(9, 8)

◆ AD738X_FLAG_NO_PWM

#define AD738X_FLAG_NO_PWM   NO_OS_BIT(2)

◆ AD738X_FLAG_OFFLOAD

#define AD738X_FLAG_OFFLOAD   NO_OS_BIT(1)

◆ AD738X_FLAG_STANDARD_SPI_DMA

#define AD738X_FLAG_STANDARD_SPI_DMA   NO_OS_BIT(0)

◆ AD738X_REG_ALERT

#define AD738X_REG_ALERT   0x03

◆ AD738X_REG_ALERT_HIGH_TH

#define AD738X_REG_ALERT_HIGH_TH   0x05

◆ AD738X_REG_ALERT_LOW_TH

#define AD738X_REG_ALERT_LOW_TH   0x04

◆ AD738X_REG_CONFIG1

#define AD738X_REG_CONFIG1   0x01

◆ AD738X_REG_CONFIG2

#define AD738X_REG_CONFIG2   0x02

◆ AD738X_REG_NOP

#define AD738X_REG_NOP   0x00

◆ AD738X_REG_READ

#define AD738X_REG_READ ( x)
Value:
((x & 0x7) << 4)

◆ AD738X_REG_WRITE

#define AD738X_REG_WRITE ( x)
Value:
((1 << 7) | ((x & 0x7) << 4))

Enumeration Type Documentation

◆ ad738x_ch_seq_sel

Enumerator
FIRST_FOUR 
ALL 
SECOND_FOUR 

◆ ad738x_conv_mode

Enumerator
TWO_WIRE_MODE 
ONE_WIRE_MODE 
FOUR_WIRE_MODE 

◆ ad738x_os_mode

Enumerator
NORMAL_OS_MODE 
ROLLING_OS_MODE 

◆ ad738x_os_ratio

Enumerator
OSR_DISABLED 
OSR_X2 
OSR_X4 
OSR_X8 
OSR_X16 
OSR_X32 

◆ ad738x_pwd_mode

Enumerator
NORMAL_PWDM 
FULL_PWDM 

◆ ad738x_ref_sel

Enumerator
INT_REF 
EXT_REF 

◆ ad738x_reset_type

Enumerator
SOFT_RESET 
HARD_RESET 

◆ ad738x_resolution

Enumerator
RES_16_BIT 
RES_18_BIT 

Function Documentation

◆ ad738x_ch_seq_sel()

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

Select the channels to be used.

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.

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 )

Set the oversampling mode and ratio.

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.

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.

Read data from device.

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.

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().

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.

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 )

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

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.

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.

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.

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.