Skip to content

adt7420: Adding Linux support #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

macylibed9
Copy link

@macylibed9 macylibed9 commented May 16, 2025

Description

Added Linux support for ADT7420 by handling Linux-specific IIO attributes (input, max, min, crit, max_hyst). It can now auto-detect whether the platform is no-OS or Linux based on the channel name (temp for no-OS, temp1 for Linux).

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How has this been tested?

Tested on actual hardware using the board example from pyadi-iio. The driver successfully reads and sets attribute values, confirming functionality on both no-OS and Linux setups.

Documentation

If this is a new feature or example please mention or link any documentation. All new hardware interface classes require documentation.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have signed off all commits and they contain "Signed-off by: "
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Signed-off-by: Macy Libed <[email protected]>
Signed-off-by: Macy Libed <[email protected]>
Signed-off-by: Macy Libed <[email protected]>
@macylibed9
Copy link
Author

Hi @tfcollins this PR is ready for review :> thanks

Comment on lines +25 to +40
for ch in self._ctrl.channels:
name = ch._id

self._rx_channel_names.append(name)
self.channel.append(name)

if name == "temp":
# no-OS
setattr(self, name, self.channel_temp(self._ctrl, name))
self.temp = self.channel_temp(self._ctrl, "temp")
elif name == "temp1":
# Linux
setattr(self, name, self.channel_temp1(self._ctrl, name))
self.temp = self.channel_temp1(self._ctrl, "temp1")
else:
raise Exception(f"Unsupported: {name}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alittle confused on this loop. Do all the channels have the same name? Is there more than one channel on the device? Maybe an emulated context will help

Comment on lines +93 to +144

class channel_temp1(attribute):
"""ADT7420 Channel for Linux"""

def __init__(self, ctrl, channel_name):
self._ctrl = ctrl
self.name = channel_name

@property
def temp_val(self):
""" ADT7420 Channel Temperature Value """
return self._get_iio_attr(self.name, "input", False)

@property
def temp_max(self):
""" ADT7420 Channel Max Temperature """
return self._get_iio_attr(self.name, "max", False)

@temp_max.setter
def temp_max(self, value):
""" ADT7420 Channel Max Temperature """
return self._set_iio_attr(self.name, "max", False, value)

@property
def temp_min(self):
""" ADT7420 Channel Min Temperature """
return self._get_iio_attr(self.name, "min", False)

@temp_min.setter
def temp_min(self, value):
""" ADT7420 Channel Min Temperature """
return self._set_iio_attr(self.name, "min", False, value)

@property
def temp_crit(self):
""" ADT7420 Channel Critical Temperature """
return self._get_iio_attr(self.name, "crit", False)

@temp_crit.setter
def temp_crit(self, value):
""" ADT7420 Channel Critical Temperature """
return self._set_iio_attr(self.name, "crit", False, value)

@property
def temp_hyst(self):
""" ADT7420 Channel Hysteresis Temperature """
return self._get_iio_attr(self.name, "max_hyst", False)

@temp_hyst.setter
def temp_hyst(self, value):
""" ADT7420 Channel Hysteresis Temperature """
return self._set_iio_attr(self.name, "max_hyst", False, value)
Copy link
Collaborator

@tfcollins tfcollins May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think just the channel names are different here. Can you instead do this inline to the properties like so:

        def __init__(self, ctrl, channel_name, is_linux):
            self._ctrl = ctrl
            self.name = channel_name
            self.is_linux = is_linux

        @property
        def temp_val(self):
            """ ADT7420 Channel Temperature Value """
            pname = "input" if self.is_linux else "temp"
            return self._get_iio_attr(self.name, pname, False)

This will reduce the change by 4x and will be a bit easier to understand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants