Skip to content

Commit aca9204

Browse files
committed
ada4355: add linux support
Add ada4355 pyadi-iio support for the linux driver. https://github.com/analogdevicesinc/linux/blob/34bb38377c9daa30d2abc632b82b4b654a32e90b/drivers/iio/adc/ada4355.c Signed-off-by: Pop Ioan Daniel <[email protected]>
1 parent 6b33acd commit aca9204

File tree

9 files changed

+163
-0
lines changed

9 files changed

+163
-0
lines changed

adi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from adi.ad9467 import ad9467
5555
from adi.ad9625 import ad9625
5656
from adi.ad9680 import ad9680
57+
from adi.ada4355 import ada4355
5758
from adi.ada4961 import ada4961
5859
from adi.adaq8092 import adaq8092
5960
from adi.adar1000 import adar1000, adar1000_array

adi/ada4355.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Copyright (C) 2025 Analog Devices, Inc.
2+
#
3+
# SPDX short identifier: ADIBSD
4+
5+
from decimal import Decimal
6+
7+
import numpy as np
8+
9+
from adi.attribute import attribute
10+
from adi.context_manager import context_manager
11+
from adi.rx_tx import rx
12+
13+
14+
class ada4355(rx, context_manager):
15+
16+
""" ADA4355 ADC """
17+
18+
_complex_data = False
19+
channel = [] # type: ignore
20+
_device_name = "ada4355"
21+
22+
def __init__(self, uri="", device_name="ada4355"):
23+
"""Constructor for ada4355 class."""
24+
context_manager.__init__(self, uri, self._device_name)
25+
26+
compatible_parts = ["ada4355"]
27+
28+
self._ctrl = None
29+
30+
if not device_name:
31+
device_name = compatible_parts[0]
32+
else:
33+
if device_name not in compatible_parts:
34+
raise Exception(f"Not a compatible device: {device_name}")
35+
36+
# Select the device matching device_name as working device
37+
for device in self._ctx.devices:
38+
if device.name == device_name:
39+
self._ctrl = device
40+
self._rxadc = device
41+
break
42+
43+
if not self._ctrl:
44+
raise Exception("Error in selecting matching device")
45+
46+
if not self._rxadc:
47+
raise Exception("Error in selecting matching device")
48+
49+
self._rx_channel_names = []
50+
self.channel = []
51+
for ch in self._ctrl.channels:
52+
name = ch._id
53+
self._rx_channel_names.append(name)
54+
self.channel.append(self._channel(self._ctrl, name))
55+
56+
rx.__init__(self)
57+
58+
def ada4355_register_read(self, reg):
59+
"""Direct Register Access via debugfs"""
60+
self._set_iio_debug_attr_str("direct_reg_access", reg, self._ctrl)
61+
return self._get_iio_debug_attr_str("direct_reg_access", self._ctrl)
62+
63+
def ada4355_register_write(self, reg, value):
64+
"""Direct Register Access via debugfs"""
65+
self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._ctrl)
66+
67+
@property
68+
def sampling_frequency(self):
69+
"""Get sampling frequency."""
70+
return self._get_iio_dev_attr("sampling_frequency")
71+
72+
class _channel(attribute):
73+
74+
""" ada4355 channel """
75+
76+
def __init__(self, ctrl, channel_name):
77+
self.name = channel_name
78+
self._ctrl = ctrl
79+
80+
@property
81+
def scale(self):
82+
"""Get channel scale value"""
83+
return float(self._get_iio_attr_str(self.name, "scale", False))
84+
85+
@scale.setter
86+
def scale(self, value):
87+
"""Set channel scale value"""
88+
self._set_iio_attr(self.name, "scale", False, str(Decimal(value).real))
89+
90+
@property
91+
def raw(self):
92+
"""Get channel raw value (single sample)"""
93+
return self._get_iio_attr(self.name, "raw", False)

doc/source/devices/adi.ada4355.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ada4355
2+
=================
3+
4+
.. automodule:: adi.ada4355
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

doc/source/devices/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Supported Devices
6262
adi.ad9680
6363
adi.ad4858
6464
adi.ad9739a
65+
adi.ada4355
6566
adi.ada4961
6667
adi.adaq8092
6768
adi.adar1000

