Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adi/ad7625: add support for AD762x/AD796x #609

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from adi.ad7134 import ad7134
from adi.ad7291 import ad7291
from adi.ad7606 import ad7606
from adi.ad7625 import ad7625
from adi.ad7689 import ad7689
from adi.ad7746 import ad7746
from adi.ad7768 import ad7768, ad7768_4
Expand Down
45 changes: 45 additions & 0 deletions adi/ad7625.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2024 Analog Devices, Inc.
#
# SPDX short identifier: ADIBSD

from adi.context_manager import context_manager
from adi.rx_tx import rx


class ad7625(rx, context_manager):
"""AD7625 device"""

_compatible_parts = [
"ad7625",
"ad7626",
"ad7960",
"ad7961",
]

_device_name = ""
_complex_data = False
_rx_channel_names = ["voltage0-voltage1"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this channel correct? Seems odd

Copy link
Contributor Author

@threexc threexc Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a differential antiphase pair of inputs making up the channel.


def __init__(self, uri="", device_name="ad7625"):
if not device_name:
_device_name = self._compatible_parts[0]
elif device_name not in self._compatible_parts:
raise Exception(f"Not a compatible device: {device_name}")
else:
_device_name = device_name

context_manager.__init__(self, uri, self._device_name)

self._rxadc = self._ctx.find_device(_device_name)
self._ctrl = self._ctx.find_device(_device_name)
rx.__init__(self)

@property
def sampling_frequency(self):
"""Get and set the sampling frequency."""
return self._get_iio_dev_attr("sampling_frequency")

@sampling_frequency.setter
def sampling_frequency(self, value):
"""Set the sampling frequency."""
self._set_iio_dev_attr("sampling_frequency", str(value))
20 changes: 20 additions & 0 deletions doc/source/devices/adi.ad7625.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
+ad7625
+=================
+
+By default, the device_name parameter in the class constructor is the
+same as the class name. To use the class with another supported model,
+the name must be given when instantiating the object. For example, if
+working with an ad7626 with a URI of "10.2.5.222", use the ad7625 class,
+but specify the device_name parameter explicitly:
+
+.. code-block:: bash
+
+ import adi
+ adc = adi.ad7625(uri="ip:10.2.5.222", device_name="ad7626")
+ ...
+
+
+.. automodule:: adi.ad7625
+ :members:
+ :undoc-members:
+ :show-inheritance:
1 change: 1 addition & 0 deletions doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Supported Devices
adi.ad7291
adi.ad738x
adi.ad7606
adi.ad7625
adi.ad7689
adi.ad7746
adi.ad7768
Expand Down
4 changes: 4 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
- AD7194
- AD7195
- AD7291
- AD7625
- AD7626
- AD7960
- AD7961
- AD7768
- AD7768-4
- AD7770
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/ad7625.xml
Original file line number Diff line number Diff line change
@@ -0,0 +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="192.168.40.140 Linux zed-tg 6.11.0-rc1-ad7625-mainline-00027-g26f7e74e040d #62 SMP PREEMPT Tue Sep 17 11:22:20 EDT 2024 armv7l" ><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_model" value="EVAL-AD7625FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EVAL-AD7625FMCZ" /><context-attribute name="hw_name" value="AD7625" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="local,kernel" value="6.11.0-rc1-ad7625-mainline-00027-g26f7e74e040d" /><context-attribute name="uri" value="ip:192.168.40.140" /><context-attribute name="ip,ip-addr" value="192.168.40.140" /><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="39000" /><attribute name="max_alarm" filename="temp1_max_alarm" value="0" /></channel></device><device id="iio:device0" 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="2042" /><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="1397" /><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="2464" /><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="2615" /><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="8" /><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="2475" /><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="1396" /><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="1395" /><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="1715" /><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:device1" name="ad7625" ><channel id="voltage0-voltage1" type="input" ><scan-element index="0" format="le:S16/16&gt;&gt;0" scale="0.125000" /><attribute name="scale" filename="in_voltage0-voltage1_scale" value="0.125000000" /></channel><attribute name="sampling_frequency" value="5952381" /><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" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>
12 changes: 12 additions & 0 deletions test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,18 @@ ad4170:
- data_devices:
- iio:device0

ad7625:
- ad7625
- ad7626
- ad7960
- ad7961
- pyadi_iio_class_support:
- ad7625
- emulate:
- filename: ad7625.xml
- data_devices:
- iio:device1

ad738x:
- ad738x
- pyadi_iio_class_support:
Expand Down
34 changes: 34 additions & 0 deletions test/test_ad7625.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest

hardware = "ad7625"
classname = "adi.ad7625"

#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, start, stop, step, tol, repeats",
[("sampling_frequency", 1000000, 6000000, 100000, 50000, 1),],
)
def test_ad7625_attr(
test_attribute_single_value,
iio_uri,
classname,
attr,
start,
stop,
step,
tol,
repeats
):
test_attribute_single_value(
iio_uri, classname, attr, start, stop, step, tol, repeats
)


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("channel", [0])
def test_ad7625_rx_data(test_dma_rx, iio_uri, classname, channel):
test_dma_rx(iio_uri, classname, channel, buffer_size=2 ** 15)
Loading