-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ad3552r driver, test script, example code, rst file and emu xml. Tested: - pytest - invoke precommit - pre-commit run --all-files - executed sample on target All tests passed. Signed-off-by: Angelo Dureghello <[email protected]> Reviewed-by: Trevor Gamblin <[email protected]>
- Loading branch information
1 parent
a004772
commit 8ff271a
Showing
9 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,104 @@ | ||
# Copyright (C) 2024 Analog Devices, Inc. | ||
# | ||
# SPDX short identifier: ADIBSD | ||
|
||
from decimal import Decimal | ||
|
||
from adi.attribute import attribute | ||
from adi.context_manager import context_manager | ||
from adi.rx_tx import tx | ||
|
||
|
||
class ad3552r(tx, context_manager): | ||
""" AD3552R DAC """ | ||
|
||
_complex_data = False | ||
_device_name = "AD3552R" | ||
|
||
def __init__(self, uri="", device_name=""): | ||
""" Constructor for AD3552R driver class """ | ||
|
||
context_manager.__init__(self, uri, self._device_name) | ||
|
||
compatible_parts = [ | ||
"ad3552r", | ||
"ad3542r", | ||
] | ||
|
||
self._ctrl = None | ||
self._txdac = None | ||
|
||
if not device_name: | ||
device_name = compatible_parts[0] | ||
else: | ||
if device_name not in compatible_parts: | ||
raise Exception( | ||
f"Not a compatible device: {device_name}. Supported device names " | ||
f"are: {','.join(compatible_parts)}" | ||
) | ||
|
||
# Select the device matching device_name as working device | ||
for device in self._ctx.devices: | ||
if device.name == device_name: | ||
self._ctrl = device | ||
self._txdac = device | ||
break | ||
|
||
if not self._ctrl: | ||
raise Exception("Error in selecting matching device") | ||
|
||
if not self._txdac: | ||
raise Exception("Error in selecting matching device") | ||
|
||
self.output_bits = [] | ||
self.channel = [] | ||
self._tx_channel_names = [] | ||
for ch in self._ctrl.channels: | ||
name = ch._id | ||
output = ch._output | ||
self.output_bits.append(ch.data_format.bits) | ||
self._tx_channel_names.append(name) | ||
self.channel.append(self._channel(self._ctrl, name, output)) | ||
if output is True: | ||
setattr(self, name, self._channel(self._ctrl, name, output)) | ||
|
||
tx.__init__(self) | ||
|
||
class _channel(attribute): | ||
"""AD3552R channel""" | ||
|
||
def __init__(self, ctrl, channel_name, output): | ||
self.name = channel_name | ||
self._ctrl = ctrl | ||
self._output = output | ||
|
||
@property | ||
def raw(self): | ||
"""Get channel raw value | ||
DAC code in the range 0-65535""" | ||
return self._get_iio_attr(self.name, "raw", True) | ||
|
||
@raw.setter | ||
def raw(self, value): | ||
"""Set channel raw value""" | ||
self._set_iio_attr(self.name, "raw", True, str(int(value))) | ||
|
||
@property | ||
def offset(self): | ||
"""Get channel offset""" | ||
return self._get_iio_attr_str(self.name, "offset", True) | ||
|
||
@offset.setter | ||
def offset(self, value): | ||
"""Set channel offset""" | ||
self._set_iio_attr(self.name, "offset", True, str(Decimal(value).real)) | ||
|
||
@property | ||
def scale(self): | ||
"""Get channel scale""" | ||
return float(self._get_iio_attr_str(self.name, "scale", True)) | ||
|
||
@scale.setter | ||
def scale(self, value): | ||
"""Set channel scale""" | ||
self._set_iio_attr(self.name, "scale", True, str(Decimal(value).real)) |
This file contains 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,30 @@ | ||
ad3552r | ||
================= | ||
|
||
The device class in this module supports multiple parts, as follows: | ||
|
||
**ad3552r:** ad3542r, ad3552r | ||
|
||
By default, the device_name parameter in the class constructor is the | ||
same as the class name (e.g. "ad3552r" for the ad3552r). To use the class | ||
with another supported model, the name must be given when instantiating | ||
the object. For example, if working with an ad3552r with a URI of | ||
"10.2.5.222", use the ad3552r class, but specify the device_name. | ||
|
||
The number of individual channels is based on the device variant. | ||
|
||
.. automodule:: adi.ad3552r | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: | ||
|
||
|
||
.. code-block:: python | ||
dev = ad3552r("", "ad3552r") | ||
dev.channel[0].raw = 10 | ||
dev.channel[1].raw = 30 | ||
data = dev.channel[0].raw | ||
print(data) |
This file contains 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ Supported Devices | |
|
||
adi.QuadMxFE_multi | ||
adi.ad2s1210 | ||
adi.ad3552r | ||
adi.ad4020 | ||
adi.ad405x | ||
adi.ad4110 | ||
|
This file contains 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,32 @@ | ||
# Copyright (C) 2024 Analog Devices, Inc. | ||
# | ||
# SPDX short identifier: ADIBSD | ||
|
||
import adi | ||
|
||
# Set up AD3552R | ||
dev = adi.ad3552r("ip:analog", "ad3552r") | ||
|
||
print("raw output cleanup ...") | ||
dev.voltage0.raw = 0 | ||
dev.voltage1.raw = 0 | ||
print("current ch 0: " + str(dev.voltage0.raw)) | ||
print("current ch 1: " + str(dev.voltage1.raw)) | ||
|
||
for ch_num in (0, 1): | ||
ad3552r_chan = dev.channel[ch_num] | ||
print("channel: " + str(ch_num)) | ||
print("writing raw: 100") | ||
ad3552r_chan.raw = 100 | ||
print("reading raw:", end=" ") | ||
print(ad3552r_chan.raw) | ||
print("reading offset:", end=" ") | ||
print(ad3552r_chan.offset) | ||
print("reading scale:", end=" ") | ||
print(ad3552r_chan.scale) | ||
|
||
print("setting ch 0 and 1 respectively as 10 and 30 ...") | ||
dev.voltage0.raw = 10 | ||
dev.voltage1.raw = 30 | ||
print("current ch 0 raw: " + str(dev.voltage0.raw)) | ||
print("current ch 1 raw: " + str(dev.voltage1.raw)) |
This file contains 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 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="network" description="10.2.5.219 Linux zed-6 6.1.0-xilinx-271662-gfbd2b84ac912-dirty #7 SMP PREEMPT Wed May 15 10:46:41 CEST 2024 armv7l" ><context-attribute name="hw_model" value="EVAL-AD3552RFMC1Z on Xilinx Zynq ZED" /><context-attribute name="hw_carrier" value="Avnet ZedBoard board" /><context-attribute name="local,kernel" value="6.1.0-xilinx-271662-gfbd2b84ac912-dirty" /><context-attribute name="uri" value="ip:10.2.5.219" /><context-attribute name="ip,ip-addr" value="10.2.5.219" /><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="41000" /><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="2007" /><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="1371" /><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="2441" /><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="2614" /><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="-11" /><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="2434" /><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="1371" /><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="1367" /><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="1689" /><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="ad3552r" ><channel id="voltage0" type="output" ><scan-element index="0" format="be:U16/16>>0" scale="0.076294" /><attribute name="en" filename="out_voltage0_en" value="1" /><attribute name="offset" filename="out_voltage0_offset" value="0.000000" /><attribute name="raw" filename="out_voltage0_raw" value="10" /><attribute name="scale" filename="out_voltage0_scale" value="0.076294" /></channel><channel id="voltage1" type="output" ><scan-element index="1" format="be:U16/16>>0" scale="0.029449" /><attribute name="en" filename="out_voltage1_en" value="1" /><attribute name="offset" filename="out_voltage1_offset" value="41630.640414" /><attribute name="raw" filename="out_voltage1_raw" value="30" /><attribute name="scale" filename="out_voltage1_scale" value="0.029449" /></channel><attribute name="waiting_for_supplier" value="0" /><buffer-attribute name="data_available" value="0" /><buffer-attribute name="direction" value="out" /></device></context> |
This file contains 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 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,30 @@ | ||
import pytest | ||
|
||
hardware = ["ad3552r", "ad3542r"] | ||
classname = "adi.ad3552r" | ||
|
||
######################################### | ||
@pytest.mark.iio_hardware(hardware) | ||
@pytest.mark.parametrize("classname", [(classname)]) | ||
@pytest.mark.parametrize( | ||
"attr, start, stop, step, tol, repeats, sub_channel", | ||
[ | ||
("raw", 0, 4000, 1000, 1, 3, "voltage0"), | ||
("raw", 0, 4000, 1000, 1, 3, "voltage1"), | ||
], | ||
) | ||
def test_ad3552r_raw_attr( | ||
test_attribute_single_value, | ||
iio_uri, | ||
classname, | ||
attr, | ||
start, | ||
stop, | ||
step, | ||
tol, | ||
repeats, | ||
sub_channel, | ||
): | ||
test_attribute_single_value( | ||
iio_uri, classname, attr, start, stop, step, tol, repeats, sub_channel | ||
) |