examples/ada4355_example.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (C) 2025 Analog Devices, Inc.
2+
#
3+
# SPDX short identifier: ADIBSD
4+
5+
import sys
6+
import time
7+
8+
import matplotlib.pyplot as plt
9+
import numpy as np
10+
11+
import adi
12+
13+
my_uri = sys.argv[1] if len(sys.argv) >= 2 else "local:"
14+
print("uri: " + str(my_uri))
15+
16+
17+
ada4355_dev = adi.ada4355(uri=my_uri)
18+
19+
ada4355_dev.rx_buffer_size = 8096
20+
ada4355_dev.rx_enabled_channels = [0]
21+
print("RX rx_enabled_channels: " + str(ada4355_dev.rx_enabled_channels))
22+
23+
print("Sampling Frequency: ", ada4355_dev.sampling_frequency)
24+
25+
# rx data
26+
27+
data = ada4355_dev.rx()
28+
29+
# plot setup
30+
31+
fig, (ch0) = plt.subplots(1, 1)
32+
33+
fig.suptitle("ADA4355 Data")
34+
ch0.plot(data)
35+
ch0.set_ylabel("Channel 0 amplitude")
36+
ch0.set_xlabel("Samples")
37+
38+
plt.show()
39+
40+
ada4355_dev.rx_destroy_buffer()

supported_parts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
- AD9680
122122
- AD4858
123123
- AD9739A
124+
- ADA4355
124125
- ADA4961
125126
- ADAQ4216
126127
- ADAQ4220

