From e9291889fbf7b06fe53be68db733df37ce5501f7 Mon Sep 17 00:00:00 2001
From: Antoniu Miclaus <antoniu.miclaus@analog.com>
Date: Mon, 5 Feb 2024 11:35:11 +0200
Subject: [PATCH] ad4080: add device_name parameter

Make the device_name parameter explicit.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 adi/ad4080.py              | 17 +++++++++++++----
 examples/ad4080_example.py |  2 +-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/adi/ad4080.py b/adi/ad4080.py
index d5ddd6f76..a51400032 100644
--- a/adi/ad4080.py
+++ b/adi/ad4080.py
@@ -10,17 +10,26 @@ class ad4080(rx, context_manager):
 
     """ AD4080 ADC """
 
+    _compatible_parts = ["ad4080"]
     _complex_data = False
     _rx_channel_names = ["voltage0"]
-    _device_name = "ad4080"
+    _device_name = ""
 
-    def __init__(self, uri=""):
+    def __init__(self, uri="", device_name="ad4080"):
 
         """Initialize."""
         context_manager.__init__(self, uri, self._device_name)
 
-        self._rxadc = self._ctx.find_device("ad4080")
-        self._ctrl = self._ctx.find_device("ad4080")
+        if device_name not in self._compatible_parts:
+            raise Exception(
+                "Not a compatible device: "
+                + str(device_name)
+                + ". Please select from "
+                + str(self.self._compatible_parts)
+            )
+        else:
+            self._ctrl = self._ctx.find_device(device_name)
+            self._rxadc = self._ctx.find_device(device_name)
 
         rx.__init__(self)
 
diff --git a/examples/ad4080_example.py b/examples/ad4080_example.py
index 4f92a1651..5c4ade10d 100644
--- a/examples/ad4080_example.py
+++ b/examples/ad4080_example.py
@@ -42,7 +42,7 @@
 my_uri = sys.argv[1] if len(sys.argv) >= 2 else "ip:analog.local"
 print("uri: " + str(my_uri))
 
-my_adc = ad4080(uri=my_uri)
+my_adc = ad4080(uri=my_uri, device_name="ad4080")
 
 print("Sampling frequency: ", my_adc.sampling_frequency)
 print("Test mode: ", my_adc.test_mode)