From df3f4308f106d5007d3191d321c095740f57e33b Mon Sep 17 00:00:00 2001 From: Trevor Gamblin Date: Tue, 17 Sep 2024 10:57:10 -0400 Subject: [PATCH] adi/ad7625: add support for AD762x/AD796x Signed-off-by: Trevor Gamblin --- adi/__init__.py | 1 + adi/ad7625.py | 45 +++++++++++++++++++++++++++++++ doc/source/devices/adi.ad7625.rst | 20 ++++++++++++++ doc/source/devices/index.rst | 1 + supported_parts.md | 4 +++ test/emu/devices/ad7625.xml | 1 + test/emu/hardware_map.yml | 12 +++++++++ test/test_ad7625.py | 34 +++++++++++++++++++++++ 8 files changed, 118 insertions(+) create mode 100644 adi/ad7625.py create mode 100644 doc/source/devices/adi.ad7625.rst create mode 100644 test/emu/devices/ad7625.xml create mode 100644 test/test_ad7625.py diff --git a/adi/__init__.py b/adi/__init__.py index 2db3ec9ee..eb1b4d3e4 100644 --- a/adi/__init__.py +++ b/adi/__init__.py @@ -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 diff --git a/adi/ad7625.py b/adi/ad7625.py new file mode 100644 index 000000000..658b4cb36 --- /dev/null +++ b/adi/ad7625.py @@ -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"] + + 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)) diff --git a/doc/source/devices/adi.ad7625.rst b/doc/source/devices/adi.ad7625.rst new file mode 100644 index 000000000..ebe357c42 --- /dev/null +++ b/doc/source/devices/adi.ad7625.rst @@ -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: diff --git a/doc/source/devices/index.rst b/doc/source/devices/index.rst index 1856b5aba..df25114e3 100644 --- a/doc/source/devices/index.rst +++ b/doc/source/devices/index.rst @@ -31,6 +31,7 @@ Supported Devices adi.ad7291 adi.ad738x adi.ad7606 + adi.ad7625 adi.ad7689 adi.ad7746 adi.ad7768 diff --git a/supported_parts.md b/supported_parts.md index 3fed533f0..e1987aade 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -88,6 +88,10 @@ - AD7194 - AD7195 - AD7291 +- AD7625 +- AD7626 +- AD7960 +- AD7961 - AD7768 - AD7768-4 - AD7770 diff --git a/test/emu/devices/ad7625.xml b/test/emu/devices/ad7625.xml new file mode 100644 index 000000000..fd0852e80 --- /dev/null +++ b/test/emu/devices/ad7625.xml @@ -0,0 +1 @@ +]> \ No newline at end of file diff --git a/test/emu/hardware_map.yml b/test/emu/hardware_map.yml index e4b0a5b3a..1375c84c2 100644 --- a/test/emu/hardware_map.yml +++ b/test/emu/hardware_map.yml @@ -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: diff --git a/test/test_ad7625.py b/test/test_ad7625.py new file mode 100644 index 000000000..2d4db8b1c --- /dev/null +++ b/test/test_ad7625.py @@ -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)