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

Header file for ad7091r5 Driver. More...

#include <stdbool.h>
#include "no-os/i2c.h"
#include "no-os/gpio.h"
Include dependency graph for ad7091r5.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ad7091r5_init_param
 Structure containing the init parameters needed by the ad7091r5 device. More...
 
struct  ad7091r5_dev
 Structure representing an ad7091r5 device. More...
 

Macros

#define AD7091R5_CHANNEL_NO   4
 
#define AD7091R5_BITS   12
 
#define AD7091R5_CONV_MASK   GENMASK(AD7091R5_BITS - 1, 0)
 
#define AD7091R5_REG_RESULT   0
 
#define AD7091R5_REG_CHANNEL   1
 
#define AD7091R5_REG_CONF   2
 
#define AD7091R5_REG_ALERT   3
 
#define AD7091R5_REG_CH_LOW_LIMIT(ch)   ((ch) * 3 + 4)
 
#define AD7091R5_REG_CH_HIGH_LIMIT(ch)   ((ch) * 3 + 5)
 
#define AD7091R5_REG_CH_HYSTERESIS(ch)   ((ch) * 3 + 6)
 
#define REG_RESULT_CH_ID(x)   (((x) >> 13) & 0x3)
 
#define REG_RESULT_CONV_DATA(x)   ((x) & AD7091R5_CONV_MASK)
 
#define REG_CONF_SLEEP_MODE_MASK   BIT(0)
 
#define REG_CONF_SLEEP_MODE(x)   ((x & 0x03) << 0)
 
#define REG_CONF_GPO1_MASK   BIT(2)
 
#define REG_CONF_GPO1(x)   ((x & 0x01) << 2)
 
#define REG_CONF_GPO0_MASK   BIT(3)
 
#define REG_CONF_GPO0(x)   ((x & 0x01) << 3)
 
#define REG_CONF_GPO0_MODE_MASK   (BIT(15) | BIT(5) | BIT(4))
 
#define REG_CONF_GPO0_ALERT(x)   ((x & 0x01) << 4)
 
#define REG_CONF_GPO0_BUSY(x)   ((x & 0x01) << 5)
 
#define REG_CONF_GPO0_DRIVE_TYPE(x)   ((x & 0x01) << 15)
 
#define REG_CONF_CYCLE_TIMER_MASK   (BIT(7) | BIT(6))
 
#define REG_CONF_CYCLE_TIMER(x)   ((x & 0x03) << 6)
 
#define REG_CONF_GPO2_MASK   BIT(14)
 
#define REG_CONF_GPO2(x)   ((x & 0x01) << 14)
 
#define REG_CONF_RESET_MASK   BIT(9)
 
#define REG_CONF_RESET(x)   ((x & 0x01) << 9)
 
#define REG_CONF_MODE_MASK   (BIT(10) | BIT(8))
 
#define REG_CONF_AUTO(x)   ((x & 0x01) << 8)
 
#define REG_CONF_CMD(x)   ((x & 0x01) << 10)
 
#define REG_ALERT_MASK(x, ch)   (x >> (ch * 2))
 

Enumerations

enum  ad7091r5_mode {
  AD7091R5_MODE_SAMPLE,
  AD7091R5_MODE_COMMAND,
  AD7091R5_MODE_AUTOCYCLE
}
 Converter supported modes. More...
 
enum  ad7091r5_sleep_mode {
  AD7091R5_SLEEP_MODE_0,
  AD7091R5_SLEEP_MODE_1,
  AD7091R5_SLEEP_MODE_2,
  AD7091R5_SLEEP_MODE_3
}
 Converter supported sleep modes. More...
 
enum  ad7091r5_port {
  AD7091R5_GPO0,
  AD7091R5_GPO1,
  AD7091R5_GPO2
}
 Converter general purpose outputs. More...
 
enum  ad7091r5_gpo0_mode {
  AD7091R5_GPO0_ENABLED,
  AD7091R5_GPO0_ALERT,
  AD7091R5_GPO0_BUSY
}
 Port 0 configuration. More...
 
enum  ad7091r5_cycle_timer {
  AD7091R5_CYCLE_TIMER_100uS,
  AD7091R5_CYCLE_TIMER_200uS,
  AD7091R5_CYCLE_TIMER_400uS,
  AD7091R5_CYCLE_TIMER_800uS
}
 Timer used for autocycle mode. More...
 
enum  ad7091r5_alert_type {
  AD7091R5_NO_ALERT,
  AD7091R5_HIGH_ALERT,
  AD7091R5_LOW_ALERT
}
 Alert status. More...
 
enum  ad7091r5_limit {
  AD7091R5_LOW_LIMIT,
  AD7091R5_HIGH_LIMIT,
  AD7091R5_HYSTERESIS
}
 Limit type. More...
 

Functions

int32_t ad7091r5_init (struct ad7091r5_dev **device, struct ad7091r5_init_param *init_param)
 
int32_t ad7091r5_remove (struct ad7091r5_dev *dev)
 Free the memory allocated by ad7091r5_init(). More...
 
