From c88aa91969e1ef11725db089453d8eb19ee79cdd Mon Sep 17 00:00:00 2001 From: Antoniu Miclaus Date: Mon, 17 Mar 2025 15:29:03 +0200 Subject: [PATCH] adi: ad9508 support Add pyadi-iio support for ad9508 device. Signed-off-by: Antoniu Miclaus --- adi/__init__.py | 1 + adi/ad9508.py | 97 +++++++++++++++++++++++++++++++ doc/source/devices/adi.ad9508.rst | 7 +++ doc/source/devices/index.rst | 1 + supported_parts.md | 1 + test/emu/devices/ad9508.xml | 2 + test/emu/hardware_map.yml | 10 +++- 7 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 adi/ad9508.py create mode 100644 doc/source/devices/adi.ad9508.rst create mode 100644 test/emu/devices/ad9508.xml diff --git a/adi/__init__.py b/adi/__init__.py index 341ba0e737..3a843a1e41 100644 --- a/adi/__init__.py +++ b/adi/__init__.py @@ -54,6 +54,7 @@ from adi.ad9265 import ad9265 from adi.ad9434 import ad9434 from adi.ad9467 import ad9467 +from adi.ad9508 import ad9508 from adi.ad9625 import ad9625 from adi.ad9680 import ad9680 from adi.ada4961 import ada4961 diff --git a/adi/ad9508.py b/adi/ad9508.py new file mode 100644 index 0000000000..052a132b73 --- /dev/null +++ b/adi/ad9508.py @@ -0,0 +1,97 @@ +# Copyright (C) 2025 Analog Devices, Inc. +# +# SPDX short identifier: ADIBSD + +from adi.attribute import attribute +from adi.context_manager import context_manager + + +class ad9508(attribute, context_manager): + + """ AD9508 ADC """ + + _device_name = "" + + def __init__(self, uri="", device_name="ad9508"): + context_manager.__init__(self, uri, self._device_name) + + compatible_part = "ad9508" + self._ctrl = None + + if not device_name: + device_name = compatible_part + else: + if device_name != compatible_part: + raise Exception(f"Not a compatible device: {device_name}") + + # Select the device matching device_name as working device + for device in self._ctx.devices: + if device.name == device_name: + self._ctrl = device + self._rxadc = device + break + + # Raise an exception if the device isn't found + if not self._ctrl: + raise Exception("ad9508 device not found") + + self.channel = [] + for ch in self._ctrl.channels: + name = ch.id + self.channel.append(self._channel(self._ctrl, name)) + + class _channel(attribute): + """AD9508 channel""" + + def __init__(self, ctrl, channel_name): + self.name = channel_name + self._ctrl = ctrl + + @property + def frequency(self): + """Get the channel output frequency""" + return self._get_iio_attr(self.name, "frequency", True) + + @frequency.setter + def frequency(self, frequency): + """Set the channel output frequency""" + self._set_iio_attr(self.name, "frequency", True, frequency, self._ctrl) + + @property + def phase(self): + """Get the channel output phase""" + return self._get_iio_attr(self.name, "phase", True) + + @phase.setter + def phase(self, phase): + """Set the channel output phase""" + self._set_iio_attr(self.name, "phase", True, phase, self._ctrl) + + @property + def raw(self): + """Get the state of a channel divider (enabled/powered-down)""" + return self._get_iio_attr(self.name, "raw", True) + + @raw.setter + def raw(self, raw): + """Set the state of a channel divider (enabled/powered-down)""" + self._set_iio_attr(self.name, "raw", True, raw, self._ctrl) + + @property + def sync_dividers(self): + """Get dividers synchronization status""" + raise AttributeError("Cannot access 'sync_dividers' directly") + + @sync_dividers.setter + def sync_dividers(self, value): + """Set dividers synchronization procedure""" + self._set_iio_dev_attr("sync_dividers", value) + + def reg_read(self, reg): + """Direct Register Access via debugfs""" + self._set_iio_debug_attr_str("direct_reg_access", reg, self._ctrl) + return self._get_iio_debug_attr_str("direct_reg_access", self._ctrl) + + def reg_write(self, reg, value): + """Direct Register Access via debugfs""" + self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._ctrl) diff --git a/doc/source/devices/adi.ad9508.rst b/doc/source/devices/adi.ad9508.rst new file mode 100644 index 0000000000..0446f9513e --- /dev/null +++ b/doc/source/devices/adi.ad9508.rst @@ -0,0 +1,7 @@ +ad9508 +================= + +.. automodule:: adi.ad9508 + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/source/devices/index.rst b/doc/source/devices/index.rst index 4f0a9f7904..442c362cb0 100644 --- a/doc/source/devices/index.rst +++ b/doc/source/devices/index.rst @@ -60,6 +60,7 @@ Supported Devices adi.ad937x adi.ad9434 adi.ad9467 + adi.ad9508 adi.ad9625 adi.ad9680 adi.ad4858 diff --git a/supported_parts.md b/supported_parts.md index 4138edacf9..3bd5d020a5 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -119,6 +119,7 @@ - AD9375 - AD9434 - AD9467 +- AD9508 - AD9625 - AD9680 - AD4858 diff --git a/test/emu/devices/ad9508.xml b/test/emu/devices/ad9508.xml new file mode 100644 index 0000000000..cd67f7f979 --- /dev/null +++ b/test/emu/devices/ad9508.xml @@ -0,0 +1,2 @@ +]> diff --git a/test/emu/hardware_map.yml b/test/emu/hardware_map.yml index 4166460884..a83ded842b 100644 --- a/test/emu/hardware_map.yml +++ b/test/emu/hardware_map.yml @@ -790,4 +790,12 @@ ad7490: - emulate: - filename: ad7490.xml - data_devices: - - iio:device0 \ No newline at end of file + - iio:device0 +ad9508: + - ad9508 + - pyadi_iio_class_support: + - ad9508 + - emulate: + - filename: ad9508.xml + - data_devices: + - iio:device3