no-OS
Classes | Macros | Enumerations | Functions
ad7091r8.h File Reference

Implementation of AD7091R-8 driver header file. More...

#include <stdbool.h>
#include "no_os_spi.h"
#include "no_os_gpio.h"
Include dependency graph for ad7091r8.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ad7091r8_dev
 
struct  ad7091r8_init_param
 

Macros

#define AD7091R_NUM_CHANNELS(id)   (1 << ((id) + 1))
 
#define AD7091R8_BITS   12
 
#define AD7091R8_CONV_MASK   NO_OS_GENMASK(AD7091R8_BITS - 1, 0)
 
#define AD7091R8_REG_RESULT   0x00
 
#define AD7091R8_REG_CHANNEL   0x01
 
#define AD7091R8_REG_CONF   0x02
 
#define AD7091R8_REG_ALERT   0x03
 
#define AD7091R8_REG_CH_LOW_LIMIT(ch)   ((ch) * 3 + 4)
 
#define AD7091R8_REG_CH_HIGH_LIMIT(ch)   ((ch) * 3 + 5)
 
#define AD7091R8_REG_CH_HYSTERESIS(ch)   ((ch) * 3 + 6)
 
#define AD7091R8_REG_RESULT_DATA_MASK   NO_OS_GENMASK(11, 0)
 
#define AD7091R8_REG_RESULT_ALT_MASK   NO_OS_BIT(12)
 
#define AD7091R8_REG_RESULT_CH_ID_MASK   NO_OS_GENMASK(15, 13)
 
#define REG_CONF_SLEEP_MODE_MASK   NO_OS_GENMASK(1, 0)
 
#define REG_CONF_GPO1_MASK   NO_OS_BIT(2)
 
#define REG_CONF_GPO0_MASK   NO_OS_BIT(3)
 
#define REG_CONF_GPO0_MODE_MASK   NO_OS_GENMASK(6, 4)
 
#define REG_CONF_ALERT_STICKY_MASK   NO_OS_BIT(7)
 
#define REG_CONF_RESET_MASK   NO_OS_BIT(9)
 
#define REG_ALERT_MASK(x, ch)   (x >> (ch * 2))
 
#define AD7091R8_REG_DATA_MSK   NO_OS_GENMASK(9, 0)
 
#define AD7091R8_RD_WR_FLAG_MSK   NO_OS_BIT(10)
 
#define AD7091R8_REG_ADDR_MSK   NO_OS_GENMASK(15, 11)
 

Enumerations

enum  ad7091r8_device_id {
  AD7091R2,
  AD7091R4,
  AD7091R8
}
 
enum  ad7091r8_sleep_mode {
  AD7091R8_SLEEP_MODE_0,
  AD7091R8_SLEEP_MODE_1,
  AD7091R8_SLEEP_MODE_2,
  AD7091R8_SLEEP_MODE_3
}
 Converter supported sleep modes. More...
 
enum  ad7091r8_port {
  AD7091R8_GPO0,
  AD7091R8_GPO1
}
 Converter general purpose outputs. More...
 
enum  ad7091r8_gpo0_mode {
  AD7091R8_GPO0_ENABLED = 0,
  AD7091R8_GPO0_ALERT = 16,
  AD7091R8_GPO0_BUSY = 48
}
 Port 0 configuration. More...
 
enum  ad7091r8_limit {
  AD7091R8_LOW_LIMIT,
  AD7091R8_HIGH_LIMIT,
  AD7091R8_HYSTERESIS
}
 Limit type. More...
 
enum  ad7091r8_alert_type {
  AD7091R8_NO_ALERT,
  AD7091R8_HIGH_ALERT,
  AD7091R8_LOW_ALERT
}
 Alert status. More...
 

Functions

int ad7091r8_init (struct ad7091r8_dev **device, struct ad7091r8_init_param *init_param)
 
int ad7091r8_remove (struct ad7091r8_dev *dev)
 Free the resources allocated by ad7091r8_init(). More...
 
int ad7091r8_set_sleep_mode (struct ad7091r8_dev *dev, enum ad7091r8_sleep_mode mode)
 Set device sleep mode. More...
 
int ad7091r8_set_port (struct ad7091r8_dev *dev, enum ad7091r8_port port, bool value)
 
int ad7091r8_set_gpo0_mode (struct ad7091r8_dev *dev, enum ad7091r8_gpo0_mode mode, bool is_cmos)
 
int ad7091r8_set_limit (struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t value)
 
int ad7091r8_get_alert (struct ad7091r8_dev *dev, uint8_t channel, enum ad7091r8_alert_type *alert)
 
int ad7091r8_get_limit (struct ad7091r8_dev *dev, enum ad7091r8_limit limit, uint8_t channel, uint16_t *value)
 
int ad7091r8_set_channel (struct ad7091r8_dev *dev, uint8_t channel)
 
int ad7091r8_read_one (struct ad7091r8_dev *dev, uint8_t chan, uint16_t *read_val)
 