int32_t ad7091r5_set_mode (struct ad7091r5_dev *dev, enum ad7091r5_mode mode)
 
int32_t ad7091r5_sleep_mode (struct ad7091r5_dev *dev, enum ad7091r5_sleep_mode mode)
 
int32_t ad7091r5_set_port (struct ad7091r5_dev *dev, enum ad7091r5_port port, bool value)
 
int32_t ad7091r5_set_gpo0_mode (struct ad7091r5_dev *dev, enum ad7091r5_gpo0_mode mode, bool is_cmos)
 
int32_t ad7091r5_set_cycle_timer (struct ad7091r5_dev *dev, enum ad7091r5_cycle_timer timer)
 
int32_t ad7091r5_set_limit (struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t value)
 
int32_t ad7091r5_get_alert (struct ad7091r5_dev *dev, uint8_t channel, enum ad7091r5_alert_type *alert)
 
int32_t ad7091r5_get_limit (struct ad7091r5_dev *dev, enum ad7091r5_limit limit, uint8_t channel, uint16_t *value)
 
int32_t ad7091r5_set_channel (struct ad7091r5_dev *dev, uint8_t channel)
 
int32_t ad7091r5_read_one (struct ad7091r5_dev *dev, uint8_t channel, uint16_t *read_val)
 

Detailed Description

Header file for ad7091r5 Driver.

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

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

◆ AD7091R5_BITS

#define AD7091R5_BITS   12

◆ AD7091R5_CHANNEL_NO

#define AD7091R5_CHANNEL_NO   4

◆ AD7091R5_CONV_MASK

#define AD7091R5_CONV_MASK   GENMASK(AD7091R5_BITS - 1, 0)

◆ AD7091R5_REG_ALERT

#define AD7091R5_REG_ALERT   3

◆ AD7091R5_REG_CH_HIGH_LIMIT

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

◆ AD7091R5_REG_CH_HYSTERESIS

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

◆ AD7091R5_REG_CH_LOW_LIMIT

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

◆ AD7091R5_REG_CHANNEL

#define AD7091R5_REG_CHANNEL   1

◆ AD7091R5_REG_CONF

#define AD7091R5_REG_CONF   2

◆ AD7091R5_REG_RESULT

#define AD7091R5_REG_RESULT   0

◆ REG_ALERT_MASK

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

◆ REG_CONF_AUTO

#define REG_CONF_AUTO (   x)    ((x & 0x01) << 8)

◆ REG_CONF_CMD

#define REG_CONF_CMD (   x)    ((x & 0x01) << 10)

◆ REG_CONF_CYCLE_TIMER

#define REG_CONF_CYCLE_TIMER (   x)    ((x & 0x03) << 6)

◆ REG_CONF_CYCLE_TIMER_MASK

#define REG_CONF_CYCLE_TIMER_MASK   (BIT(7) | BIT(6))

◆ REG_CONF_GPO0

#define REG_CONF_GPO0 (   x)    ((x & 0x01) << 3)

◆ REG_CONF_GPO0_ALERT

#define REG_CONF_GPO0_ALERT (   x)    ((x & 0x01) << 4)

◆ REG_CONF_GPO0_BUSY

#define REG_CONF_GPO0_BUSY (   x)    ((x & 0x01) << 5)

◆ REG_CONF_GPO0_DRIVE_TYPE

#define REG_CONF_GPO0_DRIVE_TYPE (   x)    ((x & 0x01) << 15)

◆ REG_CONF_GPO0_MASK

#define REG_CONF_GPO0_MASK   BIT(3)

◆ REG_CONF_GPO0_MODE_MASK

#define REG_CONF_GPO0_MODE_MASK   (BIT(15) | BIT(5) | BIT(4))

◆ REG_CONF_GPO1

#define REG_CONF_GPO1 (   x)    ((x & 0x01) << 2)

◆ REG_CONF_GPO1_MASK

#define REG_CONF_GPO1_MASK   BIT(2)

◆ REG_CONF_GPO2

#define REG_CONF_GPO2 (   x)    ((x & 0x01) << 14)

◆ REG_CONF_GPO2_MASK

#define REG_CONF_GPO2_MASK   BIT(14)

◆ REG_CONF_MODE_MASK

#define REG_CONF_MODE_MASK   (BIT(10) | BIT(8))

◆ REG_CONF_RESET

#define REG_CONF_RESET (   x)    ((x & 0x01) << 9)

◆ REG_CONF_RESET_MASK

#define REG_CONF_RESET_MASK   BIT(9)

◆ REG_CONF_SLEEP_MODE

#define REG_CONF_SLEEP_MODE (   x)    ((x & 0x03) << 0)

◆ REG_CONF_SLEEP_MODE_MASK

#define REG_CONF_SLEEP_MODE_MASK   BIT(0)

◆ REG_RESULT_CH_ID

#define REG_RESULT_CH_ID (   x)    (((x) >> 13) & 0x3)

◆ REG_RESULT_CONV_DATA

