From 06060b8ac834ec27af1392d35c9bd37d38cc090d Mon Sep 17 00:00:00 2001 From: Cristi Iacob Date: Thu, 23 Apr 2020 11:11:50 +0300 Subject: [PATCH 1/3] doc: added DeviceBufferAttr and DeviceDebugAttr in Sphinx. Added the Sphinx documentation for the DeviceBufferAttr and DeviceDebugAttr classes under the Device menu. Signed-off-by: Cristi Iacob --- bindings/python/doc/channel.rst | 11 +++++++++ bindings/python/doc/device.rst | 12 +++++++++ bindings/python/iio.py | 43 +++++++++++++++++++++++++++------ 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/bindings/python/doc/channel.rst b/bindings/python/doc/channel.rst index 398737b50..62a62fc64 100644 --- a/bindings/python/doc/channel.rst +++ b/bindings/python/doc/channel.rst @@ -5,3 +5,14 @@ Members -------------- .. autoclass:: iio.Channel :members: + +-------------------- + +Channel attributes +-------------------- +.. autoclass:: iio.DataFormat + :members: +.. autoclass:: iio.ChannelModifier + :members: +.. autoclass:: iio.ChannelType + :members: diff --git a/bindings/python/doc/device.rst b/bindings/python/doc/device.rst index 19beff020..a5512c2b5 100644 --- a/bindings/python/doc/device.rst +++ b/bindings/python/doc/device.rst @@ -6,3 +6,15 @@ Members .. autoclass:: iio.Device :members: :inherited-members: + +------------------ + +Device attributes +------------------ +.. autoclass:: iio.DeviceDebugAttr + :members: + :inherited-members: +.. autoclass:: iio.DeviceBufferAttr + :members: + :inherited-members: + diff --git a/bindings/python/iio.py b/bindings/python/iio.py index c3e3adfe5..125144822 100644 --- a/bindings/python/iio.py +++ b/bindings/python/iio.py @@ -75,7 +75,7 @@ class DataFormat(Structure): ('repeat', c_uint)] class ChannelModifier(Enum): - """Contains the modifier types of an IIO channel.""" + """Contains the modifier type of an IIO channel.""" IIO_NO_MOD = 0 IIO_MOD_X = 1 @@ -526,10 +526,6 @@ class ChannelType(Enum): _buffer_cancel.restype = c_void_p _buffer_cancel.argtypes = (_BufferPtr, ) -_buffer_get_data = _lib.iio_buffer_get_data -_buffer_get_data.restype = c_void_p -_buffer_get_data.argtypes = (_BufferPtr, ) - _buffer_get_device = _lib.iio_buffer_get_device _buffer_get_device.restype = _DevicePtr _buffer_get_device.argtypes = (_BufferPtr, ) @@ -811,6 +807,15 @@ def type(self): return ChannelType(_channel_get_type(self._channel)) def convert(self, dst, src): + """ + Converts src and saves the result in dst, using current channel's data format. + + parameters: + dst: type=list + The variable where the result is stored. + src: type=list + Data to be converted. + """ _channel_convert(self._channel, c_void_p(*dst), c_void_p(*src)) class Buffer(object): @@ -904,12 +909,22 @@ def write(self, array): return length def cancel(self): + """ + Cancels the current buffer. + """ _buffer_cancel(self._buffer) - def get_data(self): - return _buffer_get_data(self._buffer) - def set_blocking_mode(self, blocking): + """ + Sets the buffer's blocking mode. + + parameters: + blocking: type=boolean + True if in blocking_mode else False. + + returns: type=int + Return code from the C layer. + """ return _buffer_set_blocking_mode(self._buffer, c_bool(blocking)) @property @@ -922,10 +937,18 @@ def device(self): @property def poll_fd(self): + """ + This buffer's poll_fd. + type: int + """ return _buffer_get_poll_fd(self._buffer) @property def step(self): + """ + This buffer's step size. + type: int + """ return _buffer_step(self._buffer) class _DeviceOrTrigger(object): @@ -1090,6 +1113,10 @@ def _get_trigger(self): @property def context(self): + """ + This device's context. + type: iio.Context + """ return self.ctx() class Context(object): From 848f9f9d6916fad0f8e0ffd05409f2ed53ce94a3 Mon Sep 17 00:00:00 2001 From: Cristi Iacob Date: Tue, 28 Apr 2020 12:49:07 +0300 Subject: [PATCH 2/3] python: fixed Channel.convert() method. c_void_p(*dst) and c_void_p(*src) were not properly creating a pointer to dst and src. Signed-off-by: Cristi Iacob --- bindings/python/iio.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindings/python/iio.py b/bindings/python/iio.py index 125144822..5a5313d52 100644 --- a/bindings/python/iio.py +++ b/bindings/python/iio.py @@ -14,7 +14,7 @@ # Lesser General Public License for more details. from ctypes import Structure, c_char_p, c_uint, c_int, c_long, c_longlong, c_size_t, \ - c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, c_double, \ + c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, c_double, cast, \ POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref from ctypes.util import find_library from enum import Enum @@ -816,7 +816,9 @@ def convert(self, dst, src): src: type=list Data to be converted. """ - _channel_convert(self._channel, c_void_p(*dst), c_void_p(*src)) + src_ptr = cast((c_char * (len(src) * self.data_format.length))(*src), c_void_p) + dst_ptr = cast((c_char * (len(dst) * self.data_format.length))(*dst), c_void_p) + _channel_convert(self._channel, src_ptr, dst_ptr) class Buffer(object): From 13f03604acdfb8a575637c94d236eea0ecf7fea0 Mon Sep 17 00:00:00 2001 From: Cristi Iacob Date: Tue, 28 Apr 2020 12:49:45 +0300 Subject: [PATCH 3/3] python: added Channel.convert_inverse(). Added the convert_inverse() method from the Channel class and its documentation. Signed-off-by: Cristi Iacob --- bindings/python/iio.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bindings/python/iio.py b/bindings/python/iio.py index 5a5313d52..40e51fdf4 100644 --- a/bindings/python/iio.py +++ b/bindings/python/iio.py @@ -496,6 +496,10 @@ class ChannelType(Enum): _channel_convert.restype = None _channel_convert.argtypes = (_ChannelPtr, c_void_p, c_void_p) +_channel_convert_inverse = _lib.iio_channel_convert_inverse +_channel_convert_inverse.restype = None +_channel_convert_inverse.argtypes = (_ChannelPtr, c_void_p, c_void_p) + _create_buffer = _lib.iio_device_create_buffer _create_buffer.restype = _BufferPtr _create_buffer.argtypes = (_DevicePtr, c_size_t, c_bool, ) @@ -820,6 +824,20 @@ def convert(self, dst, src): dst_ptr = cast((c_char * (len(dst) * self.data_format.length))(*dst), c_void_p) _channel_convert(self._channel, src_ptr, dst_ptr) + def convert_inverse(self, dst, src): + """ + Convert the sample from host format to hardware format. + + parameters: + dst: type=list + The variable where the result is stored. + src: type=list + Data to be converted. + """ + src_ptr = cast((c_char * (len(src) * self.data_format.length))(*src), c_void_p) + dst_ptr = cast((c_char * (len(dst) * self.data_format.length))(*dst), c_void_p) + _channel_convert_inverse(self._channel, src_ptr, dst_ptr) + class Buffer(object): """The class used for all I/O operations."""