From 4ec1114d1c2bc71e2342700ec011e1e50b22ac2e Mon Sep 17 00:00:00 2001 From: Marcelo Schmitt Date: Mon, 6 Nov 2023 17:13:32 -0300 Subject: [PATCH] Make distinction between ad3552r and axi-ad3552r Currently we have two Linux drivers for ad3552r. There is the driver at drivers/iio/dac/ad3552r.c which is upstream and uses standard SPI interface. There is another driver at drivers/iio/dac/axi-ad3552r.c which is being polished for merging into ADI Linux and connects to the system through an AXI bus. The axi-ad3552r driver interfaces with cn0585 project HDL components for high speed DAC sampling frequency. The particularities of each driver implementation result in different set of attributes exported to user space, making it hard to support them as part of a single python class or class inheritance schema. So far, the python class named ad3552r actually supported axi-ad3552r. Make ad3552r class support ad3552r and make axi_ad3552r class support axi-ad3552r. Signed-off-by: Marcelo Schmitt --- adi/__init__.py | 2 +- adi/ad3552r.py | 121 ++++++++++++++++++++++++-------- examples/ad3552r_example.py | 2 +- examples/cn0585_fmcz_example.py | 4 +- 4 files changed, 96 insertions(+), 33 deletions(-) diff --git a/adi/__init__.py b/adi/__init__.py index 9e24b4966..650f3883b 100644 --- a/adi/__init__.py +++ b/adi/__init__.py @@ -7,7 +7,7 @@ from adi.ad719x import ad719x from adi.ad777x import ad777x from adi.ad936x import Pluto, ad9361, ad9363, ad9364 -from adi.ad3552r import ad3552r +from adi.ad3552r import ad3552r, axi_ad3552r from adi.ad4020 import ad4020 from adi.ad4110 import ad4110 from adi.ad4130 import ad4130 diff --git a/adi/ad3552r.py b/adi/ad3552r.py index f58675a28..eb5c00500 100755 --- a/adi/ad3552r.py +++ b/adi/ad3552r.py @@ -38,6 +38,10 @@ from adi.context_manager import context_manager from adi.rx_tx import tx +# Idealy, we would be able to have a nice abstraction in which axi-ad3552r would +# be a subclass of ad3552r if the drivers for upstream ad3552r and axi-ad3552r +# hadn't completely different set of attributes. + class ad3552r(tx, context_manager, attribute): """AD3552R DAC""" @@ -49,6 +53,92 @@ class ad3552r(tx, context_manager, attribute): def __init__(self, uri="", device_name=""): context_manager.__init__(self, uri, self._device_name) + + compatible_parts = ["ad3552r", "ad3542r"] + self._ctrl = None + + if not device_name: + # Select any device matching compatible_parts list as working device + for device in self._ctx.devices: + if device.name in compatible_parts: + print("Found device {}".format(device.name)) + self._ctrl = device + self._txdac = device + break + else: + if device_name not in compatible_parts: + raise Exception("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: + print("Found device {}".format(device.name)) + self._ctrl = device + self._txdac = device + break + + for ch in self._ctrl.channels: + name = ch.id + self._tx_channel_names.append(name) + self.channel.append(self._channel(self._ctrl, name)) + + tx.__init__(self) + + class _channel(attribute): + """AD3552R channel""" + + def __init__(self, ctrl, channel_name): + self.name = channel_name + self._ctrl = ctrl + + @property + def raw(self): + """AD3552R channel raw value""" + return self._get_iio_attr(self.name, "raw", True) + + @raw.setter + def raw(self, value): + self._set_iio_attr(self.name, "raw", True, value) + + @property + def en(self): + """AD3552R channel en value""" + return self._get_iio_attr(self.name, "en", True) + + @en.setter + def en(self, value): + self._set_iio_attr_int(self.name, "en", True, value) + + @property + def scale(self): + """AD3552R channel scale value""" + return self._get_iio_attr(self.name, "scale", True) + + @scale.setter + def scale(self, value): + self._set_iio_attr(self.name, "scale", True, value) + + @property + def offset(self): + """AD3552R channel offset value""" + return self._get_iio_attr(self.name, "offset", True) + + @offset.setter + def offset(self, value): + self._set_iio_attr(self.name, "offset", True, value) + + +class axi_ad3552r(tx, context_manager, attribute): + """AD3552R DAC for AXI DDS PCORE/COREFPGA Module""" + + _device_name = "" + channel = [] # type: ignore + _complex_data = False + + def __init__(self, uri="", device_name=""): + + context_manager.__init__(self, uri, self._device_name) + compatible_parts = ["axi-ad3552r-0", "axi-ad3552r-1", "axi-ad3552r"] self._ctrl = None @@ -117,7 +207,7 @@ def output_range(self, value): self._set_iio_dev_attr_str("output_range", value, self._txdac) class _channel(attribute): - """AD3552R channel""" + """AXI-AD3552R channel""" def __init__(self, ctrl, channel_name): self.name = channel_name @@ -125,36 +215,9 @@ def __init__(self, ctrl, channel_name): @property def raw(self): - """AD3552R channel raw value""" + """AXI-AD3552R channel raw value""" return self._get_iio_attr(self.name, "raw", True) @raw.setter def raw(self, value): self._set_iio_attr(self.name, "raw", True, value) - - @property - def en(self): - """AD3552R channel en value""" - return self._get_iio_attr(self.name, "en", True) - - @en.setter - def en(self, value): - self._set_iio_attr(self.name, "en", True, value) - - @property - def scale(self): - """AD3552R channel scale value""" - return self._get_iio_attr(self.name, "scale", True) - - @scale.setter - def scale(self, value): - self._set_iio_attr(self.name, "scale", True, value) - - @property - def offset(self): - """AD3552R channel offset value""" - return self._get_iio_attr(self.name, "offset", True) - - @offset.setter - def offset(self, value): - self._set_iio_attr(self.name, "offset", True, value) diff --git a/examples/ad3552r_example.py b/examples/ad3552r_example.py index d4b6b2e8f..821a26433 100755 --- a/examples/ad3552r_example.py +++ b/examples/ad3552r_example.py @@ -14,7 +14,7 @@ # device connections -ad3552r = adi.ad3552r(uri=my_uri, device_name="axi-ad3552r") +ad3552r = adi.axi_ad3552r(uri=my_uri, device_name="axi-ad3552r") # device configurations diff --git a/examples/cn0585_fmcz_example.py b/examples/cn0585_fmcz_example.py index ccfc3874c..5c8f42911 100755 --- a/examples/cn0585_fmcz_example.py +++ b/examples/cn0585_fmcz_example.py @@ -23,8 +23,8 @@ class adaq23876(adi.ltc2387): # device connections adaq23876_adc = adaq23876(my_uri) -ad3552r_0 = adi.ad3552r(uri=my_uri, device_name="axi-ad3552r-0") -ad3552r_1 = adi.ad3552r(uri=my_uri, device_name="axi-ad3552r-1") +ad3552r_0 = adi.axi_ad3552r(uri=my_uri, device_name="axi-ad3552r-0") +ad3552r_1 = adi.axi_ad3552r(uri=my_uri, device_name="axi-ad3552r-1") voltage_monitor = adi.ad7291(uri=my_uri) gpio_controller = adi.one_bit_adc_dac(uri=my_uri, name="one-bit-adc-dac")