Skip to content
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

adi:ad5592r: Added Rx method #625

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion adi/ad5592r.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

from adi.attribute import attribute
from adi.context_manager import context_manager
from adi.rx_tx import rx


class ad5592r(context_manager):
class ad5592r(rx, context_manager):
"""AD5592R and AD5593R SPI / I2C interface, 8-channel, 12-bit Confiburable ADC/DAC, digital GPIO

Analog I/O pins are configured in the device tree and can be ADC, DAC, or both. Channel attributes are as follows, where X corresponds to device channel number:
Expand All @@ -25,6 +26,8 @@ class ad5592r(context_manager):
"""

_device_name = ""
_complex_data = False
channel = []

def __repr__(self):
retstr = f"""
Expand Down Expand Up @@ -56,8 +59,15 @@ def __init__(self, uri="", device_name=""):
for device in self._ctx.devices:
if device.name in device_name:
self._ctrl = device
self._rxadc = device
buffers_avail = any([c.scan_element for c in self._rxadc.channels])
if not buffers_avail:
delattr(self, "rx")
break

self.channel = []
self._rx_channel_names = []

# Dynamically get channels after the index
for ch in self._ctrl.channels:
name = ch._id
Expand All @@ -70,9 +80,12 @@ def __init__(self, uri="", device_name=""):
self, name + "_dac", self.channel_dac(self._ctrl, name, output)
)
else:
self._rx_channel_names.append(name)
self.channel.append(self.channel_adc(self._ctrl, name, output))
setattr(
self, name + "_adc", self.channel_adc(self._ctrl, name, output)
)
rx.__init__(self)

class channel_adc(attribute):
"""AD5592R Input Voltage Channels"""
Expand Down
2 changes: 1 addition & 1 deletion test/emu/devices/ad5592r.xml
Original file line number Diff line number Diff line change
@@ -1 +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="192.168.86.20 Linux analog 5.10.63-v7l+ #1 SMP Fri Oct 21 08:20:48 UTC 2022 armv7l" ><context-attribute name="hw_carrier" value="Raspberry Pi 4 Model B Rev 1.1" /><context-attribute name="dtoverlay" value="gpio-shutdown,rpi-ad5592r" /><context-attribute name="hw_model" value="0x0001 on Raspberry Pi 4 Model B Rev 1.1" /><context-attribute name="hw_mezzanine" value="0x0001" /><context-attribute name="hw_name" value="Raspberry Pi to Pmod/QuikEval/PSM Adapter" /><context-attribute name="hw_vendor" value="Analog Devices, Inc." /><context-attribute name="hw_serial" value="99ed8c67-7357-4c38-9721-b1723abbaa81" /><context-attribute name="local,kernel" value="5.10.63-v7l+" /><context-attribute name="uri" value="ip:analog.local" /><context-attribute name="ip,ip-addr" value="192.168.86.20" /><device id="hwmon0" name="cpu_thermal" ><channel id="temp1" type="input" ><attribute name="input" filename="temp1_input" value="33589" /></channel></device><device id="hwmon1" name="rpi_volt" ><channel id="in0" type="input" ><attribute name="lcrit_alarm" filename="in0_lcrit_alarm" value="0" /></channel></device><device id="iio:device0" name="ad5592r" ><channel id="voltage3" type="input" ><attribute name="raw" filename="in_voltage3_raw" value="0" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="in_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="voltage2" type="output" ><attribute name="raw" filename="out_voltage2_raw" value="0" /><attribute name="scale" filename="out_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="out_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="voltage3" type="output" ><attribute name="raw" filename="out_voltage3_raw" value="0" /><attribute name="scale" filename="out_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="out_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="voltage1" type="input" ><attribute name="raw" filename="in_voltage1_raw" value="0" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="in_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="voltage0" type="output" ><attribute name="raw" filename="out_voltage0_raw" value="0" /><attribute name="scale" filename="out_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="out_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="voltage2" type="input" ><attribute name="raw" filename="in_voltage2_raw" value="0" /><attribute name="scale" filename="in_voltage_scale" value="0.610351562" /><attribute name="scale_available" filename="in_voltage_scale_available" value="0.610351562 1.220703124" /></channel><channel id="temp" type="input" ><attribute name="offset" filename="in_temp_offset" value="-753" /><attribute name="raw" filename="in_temp_raw" value="813" /><attribute name="scale" filename="in_temp_scale" value="376.789750000" /></channel></device><device id="iio_sysfs_trigger" ><attribute name="add_trigger" value="ERROR" /><attribute name="remove_trigger" value="ERROR" /></device></context>
<?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/NO_OS_PROJECT 1" ><context-attribute name="hw_carrier" value="SDP-K1" /><context-attribute name="hw_mezzanine" value="PMD-ARD-INT-LCZ" /><context-attribute name="hw_name" value="Arduino to Pmod Interposer" /><context-attribute name="uri" value="serial:/dev/ttyS0,230400,8n1n" /><context-attribute name="serial,port" value="/dev/ttyS0" /><context-attribute name="serial,description" value="ttyS0" /><device id="iio:device0" name="ad5592r" ><channel id="voltage0" name="voltage0" type="output" ><scan-element index="0" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage0_raw" value="2" /><attribute name="scale" filename="in_voltage0_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage0_offset" value="0" /></channel><channel id="voltage1" name="voltage1" type="input" ><scan-element index="1" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage1_raw" value="313" /><attribute name="scale" filename="in_voltage1_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage1_offset" value="0" /></channel><channel id="voltage2" name="voltage2" type="output" ><scan-element index="2" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage2_raw" value="4095" /><attribute name="scale" filename="in_voltage2_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage2_offset" value="0" /></channel><channel id="voltage3" name="voltage3" type="output" ><scan-element index="3" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage3_raw" value="4095" /><attribute name="scale" filename="in_voltage3_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage3_offset" value="0" /></channel><channel id="voltage4" name="voltage4" type="input" ><scan-element index="4" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage4_raw" value="4095" /><attribute name="scale" filename="in_voltage4_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage4_offset" value="0" /></channel><channel id="voltage5" name="voltage5" type="input" ><scan-element index="5" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage5_raw" value="4095" /><attribute name="scale" filename="in_voltage5_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage5_offset" value="0" /></channel><channel id="voltage6" name="voltage6" type="input" ><scan-element index="6" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage6_raw" value="4095" /><attribute name="scale" filename="in_voltage6_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage6_offset" value="0" /></channel><channel id="voltage7" name="voltage7" type="input" ><scan-element index="7" format="le:u12/16&gt;&gt;0" /><attribute name="raw" filename="in_voltage7_raw" value="18" /><attribute name="scale" filename="in_voltage7_scale" value="0.61035156" /><attribute name="offset" filename="in_voltage7_offset" value="0" /></channel><attribute name="sampling_frequency" value="1" /><attribute name="die_temperature" value="27.110022" /><attribute name="adc_buffer" value="enabled" /><attribute name="adc_buffer_available" value="disabled enabled" /><attribute name="ldac_mode" value="sync" /><attribute name="ldac_mode_available" value="sync async trigger" /><attribute name="set_repetition_bit" value="repeating" /><attribute name="set_repetition_bit_available" value="non-repeating repeating" /><debug-attribute name="direct_reg_access" value="0" /></device></context>
Loading