Implementation of AD7091R-8 driver header file.
More...
#include <stdbool.h>
#include "no_os_spi.h"
#include "no_os_gpio.h"
|
| 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...
|
| |
|
| 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().
|
| |
| int | ad7091r8_set_sleep_mode (struct ad7091r8_dev *dev, enum ad7091r8_sleep_mode mode) |
| | Set device sleep mode.
|
| |
| 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) |
| |
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.
SPDX-License-Identifier: BSD-3-Clause
◆ AD7091R8_BITS
◆ AD7091R8_CONV_MASK
◆ AD7091R8_RD_WR_FLAG_MSK
| #define AD7091R8_RD_WR_FLAG_MSK NO_OS_BIT(10) |
◆ AD7091R8_REG_ADDR_MSK
◆ AD7091R8_REG_ALERT
| #define AD7091R8_REG_ALERT 0x03 |
◆ AD7091R8_REG_CH_HIGH_LIMIT
| #define AD7091R8_REG_CH_HIGH_LIMIT |
( |
| ch | ) |
|
◆ AD7091R8_REG_CH_HYSTERESIS
| #define AD7091R8_REG_CH_HYSTERESIS |
( |
| ch | ) |
|
◆ AD7091R8_REG_CH_LOW_LIMIT
| #define AD7091R8_REG_CH_LOW_LIMIT |
( |
| ch | ) |
|
◆ AD7091R8_REG_CHANNEL
| #define AD7091R8_REG_CHANNEL 0x01 |
◆ AD7091R8_REG_CONF
| #define AD7091R8_REG_CONF 0x02 |
◆ AD7091R8_REG_DATA_MSK
◆ 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
◆ AD7091R8_REG_RESULT_DATA_MASK
◆ AD7091R_NUM_CHANNELS
| #define AD7091R_NUM_CHANNELS |
( |
| id | ) |
|
◆ REG_ALERT_MASK
| #define REG_ALERT_MASK |
( |
| x, |
|
|
| ch ) |
◆ REG_CONF_ALERT_STICKY_MASK
| #define REG_CONF_ALERT_STICKY_MASK NO_OS_BIT(7) |
◆ REG_CONF_GPO0_MASK
◆ REG_CONF_GPO0_MODE_MASK
◆ REG_CONF_GPO1_MASK
◆ REG_CONF_RESET_MASK
◆ REG_CONF_SLEEP_MODE_MASK
◆ 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
|
◆ ad7091r8_get_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()
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()
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.
◆ ad7091r8_pulse_convst()
Pull the CONVST line up then down to signal to the start of a read/write operation.
- Parameters
-
| dev | - The device structure. |
◆ 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()
Free the resources allocated by ad7091r8_init().
- Parameters
-
| dev | - The device structure. |
- Returns
- ret - The result of the remove procedure.
◆ 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.
◆ 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.
◆ ad7091r8_set_gpo0_mode()
Set GPO0 mode.
- Parameters
-
| dev | - The device structure. |
| mode | - GPO0 new mode. |
| is_cmos | - 0: GPO0 is open drain
|
- Returns
- 0 in case of success, negative error code otherwise.
◆ ad7091r8_set_limit()
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()
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()
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.
◆ 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.
◆ 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.
◆ 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.