Skip to content

Commit

Permalink
Make distinction between ad3552r and axi-ad3552r
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
machschmitt committed Nov 6, 2023
1 parent 229add4 commit 4ec1114
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 33 deletions.
2 changes: 1 addition & 1 deletion adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
121 changes: 92 additions & 29 deletions adi/ad3552r.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down Expand Up @@ -117,44 +207,17 @@ 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
self._ctrl = ctrl

@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)
2 changes: 1 addition & 1 deletion examples/ad3552r_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/cn0585_fmcz_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 4ec1114

Please sign in to comment.