no-OS
|
Source file for the ad4170 driver. More...
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "no_os_error.h"
#include "no_os_delay.h"
#include "no_os_crc8.h"
#include "ad4170.h"
Functions | |
NO_OS_DECLARE_CRC8_TABLE (ad4170_crc8) | |
int | ad4170_spi_reg_read (struct ad4170_dev *dev, uint32_t reg_addr, uint32_t *reg_data) |
Read device register. More... | |
int | ad4170_spi_reg_write (struct ad4170_dev *dev, uint32_t reg_addr, uint32_t reg_data) |
Write device register. More... | |
int | ad4170_spi_reg_write_mask (struct ad4170_dev *dev, uint32_t reg_addr, uint8_t mask, uint32_t reg_data) |
SPI write device register using a mask. More... | |
int | ad4170_reset_spi_interface (struct ad4170_dev *dev) |
Reset the SPI interface by sending reset sequence to device. More... | |
int | ad4170_get_data16 (struct ad4170_dev *dev, uint16_t *data) |
Get data from register Data_16b. More... | |
int | ad4170_get_data16s (struct ad4170_dev *dev, uint16_t *data, uint8_t *status) |
Get data and status from register Data_16b_Status. More... | |
int | ad4170_get_data24 (struct ad4170_dev *dev, uint32_t *data) |
Get data from register Data_24b. More... | |
int | ad4170_get_data24s (struct ad4170_dev *dev, uint32_t *data, uint8_t *status) |
Get data and status from register Data_24b_Status. More... | |
int | ad4170_get_data32 (struct ad4170_dev *dev, uint32_t *data) |
Get data from register Data_32b. More... | |
int | ad4170_get_ch_data (struct ad4170_dev *dev, uint8_t ch, uint32_t *data) |
Get data from register Data_Per_Channel[n]. More... | |
int | ad4170_get_status (struct ad4170_dev *dev, uint16_t *status) |
Get status from register Data_Status. More... | |
int | ad4170_read16 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples) |
Read multiple samples using direct register access from Data_16b. More... | |
int | ad4170_read16s (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples) |
Read multiple samples using direct register access from Data_16b_Status. More... | |
int | ad4170_read24 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples) |
Read multiple samples using direct register access from Data_24. More... | |
int | ad4170_read24s (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples) |
Read multiple samples using direct register access from Data_24_Status. More... | |
int | ad4170_read32 (struct ad4170_dev *dev, uint32_t *pbuf, uint16_t nb_samples) |
Read multiple samples using direct register access from Data_32b. More... | |
int | ad4170_continuous_read (struct ad4170_dev *dev, uint32_t *data_out, uint8_t *status_out, uint16_t nb_samples) |
Read multiple samples in continuous read mode. More... | |
int | ad4170_continuous_read_exit (struct ad4170_dev *dev) |
Exit continuous read mode. More... | |
int | ad4170_continuous_transmit_exit (struct ad4170_dev *dev) |
Exit continuous transmit mode. More... | |
int | ad4170_reset (struct ad4170_dev *dev) |
Perform a software reset. More... | |
int | ad4170_set_spi_settings (struct ad4170_dev *dev, const struct ad4170_spi_settings *spi_settings) |
Set the AD4170 SPI settings. More... | |
int | ad4170_set_pin_muxing (struct ad4170_dev *dev, struct ad4170_pin_muxing pin_muxing) |
Set the AD4170 Pin Muxing settings. More... | |
int | ad4170_set_dclk_div (struct ad4170_dev *dev, enum ad4170_dclk_div div) |
Set the AD4170 DCLK configuration. More... | |
int | ad4170_set_mclk_div (struct ad4170_dev *dev, enum ad4170_mclk_div div) |
Set the AD4170 MCLK configuration. More... | |
int | ad4170_set_clocksel (struct ad4170_dev *dev, enum ad4170_clocksel sel) |
Set the AD4170 clock selection configuration. More... | |
int | ad4170_set_standby_ctrl (struct ad4170_dev *dev, uint16_t standby_ctrl) |
Set the AD4170 Standby control settings. More... | |
int | ad4170_set_powerdown_sw (struct ad4170_dev *dev, uint16_t powerdown_sw) |
Set the AD4170 Powerdown switches settings. More... | |
int | ad4170_set_error_en (struct ad4170_dev *dev, uint16_t error_en) |
Set the AD4170 Error enable settings. More... | |
int | ad4170_set_error (struct ad4170_dev *dev, uint16_t error) |
Set the Error register with a value to clear specific errors. More... | |
int | ad4170_get_error (struct ad4170_dev *dev, uint16_t *error) |
Get the Error register. More... | |
int | ad4170_set_adc_ctrl (struct ad4170_dev *dev, struct ad4170_adc_ctrl adc_ctrl) |
Set the AD4170 ADC Control. More... | |
int | ad4170_set_channel_en (struct ad4170_dev *dev, uint16_t channel_en) |
Enable AD4170 channels. More... | |
int | ad4170_set_channel_setup (struct ad4170_dev *dev, uint8_t ch, struct ad4170_channel_setup setup) |
Set the AD4170 Channel specific setup. More... | |
int | ad4170_set_channel_map (struct ad4170_dev *dev, uint8_t ch, struct ad4170_channel_map map) |
Set the AD4170 Channel specific map. More... | |
int | ad4170_set_setup (struct ad4170_dev *dev, uint8_t n, struct ad4170_setup setup) |
Configure an ADC setup. More... | |
int | ad4170_set_ref_control (struct ad4170_dev *dev, bool enable) |
Set the AD4170 Ref Control. More... | |
int | ad4170_set_v_bias (struct ad4170_dev *dev, uint16_t ch_mask) |
Set the AD4170 Voltage bias. More... | |
int | ad4170_set_i_pullup (struct ad4170_dev *dev, uint16_t ch_mask) |
Set the AD4170 Input pullup. More... | |
int | ad4170_set_current_source (struct ad4170_dev *dev, uint8_t n, struct ad4170_current_source current_source) |
Set the AD4170 Excitation Current. More... | |
int | ad4170_set_fir_control (struct ad4170_dev *dev, struct ad4170_fir_control fir_control) |
Set the AD4170 FIR control settings. More... | |
int | ad4170_set_dac_config (struct ad4170_dev *dev, struct ad4170_dac_config config) |
Set the AD4170 DAC settings. More... | |
int | ad4170_set_dac_data (struct ad4170_dev *dev, uint16_t code) |
Set the AD4170 DAC data by directly writing the DAT_DATA register. More... | |
int | ad4170_set_dac_inputa (struct ad4170_dev *dev, uint16_t code) |
Set the AD4170 DAC data by writing the INPUTA register to be loaded separately by LDAC or Toggle operations. More... | |
int | ad4170_set_dac_inputb (struct ad4170_dev *dev, uint16_t code) |
Set the AD4170 DAC data by writing the INPUTB register to be loaded separately by LDAC or Toggle operations. More... | |
int | ad4170_dac_sw_ldac (struct ad4170_dev *dev, bool polarity) |
Perform a software LDAC. More... | |
int | ad4170_dac_sw_toggle (struct ad4170_dev *dev, bool polarity) |
Perform a software toggle. More... | |
int | ad4170_dac_hw_toggle (struct ad4170_dev *dev, bool polarity) |
Perform a hardware toggle using the DIG_AUX2 pin, assumed to be pre-configured for this. More... | |
int | ad4170_init (struct ad4170_dev **device, struct ad4170_init_param *init_param) |
Initialize an AD4170 device structure. More... | |
int | ad4170_remove (struct ad4170_dev *dev) |
Remove the device and free al the resources. More... | |
int | ad4170_regmap (struct ad4170_dev *dev) |
Debugging function to print the register map to console. More... | |
Variables | |
struct ad4170_config | ad4170_config_reset |
Source file for the ad4170 driver.
Copyright 2020, 2023(c) Analog Devices, Inc.
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.
int ad4170_continuous_read | ( | struct ad4170_dev * | dev, |
uint32_t * | data_out, | ||
uint8_t * | status_out, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples in continuous read mode.
dev | - The device structure. |
data_out | - Output pointer where to store the data values. |
status_out | - Output pointer where to store the status values. |
nb_samples | - The number of samples to read. |
int ad4170_continuous_read_exit | ( | struct ad4170_dev * | dev | ) |
Exit continuous read mode.
dev | - The device structure. |
int ad4170_continuous_transmit_exit | ( | struct ad4170_dev * | dev | ) |
Exit continuous transmit mode.
dev | - The device structure. |
int ad4170_dac_hw_toggle | ( | struct ad4170_dev * | dev, |
bool | polarity | ||
) |
Perform a hardware toggle using the DIG_AUX2 pin, assumed to be pre-configured for this.
dev | - The device structure. |
polarity | - Polarity of the toggle operation. |
int ad4170_dac_sw_ldac | ( | struct ad4170_dev * | dev, |
bool | polarity | ||
) |
Perform a software LDAC.
dev | - The device structure. |
polarity | - Polarity of the LDAC operation. |
int ad4170_dac_sw_toggle | ( | struct ad4170_dev * | dev, |
bool | polarity | ||
) |
Perform a software toggle.
dev | - The device structure. |
polarity | - Polarity of the toggle operation. |
int ad4170_get_ch_data | ( | struct ad4170_dev * | dev, |
uint8_t | ch, | ||
uint32_t * | data | ||
) |
Get data from register Data_Per_Channel[n].
This function assumes Per-Channel ADC Data is enabled, otherwise the output data may contain zeroes.
dev | - The device structure. |
ch | - The channel number (0 to 15) |
data | - Output pointer where to store the data value. |
int ad4170_get_data16 | ( | struct ad4170_dev * | dev, |
uint16_t * | data | ||
) |
Get data from register Data_16b.
dev | - The device structure. |
data | - Output pointer where to store the data value. |
int ad4170_get_data16s | ( | struct ad4170_dev * | dev, |
uint16_t * | data, | ||
uint8_t * | status | ||
) |
Get data and status from register Data_16b_Status.
dev | - The device structure. |
data | - Output pointer where to store the data value. |
status | - Output pointer where to store the status value. |
int ad4170_get_data24 | ( | struct ad4170_dev * | dev, |
uint32_t * | data | ||
) |
Get data from register Data_24b.
dev | - The device structure. |
data | - Output pointer where to store the data value. |
int ad4170_get_data24s | ( | struct ad4170_dev * | dev, |
uint32_t * | data, | ||
uint8_t * | status | ||
) |
Get data and status from register Data_24b_Status.
dev | - The device structure. |
data | - Output pointer where to store the data value. |
status | - Output pointer where to store the status value. |
int ad4170_get_data32 | ( | struct ad4170_dev * | dev, |
uint32_t * | data | ||
) |
Get data from register Data_32b.
dev | - The device structure. |
data | - Output pointer where to store the data value. |
int ad4170_get_error | ( | struct ad4170_dev * | dev, |
uint16_t * | error | ||
) |
Get the Error register.
dev | - The device structure. |
error | - Pointer to where Error register content should be stored. |
int ad4170_get_status | ( | struct ad4170_dev * | dev, |
uint16_t * | status | ||
) |
Get status from register Data_Status.
dev | - The device structure. |
status | - Output pointer where to store the status value. |
int ad4170_init | ( | struct ad4170_dev ** | device, |
struct ad4170_init_param * | init_param | ||
) |
Initialize an AD4170 device structure.
device | - Pointer to the device structure (memory is allocated within this function). |
init_param | - Pointer to the initialization parameters. |
int ad4170_read16 | ( | struct ad4170_dev * | dev, |
uint32_t * | pbuf, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples using direct register access from Data_16b.
dev | - The device structure. |
pbuf | - Output pointer where to store the data values. |
nb_samples | - The number of samples to read. |
int ad4170_read16s | ( | struct ad4170_dev * | dev, |
uint32_t * | pbuf, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples using direct register access from Data_16b_Status.
dev | - The device structure. |
pbuf | - Output pointer where to store the data values. |
nb_samples | - The number of samples to read. |
int ad4170_read24 | ( | struct ad4170_dev * | dev, |
uint32_t * | pbuf, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples using direct register access from Data_24.
dev | - The device structure. |
pbuf | - Output pointer where to store the data values. |
nb_samples | - The number of samples to read. |
int ad4170_read24s | ( | struct ad4170_dev * | dev, |
uint32_t * | pbuf, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples using direct register access from Data_24_Status.
dev | - The device structure. |
pbuf | - Output pointer where to store the data values. |
nb_samples | - The number of samples to read. |
int ad4170_read32 | ( | struct ad4170_dev * | dev, |
uint32_t * | pbuf, | ||
uint16_t | nb_samples | ||
) |
Read multiple samples using direct register access from Data_32b.
dev | - The device structure. |
pbuf | - Output pointer where to store the data values. |
nb_samples | - The number of samples to read. |
int ad4170_regmap | ( | struct ad4170_dev * | dev | ) |
Debugging function to print the register map to console.
dev | - The device structure. |
int ad4170_remove | ( | struct ad4170_dev * | dev | ) |
Remove the device and free al the resources.
dev | - The device structure. |
int ad4170_reset | ( | struct ad4170_dev * | dev | ) |
Perform a software reset.
dev | - The device structure. |
int ad4170_reset_spi_interface | ( | struct ad4170_dev * | dev | ) |
Reset the SPI interface by sending reset sequence to device.
dev | - The device structure. |
int ad4170_set_adc_ctrl | ( | struct ad4170_dev * | dev, |
struct ad4170_adc_ctrl | adc_ctrl | ||
) |
Set the AD4170 ADC Control.
dev | - The device structure. |
adc_ctrl | - AD4170 ADC Control configuration. |
int ad4170_set_channel_en | ( | struct ad4170_dev * | dev, |
uint16_t | channel_en | ||
) |
Enable AD4170 channels.
dev | - The device structure. |
channel_en | - Channel enable mask. |
int ad4170_set_channel_map | ( | struct ad4170_dev * | dev, |
uint8_t | ch, | ||
struct ad4170_channel_map | map | ||
) |
Set the AD4170 Channel specific map.
dev | - The device structure. |
ch | - The channel number (0 to 15). |
map | - AD4170 Channel specific map configuration. |
int ad4170_set_channel_setup | ( | struct ad4170_dev * | dev, |
uint8_t | ch, | ||
struct ad4170_channel_setup | setup | ||
) |
Set the AD4170 Channel specific setup.
dev | - The device structure. |
ch | - The channel number (0 to 15). |
setup | - AD4170 Channel specific setup configuration. |
int ad4170_set_clocksel | ( | struct ad4170_dev * | dev, |
enum ad4170_clocksel | sel | ||
) |
Set the AD4170 clock selection configuration.
dev | - The device structure. |
sel | - AD4170 clock selection configuration. |
int ad4170_set_current_source | ( | struct ad4170_dev * | dev, |
uint8_t | n, | ||
struct ad4170_current_source | current_source | ||
) |
Set the AD4170 Excitation Current.
dev | - The device structure. |
n | - Current source number (0 to 3). |
current_source | - Excitation current confguration. |
int ad4170_set_dac_config | ( | struct ad4170_dev * | dev, |
struct ad4170_dac_config | config | ||
) |
Set the AD4170 DAC settings.
dev | - The device structure. |
config | - The DAC configuration. |
int ad4170_set_dac_data | ( | struct ad4170_dev * | dev, |
uint16_t | code | ||
) |
Set the AD4170 DAC data by directly writing the DAT_DATA register.
dev | - The device structure. |
code | - The DAC code. |
int ad4170_set_dac_inputa | ( | struct ad4170_dev * | dev, |
uint16_t | code | ||
) |
Set the AD4170 DAC data by writing the INPUTA register to be loaded separately by LDAC or Toggle operations.
dev | - The device structure. |
code | - The DAC code. |
int ad4170_set_dac_inputb | ( | struct ad4170_dev * | dev, |
uint16_t | code | ||
) |
Set the AD4170 DAC data by writing the INPUTB register to be loaded separately by LDAC or Toggle operations.
dev | - The device structure. |
code | - The DAC code. |
int ad4170_set_dclk_div | ( | struct ad4170_dev * | dev, |
enum ad4170_dclk_div | div | ||
) |
Set the AD4170 DCLK configuration.
dev | - The device structure. |
div | - AD4170 DCLK configuration. |
int ad4170_set_error | ( | struct ad4170_dev * | dev, |
uint16_t | error | ||
) |
Set the Error register with a value to clear specific errors.
dev | - The device structure. |
error | - Error mask (set bits will be cleared from the Error register). |
int ad4170_set_error_en | ( | struct ad4170_dev * | dev, |
uint16_t | error_en | ||
) |
Set the AD4170 Error enable settings.
dev | - The device structure. |
error_en | - AD4170 Error enable configuration. |
int ad4170_set_fir_control | ( | struct ad4170_dev * | dev, |
struct ad4170_fir_control | fir_control | ||
) |
Set the AD4170 FIR control settings.
dev | - The device structure. |
fir_control | - FIR control configuration. |
int ad4170_set_i_pullup | ( | struct ad4170_dev * | dev, |
uint16_t | ch_mask | ||
) |
Set the AD4170 Input pullup.
dev | - The device structure. |
ch_mask | - Input pullup enable mask. |
int ad4170_set_mclk_div | ( | struct ad4170_dev * | dev, |
enum ad4170_mclk_div | div | ||
) |
Set the AD4170 MCLK configuration.
dev | - The device structure. |
div | - AD4170 MCLK configuration. |
int ad4170_set_pin_muxing | ( | struct ad4170_dev * | dev, |
struct ad4170_pin_muxing | pin_muxing | ||
) |
Set the AD4170 Pin Muxing settings.
dev | - The device structure. |
pin_muxing | - AD4170 Pin Muxing configuration. |
int ad4170_set_powerdown_sw | ( | struct ad4170_dev * | dev, |
uint16_t | powerdown_sw | ||
) |
Set the AD4170 Powerdown switches settings.
dev | - The device structure. |
powerdown_sw | - AD4170 Powerdown switches configuration. |
int ad4170_set_ref_control | ( | struct ad4170_dev * | dev, |
bool | enable | ||
) |
Set the AD4170 Ref Control.
dev | - The device structure. |
enable | - Enable/Disable Ref Control. |
int ad4170_set_setup | ( | struct ad4170_dev * | dev, |
uint8_t | n, | ||
struct ad4170_setup | setup | ||
) |
Configure an ADC setup.
dev | - The device structure. |
n | - The setup number (0 to 8). |
setup | - AD4170 setup configuration. |
int ad4170_set_spi_settings | ( | struct ad4170_dev * | dev, |
const struct ad4170_spi_settings * | spi_settings | ||
) |
Set the AD4170 SPI settings.
dev | - The device structure. |
spi_settings | - AD4170 SPI configuration. |
int ad4170_set_standby_ctrl | ( | struct ad4170_dev * | dev, |
uint16_t | standby_ctrl | ||
) |
Set the AD4170 Standby control settings.
dev | - The device structure. |
standby_ctrl | - AD4170 Standby control configuration. |
int ad4170_set_v_bias | ( | struct ad4170_dev * | dev, |
uint16_t | ch_mask | ||
) |
Set the AD4170 Voltage bias.
dev | - The device structure. |
ch_mask | - Voltage bias enable mask. |
int ad4170_spi_reg_read | ( | struct ad4170_dev * | dev, |
uint32_t | reg_addr, | ||
uint32_t * | reg_data | ||
) |
Read device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The data read from the register. |
int ad4170_spi_reg_write | ( | struct ad4170_dev * | dev, |
uint32_t | reg_addr, | ||
uint32_t | reg_data | ||
) |
Write device register.
dev | - The device structure. |
reg_addr | - The register address. |
reg_data | - The register data. |
int ad4170_spi_reg_write_mask | ( | struct ad4170_dev * | dev, |
uint32_t | reg_addr, | ||
uint8_t | mask, | ||
uint32_t | reg_data | ||
) |
SPI write device register using a mask.
dev | - The device structure. |
reg_addr | - The register address. |
mask | - The mask. |
reg_data | - The register data. |
NO_OS_DECLARE_CRC8_TABLE | ( | ad4170_crc8 | ) |
struct ad4170_config ad4170_config_reset |
ad4170_config default state when the chip is hardware/software reset.