diff --git a/adi/__init__.py b/adi/__init__.py index 19612dce1..f6c9792b6 100644 --- a/adi/__init__.py +++ b/adi/__init__.py @@ -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 diff --git a/adi/ad4020.py b/adi/ad4020.py index 7ba01f2bb..186e80e65 100644 --- a/adi/ad4020.py +++ b/adi/ad4020.py @@ -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) diff --git a/doc/source/devices/adi.ad4020.rst b/doc/source/devices/adi.ad4020.rst index 2ff35bf74..c189d6feb 100644 --- a/doc/source/devices/adi.ad4020.rst +++ b/doc/source/devices/adi.ad4020.rst @@ -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: diff --git a/supported_parts.md b/supported_parts.md index 5e67f346f..e52795d8e 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -11,6 +11,10 @@ ### Currently supported hardware - AD2S1210 +- AD4000 (AD4004, AD4008) +- AD4001 (AD4005) +- AD4002 (AD4006, AD4010) +- AD4003 (AD4007, AD4011) - AD4020 - AD4130 - AD4110 diff --git a/test/emu/devices/ad4000.xml b/test/emu/devices/ad4000.xml new file mode 100644 index 000000000..7eb66773e --- /dev/null +++ b/test/emu/devices/ad4000.xml @@ -0,0 +1 @@ +]> diff --git a/test/emu/devices/ad4001.xml b/test/emu/devices/ad4001.xml new file mode 100644 index 000000000..11fd33d4c --- /dev/null +++ b/test/emu/devices/ad4001.xml @@ -0,0 +1 @@ +]> \ No newline at end of file diff --git a/test/emu/devices/ad4002.xml b/test/emu/devices/ad4002.xml new file mode 100644 index 000000000..f7fd2c047 --- /dev/null +++ b/test/emu/devices/ad4002.xml @@ -0,0 +1 @@ +]> \ No newline at end of file diff --git a/test/emu/devices/ad4003.xml b/test/emu/devices/ad4003.xml new file mode 100644 index 000000000..b52f5587f --- /dev/null +++ b/test/emu/devices/ad4003.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 97a908444..888c62db0 100644 --- a/test/emu/hardware_map.yml +++ b/test/emu/hardware_map.yml @@ -331,6 +331,44 @@ ad9265: - filename: ad9265.xml - data_devices: - iio:device2 +ad4000: + - ad4004 + - ad4008 + - pyadi_iio_class_support: + - ad4000 + - emulate: + - filename: ad4000.xml + - data_devices: + - iio:device1 +ad4001: + - ad4001 + - ad4005 + - pyadi_iio_class_support: + - ad4001 + - emulate: + - filename: ad4001.xml + - data_devices: + - iio:device1 +ad4002: + - ad4002 + - ad4006 + - ad4010 + - pyadi_iio_class_support: + - ad4002 + - emulate: + - filename: ad4002.xml + - data_devices: + - iio:device1 +ad4003: + - ad4003 + - ad4007 + - ad4011 + - pyadi_iio_class_support: + - ad4003 + - emulate: + - filename: ad4003.xml + - data_devices: + - iio:device1 ad4020: - ad4020 - pyadi_iio_class_support: @@ -482,4 +520,4 @@ ad7124-8: - data_devices: - iio:device0 - pyadi_iio_class_support: - - ad7124 \ No newline at end of file + - ad7124 diff --git a/test/test_ad4000.py b/test/test_ad4000.py new file mode 100644 index 000000000..af895254a --- /dev/null +++ b/test/test_ad4000.py @@ -0,0 +1,28 @@ +import pytest + +hardware = "ad4000" +classname = "adi.ad4000" + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, val", + [ + ( + "sampling_frequency", + [10000, 50000, 100000, 200000, 500000, 1000000, 2000000], + ), + ], +) +def test_ad4000_attr(test_attribute_multiple_values, iio_uri, classname, attr, val): + test_attribute_multiple_values(iio_uri, classname, attr, val, 1) + + +######################################### +@pytest.mark.iio_hardware(hardware, True) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize("channel", [0]) +def test_ad4000_rx_data(test_dma_rx, iio_uri, classname, channel): + test_dma_rx(iio_uri, classname, channel, buffer_size=2 ** 15) diff --git a/test/test_ad4001.py b/test/test_ad4001.py new file mode 100644 index 000000000..b48938e2d --- /dev/null +++ b/test/test_ad4001.py @@ -0,0 +1,28 @@ +import pytest + +hardware = "ad4001" +classname = "adi.ad4001" + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, val", + [ + ( + "sampling_frequency", + [10000, 50000, 100000, 200000, 500000, 1000000, 2000000], + ), + ], +) +def test_ad4001_attr(test_attribute_multiple_values, iio_uri, classname, attr, val): + test_attribute_multiple_values(iio_uri, classname, attr, val, 1) + + +######################################### +@pytest.mark.iio_hardware(hardware, True) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize("channel", [0]) +def test_ad4001_rx_data(test_dma_rx, iio_uri, classname, channel): + test_dma_rx(iio_uri, classname, channel, buffer_size=2 ** 15) diff --git a/test/test_ad4002.py b/test/test_ad4002.py new file mode 100644 index 000000000..74ef2d9a4 --- /dev/null +++ b/test/test_ad4002.py @@ -0,0 +1,28 @@ +import pytest + +hardware = "ad4002" +classname = "adi.ad4002" + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, val", + [ + ( + "sampling_frequency", + [10000, 50000, 100000, 200000, 500000, 1000000, 2000000], + ), + ], +) +def test_ad4002_attr(test_attribute_multiple_values, iio_uri, classname, attr, val): + test_attribute_multiple_values(iio_uri, classname, attr, val, 1) + + +######################################### +@pytest.mark.iio_hardware(hardware, True) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize("channel", [0]) +def test_ad4002_rx_data(test_dma_rx, iio_uri, classname, channel): + test_dma_rx(iio_uri, classname, channel, buffer_size=2 ** 15) diff --git a/test/test_ad4003.py b/test/test_ad4003.py new file mode 100644 index 000000000..b99ebae4c --- /dev/null +++ b/test/test_ad4003.py @@ -0,0 +1,28 @@ +import pytest + +hardware = "ad4003" +classname = "adi.ad4003" + + +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, val", + [ + ( + "sampling_frequency", + [10000, 50000, 100000, 200000, 500000, 1000000, 2000000], + ), + ], +) +def test_ad4003_attr(test_attribute_multiple_values, iio_uri, classname, attr, val): + test_attribute_multiple_values(iio_uri, classname, attr, val, 1) + + +######################################### +@pytest.mark.iio_hardware(hardware, True) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize("channel", [0]) +def test_ad4003_rx_data(test_dma_rx, iio_uri, classname, channel): + test_dma_rx(iio_uri, classname, channel, buffer_size=2 ** 15) diff --git a/test/test_ad4020.py b/test/test_ad4020.py index 4d9b2b620..697fb1e85 100644 --- a/test/test_ad4020.py +++ b/test/test_ad4020.py @@ -3,6 +3,22 @@ hardware = "ad4020" classname = "adi.ad4020" +######################################### +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +@pytest.mark.parametrize( + "attr, val", + [ + ( + "sampling_frequency", + [10000, 50000, 100000, 200000, 500000, 1000000, 1800000], + ), + ], +) +def test_ad4020_attr(test_attribute_multiple_values, iio_uri, classname, attr, val): + test_attribute_multiple_values(iio_uri, classname, attr, val, 1) + + ######################################### @pytest.mark.iio_hardware(hardware, True) @pytest.mark.parametrize("classname", [(classname)])