|
| 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 | + |
| 8 | + |
| 9 | +class ad9508(attribute, context_manager): |
| 10 | + |
| 11 | + """ AD9508 ADC """ |
| 12 | + |
| 13 | + _device_name = "" |
| 14 | + |
| 15 | + def __init__(self, uri="", device_name="ad9508"): |
| 16 | + context_manager.__init__(self, uri, self._device_name) |
| 17 | + |
| 18 | + compatible_part = "ad9508" |
| 19 | + self._ctrl = None |
| 20 | + |
| 21 | + if not device_name: |
| 22 | + device_name = compatible_part |
| 23 | + else: |
| 24 | + if device_name != compatible_part: |
| 25 | + raise Exception(f"Not a compatible device: {device_name}") |
| 26 | + |
| 27 | + # Select the device matching device_name as working device |
| 28 | + for device in self._ctx.devices: |
| 29 | + if device.name == device_name: |
| 30 | + self._ctrl = device |
| 31 | + self._rxadc = device |
| 32 | + break |
| 33 | + |
| 34 | + # Raise an exception if the device isn't found |
| 35 | + if not self._ctrl: |
| 36 | + raise Exception("ad9508 device not found") |
| 37 | + |
| 38 | + self.channel = [] |
| 39 | + for ch in self._ctrl.channels: |
| 40 | + name = ch.id |
| 41 | + self.channel.append(self._channel(self._ctrl, name)) |
| 42 | + |
| 43 | + class _channel(attribute): |
| 44 | + """AD9508 channel""" |
| 45 | + |
| 46 | + def __init__(self, ctrl, channel_name): |
| 47 | + self.name = channel_name |
| 48 | + self._ctrl = ctrl |
| 49 | + |
| 50 | + @property |
| 51 | + def frequency(self): |
| 52 | + """""" |
| 53 | + return self._get_iio_attr(self.name, "frequency", True) |
| 54 | + |
| 55 | + @frequency.setter |
| 56 | + def frequency(self, frequency): |
| 57 | + """""" |
| 58 | + self._set_iio_attr(self.name, "frequency", False, frequency, self._ctrl) |
| 59 | + |
| 60 | + @property |
| 61 | + def phase(self): |
| 62 | + """""" |
| 63 | + return self._get_iio_attr(self.name, "phase", False) |
| 64 | + |
| 65 | + @phase.setter |
| 66 | + def phase(self, phase): |
| 67 | + """""" |
| 68 | + self._set_iio_attr(self.name, "phase", False, phase, self._ctrl) |
| 69 | + |
| 70 | + @property |
| 71 | + def raw(self): |
| 72 | + """""" |
| 73 | + return self._get_iio_attr(self.name, "raw", False) |
| 74 | + |
| 75 | + @raw.setter |
| 76 | + def raw(self, raw): |
| 77 | + """""" |
| 78 | + self._set_iio_attr(self.name, "raw", False, raw, self._ctrl) |
| 79 | + |
| 80 | + @property |
| 81 | + def sync_dividers(self): |
| 82 | + """""" |
| 83 | + raise AttributeError("Cannot access 'sync_dividers' directly") |
| 84 | + |
| 85 | + @sync_dividers.setter |
| 86 | + def sync_dividers(self, value): |
| 87 | + self._set_iio_dev_attr("sync_dividers", value) |
| 88 | + |
| 89 | + def reg_read(self, reg): |
| 90 | + """Direct Register Access via debugfs""" |
| 91 | + self._set_iio_debug_attr_str("direct_reg_access", reg, self._ctrl) |
| 92 | + return self._get_iio_debug_attr_str("direct_reg_access", self._ctrl) |
| 93 | + |
| 94 | + def reg_write(self, reg, value): |
| 95 | + """Direct Register Access via debugfs""" |
| 96 | + self._set_iio_debug_attr_str("direct_reg_access", f"{reg} {value}", self._ctrl) |
0 commit comments