diff --git a/adi/ad4630.py b/adi/ad4630.py index cd9039864..f57875f04 100644 --- a/adi/ad4630.py +++ b/adi/ad4630.py @@ -2,6 +2,7 @@ # # SPDX short identifier: ADIBSD +from decimal import Decimal import numpy as np from adi.attribute import attribute @@ -32,6 +33,20 @@ class ad4630(rx, context_manager, attribute): """ Default part to initialize is ad4630-24. If you don't hardware test fails""" + def __init_channels__(self): + _channels = [] + self.output_bits = [] + for ch in self._ctrl.channels: + self.output_bits.append(ch.data_format.bits) + self._rx_channel_names.append(ch.id) + _channels.append((ch.id, self._channel(self._ctrl, ch.id))) + if "0" in ch.id: + self.chan0 = self._channel(self._ctrl, ch.id) + if "1" in ch.id: + self.chan1 = self._channel(self._ctrl, ch.id) + + rx.__init__(self) + def __init__(self, uri="", device_name="ad4630-24"): context_manager.__init__(self, uri, self._device_name) @@ -49,18 +64,7 @@ def __init__(self, uri="", device_name="ad4630-24"): self._ctrl = self._ctx.find_device(device_name) self._rxadc = self._ctx.find_device(device_name) - _channels = [] - self.output_bits = [] - for ch in self._ctrl.channels: - self.output_bits.append(ch.data_format.bits) - self._rx_channel_names.append(ch.id) - _channels.append((ch.id, self._channel(self._ctrl, ch.id))) - if "0" in ch.id: - self.chan0 = self._channel(self._ctrl, ch.id) - if "1" in ch.id: - self.chan1 = self._channel(self._ctrl, ch.id) - - rx.__init__(self) + self.__init_channels__(self) def rx(self): if not self._rx__rxbuf: @@ -166,3 +170,70 @@ def calibscale(self): def calibscale(self, calibscale): """Set calibration scale value.""" self._set_iio_attr(self.name, "calibscale", False, calibscale, self._ctrl) + + +class adaq42xx(ad4630): + + """ ADAQ4224 is a 24-bit precision SAR ADC data acquisition module """ + + def __init__(self, uri="", device_name="adaq4224"): + + context_manager.__init__(self, uri, self._device_name) + + compatible_parts = ["adaq4224", "adaq4216", "adaq4220"] + + if device_name not in compatible_parts: + raise Exception( + "Not a compatible device: " + + str(device_name) + + ". Please select from " + + str(compatible_parts) + ) + else: + self._ctrl = self._ctx.find_device(device_name) + self._rxadc = self._ctx.find_device(device_name) + + self.__init_channels__(self) + + class _channel(attribute): + """ADAQ42xx differential channel.""" + + def __init__(self, ctrl, channel_name): + self.name = channel_name + self._ctrl = ctrl + + @property + def calibbias(self): + """Get calibration bias/offset value.""" + return self._get_iio_attr(self.name, "calibbias", False, self._ctrl) + + @calibbias.setter + def calibbias(self, calibbias): + """Set calibration bias/offset value.""" + self._set_iio_attr( + self.name, "calibbias", False, int(calibbias), self._ctrl + ) + + @property + def calibscale(self): + """Get calibration scale value.""" + return self._get_iio_attr(self.name, "calibscale", False, self._ctrl) + + @calibscale.setter + def calibscale(self, calibscale): + """Set calibration scale value.""" + self._set_iio_attr(self.name, "calibscale", False, calibscale, self._ctrl) + + @property + def scale_available(self): + """Provides all available scale(gain) settings for the ADAQ42xx channel""" + return self._get_iio_attr(self.channel[0].name, "scale_available", False) + + @property + def scale(self): + """ADAQ42xx channel scale""" + return float(self._get_iio_attr_str(self.name, "scale", False)) + + @scale.setter + def scale(self, value): + self._set_iio_attr(self.name, "scale", False, str(Decimal(value).real)) diff --git a/supported_parts.md b/supported_parts.md index faf881689..d4635db66 100644 --- a/supported_parts.md +++ b/supported_parts.md @@ -99,6 +99,9 @@ - AD4858 - AD9739A - ADA4961 +- ADAQ4216 +- ADAQ4220 +- ADAQ4224 - ADAQ8092 - ADAR1000 - ADF4159