int ad7091r8_sequenced_read (struct ad7091r8_dev *dev, uint16_t *read_val)
 
int ad7091r8_spi_reg_read (struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t *reg_data)
 
int ad7091r8_spi_reg_write (struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t reg_data)
 
int ad7091r8_spi_write_mask (struct ad7091r8_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data)
 
int ad7091r8_pulse_convst (struct ad7091r8_dev *dev)
 

Detailed Description

Implementation of AD7091R-8 driver header file.

Author
Marcelo Schmitt (marce.nosp@m.lo.s.nosp@m.chmit.nosp@m.t@an.nosp@m.alog..nosp@m.com)

Copyright 2024(c) Analog Devices, Inc.

All rights reserved.

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 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, 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

◆ AD7091R8_BITS

#define AD7091R8_BITS   12

◆ AD7091R8_CONV_MASK

#define AD7091R8_CONV_MASK   NO_OS_GENMASK(AD7091R8_BITS - 1, 0)

◆ AD7091R8_RD_WR_FLAG_MSK

#define AD7091R8_RD_WR_FLAG_MSK   NO_OS_BIT(10)

◆ AD7091R8_REG_ADDR_MSK

#define AD7091R8_REG_ADDR_MSK   NO_OS_GENMASK(15, 11)

◆ AD7091R8_REG_ALERT

#define AD7091R8_REG_ALERT   0x03

◆ AD7091R8_REG_CH_HIGH_LIMIT

#define AD7091R8_REG_CH_HIGH_LIMIT (   ch)    ((ch) * 3 + 5)

◆ AD7091R8_REG_CH_HYSTERESIS

#define AD7091R8_REG_CH_HYSTERESIS (   ch)    ((ch) * 3 + 6)

◆ AD7091R8_REG_CH_LOW_LIMIT

#define AD7091R8_REG_CH_LOW_LIMIT (   ch)    ((ch) * 3 + 4)

◆ AD7091R8_REG_CHANNEL

#define AD7091R8_REG_CHANNEL   0x01

◆ AD7091R8_REG_CONF

#define AD7091R8_REG_CONF   0x02

◆ AD7091R8_REG_DATA_MSK

#define AD7091R8_REG_DATA_MSK   NO_OS_GENMASK(9, 0)

◆ AD7091R8_REG_RESULT

#define AD7091R8_REG_RESULT   0x00

◆ AD7091R8_REG_RESULT_ALT_MASK

#define AD7091R8_REG_RESULT_ALT_MASK   NO_OS_BIT(12)

◆ AD7091R8_REG_RESULT_CH_ID_MASK

#define AD7091R8_REG_RESULT_CH_ID_MASK   NO_OS_GENMASK(15, 13)

◆ AD7091R8_REG_RESULT_DATA_MASK

#define AD7091R8_REG_RESULT_DATA_MASK   NO_OS_GENMASK(11, 0)

◆ AD7091R_NUM_CHANNELS

#define AD7091R_NUM_CHANNELS (   id)    (1 << ((id) + 1))

◆ REG_ALERT_MASK

#define REG_ALERT_MASK (   x,
  ch 
)    (x >> (ch * 2))

◆ REG_CONF_ALERT_STICKY_MASK

#define REG_CONF_ALERT_STICKY_MASK   NO_OS_BIT(7)

◆ REG_CONF_GPO0_MASK

#define REG_CONF_GPO0_MASK   NO_OS_BIT(3)

◆ REG_CONF_GPO0_MODE_MASK

#define REG_CONF_GPO0_MODE_MASK   NO_OS_GENMASK(6, 4)

◆ REG_CONF_GPO1_MASK

#define REG_CONF_GPO1_MASK   NO_OS_BIT(2)

◆ REG_CONF_RESET_MASK

#define REG_CONF_RESET_MASK   NO_OS_BIT(9)

◆ REG_CONF_SLEEP_MODE_MASK

#define REG_CONF_SLEEP_MODE_MASK   NO_OS_GENMASK(1, 0)

Enumeration Type Documentation

◆ ad7091r8_alert_type

Alert status.

Enumerator
AD7091R8_NO_ALERT 

No alert

AD7091R8_HIGH_ALERT 

High alert

AD7091R8_LOW_ALERT 

Low alert

◆ ad7091r8_device_id

Enumerator
AD7091R2 
AD7091R4 
AD7091R8 

◆ ad7091r8_gpo0_mode

Port 0 configuration.

Enumerator
AD7091R8_GPO0_ENABLED 

GPO0 is output port

AD7091R8_GPO0_ALERT 

GPO0 is Alert indicator

AD7091R8_GPO0_BUSY 

GPO0 is busy indicator, device is converting

◆ ad7091r8_limit

Limit type.

Enumerator
AD7091R8_LOW_LIMIT 

Low limit

AD7091R8_HIGH_LIMIT 

High limit

AD7091R8_HYSTERESIS 

Hysteresis

◆ ad7091r8_port

Converter general purpose outputs.

Enumerator
AD7091R8_GPO0 

GPO0

AD7091R8_GPO1 

