From 2a58df20fc224390407d79285f5bf8acfaf6f082 Mon Sep 17 00:00:00 2001 From: Trecia Agoylo Date: Tue, 22 Oct 2024 10:18:06 +0800 Subject: [PATCH] ad937x: updated dec8/int8 implementation Signed-off-by: Trecia Agoylo --- adi/ad937x.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/adi/ad937x.py b/adi/ad937x.py index 4dfa425a6..d529b4a78 100644 --- a/adi/ad937x.py +++ b/adi/ad937x.py @@ -170,18 +170,18 @@ def tx_rf_bandwidth(self): @property def rx_enable_dec8(self): """rx_enable_dec8: Enable x8 decimation filter in RX path""" - val = self._get_iio_attr_str( - "voltage0_i", "sampling_frequency", False, self._rxadc - ) - avail = None try: avail = self._get_iio_attr_str( "voltage0_i", "sampling_frequency_available", False, self._rxadc ) + except KeyError: + return False + else: avail = avail.strip().split(" ") + val = self._get_iio_attr_str( + "voltage0_i", "sampling_frequency", False, self._rxadc + ) return val == avail[1] - except KeyError: - return val == avail @rx_enable_dec8.setter def rx_enable_dec8(self, value): @@ -189,29 +189,33 @@ def rx_enable_dec8(self, value): avail = self._get_iio_attr_str( "voltage0_i", "sampling_frequency_available", False, self._rxadc ) + except KeyError: + if value: + print( + "x8 decimation filter is not supported. Using default sampling frequency." + ) + else: avail = sorted(avail.strip().split(" ")) val = int(avail[1] if value else avail[0]) self._set_iio_attr( "voltage0_i", "sampling_frequency", False, val, self._rxadc ) - except KeyError: - print("x8 decimation filter is not supported.") @property def tx_enable_int8(self): """tx_enable_int8: Enable x8 interpolation filter in TX path""" - val = self._get_iio_attr_str( - "voltage0", "sampling_frequency", True, self._txdac - ) - avail = None try: avail = self._get_iio_attr_str( "voltage0", "sampling_frequency_available", True, self._txdac ) + except KeyError: + return False + else: avail = avail.strip().split(" ") + val = self._get_iio_attr_str( + "voltage0", "sampling_frequency", True, self._txdac + ) return val == avail[1] - except KeyError: - return val == avail @tx_enable_int8.setter def tx_enable_int8(self, value): @@ -219,11 +223,15 @@ def tx_enable_int8(self, value): avail = self._get_iio_attr_str( "voltage0", "sampling_frequency_available", True, self._txdac ) + except KeyError: + if value: + print( + "x8 interpolation filter is not supported. Using default sampling frequency." + ) + else: avail = sorted(avail.strip().split(" ")) val = int(avail[1] if value else avail[0]) self._set_iio_attr("voltage0", "sampling_frequency", True, val, self._txdac) - except KeyError: - print("x8 decimation filter is not supported.") @property def rx_sample_rate(self):