Skip to content

Commit

Permalink
Merge pull request #436 from mthoren-adi/cn0575_dev
Browse files Browse the repository at this point in the history
Add support for CN0575, 10BASE-T1L Raspberry Pi Hat with Button, LED,…
  • Loading branch information
tfcollins authored May 15, 2023
2 parents 62d9184 + 02426bf commit a5132a2
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 5 deletions.
1 change: 1 addition & 0 deletions adi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
from adi.cn0511 import cn0511
from adi.cn0532 import cn0532
from adi.cn0554 import cn0554
from adi.cn0575 import cn0575
from adi.daq2 import DAQ2
from adi.daq3 import DAQ3
from adi.fmc_vna import fmcvna
Expand Down
62 changes: 62 additions & 0 deletions adi/cn0575.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (C) 2023 Analog Devices, Inc.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# - Neither the name of Analog Devices, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# - The use of this software may or may not infringe the patent rights
# of one or more patent holders. This license does not release you
# from the requirement that you obtain separate licenses from these
# patent holders to use this software.
# - Use of the software either in source or binary form, must be run
# on or directly connected to an Analog Devices Inc. component.
#
# THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.
#
# IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
# RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import adi


class cn0575:
""" CN0575 class, exposing onboard temperature sensor, pushbutton,
and LED. Also reads the platform CPU's temperature, which under
most operating conditions should be higher than the onboard sensor.
"""

def __init__(self, uri=""):

self.gpios = adi.one_bit_adc_dac(uri)
self.adt75 = adi.lm75(uri) # ADI version of LM75
self.gpios.gpio_ext_led = 0 # turn off LED

@property
def button(self):
"""Read button state."""
return self.gpios.gpio_ext_btn

@property
def led(self):
"""Read LED state."""
return self.gpios.gpio_ext_led

@led.setter
def led(self, value):
"""Set LED state"""
self.gpios.gpio_ext_led = value
35 changes: 31 additions & 4 deletions adi/lm75.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,37 @@


class lm75(context_manager, attribute):
""" LM75 Temperature Sensor """

_device_name = "lm75"
""" LM75 Temperature Sensor
def __init__(self, uri=""):
Parameters
----------
uri: type=string
Context URI. Default: Empty (auto-scan)
device_index: type=integer
Device index in contexts with multiple LM75 compatible devices. Default: 0
returns:
LM75 compatible device
"""

_device_name = ""

def __init__(self, uri="", device_index=0):

context_manager.__init__(self, uri, self._device_name)
self._ctrl = self._ctx.find_device("lm75")

compatible_parts = ["lm75", "adt75"]

self._ctrl = None
index = 0
# Select the device_index-th device from the lm75 family as working device.
for device in self._ctx.devices:
if device.name in compatible_parts:
if index == device_index:
self._ctrl = device
break
else:
index += 1

@property
def update_interval(self):
Expand Down Expand Up @@ -82,3 +105,7 @@ def max_hyst(self):
def max_hyst(self, value):
"""LM75 max_hyst value"""
return self._set_iio_attr("temp1", "max_hyst", False, value)

def __call__(self):
"""Utility function, returns deg. C"""
return self.input / 1000
7 changes: 7 additions & 0 deletions doc/source/devices/adi.cn0575.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cn0575
=================

.. automodule:: adi.cn0575
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions doc/source/devices/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Supported Devices
adi.cn0532
adi.cn0540
adi.cn0554
adi.cn0575
adi.daq2
adi.daq3
adi.fmc_vna
Expand Down
61 changes: 61 additions & 0 deletions examples/cn0575_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (C) 2023 Analog Devices, Inc.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# - Neither the name of Analog Devices, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
# - The use of this software may or may not infringe the patent rights
# of one or more patent holders. This license does not release you
# from the requirement that you obtain separate licenses from these
# patent holders to use this software.
# - Use of the software either in source or binary form, must be run
# on or directly connected to an Analog Devices Inc. component.
#
# THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.
#
# IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
# RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import sys
from time import sleep

import adi

# Optionally pass URI as command line argument,
# else use default context manager search
my_uri = sys.argv[1] if len(sys.argv) >= 2 else None
print("uri: " + str(my_uri))

# Connect to CN0575
my_cn0575 = adi.cn0575(uri=my_uri)

print("\nReading onboard ADT75 ...")
print("Temperature: ", my_cn0575.adt75(), " deg. C")

print("Blinking LED and reading button:")
for i in range(1, 10):
my_cn0575.led = 1
sleep(0.5)
my_cn0575.led = 0
sleep(0.5)
if my_cn0575.button == 1:
print("Button Pressed")
else:
print("Button NOT Pressed")

# del my_cn0575
1 change: 1 addition & 0 deletions supported_parts.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
- CN0540
- CN0554
- CN0549
- CN0575
- DAQ2
- DAQ3
- FMCADC3
Expand Down
11 changes: 11 additions & 0 deletions test/emu/hardware_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ cn0554:
- iio:device0
- iio:device1

cn0575:
- adt75
- one-bit-adc-dac
- pyadi_iio_class_support:
- cn0575
- emulate:
- filename: cn0575.xml
- data_devices:
- hwmon2
- iio:device0

# SOMS
adrv9361:
- ad7291
Expand Down
40 changes: 40 additions & 0 deletions test/test_cn0575.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

hardware = "cn0575"
classname = "adi.cn0575"

#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, start, stop, step, tol, repeats, sub_channel",
[
("max", -55000, 125000, 30000, 1, 10, "adt75"),
("max_hyst", -55000, 125000, 30000, 1, 10, "adt75"),
],
)
def test_adt75_attr(
test_attribute_single_value,
iio_uri,
classname,
attr,
start,
stop,
step,
tol,
repeats,
sub_channel,
):
test_attribute_single_value(
iio_uri, classname, attr, start, stop, step, tol, repeats, sub_channel
)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, val", [("led", [1, 0],),],
)
def test_led_attr(test_attribute_multipe_values, iio_uri, classname, attr, val):
test_attribute_multipe_values(iio_uri, classname, attr, val, 0, repeats=10)
2 changes: 1 addition & 1 deletion test/test_lm75.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
("max_hyst", -55000, 125000, 30000, 1, 10),
],
)
def test_adxrs355_attr(
def test_lm75_attr(
test_attribute_single_value,
iio_uri,
classname,
Expand Down

0 comments on commit a5132a2

Please sign in to comment.