#define REG_RESULT_CONV_DATA (   x)    ((x) & AD7091R5_CONV_MASK)

Enumeration Type Documentation

◆ ad7091r5_alert_type

Alert status.

Enumerator
AD7091R5_NO_ALERT 

No alert

AD7091R5_HIGH_ALERT 

High alert

AD7091R5_LOW_ALERT 

Low alert

◆ ad7091r5_cycle_timer

Timer used for autocycle mode.

Enumerator
AD7091R5_CYCLE_TIMER_100uS 

100 uS

AD7091R5_CYCLE_TIMER_200uS 

200 uS

AD7091R5_CYCLE_TIMER_400uS 

400 uS

AD7091R5_CYCLE_TIMER_800uS 

800 uS

◆ ad7091r5_gpo0_mode

Port 0 configuration.

Enumerator
AD7091R5_GPO0_ENABLED 

GPO0 is output port

AD7091R5_GPO0_ALERT 

GPO0 is Alert indicator

AD7091R5_GPO0_BUSY 

GPO0 is busy indicator, device is converting

◆ ad7091r5_limit

Limit type.

Enumerator
AD7091R5_LOW_LIMIT 

Low limit

AD7091R5_HIGH_LIMIT 

High limit

AD7091R5_HYSTERESIS 

Hysteresis

◆ ad7091r5_mode

Converter supported modes.

Enumerator
AD7091R5_MODE_SAMPLE 

Sample mode, conversion started by CONVST

AD7091R5_MODE_COMMAND 

Command mode, conversion starts on the first pos edge of SCL

AD7091R5_MODE_AUTOCYCLE 

Sample mode, convert continuously

◆ ad7091r5_port

Converter general purpose outputs.

Enumerator
AD7091R5_GPO0 

GPO0

AD7091R5_GPO1 

GPO1

AD7091R5_GPO2 

GPO2

◆ ad7091r5_sleep_mode

Converter supported sleep modes.

Enumerator
AD7091R5_SLEEP_MODE_0 

Default operation: Sleep mode Off, Internal reference Off

AD7091R5_SLEEP_MODE_1 

Sleep mode Off, Internal reference On

AD7091R5_SLEEP_MODE_2 

Sleep mode On, Internal reference Off

AD7091R5_SLEEP_MODE_3 

Sleep mode On, Internal reference On

Function Documentation

◆ ad7091r5_get_alert()

int32_t ad7091r5_get_alert ( struct ad7091r5_dev dev,
uint8_t  channel,
enum ad7091r5_alert_type alert 
)

Get alert.

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

◆ ad7091r5_get_limit()

int32_t ad7091r5_get_limit ( struct ad7091r5_dev dev,
enum ad7091r5_limit  limit,
uint8_t  channel,
uint16_t *  value 
)

Get high limit, low limit, hysteresis.

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

◆ ad7091r5_init()

int32_t ad7091r5_init ( struct ad7091r5_dev **  device,
struct ad7091r5_init_param init_param 
)

Initialize the device.

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

◆ ad7091r5_read_one()

int32_t ad7091r5_read_one ( struct ad7091r5_dev dev,
uint8_t  channel,
uint16_t *  read_val 
)

Read one sample.

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

◆ ad7091r5_remove()

int32_t ad7091r5_remove ( struct ad7091r5_dev dev)

Free the memory allocated by ad7091r5_init().

Parameters
dev- Pointer to the device handler.
Returns
SUCCESS in case of success, negative error code otherwise.

◆ ad7091r5_set_channel()

int32_t ad7091r5_set_channel ( struct ad7091r5_dev dev,
uint8_t  channel 
)

Set device channel.

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

◆ ad7091r5_set_cycle_timer()

int32_t ad7091r5_set_cycle_timer ( struct ad7091r5_dev dev,
enum ad7091r5_cycle_timer  timer 
)

Set cycle timer for autocycle mode.

Parameters
dev- The device structure.
timer- Converter sampling period.
Returns
SUCCESS in case of success, negative error code otherwise.

◆ ad7091r5_set_gpo0_mode()

int32_t ad7091r5_set_gpo0_mode ( struct ad7091r5_dev dev,
enum ad7091r5_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
SUCCESS in case of success, negative error code otherwise.

◆ ad7091r5_set_limit()

int32_t ad7091r5_set_limit ( struct ad7091r5_dev dev,
enum ad7091r5_limit  limit,
uint8_t  channel,
uint16_t  value 
)

Set high limit, low limit, hysteresis.

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

◆ ad7091r5_set_mode()

int32_t ad7091r5_set_mode ( struct ad7091r5_dev dev,
enum ad7091r5_mode  mode 
)

Set mode.

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

◆ ad7091r5_set_port()

int32_t ad7091r5_set_port ( struct ad7091r5_dev dev,
enum ad7091r5_port  port,
bool  value 
)

Set output port value.

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

◆ ad7091r5_sleep_mode()

int32_t ad7091r5_sleep_mode ( struct ad7091r5_dev dev,
enum ad7091r5_sleep_mode  mode 
)

Set sleep mode.

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