|
| 1 | +# Copyright (C) 2025 Analog Devices, Inc. |
| 2 | +# |
| 3 | +# SPDX short identifier: ADIBSD |
| 4 | + |
| 5 | +from adi.attribute import attribute |
| 6 | +from adi.context_manager import context_manager |
| 7 | +from adi.rx_tx import rx |
| 8 | + |
| 9 | + |
| 10 | +class ad4080(rx, context_manager): |
| 11 | + |
| 12 | + """ AD4080 ADC """ |
| 13 | + |
| 14 | + _complex_data = False |
| 15 | + _device_name = "" |
| 16 | + channel = [] # type: ignore |
| 17 | + |
| 18 | + def __init__(self, uri="", device_name="ad4080"): |
| 19 | + context_manager.__init__(self, uri, self._device_name) |
| 20 | + |
| 21 | + compatible_part = "ad4080" |
| 22 | + self._ctrl = None |
| 23 | + |
| 24 | + if not device_name: |
| 25 | + device_name = compatible_part |
| 26 | + else: |
| 27 | + if device_name != compatible_part: |
| 28 | + raise Exception(f"Not a compatible device: {device_name}") |
| 29 | + |
| 30 | + # Select the device matching device_name as working device |
| 31 | + for device in self._ctx.devices: |
| 32 | + if device.name == device_name: |
| 33 | + self._ctrl = device |
| 34 | + self._rxadc = device |
| 35 | + break |
| 36 | + |
| 37 | + # Raise an exception if the device isn't found |
| 38 | + if not self._ctrl: |
| 39 | + raise Exception("AD4080 device not found") |
| 40 | + |
| 41 | + if not self._rxadc: |
| 42 | + raise Exception("Error in selecting matching device") |
| 43 | + |
| 44 | + self._rx_channel_names = [] |
| 45 | + self.channel = [] |
| 46 | + for ch in self._ctrl.channels: |
| 47 | + name = ch.id |
| 48 | + self._rx_channel_names.append(name) |
| 49 | + self.channel.append(self._channel(self._ctrl, name)) |
| 50 | + |
| 51 | + rx.__init__(self) |
| 52 | + |
| 53 | + class _channel(attribute): |
| 54 | + """AD4080 channel""" |
| 55 | + |
| 56 | + def __init__(self, ctrl, channel_name): |
| 57 | + self.name = channel_name |
| 58 | + self._ctrl = ctrl |
| 59 | + |
| 60 | + @property |
| 61 | + def scale(self): |
| 62 | + """Get Scale value""" |
| 63 | + return self._get_iio_attr("voltage0", "scale", False) |
| 64 | + |
| 65 | + @property |
| 66 | + def sampling_frequency(self): |
| 67 | + """Get Sampling frequency value""" |
| 68 | + return self._get_iio_dev_attr("sampling_frequency", False) |
| 69 | + |
| 70 | + @property |
| 71 | + def oversampling_ratio_available(self): |
| 72 | + """Get the oversampling ratio available values""" |
| 73 | + return self._get_iio_dev_attr("oversampling_ratio_available", False) |
| 74 | + |
| 75 | + @property |
| 76 | + def oversampling_ratio(self): |
| 77 | + """Get the oversampling ratio value""" |
| 78 | + return self._get_iio_dev_attr("oversampling_ratio", False) |
| 79 | + |
| 80 | + @oversampling_ratio.setter |
| 81 | + def oversampling_ratio(self, value): |
| 82 | + """Set the oversampling ratio value""" |
| 83 | + self._set_iio_dev_attr("oversampling_ratio", value) |
| 84 | + |
| 85 | + @property |
| 86 | + def filter_type_available(self): |
| 87 | + """Get the filter type available values""" |
| 88 | + return self._get_iio_dev_attr_str("filter_type_available", False) |
| 89 | + |
| 90 | + @property |
| 91 | + def filter_type(self): |
| 92 | + """Get the filter type value""" |
| 93 | + return self._get_iio_dev_attr_str("filter_type") |
| 94 | + |
| 95 | + @filter_type.setter |
| 96 | + def filter_type(self, value): |
| 97 | + """Set the filter type value""" |
| 98 | + self._set_iio_dev_attr_str("filter_type", value) |
| 99 | + |
| 100 | + def reg_read(self, reg): |
| 101 | + """Direct Register Access via debugfs""" |
| 102 | + self._set_iio_debug_attr_str("direct_reg_access", reg, self._ctrl) |
| 103 | + return self._get_iio_debug_attr_str("direct_reg_access", self._ctrl) |
| 104 | + |
| 105 | + def reg_write(self, reg, value): |
| 106 | + """Direct Register Access via debugfs""" |
| 107 | + self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._ctrl) |
0 commit comments