Example program for EVAL-AD4130

Dependencies:   tempsensors sdp_k1_sdram

Committer:
Mahesh Phalke
Date:
Wed Jul 20 18:12:00 2022 +0530
Revision:
2:7b2b268ea49c
Initial firmware commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mahesh Phalke 2:7b2b268ea49c 1 # Copyright (C) 2022 Analog Devices, Inc.
Mahesh Phalke 2:7b2b268ea49c 2 #
Mahesh Phalke 2:7b2b268ea49c 3 # All rights reserved.
Mahesh Phalke 2:7b2b268ea49c 4 #
Mahesh Phalke 2:7b2b268ea49c 5 # Redistribution and use in source and binary forms, with or without modification,
Mahesh Phalke 2:7b2b268ea49c 6 # are permitted provided that the following conditions are met:
Mahesh Phalke 2:7b2b268ea49c 7 # - Redistributions of source code must retain the above copyright
Mahesh Phalke 2:7b2b268ea49c 8 # notice, this list of conditions and the following disclaimer.
Mahesh Phalke 2:7b2b268ea49c 9 # - Redistributions in binary form must reproduce the above copyright
Mahesh Phalke 2:7b2b268ea49c 10 # notice, this list of conditions and the following disclaimer in
Mahesh Phalke 2:7b2b268ea49c 11 # the documentation and/or other materials provided with the
Mahesh Phalke 2:7b2b268ea49c 12 # distribution.
Mahesh Phalke 2:7b2b268ea49c 13 # - Neither the name of Analog Devices, Inc. nor the names of its
Mahesh Phalke 2:7b2b268ea49c 14 # contributors may be used to endorse or promote products derived
Mahesh Phalke 2:7b2b268ea49c 15 # from this software without specific prior written permission.
Mahesh Phalke 2:7b2b268ea49c 16 # - The use of this software may or may not infringe the patent rights
Mahesh Phalke 2:7b2b268ea49c 17 # of one or more patent holders. This license does not release you
Mahesh Phalke 2:7b2b268ea49c 18 # from the requirement that you obtain separate licenses from these
Mahesh Phalke 2:7b2b268ea49c 19 # patent holders to use this software.
Mahesh Phalke 2:7b2b268ea49c 20 # - Use of the software either in source or binary form, must be run
Mahesh Phalke 2:7b2b268ea49c 21 # on or directly connected to an Analog Devices Inc. component.
Mahesh Phalke 2:7b2b268ea49c 22 #
Mahesh Phalke 2:7b2b268ea49c 23 # THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
Mahesh Phalke 2:7b2b268ea49c 24 # INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
Mahesh Phalke 2:7b2b268ea49c 25 # PARTICULAR PURPOSE ARE DISCLAIMED.
Mahesh Phalke 2:7b2b268ea49c 26 #
Mahesh Phalke 2:7b2b268ea49c 27 # IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Mahesh Phalke 2:7b2b268ea49c 28 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY
Mahesh Phalke 2:7b2b268ea49c 29 # RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
Mahesh Phalke 2:7b2b268ea49c 30 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
Mahesh Phalke 2:7b2b268ea49c 31 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
Mahesh Phalke 2:7b2b268ea49c 32 # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Mahesh Phalke 2:7b2b268ea49c 33
Mahesh Phalke 2:7b2b268ea49c 34 from adi import ad4130
Mahesh Phalke 2:7b2b268ea49c 35 from adi.attribute import attribute
Mahesh Phalke 2:7b2b268ea49c 36 from decimal import Decimal
Mahesh Phalke 2:7b2b268ea49c 37
Mahesh Phalke 2:7b2b268ea49c 38 # Create a child class of ad4130 parent class for defining extended iio attributes (the ones which
Mahesh Phalke 2:7b2b268ea49c 39 # are not part of original linux iio drivers and created for non-linux iio applications)
Mahesh Phalke 2:7b2b268ea49c 40 class ad4130_xattr(ad4130):
Mahesh Phalke 2:7b2b268ea49c 41
Mahesh Phalke 2:7b2b268ea49c 42 # List of extended iio channels
Mahesh Phalke 2:7b2b268ea49c 43 xchannel = []
Mahesh Phalke 2:7b2b268ea49c 44
Mahesh Phalke 2:7b2b268ea49c 45 def __init__(self, uri, device_name):
Mahesh Phalke 2:7b2b268ea49c 46 super().__init__(uri, device_name)
Mahesh Phalke 2:7b2b268ea49c 47
Mahesh Phalke 2:7b2b268ea49c 48 # Create an instances of the extended channel class
Mahesh Phalke 2:7b2b268ea49c 49 for ch in self._ctrl.channels:
Mahesh Phalke 2:7b2b268ea49c 50 name = ch._id
Mahesh Phalke 2:7b2b268ea49c 51 self._rx_channel_names.append(name)
Mahesh Phalke 2:7b2b268ea49c 52 self.xchannel.append(self._xchannel(self._ctrl, name))
Mahesh Phalke 2:7b2b268ea49c 53
Mahesh Phalke 2:7b2b268ea49c 54 # Add the _xchannel class methods as _channel methods, so that they can be accessed with
Mahesh Phalke 2:7b2b268ea49c 55 # attribute name as 'channel' instead 'xchannel'
Mahesh Phalke 2:7b2b268ea49c 56 # e.g. channel attribute 'system_calibration' can be accessed as either "obj.channel[chn_num].system_calibration" Or
Mahesh Phalke 2:7b2b268ea49c 57 # "obj.xchannel[chn_num].system_calibration", where obj refers to object of 'ad4130_xattr' class
Mahesh Phalke 2:7b2b268ea49c 58 self._channel.system_calibration = self._xchannel.system_calibration
Mahesh Phalke 2:7b2b268ea49c 59 self._channel.internal_calibration = self._xchannel.internal_calibration
Mahesh Phalke 2:7b2b268ea49c 60 self._channel.loadcell_offset_calibration = self._xchannel.loadcell_offset_calibration
Mahesh Phalke 2:7b2b268ea49c 61 self._channel.loadcell_gain_calibration = self._xchannel.loadcell_gain_calibration
Mahesh Phalke 2:7b2b268ea49c 62
Mahesh Phalke 2:7b2b268ea49c 63 #------------------------------------------------
Mahesh Phalke 2:7b2b268ea49c 64 # Device extended attributes
Mahesh Phalke 2:7b2b268ea49c 65 #------------------------------------------------
Mahesh Phalke 2:7b2b268ea49c 66
Mahesh Phalke 2:7b2b268ea49c 67 @property
Mahesh Phalke 2:7b2b268ea49c 68 def demo_config(self):
Mahesh Phalke 2:7b2b268ea49c 69 """AD4130 demo mode config"""
Mahesh Phalke 2:7b2b268ea49c 70 return self._get_iio_dev_attr_str("demo_config")
Mahesh Phalke 2:7b2b268ea49c 71
Mahesh Phalke 2:7b2b268ea49c 72 @property
Mahesh Phalke 2:7b2b268ea49c 73 def sample_rate(self):
Mahesh Phalke 2:7b2b268ea49c 74 """AD4130 device sample_rate"""
Mahesh Phalke 2:7b2b268ea49c 75 return int(self._get_iio_dev_attr_str("sampling_frequency"))
Mahesh Phalke 2:7b2b268ea49c 76
Mahesh Phalke 2:7b2b268ea49c 77 #------------------------------------------------
Mahesh Phalke 2:7b2b268ea49c 78 # Channel extended attributes
Mahesh Phalke 2:7b2b268ea49c 79 #------------------------------------------------
Mahesh Phalke 2:7b2b268ea49c 80
Mahesh Phalke 2:7b2b268ea49c 81 class _xchannel(attribute):
Mahesh Phalke 2:7b2b268ea49c 82
Mahesh Phalke 2:7b2b268ea49c 83 def __init__(self, ctrl, channel_name):
Mahesh Phalke 2:7b2b268ea49c 84 self.name = channel_name
Mahesh Phalke 2:7b2b268ea49c 85 self._ctrl = ctrl
Mahesh Phalke 2:7b2b268ea49c 86
Mahesh Phalke 2:7b2b268ea49c 87 @property
Mahesh Phalke 2:7b2b268ea49c 88 def system_calibration(self):
Mahesh Phalke 2:7b2b268ea49c 89 """AD4130 channel system calibration"""
Mahesh Phalke 2:7b2b268ea49c 90 return self._get_iio_attr_str(self.name, "system_calibration", False)
Mahesh Phalke 2:7b2b268ea49c 91
Mahesh Phalke 2:7b2b268ea49c 92 @system_calibration.setter
Mahesh Phalke 2:7b2b268ea49c 93 def system_calibration(self, value):
Mahesh Phalke 2:7b2b268ea49c 94 self._set_iio_attr(self.name, "system_calibration", False, value)
Mahesh Phalke 2:7b2b268ea49c 95
Mahesh Phalke 2:7b2b268ea49c 96 @property
Mahesh Phalke 2:7b2b268ea49c 97 def internal_calibration(self):
Mahesh Phalke 2:7b2b268ea49c 98 """AD4130 channel internal calibration"""
Mahesh Phalke 2:7b2b268ea49c 99 return self._get_iio_attr_str(self.name, "internal_calibration", False)
Mahesh Phalke 2:7b2b268ea49c 100
Mahesh Phalke 2:7b2b268ea49c 101 @internal_calibration.setter
Mahesh Phalke 2:7b2b268ea49c 102 def internal_calibration(self, value):
Mahesh Phalke 2:7b2b268ea49c 103 self._set_iio_attr(self.name, "internal_calibration", False, value)
Mahesh Phalke 2:7b2b268ea49c 104
Mahesh Phalke 2:7b2b268ea49c 105 @property
Mahesh Phalke 2:7b2b268ea49c 106 def loadcell_offset_calibration(self):
Mahesh Phalke 2:7b2b268ea49c 107 """AD4130 loadcell offset calibration"""
Mahesh Phalke 2:7b2b268ea49c 108 return self._get_iio_attr_str(self.name, "loadcell_offset_calibration", False)
Mahesh Phalke 2:7b2b268ea49c 109
Mahesh Phalke 2:7b2b268ea49c 110 @loadcell_offset_calibration.setter
Mahesh Phalke 2:7b2b268ea49c 111 def loadcell_offset_calibration(self, value):
Mahesh Phalke 2:7b2b268ea49c 112 self._set_iio_attr(self.name, "loadcell_offset_calibration", False, value)
Mahesh Phalke 2:7b2b268ea49c 113
Mahesh Phalke 2:7b2b268ea49c 114 @property
Mahesh Phalke 2:7b2b268ea49c 115 def loadcell_gain_calibration(self):
Mahesh Phalke 2:7b2b268ea49c 116 """AD4130 loadcell gain calibration"""
Mahesh Phalke 2:7b2b268ea49c 117 return self._get_iio_attr_str(self.name, "loadcell_gain_calibration", False)
Mahesh Phalke 2:7b2b268ea49c 118
Mahesh Phalke 2:7b2b268ea49c 119 @loadcell_gain_calibration.setter
Mahesh Phalke 2:7b2b268ea49c 120 def loadcell_gain_calibration(self, value):
Mahesh Phalke 2:7b2b268ea49c 121 self._set_iio_attr(self.name, "loadcell_gain_calibration", False, value)
Mahesh Phalke 2:7b2b268ea49c 122