Skip to content

Commit

Permalink
projects:ad4170_iio: Add support to AD4190
Browse files Browse the repository at this point in the history
Add support to AD4190, update documentation and copyright

Corrected the virtual com port parameters and configured VCOM as default

Add runtime detection of connected device with the EEPROM contents

Added macros/APIs for configuring the sampling rate/FS values

Signed-off-by: Janani Sunil <[email protected]>
  • Loading branch information
jansunil committed Feb 3, 2025
1 parent f20e3d3 commit c33b554
Show file tree
Hide file tree
Showing 18 changed files with 205 additions and 39 deletions.
1 change: 1 addition & 0 deletions doc/sphinx/source/projects/ad4170_iio/ad4170_iio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Supported Hardware
**Supported Devices:**

* `AD4170 <https://www.analog.com/en/products/ad4170-4.html>`_
* `AD4190 <https://www.analog.com/en/products/ad4190-4.html>`_

**Supported Carrier Boards:**

Expand Down
2 changes: 2 additions & 0 deletions projects/ad4170_iio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ STM32/sdp_k1/.mxproject
STM32/sdp_k1/ad4170_iio Debug.launch
STM32/sdp_k1/STM32F469NIHX_FLASH.ld
STM32/sdp_k1/STM32F469NIHX_RAM.ld
STM32/sdp_k1/Middlewares
STM32/sdp_k1/USB_DEVICE
scripts/__pycache__
tests/.pytest_cache
tests/__pycache__
Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/STM32/sdp_k1/.extSettings
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ app/libraries/no-OS/iio/=../../../../libraries/no-OS/iio/iio.c;../../../../libra
app/libraries/no-OS/drivers/api/=../../../../libraries/no-OS/drivers/api/no_os_gpio.c;../../../../libraries/no-OS/drivers/api/no_os_spi.c;../../../../libraries/no-OS/drivers/api/no_os_irq.c;../../../../libraries/no-OS/drivers/api/no_os_i2c.c;../../../../libraries/no-OS/drivers/api/no_os_eeprom.c;../../../../libraries/no-OS/drivers/api/no_os_uart.c;../../../../libraries/no-OS/drivers/api/no_os_tdm.c;../../../../libraries/no-OS/drivers/api/no_os_pwm.c;../../../../libraries/no-OS/drivers/api/no_os_dma.c;