test/emu/devices/ada4355.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE context [<!ELEMENT context (device | context-attribute)*><!ELEMENT context-attribute EMPTY><!ELEMENT device (channel | attribute | debug-attribute | buffer-attribute)*><!ELEMENT channel (scan-element?, attribute*)><!ELEMENT attribute EMPTY><!ELEMENT scan-element EMPTY><!ELEMENT debug-attribute EMPTY><!ELEMENT buffer-attribute EMPTY><!ATTLIST context name CDATA #REQUIRED description CDATA #IMPLIED><!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED><!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED><!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED><!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED><!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED value CDATA #IMPLIED><!ATTLIST debug-attribute name CDATA #REQUIRED value CDATA #IMPLIED><!ATTLIST buffer-attribute name CDATA #REQUIRED value CDATA #IMPLIED>]><context name="network" description="10.48.65.215 Linux analog 6.6.0-25269-g34bb38377c9d #145 SMP PREEMPT Mon Jul 14 14:02:32 EEST 2025 armv7l" ><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hdl_system_id" value="[ada4355_fmc] [BUFMRCE_EN] on [zed] git branch [ada4355_xdc_update] git [5781fd85b80b06cce0cd608f0440a30fd11cabb4] dirty [2025-08-13 05:58:27] UTC" /><context-attribute name="local,kernel" value="6.6.0-25269-g34bb38377c9d" /><context-attribute name="uri" value="ip:10.48.65.215" /><context-attribute name="ip,ip-addr" value="10.48.65.215" /><device id="hwmon0" name="e000b000ethernetffffffff00" ><channel id="temp1" type="input" ><attribute name="crit" filename="temp1_crit" value="100000" /><attribute name="input" filename="temp1_input" value="41000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device0" name="ad7291" ><channel id="voltage6" type="input" ><attribute name="raw" filename="in_voltage6_raw" value="2" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="temp0" type="input" ><attribute name="mean_raw" filename="in_temp0_mean_raw" value="134" /><attribute name="raw" filename="in_temp0_raw" value="134" /><attribute name="scale" filename="in_temp0_scale" value="250" /></channel><channel id="voltage3" type="input" ><attribute name="raw" filename="in_voltage3_raw" value="1674" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage7" type="input" ><attribute name="raw" filename="in_voltage7_raw" value="2" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage0" type="input" ><attribute name="raw" filename="in_voltage0_raw" value="2092" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage4" type="input" ><attribute name="raw" filename="in_voltage4_raw" value="1" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage1" type="input" ><attribute name="raw" filename="in_voltage1_raw" value="1585" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage5" type="input" ><attribute name="raw" filename="in_voltage5_raw" value="2" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><channel id="voltage2" type="input" ><attribute name="raw" filename="in_voltage2_raw" value="1818" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /></channel><attribute name="waiting_for_supplier" value="0" /></device><device id="iio:device2" name="ada4355" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s14/16&gt;&gt;2" scale="0.000366" /><attribute name="scale" filename="in_voltage0_scale" value="0.000366210" /></channel><attribute name="sampling_frequency" value="125000000" /><attribute name="sync_start_enable" value="disarm" /><attribute name="sync_start_enable_available" value="arm" /><attribute name="waiting_for_supplier" value="0" /><buffer-attribute name="data_available" value="0" /><buffer-attribute name="direction" value="in" /><buffer-attribute name="length_align_bytes" value="8" /><debug-attribute name="pseudorandom_err_check" value="CH0 : PN9 : In Sync : OK" /><debug-attribute name="direct_reg_access" value="0x18" /></device><device id="iio:device3" name="xadc" ><channel id="voltage5" name="vccoddr" type="input" ><attribute name="label" filename="in_voltage5_vccoddr_label" value="vccoddr" /><attribute name="raw" filename="in_voltage5_vccoddr_raw" value="2031" /><attribute name="scale" filename="in_voltage5_vccoddr_scale" value="0.732421875" /></channel><channel id="voltage0" name="vccint" type="input" ><attribute name="label" filename="in_voltage0_vccint_label" value="vccint" /><attribute name="raw" filename="in_voltage0_vccint_raw" value="1373" /><attribute name="scale" filename="in_voltage0_vccint_scale" value="0.732421875" /></channel><channel id="voltage4" name="vccpaux" type="input" ><attribute name="label" filename="in_voltage4_vccpaux_label" value="vccpaux" /><attribute name="raw" filename="in_voltage4_vccpaux_raw" value="2436" /><attribute name="scale" filename="in_voltage4_vccpaux_scale" value="0.732421875" /></channel><channel id="temp0" type="input" ><attribute name="offset" filename="in_temp0_offset" value="-2219" /><attribute name="raw" filename="in_temp0_raw" value="2554" /><attribute name="scale" filename="in_temp0_scale" value="123.040771484" /></channel><channel id="voltage7" name="vrefn" type="input" ><attribute name="label" filename="in_voltage7_vrefn_label" value="vrefn" /><attribute name="raw" filename="in_voltage7_vrefn_raw" value="-11" /><attribute name="scale" filename="in_voltage7_vrefn_scale" value="0.732421875" /></channel><channel id="voltage1" name="vccaux" type="input" ><attribute name="label" filename="in_voltage1_vccaux_label" value="vccaux" /><attribute name="raw" filename="in_voltage1_vccaux_raw" value="2438" /><attribute name="scale" filename="in_voltage1_vccaux_scale" value="0.732421875" /></channel><channel id="voltage2" name="vccbram" type="input" ><attribute name="label" filename="in_voltage2_vccbram_label" value="vccbram" /><attribute name="raw" filename="in_voltage2_vccbram_raw" value="1371" /><attribute name="scale" filename="in_voltage2_vccbram_scale" value="0.732421875" /></channel><channel id="voltage3" name="vccpint" type="input" ><attribute name="label" filename="in_voltage3_vccpint_label" value="vccpint" /><attribute name="raw" filename="in_voltage3_vccpint_raw" value="1371" /><attribute name="scale" filename="in_voltage3_vccpint_scale" value="0.732421875" /></channel><channel id="voltage6" name="vrefp" type="input" ><attribute name="label" filename="in_voltage6_vrefp_label" value="vrefp" /><attribute name="raw" filename="in_voltage6_vrefp_raw" value="1690" /><attribute name="scale" filename="in_voltage6_vrefp_scale" value="0.732421875" /></channel><attribute name="sampling_frequency" value="961538" /><attribute name="waiting_for_supplier" value="0" /></device><device id="iio:device4" name="one-bit-adc-dac" ><channel id="voltage1" type="output" ><attribute name="label" filename="out_voltage1_label" value="GSEL1" /><attribute name="raw" filename="out_voltage1_raw" value="0" /></channel><channel id="voltage5" type="output" ><attribute name="label" filename="out_voltage5_label" value="GSEL3" /><attribute name="raw" filename="out_voltage5_raw" value="0" /></channel><channel id="voltage0" type="output" ><attribute name="label" filename="out_voltage0_label" value="GSEL0" /><attribute name="raw" filename="out_voltage0_raw" value="0" /></channel><channel id="voltage3" type="output" ><attribute name="label" filename="out_voltage3_label" value="GSEL2" /><attribute name="raw" filename="out_voltage3_raw" value="0" /></channel><channel id="voltage6" type="output" ><attribute name="label" filename="out_voltage6_label" value="FSEL1" /><attribute name="raw" filename="out_voltage6_raw" value="0" /></channel><channel id="voltage2" type="output" ><attribute name="label" filename="out_voltage2_label" value="FSEL0" /><attribute name="raw" filename="out_voltage2_raw" value="0" /></channel><channel id="voltage4" type="output" ><attribute name="label" filename="out_voltage4_label" value="GPIO_TEST" /><attribute name="raw" filename="out_voltage4_raw" value="0" /></channel><attribute name="waiting_for_supplier" value="0" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>

test/emu/hardware_map.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,11 @@ ad738x:
748748
- data_devices:
749749
- iio:device0
750750

751+
ada4355:
752+
- ada4355
753+
- pyadi_iio_class_support:
754+
- ada4355
755+
- emulate:
756+
- filename: ada4355.xml
757+
- data_devices:
758+
- iio:device2

test/test_ada4355.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pytest
2+
3+
hardware = "ada4355"
4+
classname = "adi.ada4355"
5+
6+
#########################################
7+
@pytest.mark.iio_hardware(hardware, True)
8+
@pytest.mark.parametrize("classname", [(classname)])
9+
@pytest.mark.parametrize("channel", [0])
10+
def test_ada4355_rx_data(test_dma_rx, iio_uri, classname, channel):
11+
test_dma_rx(iio_uri, classname, channel)

0 commit comments

Comments
 (0)