Skip to content

Commit

Permalink
Merge pull request #548 from analogdevicesinc/tfcollins/ad5592r-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
tfcollins authored Mar 29, 2024
2 parents 4d30e01 + 5c0b806 commit cb47d61
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
49 changes: 25 additions & 24 deletions adi/ad5592r.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,32 @@


class ad5592r(context_manager):
"""AD5592R and AD5593R SPI / I2C interface,
8-channel, 12-bit Confiburable ADC/DAC, digital GPIO"""
"""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:
voltageX_adc.raw: Raw 12-bit ADC code. read only for ADC channels\n
voltageX_adc.scale: ADC scale, millivolts per lsb\n
voltageX_adc.scale_available: Available scales, corresponding to Vref*1, Vref*2\n
voltageX(): Returns ADC reading in millivolts (read only)\n
voltageX_dac.raw: Raw 12-bit DAC code. read/write for DAC channels\n
voltageX_dac.scale: ADC scale, millivolts per lsb\n
voltageX_dac.scale_available: Available scales (corresponding to 1X/2X gain)\n
voltageX(1234.5): Sets/Returns ADC reading in millivolts\n
temp.raw: Temperature raw value\n
temp.scale: Temperature scale value\n
temp.offset Temperature offset value\n
temp(): Returns temperature in degrees Celsius\n
"""

_device_name = ""

def __repr__(self):
retstr = f"""
ad5592r(uri="{self.uri}") object "{self._device_name}"
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:
voltageX_adc.raw: Raw 12-bit ADC code. read only for ADC channels
voltageX_adc.scale: ADC scale, millivolts per lsb
voltageX_adc.scale_available: Available scales, corresponding to Vref*1, Vref*2
voltageX(): Returns ADC reading in millivolts (read only)
voltageX_dac.raw: Raw 12-bit DAC code. read/write for DAC channels
voltageX_dac.scale: ADC scale, millivolts per lsb
voltageX_dac.scale_available: Available scales (corresponding to 1X/2X gain)
voltageX(1234.5): Sets/Returns ADC reading in millivolts
temp.raw: Temperature raw value
temp.scale: Temperature scale value
temp.offset Temperature offset value
temp(): Returns temperature in degrees Celsius
ad5592r(uri="{self.uri}, device_name={self._device_name})"
{self.__doc__}
"""

return retstr

def __init__(self, uri="", device_name=""):
Expand Down Expand Up @@ -62,18 +63,18 @@ def __init__(self, uri="", device_name=""):
name = ch._id
output = ch._output
if name == "temp":
setattr(self, name, self._channel_temp(self._ctrl, name, output))
setattr(self, name, self.channel_temp(self._ctrl, name, output))
else:
if output is True:
setattr(
self, name + "_dac", self._channel_dac(self._ctrl, name, output)
self, name + "_dac", self.channel_dac(self._ctrl, name, output)
)
else:
setattr(
self, name + "_adc", self._channel_adc(self._ctrl, name, output)
self, name + "_adc", self.channel_adc(self._ctrl, name, output)
)

class _channel_adc(attribute):
class channel_adc(attribute):
"""AD5592R Input Voltage Channels"""

# AD559XR ADC channel
Expand Down Expand Up @@ -117,7 +118,7 @@ def __call__(self, mV=None):
self.raw = int(float(mV) / float(self.scale))
return self.raw * self.scale

class _channel_dac(_channel_adc):
class channel_dac(channel_adc):
"""AD5592R Output Voltage Channels
(Add setter to raw property)"""

Expand All @@ -134,7 +135,7 @@ def raw(self):
def raw(self, value):
self._set_iio_attr(self.name, "raw", self._output, value)

class _channel_temp(attribute):
class channel_temp(attribute):
"""AD5592R Temperature Channel"""

# AD559XR voltage channel
Expand Down
13 changes: 13 additions & 0 deletions doc/source/devices/adi.ad5592r.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@ ad5592r
:members:
:undoc-members:
:show-inheritance:


The number of individual channels is based on the hardware configuration of the device. The are individually accessed as properties like so:

.. code-block:: python
dev = adi.ad5592r(uri="ip:analog")
dev.dac_0.raw = 10
dev.dac_1.raw = 30
data = dev.adc_0.raw
print(data)
temp_c = (dev.temp_0.raw + dev.temp_0.offset) * dev.temp_0.scale
print(temp_c)
2 changes: 1 addition & 1 deletion doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Supported Devices


.. toctree::
:maxdepth: 4
:maxdepth: 2

adi.QuadMxFE_multi
adi.ad2s1210
Expand Down

0 comments on commit cb47d61

Please sign in to comment.