[Others]
Define=_USE_STD_INT_TYPES;TINYIIOD_VERSION_MAJOR;TINYIIOD_VERSION_MINOR;TINYIIOD_VERSION_GIT;IIOD_BUFFER_SIZE;IIO_IGNORE_BUFF_OVERRUN_ERR;USE_PHY_COM_PORT;NO_OS_VERSION;TARGET_SDP_K1
Define=_USE_STD_INT_TYPES;TINYIIOD_VERSION_MAJOR;TINYIIOD_VERSION_MINOR;TINYIIOD_VERSION_GIT;IIOD_BUFFER_SIZE;IIO_IGNORE_BUFF_OVERRUN_ERR;NO_OS_VERSION;TARGET_SDP_K1
5 changes: 4 additions & 1 deletion projects/ad4170_iio/STM32/sdp_k1/ad4170_iio.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ TIM8.TIM_MasterSlaveMode=TIM_MASTERSLAVEMODE_ENABLE
UART5.IPParameters=VirtualMode
UART5.VirtualMode=Asynchronous
USB_DEVICE.CLASS_NAME_HS=CDC
USB_DEVICE.IPParameters=VirtualMode-CDC_HS,VirtualModeHS,CLASS_NAME_HS
USB_DEVICE.IPParameters=VirtualMode-CDC_HS,VirtualModeHS,CLASS_NAME_HS,PRODUCT_STRING_CDC_HS,VID-CDC_HS,PID_CDC_HS
USB_DEVICE.PID_CDC_HS=0xB66C
USB_DEVICE.PRODUCT_STRING_CDC_HS=STM32_Virtual_Com_Port
USB_DEVICE.VID-CDC_HS=0x456
USB_DEVICE.VirtualMode-CDC_HS=Cdc
USB_DEVICE.VirtualModeHS=Cdc_HS
USB_OTG_HS.IPParameters=VirtualMode-Device_HS
Expand Down
10 changes: 9 additions & 1 deletion projects/ad4170_iio/app/ad4170_accelerometer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ad4170_accelerometer_config.c
* @brief Accelerometer user configurations module for AD4170 IIO firmware
******************************************************************************
* Copyright (c) 2021-22,24 Analog Devices, Inc.
* Copyright (c) 2021-22,2024-25 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand Down Expand Up @@ -56,7 +56,11 @@ struct ad4170_init_param ad4170_accelerometer_config_params = {
.pin_muxing = {
.chan_to_gpio = AD4170_CHANNEL_NOT_TO_GPIO,
#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
#if defined(DEV_AD4190)
.dig_aux2_ctrl = AD4170_DIG_AUX2_SYNC, // Used as START Input.
#else
.dig_aux2_ctrl = AD4170_DIG_AUX2_LDAC, // Used as h/w LDACB
#endif // DEV_AD4190
.dig_aux1_ctrl = AD4170_DIG_AUX1_RDY, // Used as RDY (end of conversion)
#elif (INTERFACE_MODE == TDM_MODE)
.dig_aux1_ctrl = AD4170_DIG_AUX1_DISABLED,
Expand Down Expand Up @@ -105,6 +109,8 @@ struct ad4170_init_param ad4170_accelerometer_config_params = {
/* Setup configurations */
.setups = {
{
/* NOTE: chop_adc = AD4170_CHOP_IEXC_CD and AD4170_CHOP_IEXC_ABCD options
* are not available on the AD4190 */
.misc = {
.chop_iexc = AD4170_CHOP_IEXC_OFF,
.chop_adc = AD4170_CHOP_OFF,
Expand Down Expand Up @@ -137,6 +143,7 @@ struct ad4170_init_param ad4170_accelerometer_config_params = {
{ .i_out_pin = AD4170_I_OUT_AIN0, .i_out_val = AD4170_I_OUT_0UA },
{ .i_out_pin = AD4170_I_OUT_AIN0, .i_out_val = AD4170_I_OUT_0UA }
},
#if !defined(DEV_AD4190)
.fir_control = {
.fir_mode = AD4170_FIR_DEFAULT,
.coeff_set = AD4170_FIR_COEFF_SET0,
Expand All @@ -149,6 +156,7 @@ struct ad4170_init_param ad4170_accelerometer_config_params = {
.hw_toggle = false,
.hw_ldac = false
}
#endif
},

&gpio_init_sync_inb,
Expand Down
107 changes: 95 additions & 12 deletions projects/ad4170_iio/app/ad4170_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @brief Implementation of AD4170 IIO application interfaces
* @details This module acts as an interface for AD4170 IIO application
********************************************************************************
* Copyright (c) 2021-24 Analog Devices, Inc.
* Copyright (c) 2021-2024-25 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand Down Expand Up @@ -429,6 +429,25 @@ struct ad4170_cached_reg reg_values[N_REGISTERS_CACHED];
/* Register index */
uint8_t read_reg_id = 0;

/* Permissible HW Mezzanine names */
static const char *mezzanine_names[] = {
"EVAL-AD4170-4ARDZ",
"",
"",
"EVAL-AD4190-4ARDZ"
};

/* Active device available options */
static const char* active_dev[] = {
"ad4170",
"",
"",
"ad4190",
};

/* Effective sampling rate of the device */
static uint32_t sampling_rate = AD4170_MAX_SAMPLING_RATE;

/******************************************************************************/
/************************ Functions Prototypes ********************************/
/******************************************************************************/
Expand Down Expand Up @@ -514,7 +533,7 @@ static int get_sampling_frequency(void *device,
* indicate an actual sampling rate of device.
* Refer the 'note' in function description above for timeout calculations */
return sprintf(buf, "%d",
(AD4170_DEFLT_SAMPLING_FREQUENCY / num_of_channels));
(sampling_rate / num_of_channels));
}

static int set_sampling_frequency(void *device,
Expand Down Expand Up @@ -544,7 +563,7 @@ static int get_adc_raw(void *device,
intptr_t id)
{
int32_t ret;
static int32_t adc_data_raw = 0;
static uint32_t adc_data_raw = 0;
int32_t offset = 0;
uint8_t setup = p_ad4170_dev_inst->config.setup[channel->ch_num].setup_n;
bool bipolar = p_ad4170_dev_inst->config.setups[setup].afe.bipolar;
Expand Down Expand Up @@ -1505,6 +1524,13 @@ int32_t debug_reg_read(void *dev, uint32_t reg, uint32_t *readval)

reg_base_add = debug_reg_search(reg, &reg_addr_offset);

if (p_ad4170_dev_inst->id == ID_AD4190) {
if ((reg_base_add >= AD4170_REG_FIR_CONTROL)
&& (reg_base_add <= AD4170_REG_DAC_INPUTB(0))) {
return -EINVAL;
}
}

/* Read data from device register */
ret = ad4170_spi_reg_read(dev, reg_base_add, readval);
if (ret) {
Expand Down Expand Up @@ -1537,6 +1563,13 @@ int32_t debug_reg_write(void *dev, uint32_t reg, uint32_t writeval)

reg_base_add = debug_reg_search(reg, &reg_addr_offset);

if (p_ad4170_dev_inst->id == ID_AD4190) {
if ((reg_base_add >= AD4170_REG_FIR_CONTROL)
&& (reg_base_add <= AD4170_REG_DAC_INPUTB(0))) {
return -EINVAL;
}
}

/* Read the register contents */
ret = ad4170_spi_reg_read(dev, reg_base_add, &data);
if (ret) {
Expand Down Expand Up @@ -2852,6 +2885,45 @@ void ticker_callback(void *ctx)
}
}

/**
* @brief Configure filter parameters according to active device chosen
* @param None
* @return none
*/
void ad4170_configure_filter_params(void)
{
uint16_t filter_fs;
uint8_t setup_id;
enum ad4170_filter_type filter_type;

if (ad4170_init_params.id == ID_AD4170) {
#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
filter_fs = FS_SINC5_AVG_24_KSPS;
filter_type = AD4170_FILT_SINC5_AVG;
#else // TDM_MODE and SPI_DMA_MODE
filter_fs = FS_SINC5_512_KSPS;
filter_type = AD4170_FILT_SINC5;
#endif
} else if (ad4170_init_params.id == ID_AD4190) {
#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
filter_fs = FS_SINC5_AVG_24_KSPS;
filter_fs = AD4170_FILT_SINC5_AVG;
#else // TDM_MODE and SPI_DMA Mode
filter_fs = FS_SINC3_62P5_KSPS;
filter_type = AD4170_FILT_SINC3;
#endif
}

/* Update the setup register with the filter and FS value */
for (setup_id = 0; setup_id < AD4170_NUM_SETUPS; setup_id++) {
ad4170_init_params.config.setups[setup_id].filter.filter_type = filter_type;
ad4170_init_params.config.setups[setup_id].filter_fs = filter_fs;
}

/* Calculate the effective sampling rate of the device */
sampling_rate = (AD4170_INTERNAL_CLOCK / (FILTER_SCALE * filter_fs));
}

/**
* @brief Initialize the IIO interface for AD4170 IIO device
* @return none
Expand All @@ -2860,6 +2932,7 @@ void ticker_callback(void *ctx)
int32_t ad4170_iio_initialize(void)
{
int32_t init_status;
uint8_t read_id;

/* Init the system peripherals */
init_status = init_system();
Expand All @@ -2868,16 +2941,26 @@ int32_t ad4170_iio_initialize(void)
}

/* Read context attributes */
init_status = get_iio_context_attributes(&iio_init_params.ctx_attrs,
&iio_init_params.nb_ctx_attr,
eeprom_desc,
HW_MEZZANINE_NAME,
STR(HW_CARRIER_NAME),
&hw_mezzanine_is_valid);
if (init_status) {
return init_status;
for (read_id = 0; read_id < NO_OS_ARRAY_SIZE(mezzanine_names); read_id++) {
init_status = get_iio_context_attributes(&iio_init_params.ctx_attrs,
&iio_init_params.nb_ctx_attr,
eeprom_desc,
mezzanine_names[read_id],
STR(HW_CARRIER_NAME),
&hw_mezzanine_is_valid);
if (init_status) {
return init_status;
}

if (hw_mezzanine_is_valid) {
ad4170_init_params.id = read_id;
break;
}
}

/* Re-assign the parameters according to the active device */
ad4170_configure_filter_params();

if (hw_mezzanine_is_valid) {
/* Initialize AD4170 device and peripheral interface */
init_status = ad4170_init(&p_ad4170_dev_inst, &ad4170_init_params);
Expand All @@ -2891,7 +2974,7 @@ int32_t ad4170_iio_initialize(void)
return init_status;
}

iio_device_init_params[0].name = ACTIVE_DEVICE_NAME;
iio_device_init_params[0].name = active_dev[p_ad4170_dev_inst->id];
iio_device_init_params[0].raw_buf = adc_data_buffer;
iio_device_init_params[0].raw_buf_len = DATA_BUFFER_SIZE;

Expand Down
10 changes: 9 additions & 1 deletion projects/ad4170_iio/app/ad4170_loadcell_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ad4170_loadcell_config.c
* @brief Loadcell user configurations module for AD4170 IIO firmware
******************************************************************************
* Copyright (c) 2021-22,24 Analog Devices, Inc.
* Copyright (c) 2021-22,2024-25 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand Down Expand Up @@ -56,7 +56,11 @@ struct ad4170_init_param ad4170_loadcell_config_params = {
.pin_muxing = {
.chan_to_gpio = AD4170_CHANNEL_NOT_TO_GPIO,
#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
#if defined(DEV_AD4190)
.dig_aux2_ctrl = AD4170_DIG_AUX2_SYNC, // Used as START Input.
#else
.dig_aux2_ctrl = AD4170_DIG_AUX2_LDAC, // Used as h/w LDACB
#endif // DEV_AD4190
.dig_aux1_ctrl = AD4170_DIG_AUX1_RDY, // Used as RDY (end of conversion)
#elif (INTERFACE_MODE == TDM_MODE)
.dig_aux1_ctrl = AD4170_DIG_AUX1_DISABLED,
Expand Down Expand Up @@ -127,6 +131,8 @@ struct ad4170_init_param ad4170_loadcell_config_params = {
{
.misc = {
#if defined(LOADCELL_AC_EXCITATION)
/* NOTE: chop_adc = AD4170_CHOP_IEXC_CD and AD4170_CHOP_IEXC_ABCD options
* are not available on the AD4190 */
/* Excitation currents are periodically chopped for AC excitation measurement */
.chop_adc = AD4170_CHOP_ACX_4PIN,
#else
Expand Down Expand Up @@ -243,6 +249,7 @@ struct ad4170_init_param ad4170_loadcell_config_params = {
{ .i_out_pin = AD4170_I_OUT_AIN0, .i_out_val = AD4170_I_OUT_0UA },
{ .i_out_pin = AD4170_I_OUT_AIN0, .i_out_val = AD4170_I_OUT_0UA }
},
#if !defined(DEV_AD4190)
.fir_control = {
.fir_mode = AD4170_FIR_DEFAULT,
.coeff_set = AD4170_FIR_COEFF_SET0,
Expand All @@ -255,6 +262,7 @@ struct ad4170_init_param ad4170_loadcell_config_params = {
.hw_toggle = false,
.hw_ldac = false
}
#endif
},

&gpio_init_sync_inb,
Expand Down
5 changes: 3 additions & 2 deletions projects/ad4170_iio/app/ad4170_loadcell_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ad4170_loadcell_config.h
* @brief Header for AD4170 Loadcell configurations module
******************************************************************************
* Copyright (c) 2021-22 Analog Devices, Inc.
* Copyright (c) 2021-22,25 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand All @@ -25,7 +25,8 @@
/********************** Macros and Constants Definition ***********************/
/******************************************************************************/

/* Select the excitation type for load cell (AC/DC) - one at a time */
/* Select the excitation type for load cell (AC/DC) - one at a time
* Note- AC excitation is not applicable in case of AD4190 */
#define LOADCELL_DC_EXCITATION
//#define LOADCELL_AC_EXCITATION

Expand Down
2 changes: 1 addition & 1 deletion projects/ad4170_iio/app/ad4170_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ad4170_regs.h
* @brief Global declarations for ad4170_regs module
********************************************************************************
* Copyright (c) 2021,2024 Analog Devices, Inc.
* Copyright (c) 2021,2025 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand Down
10 changes: 9 additions & 1 deletion projects/ad4170_iio/app/ad4170_rtd_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file ad4170_rtd_config.c
* @brief RTD (2/3/4-wire) user configurations module for AD4170 IIO firmware
******************************************************************************
* Copyright (c) 2021-22,24 Analog Devices, Inc.
* Copyright (c) 2021-22,2024-25 Analog Devices, Inc.
* All rights reserved.
*
* This software is proprietary to Analog Devices, Inc. and its licensors.
Expand Down Expand Up @@ -56,7 +56,11 @@ struct ad4170_init_param ad4170_rtd_config_params = {
.pin_muxing = {
.chan_to_gpio = AD4170_CHANNEL_NOT_TO_GPIO,
#if (INTERFACE_MODE == SPI_INTERRUPT_MODE)
#if defined(DEV_AD4190)
.dig_aux2_ctrl = AD4170_DIG_AUX2_SYNC, // Used as START Input.
#else
.dig_aux2_ctrl = AD4170_DIG_AUX2_LDAC, // Used as h/w LDACB
#endif // DEV_AD4190
.dig_aux1_ctrl = AD4170_DIG_AUX1_RDY, // Used as RDY (end of conversion)
#elif (INTERFACE_MODE == TDM_MODE)
.dig_aux1_ctrl = AD4170_DIG_AUX1_DISABLED,
Expand Down Expand Up @@ -110,6 +114,8 @@ struct ad4170_init_param ad4170_rtd_config_params = {
.setups = {
// Setup0
{
/* NOTE: chop_adc = AD4170_CHOP_IEXC_CD and AD4170_CHOP_IEXC_ABCD
* options are not available on the AD4190 */
.misc = {
.chop_iexc = AD4170_CHOP_IEXC_OFF,
.chop_adc = AD4170_CHOP_OFF,
Expand Down Expand Up @@ -156,6 +162,7 @@ struct ad4170_init_param ad4170_rtd_config_params = {
{ .i_out_pin = AD4170_I_OUT_AIN0, .i_out_val = AD4170_I_OUT_0UA },
#endif
},
#if !defined(DEV_AD4190)
.fir_control = {
.fir_mode = AD4170_FIR_DEFAULT,
.coeff_set = AD4170_FIR_COEFF_SET0,
Expand All @@ -168,6 +175,7 @@ struct ad4170_init_param ad4170_rtd_config_params = {
.hw_toggle = false,
.hw_ldac = false
}
#endif
},

&gpio_init_sync_inb,
Expand Down
Loading

0 comments on commit c33b554

Please sign in to comment.