-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ltc2672.py driver Add test script, example code Update index.rst, init.py, supported_parts.md files Add ltc2672 rst file Add iio-emu xml file for ltc2672 Update hardware_map.yml emulation context map Signed-off-by: SGudla <Saikiran.Gudla@analog.com>
- Loading branch information
1 parent
ddb3ec3
commit 145697c
Showing
9 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
# Copyright (C) 2024 Analog Devices, Inc. | ||
# | ||
# SPDX short identifier: ADIBSD | ||
|
||
from decimal import Decimal | ||
|
||
from adi.attribute import attribute | ||
from adi.context_manager import context_manager | ||
|
||
|
||
class ltc2672(context_manager, attribute): | ||
"""LTC2672 DAC""" | ||
|
||
_complex_data = False | ||
channel = [] | ||
_device_name = "" | ||
|
||
def __init__(self, uri="", device_name=""): | ||
"""Constructor for LTC2672 class""" | ||
context_manager.__init__(self, uri, self._device_name) | ||
|
||
compatible_parts = ["ltc2672-16", "ltc2672-12"] | ||
|
||
self._ctrl = None | ||
|
||
if not device_name: | ||
device_name = compatible_parts[0] | ||
else: | ||
if device_name not in compatible_parts: | ||
raise Exception( | ||
f"Not a compatible device: {device_name}. Supported device names" | ||
f"are: {','.join(compatible_parts)}" | ||
) | ||
|
||
# Select the device matching device_name as working device | ||
for device in self._ctx.devices: | ||
if device.name == device_name: | ||
self._ctrl = device | ||
break | ||
|
||
if not self._ctrl: | ||
raise Exception("Error in selecting matching device") | ||
|
||
self.output_bits = [] | ||
for ch in self._ctrl.channels: | ||
name = ch.id | ||
self.output_bits.append(ch.data_format.bits) | ||
self.channel.append(self._channel(self._ctrl, name)) | ||
|
||
@property | ||
def all_chns_span(self): | ||
"""Get all channels span in mA""" | ||
return self._get_iio_dev_attr_str("all_chns_span") | ||
|
||
@property | ||
def all_chns_span_avail(self): | ||
"""Get list of span options in mA""" | ||
return self._get_iio_dev_attr_str("all_chns_span_available") | ||
|
||
@all_chns_span.setter | ||
def all_chns_span(self, value): | ||
"""Set all channels span""" | ||
if value in self.all_chns_span_avail: | ||
self._set_iio_dev_attr_str("all_chns_span", value) | ||
else: | ||
raise ValueError( | ||
"Error: span setting not supported \nUse one of: " | ||
"str(self.all_chns_span_avail)" | ||
) | ||
|
||
@property | ||
def all_chns_raw(self): | ||
"""Get raw value""" | ||
return self._get_iio_dev_attr_str("all_chns_raw") | ||
|
||
@all_chns_raw.setter | ||
def all_chns_raw(self, value): | ||
"""Set raw value""" | ||
self._set_iio_dev_attr_str("all_chns_raw", value) | ||
|
||
@property | ||
def all_chns_current(self): | ||
"""Get current value in mA""" | ||
return self._get_iio_dev_attr_str("all_chns_current") | ||
|
||
@all_chns_current.setter | ||
def all_chns_current(self, value): | ||
"""Set current value in mA""" | ||
self._set_iio_dev_attr_str("all_chns_current", value) | ||
|
||
@property | ||
def all_chns_powerdown(self): | ||
"""Get powerdown value""" | ||
return self._get_iio_dev_attr_str("all_chns_powerdown") | ||
|
||
@property | ||
def all_chns_powerdown_avail(self): | ||
"""Get powerdown options""" | ||
return self._get_iio_dev_attr_str("all_chns_powerdown_available") | ||
|
||
@all_chns_powerdown.setter | ||
def all_chns_powerdown(self, value): | ||
"""Set all channels powerdown""" | ||
if value in self.all_chns_powerdown_avail: | ||
self._set_iio_dev_attr_str("all_chns_powerdown", value) | ||
else: | ||
raise ValueError( | ||
"Error: powerdown option not supported \nUse one of: " | ||
"str(self.all_chns_powerdown_avail)" | ||
) | ||
|
||
@property | ||
def mux(self): | ||
"""Get mux setting value""" | ||
return self._get_iio_dev_attr_str("mux") | ||
|
||
@property | ||
def mux_avail(self): | ||
"""Get mux setting options""" | ||
return self._get_iio_dev_attr_str("mux_available") | ||
|
||
@mux.setter | ||
def mux(self, value): | ||
"""Set mux option""" | ||
if value in self.mux_avail: | ||
self._set_iio_dev_attr_str("mux", value) | ||
else: | ||
raise ValueError( | ||
"Error: mux setting not supported \nUse one of: " "str(self.mux_avail)" | ||
) | ||
|
||
@property | ||
def fault_detect(self): | ||
"""Get fault condition if any""" | ||
return self._get_iio_dev_attr_str("fault_detect") | ||
|
||
@property | ||
def fault_detect_avail(self): | ||
"""Get fault detect options""" | ||
return self._get_iio_dev_attr_str("fault_detect_available") | ||
|
||
class _channel(attribute): | ||
"""LTC2672 channel""" | ||
|
||
def __init__(self, ctrl, channel_name): | ||
self.name = channel_name | ||
self._ctrl = ctrl | ||
|
||
@property | ||
def raw(self): | ||
"""Get channel raw value""" | ||
return self._get_iio_attr(self.name, "raw", True) | ||
|
||
@raw.setter | ||
def raw(self, value): | ||
"""Set channel raw value""" | ||
self._set_iio_attr(self.name, "raw", True, str(int(value))) | ||
|
||
@property | ||
def scale(self): | ||
"""Get channel scale""" | ||
return self._get_iio_attr(self.name, "scale", True) | ||
|
||
@property | ||
def offset(self): | ||
"""get channel offset""" | ||
return self._get_iio_attr(self.name, "offset", True) | ||
|
||
@property | ||
def current(self): | ||
"""Get channel current value in mA""" | ||
return self._get_iio_attr(self.name, "current", True) | ||
|
||
@current.setter | ||
def current(self, value): | ||
"""Set channel current value in mA""" | ||
self._set_iio_attr(self.name, "current", True, str(Decimal(value))) | ||
|
||
@property | ||
def span(self): | ||
"""Get channel span value""" | ||
return self._get_iio_attr(self.name, "span", True) | ||
|
||
@property | ||
def span_avail(self): | ||
"""Get channel span options""" | ||
return self._get_iio_attr(self.name, "span_available", True) | ||
|
||
@span.setter | ||
def span(self, value): | ||
"""Set channel span setting""" | ||
if value in self.span_avail: | ||
self._set_iio_attr(self.name, "span", True, value) | ||
else: | ||
raise ValueError( | ||
"Error: span setting not supported \nUse one of: " | ||
"str(self.span_avail)" | ||
) | ||
|
||
@property | ||
def powerdown(self): | ||
"""Get channel powerdown""" | ||
return self._get_iio_attr(self.name, "powerdown", True) | ||
|
||
@property | ||
def powerdown_avail(self): | ||
"""Get channel powerdown options""" | ||
return self._get_iio_attr(self.name, "powerdown_available", True) | ||
|
||
@powerdown.setter | ||
def powerdown(self, value): | ||
"""Set channel powerdown setting""" | ||
if value in self.powerdown_avail: | ||
self._set_iio_attr(self.name, "powerdown", True, value) | ||
else: | ||
raise ValueError( | ||
"Error: powerdown setting not supported \nUse one of: " | ||
"str(self.powerdown_avail)" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ltc2672 | ||
================== | ||
|
||
.. automodule:: adi.ltc2672 | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (C) 2024 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. | ||
|
||
from adi.ltc2672 import * | ||
|
||
# Set up LTC2672 | ||
ltc2672_dev = ltc2672(uri="serial:COM5,230400,8n1") | ||
|
||
# Set all channels span to 50mA | ||
ltc2672_dev.all_chns_span = "50mA" | ||
|
||
# Configure channel 0 and update dac output using the 'raw' attribute | ||
chn_num = 0 | ||
ltc2672_chan = ltc2672_dev.channel[chn_num] | ||
ltc2672_chan.raw = 25000 | ||
|
||
# Get the current value of channel 0 in mA for the corresponding raw value set | ||
current_val_ma = ltc2672_chan.current | ||
print(f"Channel{chn_num} current in mA: {current_val_ma}") | ||
|
||
# Set current value for channel 0 in mA | ||
ltc2672_chan.current = 45 | ||
|
||
# Set mux value to "iout0" to monitor iout0 value on the mux_out pin | ||
ltc2672_dev.mux = "iout0" | ||
|
||
# Powerdown all the channels of the DAC | ||
ltc2672_dev.all_chns_powerdown = "powerdown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,8 @@ | |
- LTC2499 | ||
- LTC2664 | ||
- LTC2688 | ||
- LTC2672-12 | ||
- LTC2672-16 | ||
- LTC2983 | ||
- AD7606 | ||
- AD7745 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE context [<!ELEMENT context (device | context-attribute)*><!ELEMENT context-attribute EMPTY><!ELEMENT device (channel | attribute | debug-attribute | buffer-attribute)*><!ELEMENT channel (scan-element?, attribute*)><!ELEMENT attribute EMPTY><!ELEMENT scan-element EMPTY><!ELEMENT debug-attribute EMPTY><!ELEMENT buffer-attribute EMPTY><!ATTLIST context name CDATA #REQUIRED description CDATA #IMPLIED><!ATTLIST context-attribute name CDATA #REQUIRED value CDATA #REQUIRED><!ATTLIST device id CDATA #REQUIRED name CDATA #IMPLIED><!ATTLIST channel id CDATA #REQUIRED type (input|output) #REQUIRED name CDATA #IMPLIED><!ATTLIST scan-element index CDATA #REQUIRED format CDATA #REQUIRED scale CDATA #IMPLIED><!ATTLIST attribute name CDATA #REQUIRED filename CDATA #IMPLIED value CDATA #IMPLIED><!ATTLIST debug-attribute name CDATA #REQUIRED value CDATA #IMPLIED><!ATTLIST buffer-attribute name CDATA #REQUIRED value CDATA #IMPLIED>]><context name="serial" description="no-OS/projects/NO_OS_PROJECT 0.1" ><context-attribute name="uri" value="serial:/dev/ttyS0,230400,8n1n" /><context-attribute name="serial,port" value="/dev/ttyS0" /><context-attribute name="serial,description" value="ttyS0" /><device id="iio:device0" name="ltc2672-16" ><channel id="current0" name="Chn0" type="output" ><scan-element index="0" format="le:U16/16>>0" /><attribute name="raw" filename="out_current0_raw" value="0" /><attribute name="scale" filename="out_current0_scale" value="0.0000000000" /><attribute name="offset" filename="out_current0_offset" value="0" /><attribute name="current" filename="out_current0_current" value="0.0000mA" /><attribute name="span" filename="out_current0_span" value="off_mode" /><attribute name="span_available" filename="out_current0_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="powerdown" filename="out_current0_powerdown" value="powerdown" /><attribute name="powerdown_available" filename="out_current0_powerdown_available" value="powerdown" /></channel><channel id="current1" name="Chn1" type="output" ><scan-element index="1" format="le:U16/16>>0" /><attribute name="raw" filename="out_current1_raw" value="0" /><attribute name="scale" filename="out_current1_scale" value="0.0000000000" /><attribute name="offset" filename="out_current1_offset" value="0" /><attribute name="current" filename="out_current1_current" value="0.0000mA" /><attribute name="span" filename="out_current1_span" value="off_mode" /><attribute name="span_available" filename="out_current1_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="powerdown" filename="out_current1_powerdown" value="powerdown" /><attribute name="powerdown_available" filename="out_current1_powerdown_available" value="powerdown" /></channel><channel id="current2" name="Chn2" type="output" ><scan-element index="2" format="le:U16/16>>0" /><attribute name="raw" filename="out_current2_raw" value="0" /><attribute name="scale" filename="out_current2_scale" value="0.0000000000" /><attribute name="offset" filename="out_current2_offset" value="0" /><attribute name="current" filename="out_current2_current" value="0.0000mA" /><attribute name="span" filename="out_current2_span" value="off_mode" /><attribute name="span_available" filename="out_current2_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="powerdown" filename="out_current2_powerdown" value="powerdown" /><attribute name="powerdown_available" filename="out_current2_powerdown_available" value="powerdown" /></channel><channel id="current3" name="Chn3" type="output" ><scan-element index="3" format="le:U16/16>>0" /><attribute name="raw" filename="out_current3_raw" value="0" /><attribute name="scale" filename="out_current3_scale" value="0.0000000000" /><attribute name="offset" filename="out_current3_offset" value="0" /><attribute name="current" filename="out_current3_current" value="0.0000mA" /><attribute name="span" filename="out_current3_span" value="off_mode" /><attribute name="span_available" filename="out_current3_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="powerdown" filename="out_current3_powerdown" value="powerdown" /><attribute name="powerdown_available" filename="out_current3_powerdown_available" value="powerdown" /></channel><channel id="current4" name="Chn4" type="output" ><scan-element index="4" format="le:U16/16>>0" /><attribute name="raw" filename="out_current4_raw" value="0" /><attribute name="scale" filename="out_current4_scale" value="0.0000000000" /><attribute name="offset" filename="out_current4_offset" value="0" /><attribute name="current" filename="out_current4_current" value="0.0000mA" /><attribute name="span" filename="out_current4_span" value="off_mode" /><attribute name="span_available" filename="out_current4_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="powerdown" filename="out_current4_powerdown" value="powerdown" /><attribute name="powerdown_available" filename="out_current4_powerdown_available" value="powerdown" /></channel><attribute name="all_chns_raw" value="0" /><attribute name="all_chns_current" value="0.0000mA" /><attribute name="all_chns_span" value="off_mode" /><attribute name="all_chns_span_available" value="off_mode 3.125mA 6.25mA 12.5mA 25mA 50mA 100mA 200mA MVREF 300mA" /><attribute name="all_chns_powerdown" value="powerdown" /><attribute name="all_chns_powerdown_available" value="powerdown" /><attribute name="mux" value="disable" /><attribute name="mux_available" value="disable iout0 iout1 iout2 iout3 iout4 vcc vref vref_lo die_temperature vdd0 vdd1 vdd2 vdd3 vdd4 v_minus gnd vout0 vout1 vout2 vout3 vout4" /><attribute name="fault_detect" value="no_fault" /><attribute name="fault_detect_available" value="no_fault open_circuit_ch0 open_circuit_ch1 open_circuit_ch2 open_circuit_ch3 open_circuit_ch4 Over_temperature Invalid_SPI_seq_length multiple_faults" /><debug-attribute name="direct_reg_access" value="0" /></device></context> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.