![]() |
no-OS
|
Implementation of AD405X Driver. More...
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "ad405x.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
Functions | |
int | ad405x_init (struct ad405x_dev **device, struct ad405x_init_param init_param) |
Initialize the communication device. | |
int | ad405x_remove (struct ad405x_dev *dev) |
Remove device and free the resources allocated by ad405x_init(). | |
int | ad405x_soft_reset (struct ad405x_dev *dev) |
Soft reset of the device. For I3C, the I3C peripheral is not reset, keeping its dynamic address and any other I3C property. | |
int | ad405x_clear_reset_flags (struct ad405x_dev *dev) |
Clear reset flags. | |
int | ad405x_read (struct ad405x_dev *dev, uint8_t addr, uint8_t *data, uint8_t size) |
Read device registers. | |
int | ad405x_write (struct ad405x_dev *dev, uint8_t addr, uint8_t *data, uint8_t size) |
Write registers. | |
int | ad405x_get_adc (struct ad405x_dev *dev, int32_t *value) |
Get formatted ADC reading. If gp0 is set as data ready, will be used to delay the acquisition until the signal is deserted (SPI only). | |
int | ad405x_get_raw (struct ad405x_dev *dev, uint32_t *raw) |
Get raw ADC reading. | |
int | ad405x_get_sts_reg (struct ad405x_dev *dev, uint8_t *status_flags, uint8_t *intf_status_flags) |
Read the interface status and status registers. | |
int | ad405x_clear_sts_reg (struct ad405x_dev *dev, uint8_t *status_flags, uint8_t *intf_status_flags) |
Write to clear the interface status and status registers. | |
int | ad405x_test_scratch_pad (struct ad405x_dev *dev) |
Test the scratch pad register. A pseudo-random value to test against is defined at compile time. | |
int | ad405x_set_adc_mode (struct ad405x_dev *dev) |
Enter ADC Mode. | |
int | ad405x_set_burst_averaging_mode (struct ad405x_dev *dev) |
Enter Burst Averaging Mode. | |
int | ad405x_set_persistent_auto_mode (struct ad405x_dev *dev) |
Enter Persistent Auto Mode. | |
int | ad405x_set_nonpersistent_auto_mode (struct ad405x_dev *dev) |
Enter Non-Persistent Auto Mode. | |
int | ad405x_set_operation_mode (struct ad405x_dev *dev, enum ad405x_operation_mode mode) |
Set operation mode. | |
int | ad405x_set_sample_rate (struct ad405x_dev *dev, enum ad405x_sample_rate rate) |
Select sample rate for Burst and Autonomous Modes. | |
enum ad405x_sample_rate | ad405x_get_sample_rate (struct ad405x_dev *dev) |
Get sample rate for Burst and Autonomous Modes. | |
int | ad405x_set_avg_filter_length (struct ad405x_dev *dev, enum ad405x_avg_filter_l length) |
Set averaging filter window length. | |
enum ad405x_avg_filter_l | ad405x_get_avg_filter_length (struct ad405x_dev *dev) |
Get averaging filter window length. | |
int | ad405x_set_dev_en_polarity (struct ad405x_dev *dev, enum ad405x_dev_en_polarity polarity) |
Set DEV_EN signal polarity. | |
enum ad405x_dev_en_polarity | ad405x_get_dev_en_polarity (struct ad405x_dev *dev) |
Get DEV_EN signal polarity. | |
int | ad405x_set_dev_en_timer_pwr_on (struct ad405x_dev *dev, enum ad405x_dev_en_timer_pwr_on time) |
Set DEV_EN TIMER_PWR_ON. | |
enum ad405x_dev_en_timer_pwr_on | ad405x_get_dev_en_timer_pwr_on (struct ad405x_dev *dev) |
Get DEV_EN TIMER_PWR_ON. | |
int | ad405x_enable_invert_on_chop (struct ad405x_dev *dev) |
Enable INVERT_ON_CHOP. | |
int | ad405x_disable_invert_on_chop (struct ad405x_dev *dev) |
Disable INVERT_ON_CHOP. | |
enum ad405x_invert_on_chop | ad405x_get_invert_on_chop_state (struct ad405x_dev *dev) |
Get INVERT_ON_CHOP setting. | |
int | ad405x_set_gp_mode (struct ad405x_dev *dev, enum ad405x_gp_select gp, enum ad405x_gp_mode mode) |
Set GP mode. | |
enum ad405x_gp_mode | ad405x_get_gp_mode (struct ad405x_dev *dev, enum ad405x_gp_select gp) |
Get GP mode setting. | |
int | ad405x_set_data_format (struct ad405x_dev *dev, enum ad405x_out_data_format data_format) |
Set output data format. | |
int | ad405x_set_data_format_straight_binary (struct ad405x_dev *dev) |
Set ADC output data format as straight binary. | |
int | ad405x_set_data_format_twos_complement (struct ad405x_dev *dev) |
Set ADC output data format as two's complement. | |
enum ad405x_out_data_format | ad405x_get_data_format (struct ad405x_dev *dev) |
Get output data format setting. | |
int | ad405x_set_threshold (struct ad405x_dev *dev, struct ad405x_thresh *thresh) |
Set threshold configuration. A simple memory swap puts the ad405x_thresh strict into format to write the 6 registers of interest. | |
int | ad405x_get_threshold (struct ad405x_dev *dev, struct ad405x_thresh *thresh) |
Get threshold configuration. | |
int | ad405x_exit_command (struct ad405x_dev *dev) |
Send EXIT command (SPI only). | |
int | ad405x_trigger_adc_conv (struct ad405x_dev *dev) |
Trigger an ADC conversion (SPI only). Toggle the CNV pin to start the conversion. | |
int | ad405x_set_averaging_mode (struct ad405x_dev *dev) |
Enter Averaging Mode (SPI only). | |
int | ad405x_set_config_mode (struct ad405x_dev *dev, enum ad405x_operation_mode *mode) |
Enter Configuration Mode (SPI only). | |
int | ad405x_test_common_ccc (struct ad405x_dev *dev) |
Test the GETBCR, GETDCR, GETPID, AND GETSTATUS CCCs (I3C only). Compare received BCR and DCR against expected values. | |
int | ad405x_pool_ibi_config (struct ad405x_dev *dev) |
Pool IBI status and config registers (I3C only). Values are updated on the device descriptor. | |
int | ad405x_set_ibi_enable (struct ad405x_dev *dev, bool enable) |
Enable/disable IBI (I3C only). | |
int | ad405x_set_ibi_mask (struct ad405x_dev *dev, uint16_t en_mask) |
Set IBI mask (I3C only). | |
Implementation of AD405X Driver.
Copyright 2024~2025(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 ad405x_clear_reset_flags | ( | struct ad405x_dev * | dev | ) |
Clear reset flags.
dev | - The device descriptor. |
int ad405x_clear_sts_reg | ( | struct ad405x_dev * | dev, |
uint8_t * | status_flags, | ||
uint8_t * | intf_status_flags ) |
Write to clear the interface status and status registers.
dev | - The device descriptor. |
status_flags | - Status register value (optional). |
intf_status_flags | - Interface register value (optional). |
int ad405x_disable_invert_on_chop | ( | struct ad405x_dev * | dev | ) |
Disable INVERT_ON_CHOP.
dev | - The device descriptor. |
int ad405x_enable_invert_on_chop | ( | struct ad405x_dev * | dev | ) |
Enable INVERT_ON_CHOP.
dev | - The device descriptor. |
int ad405x_exit_command | ( | struct ad405x_dev * | dev | ) |
Send EXIT command (SPI only).
dev | - The device descriptor. |
int ad405x_get_adc | ( | struct ad405x_dev * | dev, |
int32_t * | value ) |
Get formatted ADC reading. If gp0 is set as data ready, will be used to delay the acquisition until the signal is deserted (SPI only).
dev | - The device descriptor. |
value | - ADC value. |
enum ad405x_avg_filter_l ad405x_get_avg_filter_length | ( | struct ad405x_dev * | dev | ) |
Get averaging filter window length.
dev | - The device descriptor. |
enum ad405x_out_data_format ad405x_get_data_format | ( | struct ad405x_dev * | dev | ) |
Get output data format setting.
dev | - The device descriptor. |
enum ad405x_dev_en_polarity ad405x_get_dev_en_polarity | ( | struct ad405x_dev * | dev | ) |
Get DEV_EN signal polarity.
dev | - The device descriptor. |
enum ad405x_dev_en_timer_pwr_on ad405x_get_dev_en_timer_pwr_on | ( | struct ad405x_dev * | dev | ) |
Get DEV_EN TIMER_PWR_ON.
dev | - The device descriptor. |
enum ad405x_gp_mode ad405x_get_gp_mode | ( | struct ad405x_dev * | dev, |
enum ad405x_gp_select | gp ) |
Get GP mode setting.
dev | - The device descriptor. |
gp | - GP1/GP0 select. |
enum ad405x_invert_on_chop ad405x_get_invert_on_chop_state | ( | struct ad405x_dev * | dev | ) |
Get INVERT_ON_CHOP setting.
dev | - The device descriptor. |
int ad405x_get_raw | ( | struct ad405x_dev * | dev, |
uint32_t * | raw ) |
Get raw ADC reading.
dev | - The device descriptor. |
raw | - Raw ADC data. |
enum ad405x_sample_rate ad405x_get_sample_rate | ( | struct ad405x_dev * | dev | ) |
Get sample rate for Burst and Autonomous Modes.
dev | - The device descriptor. |
int ad405x_get_sts_reg | ( | struct ad405x_dev * | dev, |
uint8_t * | status_flags, | ||
uint8_t * | intf_status_flags ) |
Read the interface status and status registers.
dev | - The device descriptor. |
status_flags | - Status register value. |
intf_status_flags | - Interface register value (optional). |
int ad405x_get_threshold | ( | struct ad405x_dev * | dev, |
struct ad405x_thresh * | thresh ) |
Get threshold configuration.
dev | - The device descriptor. |
thresh | - The threshold configuration structure. |
int ad405x_init | ( | struct ad405x_dev ** | device, |
struct ad405x_init_param | init_param ) |
Initialize the communication device.
device | - The device descriptor. |
init_param | - The device initial descriptor. |
int ad405x_pool_ibi_config | ( | struct ad405x_dev * | dev | ) |
Pool IBI status and config registers (I3C only). Values are updated on the device descriptor.
dev | - The device descriptor. |
int ad405x_read | ( | struct ad405x_dev * | dev, |
uint8_t | addr, | ||
uint8_t * | data, | ||
uint8_t | size ) |
Read device registers.
dev | - The device descriptor. |
addr | - Address of the base register. |
data | - The read data buffer |
size | - The number of bytes to be read. |
int ad405x_remove | ( | struct ad405x_dev * | dev | ) |
Remove device and free the resources allocated by ad405x_init().
dev | - The device descriptor. |
int ad405x_set_adc_mode | ( | struct ad405x_dev * | dev | ) |
Enter ADC Mode.
dev | - The device descriptor. |
int ad405x_set_averaging_mode | ( | struct ad405x_dev * | dev | ) |
Enter Averaging Mode (SPI only).
dev | - The device descriptor. |
int ad405x_set_avg_filter_length | ( | struct ad405x_dev * | dev, |
enum ad405x_avg_filter_l | length ) |
Set averaging filter window length.
dev | - The device descriptor. |
length | - Averaging filter length value. |
int ad405x_set_burst_averaging_mode | ( | struct ad405x_dev * | dev | ) |
Enter Burst Averaging Mode.
dev | - The device descriptor. |
int ad405x_set_config_mode | ( | struct ad405x_dev * | dev, |
enum ad405x_operation_mode * | mode ) |
Enter Configuration Mode (SPI only).
dev | - The device descriptor. |
mode | - Store the current op mode, to resume later (optional). |
int ad405x_set_data_format | ( | struct ad405x_dev * | dev, |
enum ad405x_out_data_format | data_format ) |
Set output data format.
dev | - The device descriptor. |
data_format | - Format select. |
int ad405x_set_data_format_straight_binary | ( | struct ad405x_dev * | dev | ) |
Set ADC output data format as straight binary.
dev | - The device descriptor. |
int ad405x_set_data_format_twos_complement | ( | struct ad405x_dev * | dev | ) |
Set ADC output data format as two's complement.
dev | - The device descriptor. |
int ad405x_set_dev_en_polarity | ( | struct ad405x_dev * | dev, |
enum ad405x_dev_en_polarity | polarity ) |
Set DEV_EN signal polarity.
dev | - The device descriptor. |
polarity | - DEV_EN signal polarity. |
int ad405x_set_dev_en_timer_pwr_on | ( | struct ad405x_dev * | dev, |
enum ad405x_dev_en_timer_pwr_on | time ) |
Set DEV_EN TIMER_PWR_ON.
dev | - The device descriptor. |
time | - DEV_EN power-on timer setting. |
int ad405x_set_gp_mode | ( | struct ad405x_dev * | dev, |
enum ad405x_gp_select | gp, | ||
enum ad405x_gp_mode | mode ) |
Set GP mode.
dev | - The device descriptor. |
gp | - GP1/GP0 select. |
mode | - mode select. |
int ad405x_set_ibi_enable | ( | struct ad405x_dev * | dev, |
bool | enable ) |
Enable/disable IBI (I3C only).
dev | - The device descriptor. |
enable | - Enable IBI. |
int ad405x_set_ibi_mask | ( | struct ad405x_dev * | dev, |
uint16_t | en_mask ) |
Set IBI mask (I3C only).
dev | - The device descriptor. |
en_mask | - Enable interface and ADC flags. |
int ad405x_set_nonpersistent_auto_mode | ( | struct ad405x_dev * | dev | ) |
Enter Non-Persistent Auto Mode.
dev | - The device descriptor. |
int ad405x_set_operation_mode | ( | struct ad405x_dev * | dev, |
enum ad405x_operation_mode | mode ) |
Set operation mode.
dev | - The device descriptor. |
mode | - Operation mode. |
int ad405x_set_persistent_auto_mode | ( | struct ad405x_dev * | dev | ) |
Enter Persistent Auto Mode.
dev | - The device descriptor. |
int ad405x_set_sample_rate | ( | struct ad405x_dev * | dev, |
enum ad405x_sample_rate | rate ) |
Select sample rate for Burst and Autonomous Modes.
dev | - The device descriptor. |
rate | - The sample rate. |
int ad405x_set_threshold | ( | struct ad405x_dev * | dev, |
struct ad405x_thresh * | thresh ) |
Set threshold configuration. A simple memory swap puts the ad405x_thresh strict into format to write the 6 registers of interest.
dev | - The device descriptor. |
thresh | - The threshold configuration structure. |
int ad405x_soft_reset | ( | struct ad405x_dev * | dev | ) |
Soft reset of the device. For I3C, the I3C peripheral is not reset, keeping its dynamic address and any other I3C property.
dev | - The device descriptor. |
int ad405x_test_common_ccc | ( | struct ad405x_dev * | dev | ) |
Test the GETBCR, GETDCR, GETPID, AND GETSTATUS CCCs (I3C only). Compare received BCR and DCR against expected values.
dev | - The device descriptor. |
int ad405x_test_scratch_pad | ( | struct ad405x_dev * | dev | ) |
Test the scratch pad register. A pseudo-random value to test against is defined at compile time.
dev | - The device descriptor. |
int ad405x_trigger_adc_conv | ( | struct ad405x_dev * | dev | ) |
Trigger an ADC conversion (SPI only). Toggle the CNV pin to start the conversion.
dev | - The device descriptor. |
int ad405x_write | ( | struct ad405x_dev * | dev, |
uint8_t | addr, | ||
uint8_t * | data, | ||
uint8_t | size ) |
Write registers.
dev | - The device descriptor. |
addr | - Address of the base register. |
data | - The data which is going to be written. |
size | - The number of bytes to be written. |