GPO1

◆ ad7091r8_sleep_mode

Converter supported sleep modes.

Enumerator
AD7091R8_SLEEP_MODE_0 

Default operation: Sleep mode Off, Internal reference Off

AD7091R8_SLEEP_MODE_1 

Sleep mode Off, Internal reference On

AD7091R8_SLEEP_MODE_2 

Sleep mode On, Internal reference Off

AD7091R8_SLEEP_MODE_3 

Sleep mode On, Internal reference On

Function Documentation

◆ ad7091r8_get_alert()

int ad7091r8_get_alert ( struct ad7091r8_dev dev,
uint8_t  channel,
enum ad7091r8_alert_type alert 
)

Get alert.

Parameters
dev- The device structure.
channel- Channel.
alert- Alert type.
Returns
0 in case of success, negative error code otherwise.

◆ ad7091r8_get_limit()

int ad7091r8_get_limit ( struct ad7091r8_dev dev,
enum ad7091r8_limit  limit,
uint8_t  channel,
uint16_t *  value 
)

Get high limit, low limit, hysteresis. The 3 LSBs of the internal 12-bit registers are set either to 000 or 111. Adjust limit data to reflect actual limit in use by the device.

Parameters
dev- The device structure.
limit- Limit.
channel- Channel.
value- Value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7091r8_init()

int ad7091r8_init ( struct ad7091r8_dev **  device,
struct ad7091r8_init_param init_param 
)

Initializes the communication peripheral and the initial Values for AD7092R-8 Board.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
ret - The result of the initialization procedure. Example: -1 - SPI peripheral was not initialized or the device is not present. 0 - SPI peripheral was initialized and the device is present.
Here is the caller graph for this function:

◆ ad7091r8_pulse_convst()

int ad7091r8_pulse_convst ( struct ad7091r8_dev dev)

Pull the CONVST line up then down to signal to the start of a read/write operation.

Parameters
dev- The device structure.
Here is the caller graph for this function:

◆ ad7091r8_read_one()

int ad7091r8_read_one ( struct ad7091r8_dev dev,
uint8_t  channel,
uint16_t *  read_val 
)

Read one sample.

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

◆ ad7091r8_remove()

int ad7091r8_remove ( struct ad7091r8_dev dev)

Free the resources allocated by ad7091r8_init().

Parameters
dev- The device structure.
Returns
ret - The result of the remove procedure.
Here is the caller graph for this function:

◆ ad7091r8_sequenced_read()

int ad7091r8_sequenced_read ( struct ad7091r8_dev dev,
uint16_t *  read_val 
)

Read the next channel set in the channel sequencer (channel register).

Parameters
dev- The device structure.
read_val- Value.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7091r8_set_channel()

int ad7091r8_set_channel ( struct ad7091r8_dev dev,
uint8_t  channel 
)

Set device channel.

Parameters
dev- The device structure.
channel- Channel.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7091r8_set_gpo0_mode()

int ad7091r8_set_gpo0_mode ( struct ad7091r8_dev dev,
enum ad7091r8_gpo0_mode  mode,
bool  is_cmos 
)

Set GPO0 mode.

Parameters
dev- The device structure.
mode- GPO0 new mode.
is_cmos- 0: GPO0 is open drain
  • 1: GPO0 is CMOS.
Returns
0 in case of success, negative error code otherwise.

◆ ad7091r8_set_limit()

int ad7091r8_set_limit ( struct ad7091r8_dev dev,
enum ad7091r8_limit  limit,
uint8_t  channel,
uint16_t  value 
)

Set high limit, low limit, hysteresis. Device accepts 9 bits provided by the user and sets them as the MSBs. The 3 LSBs of the internal 12-bit registers are set either to 000 or 111. Round user input according to each case.

Parameters
dev- The device structure.
limit- Limit.
channel- Channel.
value- Value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7091r8_set_port()

int ad7091r8_set_port ( struct ad7091r8_dev dev,
enum ad7091r8_port  port,
bool  value 
)

Set output port value.

Parameters
dev- The device structure.
port- Port number.
value- Value.
Returns
0 in case of success, negative error code otherwise.

◆ ad7091r8_set_sleep_mode()

int ad7091r8_set_sleep_mode ( struct ad7091r8_dev dev,
enum ad7091r8_sleep_mode  mode 
)

Set device sleep mode.

Parameters
dev- The device structure.
mode- The device sleep mode to set.
Returns
0 in case of success, negative error code otherwise.
Here is the caller graph for this function:

◆ ad7091r8_spi_reg_read()

int ad7091r8_spi_reg_read ( struct ad7091r8_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.
Here is the caller graph for this function:

◆ ad7091r8_spi_reg_write()

int ad7091r8_spi_reg_write ( struct ad7091r8_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.
Here is the caller graph for this function:

◆ ad7091r8_spi_write_mask()

int ad7091r8_spi_write_mask ( struct ad7091r8_dev dev,
uint8_t  reg_addr,
uint16_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.
Here is the caller graph for this function: