Skip to content

Commit

Permalink
Merge pull request #524 from threexc/tgamblin/ad400x
Browse files Browse the repository at this point in the history
ad4020.py: add compatibility for ad400x parts
  • Loading branch information
mhennerich authored Feb 26, 2024
2 parents a5eb253 + e7d2e91 commit 318e000
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 8 deletions.
2 changes: 1 addition & 1 deletion adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from adi.ad777x import ad777x
from adi.ad936x import Pluto, ad9361, ad9363, ad9364
from adi.ad937x import ad9371, ad9375
from adi.ad4020 import ad4020
from adi.ad4020 import ad4000, ad4001, ad4002, ad4003, ad4020
from adi.ad4110 import ad4110
from adi.ad4130 import ad4130
from adi.ad4630 import ad4630, adaq42xx
Expand Down
79 changes: 73 additions & 6 deletions adi/ad4020.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,88 @@
class ad4020(rx, context_manager):
"""AD4020 device"""

_device_name = "ad4020"
_compatible_parts = [
"ad4020",
"ad4021",
"ad4022",
]

_device_name = ""
_rx_data_type = np.int32
_complex_data = False
_rx_channel_names = ["voltage0"]

def __init__(self, uri=""):
def __init__(self, uri="", device_name="ad4020"):
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("ad4020")
self._ctrl = self._ctx.find_device("ad4020")
self._rxadc = self._ctx.find_device(_device_name)
self._ctrl = self._ctx.find_device(_device_name)
rx.__init__(self)

@property
def sampling_frequency(self):
"""sample_rate: Only readable
"""
"""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))


class ad4000(ad4020):
_compatible_parts = [
"ad4000",
"ad4004",
"ad4008",
]

_rx_data_type = np.int16

def __init__(self, uri="ip:analog.local", device_name="ad4000"):
super().__init__(uri, device_name)


class ad4001(ad4020):
_compatible_parts = [
"ad4001",
"ad4005",
]

_rx_data_type = np.int16

def __init__(self, uri="ip:analog.local", device_name="ad4001"):
super().__init__(uri, device_name)


class ad4002(ad4020):
_compatible_parts = [
"ad4002",
"ad4006",
"ad4010",
]

_rx_data_type = np.int32

def __init__(self, uri="ip:analog.local", device_name="ad4002"):
super().__init__(uri, device_name)


class ad4003(ad4020):
_compatible_parts = [
"ad4003",
"ad4007",
"ad4011",
]

_rx_data_type = np.int32

def __init__(self, uri="ip:analog.local", device_name="ad4003"):
super().__init__(uri, device_name)
26 changes: 26 additions & 0 deletions doc/source/devices/adi.ad4020.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
ad4020
=================

Each device class in this module supports multiple parts, as follows:

**ad4020:** ad4020, ad4021, ad4022

**ad4000:** ad4000, ad4004, ad4008

**ad4001:** ad4001, ad4005

**ad4002:** ad4002, ad4006, ad4010

**ad4003:** ad4003, ad4007, ad4011

By default, the device_name parameter in the class constructor is the
same as the class name (e.g. "ad4001" for the ad4001). To use the class
with another supported model, the name must be given when instantiating
the object. For example, if working with an ad4007 with a URI of
"10.2.5.222", use the ad4003 class, but specify the device_name
parameter explicitly:

.. code-block:: bash
import adi
adc = adi.ad4003(uri="ip:10.2.5.222", device_name="ad4007")
...
.. automodule:: adi.ad4020
:members:
:undoc-members:
Expand Down
4 changes: 4 additions & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

### Currently supported hardware
- AD2S1210
- AD4000 (AD4004, AD4008)
- AD4001 (AD4005)
- AD4002 (AD4006, AD4010)
- AD4003 (AD4007, AD4011)
- AD4020
- AD4130
- AD4110
Expand Down
1 change: 1 addition & 0 deletions test/emu/devices/ad4000.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="10.2.5.210 Linux zed-4 6.1.0-ad400x-dev-22242-gfa89d198ebcf #2 SMP PREEMPT Thu Feb 1 09:14:17 EST 2024 armv7l" ><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_model" value="EVAL-AD4000FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EVAL-AD4000FMCZ" /><context-attribute name="hw_name" value="AD4000" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="hdl_system_id" value="[pulsar_adc_pmdz] [ad40xx: 1] on [zed] git branch [dev_ad7944_ad798x] git [c704018b1db9be0eb30ca4c62b6ed38492fd4a63] dirty [2023-11-06 08:00:56] UTC" /><context-attribute name="local,kernel" value="6.1.0-ad400x-dev-22242-gfa89d198ebcf" /><context-attribute name="uri" value="ip:10.2.5.210" /><context-attribute name="ip,ip-addr" value="10.2.5.210" /><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="43000" /><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="2046" /><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="1386" /><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="2457" /><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="2593" /><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="3" /><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="2453" /><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="1392" /><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="1389" /><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="1706" /><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="ad4000" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s16/16&gt;&gt;0" scale="0.009537" /><attribute name="offset" filename="in_voltage0_offset" value="-262144" /><attribute name="raw" filename="in_voltage0_raw" value="114631" /><attribute name="scale" filename="in_voltage0_scale" value="0.009536743" /></channel><attribute name="sampling_frequency" value="2000000" /><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" /><debug-attribute name="direct_reg_access" value="0xEE" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>
1 change: 1 addition & 0 deletions test/emu/devices/ad4001.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="10.2.5.210 Linux zed-4 6.1.0-ad400x-dev-22242-gfa89d198ebcf #2 SMP PREEMPT Thu Feb 1 09:14:17 EST 2024 armv7l" ><context-attribute name="hw_carrier" value="Xilinx Zynq ZED" /><context-attribute name="hw_model" value="EVAL-AD4001FMCZ on Xilinx Zynq ZED" /><context-attribute name="hw_mezzanine" value="EVAL-AD4001FMCZ" /><context-attribute name="hw_name" value="AD4001" /><context-attribute name="hw_vendor" value="Analog Devices" /><context-attribute name="hw_serial" value="Empty Field" /><context-attribute name="hdl_system_id" value="[pulsar_adc_pmdz] [ad40xx: 1] on [zed] git branch [dev_ad7944_ad798x] git [c704018b1db9be0eb30ca4c62b6ed38492fd4a63] dirty [2023-11-06 08:00:56] UTC" /><context-attribute name="local,kernel" value="6.1.0-ad400x-dev-22242-gfa89d198ebcf" /><context-attribute name="uri" value="ip:10.2.5.210" /><context-attribute name="ip,ip-addr" value="10.2.5.210" /><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="44000" /><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="2044" /><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="1387" /><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="2456" /><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="2597" /><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="2" /><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="2454" /><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="1388" /><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="1386" /><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="1708" /><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="ad4001" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:s16/32&gt;&gt;0" scale="0.038147" /><attribute name="offset" filename="in_voltage0_offset" value="-65536" /><attribute name="raw" filename="in_voltage0_raw" value="65530" /><attribute name="scale" filename="in_voltage0_scale" value="0.038146972" /></channel><attribute name="sampling_frequency" value="2000000" /><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" /><debug-attribute name="direct_reg_access" value="0xF9" /></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>
Loading

0 comments on commit 318e000

Please sign in to comment.