no-OS
|
Implementation of AD7616 Driver. More...
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "ad7616.h"
#include "no_os_gpio.h"
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
#include "no_os_util.h"
#include "no_os_spi.h"
Macros | |
#define | AD7616_GET_BIT(v, b) ((v >> b) & 1) |
#define | AD7616_TOGGLE_TIMEOUT_DELAY (8192 * 1024) |
#define | SPI_ENGINE_WORDS_PER_READ 1 |
Functions | |
int32_t | ad7616_select_channel_source (struct ad7616_dev *dev, enum ad7616_ch ch) |
Select a new source for a channel. More... | |
int32_t | ad7616_read_channel_source (struct ad7616_dev *dev, enum ad7616_ch *ch_a, enum ad7616_ch *ch_b) |
Read the current selected channels. More... | |
int32_t | ad7616_read (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t *reg_data) |
int32_t | ad7616_write (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t reg_data) |
int32_t | ad7616_read_mask (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t *data) |
int32_t | ad7616_write_mask (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t mask, uint16_t data) |
int32_t | ad7616_spi_read (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t *reg_data) |
int32_t | ad7616_spi_write (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t reg_data) |
int32_t | ad7616_reset (struct ad7616_dev *dev) |
int32_t | ad7616_set_range (struct ad7616_dev *dev, enum ad7616_ch ch, enum ad7616_range range) |
int32_t | ad7616_set_mode (struct ad7616_dev *dev, enum ad7616_mode mode) |
int32_t | ad7616_set_oversampling_ratio (struct ad7616_dev *dev, enum ad7616_osr osr) |
int32_t | ad7616_read_data_serial (struct ad7616_dev *dev, struct ad7616_conversion_result *results, uint32_t samples) |
Read conversion result from device, checking with CRC if enabled. More... | |
int32_t | ad7616_par_read (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t *reg_data) |
int32_t | ad7616_par_write (struct ad7616_dev *dev, uint8_t reg_addr, uint16_t reg_data) |
int32_t | ad7616_read_data_parallel (struct ad7616_dev *dev, uint32_t *buf, uint32_t samples) |
Read from device in parallel mode. Enter register mode to read/write registers. More... | |
int32_t | ad7616_setup_sequencer (struct ad7616_dev *dev, struct ad7616_sequencer_layer *layers, uint32_t layers_nb, uint8_t burst) |
Setup the sequencer layers. More... | |
int32_t | ad7616_disable_sequencer (struct ad7616_dev *dev) |
int32_t | ad7616_self_test (struct ad7616_dev *dev) |
Perform a self test. Channels selection will be left untouched. More... | |
int32_t | ad7616_setup (struct ad7616_dev **device, struct ad7616_init_param *init_param) |
void | ad7616_remove (struct ad7616_dev *dev) |
Implementation of AD7616 Driver.
Copyright 2020(c) Analog Devices, Inc. Copyright 2023(c) BayLibre, SAS.
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, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 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.
#define AD7616_GET_BIT | ( | v, | |
b | |||
) | ((v >> b) & 1) |
#define AD7616_TOGGLE_TIMEOUT_DELAY (8192 * 1024) |
#define SPI_ENGINE_WORDS_PER_READ 1 |
int32_t ad7616_disable_sequencer | ( | struct ad7616_dev * | dev | ) |
int32_t ad7616_par_read | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t * | reg_data | ||
) |
PAR read from device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_par_write | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t | reg_data | ||
) |
PAR write to device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_read | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t * | reg_data | ||
) |
Read from device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_read_channel_source | ( | struct ad7616_dev * | dev, |
enum ad7616_ch * | ch_a, | ||
enum ad7616_ch * | ch_b | ||
) |
Read the current selected channels.
dev | - The device structure |
ch_a | - Pointer to store the current source for channel A |
ch_b | - Pointer to store the current source for channel B |
int32_t ad7616_read_data_parallel | ( | struct ad7616_dev * | dev, |
uint32_t * | buf, | ||
uint32_t | samples | ||
) |
Read from device in parallel mode. Enter register mode to read/write registers.
dev | - ad7616_dev device handler. |
buf | - data buffer. |
samples | - sample number. |
int32_t ad7616_read_data_serial | ( | struct ad7616_dev * | dev, |
struct ad7616_conversion_result * | results, | ||
uint32_t | samples | ||
) |
Read conversion result from device, checking with CRC if enabled.
dev | - ad7616_dev device handler. |
results | - results buffer. |
samples | - sample number. |
int32_t ad7616_read_mask | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t | mask, | ||
uint16_t * | data | ||
) |
Read from device using a mask.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
data | - The register data. |
void ad7616_remove | ( | struct ad7616_dev * | dev | ) |
int32_t ad7616_reset | ( | struct ad7616_dev * | dev | ) |
Perform a full reset of the device.
dev | - The device structure. |
int32_t ad7616_select_channel_source | ( | struct ad7616_dev * | dev, |
enum ad7616_ch | ch | ||
) |
Select a new source for a channel.
dev | - The device structure. |
ch | - The new channel source |
int32_t ad7616_self_test | ( | struct ad7616_dev * | dev | ) |
Perform a self test. Channels selection will be left untouched.
Self test
dev | The device structure |
int32_t ad7616_set_mode | ( | struct ad7616_dev * | dev, |
enum ad7616_mode | mode | ||
) |
Set the operation mode (software or hardware).
dev | - The device structure. |
mode | - The operation mode. Accepted values: AD7616_SW AD7616_HW |
int32_t ad7616_set_oversampling_ratio | ( | struct ad7616_dev * | dev, |
enum ad7616_osr | osr | ||
) |
Set the oversampling ratio.
dev | - The device structure. |
osr | - The oversampling ratio. Accepted values: AD7616_OSR_0 AD7616_OSR_2 AD7616_OSR_4 AD7616_OSR_8 AD7616_OSR_16 AD7616_OSR_32 AD7616_OSR_64 AD7616_OSR_128 |
int32_t ad7616_set_range | ( | struct ad7616_dev * | dev, |
enum ad7616_ch | ch, | ||
enum ad7616_range | range | ||
) |
Set the analog input range for the selected analog input channel.
dev | - The device structure. |
ch | - The channel number. Accepted values: AD7616_VA0 AD7616_VA1 AD7616_VA2 AD7616_VA3 AD7616_VA4 AD7616_VA5 AD7616_VA6 AD7616_VA7 AD7616_VB0 AD7616_VB1 AD7616_VB2 AD7616_VB3 AD7616_VB4 AD7616_VB5 AD7616_VB6 AD7616_VB7 |
range | - The analog input range. Accepted values: AD7616_2V5 AD7616_5V AD7616_10V |
int32_t ad7616_setup | ( | struct ad7616_dev ** | device, |
struct ad7616_init_param * | init_param | ||
) |
Initialize the device.
device | - The device structure. |
init_param | - The structure that contains the device initial parameters. |
int32_t ad7616_setup_sequencer | ( | struct ad7616_dev * | dev, |
struct ad7616_sequencer_layer * | layers, | ||
uint32_t | layers_nb, | ||
uint8_t | burst | ||
) |
Setup the sequencer layers.
dev | The device structure |
layers | Arrays of layers |
layers_nb | Nubers of items in the layers array. |
burst | 1 if needed, 0 otherwise |
int32_t ad7616_spi_read | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t * | reg_data | ||
) |
SPI read from device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_spi_write | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t | reg_data | ||
) |
SPI write to device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_write | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t | reg_data | ||
) |
Write to device.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int32_t ad7616_write_mask | ( | struct ad7616_dev * | dev, |
uint8_t | reg_addr, | ||
uint16_t | mask, | ||
uint16_t | data | ||
) |
SPI write to device using a mask.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
data | - The register data. |