-
Notifications
You must be signed in to change notification settings - Fork 133
ad7490: add pyadi-iio support #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Copyright (C) 2025 Analog Devices, Inc. | ||
| # | ||
| # SPDX short identifier: ADIBSD | ||
|
|
||
| import numpy as np | ||
|
|
||
| from adi.attribute import attribute | ||
| from adi.context_manager import context_manager | ||
| from adi.rx_tx import rx | ||
|
|
||
|
|
||
| class ad7490(rx, context_manager): | ||
| """AD7490 ADC""" | ||
|
|
||
| _complex_data = False | ||
| channel = [] # type: ignore | ||
| _device_name = "" | ||
|
|
||
| def __init__(self, uri="", device_name=""): | ||
|
|
||
| context_manager.__init__(self, uri, self._device_name) | ||
|
|
||
| compatible_parts = [ | ||
| "ad7490", | ||
| ] | ||
|
|
||
| self._ctrl = None | ||
|
|
||
| if not device_name: | ||
| device_name = compatible_parts[0] | ||
| 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: | ||
| self._ctrl = device | ||
| self._rxadc = device | ||
| break | ||
|
|
||
| self._rx_channel_names = [] | ||
| self.channel = [] | ||
| for ch in self._ctrl.channels: | ||
| name = ch._id | ||
| self._rx_channel_names.append(name) | ||
| self.channel.append(self._channel(self._ctrl, name)) | ||
|
|
||
| rx.__init__(self) | ||
|
|
||
| @property | ||
| def polarity_available(self): | ||
| """Provides all available polarity settings for the AD7490 channels""" | ||
| return self._get_iio_dev_attr_str("polarity_available") | ||
|
|
||
| @property | ||
| def range_available(self): | ||
| """Provides all available range settings for the AD7490 channels""" | ||
| return self._get_iio_dev_attr_str("range_available") | ||
|
|
||
| @property | ||
| def polarity(self): | ||
| """AD7490 polarity""" | ||
| return self._get_iio_dev_attr_str("polarity") | ||
|
|
||
| @polarity.setter | ||
| def polarity(self, ptype): | ||
| """Set polarity.""" | ||
| if ptype in self.polarity_available: | ||
| self._set_iio_dev_attr_str("polarity", ptype) | ||
| else: | ||
| raise ValueError( | ||
| "Error: Polarity type not supported \nUse one of: " | ||
| + str(self.polarity_available) | ||
| ) | ||
|
|
||
| @property | ||
| def range(self): | ||
| """AD7490 range""" | ||
| return self._get_iio_dev_attr_str("range") | ||
|
|
||
| @range.setter | ||
| def range(self, rtype): | ||
| """Set range.""" | ||
| if rtype in self.range_available: | ||
| self._set_iio_dev_attr_str("range", rtype) | ||
| else: | ||
| raise ValueError( | ||
| "Error: Range type not supported \nUse one of: " | ||
| + str(self.range_available) | ||
| ) | ||
|
|
||
| @property | ||
| def sampling_frequency(self): | ||
| """AD7490 sampling frequency""" | ||
| return self._get_iio_dev_attr_str("sampling_frequency") | ||
|
|
||
| class _channel(attribute): | ||
| """AD7490 channel""" | ||
|
|
||
| def __init__(self, ctrl, channel_name): | ||
| self.name = channel_name | ||
| self._ctrl = ctrl | ||
|
|
||
| @property | ||
| def raw(self): | ||
| """AD7490 channel raw value""" | ||
| return self._get_iio_attr(self.name, "raw", False) | ||
|
|
||
| @property | ||
| def scale(self): | ||
| """AD7490 channel scale""" | ||
| return float(self._get_iio_attr_str(self.name, "scale", False)) | ||
|
|
||
| def to_volts(self, index, val): | ||
| """Converts raw value to SI""" | ||
| _scale = self.channel[index].scale | ||
|
|
||
| ret = None | ||
|
|
||
| if isinstance(val, np.int16): | ||
| ret = val * _scale | ||
|
|
||
| if isinstance(val, np.ndarray): | ||
| ret = [x * _scale for x in val] | ||
|
|
||
| return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ad7490 | ||
| ================= | ||
|
|
||
| .. automodule:: adi.ad7490 | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ Supported Devices | |
| adi.ad719x | ||
| adi.ad7291 | ||
| adi.ad738x | ||
| adi.ad7490 | ||
| adi.ad7606 | ||
| adi.ad7689 | ||
| adi.ad7746 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Copyright (C) 2025 Analog Devices, Inc. | ||
| # | ||
| # SPDX short identifier: ADIBSD | ||
|
|
||
| import argparse | ||
| import sys | ||
| from time import sleep | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| from scipy import signal | ||
|
|
||
| import adi | ||
| from adi import ad7490 | ||
|
|
||
| # Optionally pass URI as command line argument with -u option, | ||
| # else use default to "ip:analog.local" | ||
| parser = argparse.ArgumentParser(description="AD7490 Example Script") | ||
| parser.add_argument( | ||
| "-u", | ||
| default=["serial:/dev/ttyACM0,57600,8n1"], | ||
| help="-u (arg) URI of target device's context, eg: 'ip:analog.local',\ | ||
| 'ip:192.168.2.1',\ | ||
| 'serial:/dev/ttyACM0,57600,8n1n'", | ||
| action="store", | ||
| nargs="*", | ||
| ) | ||
| args = parser.parse_args() | ||
| my_uri = args.u[0] | ||
|
|
||
| print("uri: " + str(my_uri)) | ||
|
|
||
| # Set up AD7490 | ||
| my_adc = adi.ad7490(uri=my_uri) | ||
| my_adc.rx_buffer_size = 200 | ||
|
|
||
| # Choose Polarity | ||
| my_adc.polarity = "UNIPOLAR" | ||
| # my_adc.polarity = "BIPOLAR" | ||
|
|
||
| # Choose range: | ||
| my_adc.range = "REF_IN" | ||
| # my_adc.range = "2X_REF_IN" | ||
|
|
||
| # Choose output format: | ||
| my_adc.rx_output_type = "raw" | ||
| # my_adc.rx_output_type = "SI" | ||
|
|
||
| # Verify settings: | ||
| print("Polarity: ", my_adc.polarity) | ||
| print("Range: ", my_adc.range) | ||
| print("Sampling Frequency: ", my_adc.sampling_frequency) | ||
| print("Enabled Channels: ", my_adc.rx_enabled_channels) | ||
|
|
||
|
|
||
| plt.clf() | ||
| sleep(0.5) | ||
| data = my_adc.rx() | ||
| for ch in my_adc.rx_enabled_channels: | ||
| plt.plot(range(0, len(data[0])), data[ch], label="voltage" + str(ch)) | ||
| plt.xlabel("Data Point") | ||
| if my_adc.rx_output_type == "SI": | ||
| plt.ylabel("Millivolts") | ||
| else: | ||
| plt.ylabel("ADC counts") | ||
| plt.legend( | ||
| bbox_to_anchor=(0.0, 1.02, 1.0, 0.102), | ||
| loc="lower left", | ||
| ncol=4, | ||
| mode="expand", | ||
| borderaxespad=0.0, | ||
| ) | ||
| plt.pause(10) | ||
|
|
||
| del my_adc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,7 @@ | |
| - AD7194 | ||
| - AD7195 | ||
| - AD7291 | ||
| - AD7490 | ||
| - AD7768 | ||
| - AD7768-4 | ||
| - AD7770 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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="serial" description="no-OS/projects/eval-ad7490sdz staging/ad7940-3c1f72f30" ><context-attribute name="uri" value="serial:/dev/ttyACM0,57600,8n1n" /><context-attribute name="serial,port" value="/dev/ttyACM0" /><context-attribute name="serial,description" value="DAPLink CMSIS-DAP - 04261702f0edc84c00000000000000000000000097969906" /><device id="iio:device0" name="ad7490" ><channel id="voltage0" type="input" ><scan-element index="0" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage0_raw" value="0" /><attribute name="scale" filename="in_voltage0_scale" value="0.610351562" /></channel><channel id="voltage1" type="input" ><scan-element index="1" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage1_raw" value="0" /><attribute name="scale" filename="in_voltage1_scale" value="0.610351562" /></channel><channel id="voltage2" type="input" ><scan-element index="2" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage2_raw" value="0" /><attribute name="scale" filename="in_voltage2_scale" value="0.610351562" /></channel><channel id="voltage3" type="input" ><scan-element index="3" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage3_raw" value="0" /><attribute name="scale" filename="in_voltage3_scale" value="0.610351562" /></channel><channel id="voltage4" type="input" ><scan-element index="4" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage4_raw" value="0" /><attribute name="scale" filename="in_voltage4_scale" value="0.610351562" /></channel><channel id="voltage5" type="input" ><scan-element index="5" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage5_raw" value="0" /><attribute name="scale" filename="in_voltage5_scale" value="0.610351562" /></channel><channel id="voltage6" type="input" ><scan-element index="6" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage6_raw" value="0" /><attribute name="scale" filename="in_voltage6_scale" value="0.610351562" /></channel><channel id="voltage7" type="input" ><scan-element index="7" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage7_raw" value="0" /><attribute name="scale" filename="in_voltage7_scale" value="0.610351562" /></channel><channel id="voltage8" type="input" ><scan-element index="8" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage8_raw" value="0" /><attribute name="scale" filename="in_voltage8_scale" value="0.610351562" /></channel><channel id="voltage9" type="input" ><scan-element index="9" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage9_raw" value="0" /><attribute name="scale" filename="in_voltage9_scale" value="0.610351562" /></channel><channel id="voltage10" type="input" ><scan-element index="10" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage10_raw" value="0" /><attribute name="scale" filename="in_voltage10_scale" value="0.610351562" /></channel><channel id="voltage11" type="input" ><scan-element index="11" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage11_raw" value="0" /><attribute name="scale" filename="in_voltage11_scale" value="0.610351562" /></channel><channel id="voltage12" type="input" ><scan-element index="12" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage12_raw" value="0" /><attribute name="scale" filename="in_voltage12_scale" value="0.610351562" /></channel><channel id="voltage13" type="input" ><scan-element index="13" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage13_raw" value="0" /><attribute name="scale" filename="in_voltage13_scale" value="0.610351562" /></channel><channel id="voltage14" type="input" ><scan-element index="14" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage14_raw" value="0" /><attribute name="scale" filename="in_voltage14_scale" value="0.610351562" /></channel><channel id="voltage15" type="input" ><scan-element index="15" format="le:u12/16>>0" /><attribute name="raw" filename="in_voltage15_raw" value="0" /><attribute name="scale" filename="in_voltage15_scale" value="0.610351562" /></channel><attribute name="polarity" value="UNIPOLAR " /><attribute name="polarity_available" value="BIPOLAR UNIPOLAR " /><attribute name="range" value="REF_IN " /><attribute name="range_available" value="2X_REF_IN REF_IN " /><attribute name="sampling_frequency" value="1000000" /></device></context> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import pytest | ||
|
|
||
| hardware = "ad7490" | ||
| classname = "adi.ad7490" | ||
|
|
||
|
|
||
| ######################################### | ||
| @pytest.mark.iio_hardware(hardware, True) | ||
| @pytest.mark.parametrize("classname", [(classname)]) | ||
| @pytest.mark.parametrize("channel", [0]) | ||
| def test_ad7490_rx_data(test_dma_rx, iio_uri, classname, channel): | ||
| test_dma_rx(iio_uri, classname, channel) | ||
|
|
||
|
|
||
| ######################################### | ||
| @pytest.mark.iio_hardware(hardware) | ||
| @pytest.mark.parametrize("classname", [(classname)]) | ||
| @pytest.mark.parametrize( | ||
| "attr, val", | ||
| [ | ||
| ("polarity", ["BIPOLAR", "UNIPOLAR"],), | ||
| ("range", ["2X_REF_IN", "REF_IN"],), | ||
| ], | ||
| ) | ||
| def test_ad7490_attr_multiple( | ||
| test_attribute_multiple_values, iio_uri, classname, attr, val | ||
| ): | ||
| test_attribute_multiple_values(iio_uri, classname, attr, val, 0) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.