diff --git a/bindings/matlab/attribute.m b/bindings/matlab/attribute.m index 5b8937cc2..cdbc9adbd 100644 --- a/bindings/matlab/attribute.m +++ b/bindings/matlab/attribute.m @@ -27,7 +27,7 @@ end function status = iio_attr_write_raw(attrPtr, srcPtr, len) - % Read the content of the given attribute + % Set the value of the given attribute % % Args: % attrPtr: A pointer to an iio_attr structure. @@ -106,6 +106,21 @@ end function [status, value] = iio_attr_read_bool(attrPtr) + % Read the content of the given (boolean) attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % + % Returns: + % On success, + % status is 0, and + % value is the (boolean) value read from the attribute + % On error, + % status is a negative errno code, and + % value is a NULL-pointer. + % + % libiio function: iio_attr_read_bool + valPtr = libpointer('bool', 0); if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_read_bool', attrPtr, valPtr); @@ -121,6 +136,21 @@ end function [status, value] = iio_attr_read_longlong(attrPtr) + % Read the content of the given (longlong) attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % + % Returns: + % On success, + % status is 0, and + % value is the (longlong) value read from the attribute + % On error, + % status is a negative errno code, and + % value is a NULL-pointer. + % + % libiio function: iio_attr_read_longlong + valPtr = libpointer('int64Ptr', 0); if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_read_longlong', attrPtr, valPtr); @@ -136,6 +166,21 @@ end function [status, value] = iio_attr_read_double(attrPtr) + % Read the content of the given (double) attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % + % Returns: + % On success, + % status is 0, and + % value is the (double) value read from the attribute + % On error, + % status is a negative errno code, and + % value is a NULL-pointer. + % + % libiio function: iio_attr_read_double + valPtr = libpointer('double', 0); if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_read_double', attrPtr, valPtr); @@ -151,14 +196,38 @@ end function status = iio_attr_write_string(attrPtr, value) + % Set the (string) value of the given attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % value: The (string) data to be written. + % + % Returns: + % On success, 0 is returned. + % On error, a negative errno code is returned. + % + % libiio function: iio_attr_write_string + if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_write_string', attrPtr, value); else - status = coder.ceval('iio_attr_write_string', attrPtr, value); + status = coder.ceval('iio_attr_write_string', attrPtr, adi.libiio.helpers.ntstr(value)); end end function status = iio_attr_write_bool(attrPtr, value) + % Set the (boolean) value of the given attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % value: The (boolean) data to be written. + % + % Returns: + % On success, 0 is returned. + % On error, a negative errno code is returned. + % + % libiio function: iio_attr_write_bool + if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_write_bool', attrPtr, value); else @@ -167,6 +236,18 @@ end function status = iio_attr_write_longlong(attrPtr, value) + % Set the (longlong) value of the given attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % value: The (longlong) data to be written. + % + % Returns: + % On success, 0 is returned. + % On error, a negative errno code is returned. + % + % libiio function: iio_attr_write_longlong + if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_write_longlong', attrPtr, value); else @@ -175,6 +256,18 @@ end function status = iio_attr_write_double(attrPtr, value) + % Set the (double) value of the given attribute + % + % Args: + % attrPtr: A pointer to an iio_attr structure. + % value: The (double) data to be written. + % + % Returns: + % On success, 0 is returned. + % On error, a negative errno code is returned. + % + % libiio function: iio_attr_write_double + if coder.target('MATLAB') status = adi.libiio.helpers.calllibADI('iio_attr_write_double', attrPtr, value); else diff --git a/bindings/matlab/block.m b/bindings/matlab/block.m index 4eae4a603..425ba747c 100644 --- a/bindings/matlab/block.m +++ b/bindings/matlab/block.m @@ -56,7 +56,7 @@ function iio_block_destroy(blockPtr) end end - function addr = iio_block_first(blockPtr, chnPtr) + function firstSamplePtr = iio_block_first(blockPtr, chnPtr) % Find the first sample of a channel in a block % % Args: @@ -86,14 +86,14 @@ function iio_block_destroy(blockPtr) % libiio function: iio_block_first if coder.target('MATLAB') - addr = adi.libiio.helpers.calllibADI('iio_block_first', blockPtr, chnPtr); + firstSamplePtr = adi.libiio.helpers.calllibADI('iio_block_first', blockPtr, chnPtr); else - addr = coder.opaque('void*', 'NULL'); - addr = coder.ceval('iio_block_first', blockPtr, chnPtr); + firstSamplePtr = coder.opaque('void*', 'NULL'); + firstSamplePtr = coder.ceval('iio_block_first', blockPtr, chnPtr); end end - function endAddr = iio_block_end(blockPtr) + function lastSamplePtr = iio_block_end(blockPtr) % Get the address after the last sample in a block % % Args: @@ -106,10 +106,10 @@ function iio_block_destroy(blockPtr) % libiio function: iio_block_end if coder.target('MATLAB') - endAddr = adi.libiio.helpers.calllibADI('iio_block_end', blockPtr); + lastSamplePtr = adi.libiio.helpers.calllibADI('iio_block_end', blockPtr); else - endAddr = coder.opaque('void*', 'NULL'); - endAddr = coder.ceval('iio_block_end', blockPtr); + lastSamplePtr = coder.opaque('void*', 'NULL'); + lastSamplePtr = coder.ceval('iio_block_end', blockPtr); end end %{ diff --git a/bindings/matlab/channel.m b/bindings/matlab/channel.m index 70572ee0c..bb803faa0 100644 --- a/bindings/matlab/channel.m +++ b/bindings/matlab/channel.m @@ -143,7 +143,7 @@ % Try to find a channel-specific attribute by its name % % Args: - % chnPtr: A pointer to an iio_channel structure + % chnPtr: A pointer to an iio_channel structure. % name: A NULL-terminated string corresponding to the name % of the attribute. % @@ -243,11 +243,11 @@ function iio_channel_disable(chnPtr, maskPtr) % Args: % chnPtr: A pointer to an iio_channel structure. % blockPtr: A pointer to an iio_block structure. - % srcPtr: A pointer to the memory area where the sequential data will - % be read from. + % srcPtr: A pointer to the memory area where the sequential + % data will be read from. % len: The available length of the memory area, in bytes. - % raw: True if the samples are already in hardware format, false if they - % need to be converted. + % raw: True if the samples are already in hardware format, + % false if they need to be converted. % % Returns: % The number of bytes actually converted and multiplexed. diff --git a/bindings/matlab/context.m b/bindings/matlab/context.m index 3bcc1e0fd..086e6bfbc 100644 --- a/bindings/matlab/context.m +++ b/bindings/matlab/context.m @@ -1,13 +1,13 @@ classdef context < handle methods (Static) %% context methods - function ctxPtr = iio_create_context(ctxParamsPtr, uri) + function ctxPtr = iio_create_context(varargin) % Create a context from a URI description % % Args: - % ctxParamsPtr: A pointer to a iio_context_params structure - % that contains context creation information; can be - % NULL. + % (optional) ctxParamsPtr: A pointer to a iio_context_params + % structure that contains context creation information; + % can be NULL. % uri: a URI describing the context location. If NULL, the % backend will be created using the URI string present in % the IIOD_REMOTE environment variable, or if not set, a @@ -63,6 +63,18 @@ % % libiio function: iio_create_context + if nargin == 1 + if coder.target('MATLAB') + ctxParamsPtr = libpointer; + else + ctxParamsPtr = coder.opaque('const struct iio_context_params*', 'NULL'); + end + uri = varargin{1}; + elseif nargin == 2 + ctxParamsPtr = varargin{1}; + uri = varargin{2}; + end + if coder.target('MATLAB') ctxPtr = adi.libiio.helpers.calllibADI('iio_create_context', ctxParamsPtr, uri); else @@ -86,11 +98,11 @@ function iio_context_destroy(ctxPtr) end end - function major = iio_context_get_version_major(ctxPtr) + function major = iio_context_get_version_major(varargin) % Get the major number of the library version % % Args: - % ctxPtr: Optional pointer to a iio_context structure. + % (optional) ctxPtr: A pointer to a iio_context structure. % % Returns: % The major number. @@ -101,6 +113,16 @@ function iio_context_destroy(ctxPtr) % % libiio function: iio_context_get_version_major + if nargin == 0 + if coder.target('MATLAB') + ctxPtr = libpointer; + else + ctxPtr = coder.opaque('const struct iio_context*', 'NULL'); + end + elseif nargin == 1 + ctxPtr = varargin{1}; + end + if coder.target('MATLAB') major = adi.libiio.helpers.calllibADI('iio_context_get_version_major', ctxPtr); else @@ -108,11 +130,11 @@ function iio_context_destroy(ctxPtr) end end - function minor = iio_context_get_version_minor(ctxPtr) + function minor = iio_context_get_version_minor(varargin) % Get the minor number of the library version % % Args: - % ctxPtr: Optional pointer to a iio_context structure. + % (optional) ctxPtr: A pointer to a iio_context structure. % % Returns: % The minor number. @@ -123,6 +145,16 @@ function iio_context_destroy(ctxPtr) % % libiio function: iio_context_get_version_minor + if nargin == 0 + if coder.target('MATLAB') + ctxPtr = libpointer; + else + ctxPtr = coder.opaque('const struct iio_context*', 'NULL'); + end + elseif nargin == 1 + ctxPtr = varargin{1}; + end + if coder.target('MATLAB') minor = adi.libiio.helpers.calllibADI('iio_context_get_version_minor', ctxPtr); else @@ -130,11 +162,11 @@ function iio_context_destroy(ctxPtr) end end - function vtag = iio_context_get_version_tag(ctxPtr) + function vtag = iio_context_get_version_tag(varargin) % Get the git hash string of the library version % % Args: - % ctxPtr: Optional pointer to a iio_context structure. + % (optional) ctxPtr: A pointer to a iio_context structure. % % Returns: % A NULL-terminated string that contains the git tag or hash. @@ -145,6 +177,16 @@ function iio_context_destroy(ctxPtr) % % libiio function: iio_context_get_version_tag + if nargin == 0 + if coder.target('MATLAB') + ctxPtr = libpointer; + else + ctxPtr = coder.opaque('const struct iio_context*', 'NULL'); + end + elseif nargin == 1 + ctxPtr = varargin{1}; + end + if coder.target('MATLAB') vtag = adi.libiio.helpers.calllibADI('iio_context_get_version_tag', ctxPtr); else diff --git a/bindings/matlab/scan.m b/bindings/matlab/scan.m index a745c468f..6285960c8 100644 --- a/bindings/matlab/scan.m +++ b/bindings/matlab/scan.m @@ -1,16 +1,17 @@ classdef scan < handle methods (Static) %% scan methods - function scanPtr = iio_scan(ctxParamsPtr, backends) + function scanPtr = iio_scan(varargin) % Scan backends for IIO contexts % % Args: - % ctxParamsPtr: A pointer to a iio_context_params structure - % that contains context creation information; can be - % NULL. - % backends: A NULL-terminated string containing a comma-separated list - % of the backends to be scanned for contexts. If NULL, all the available - % backends are scanned. + % (optional) ctxParamsPtr: A pointer to a iio_context_params + % structure that contains context creation information; + % can be NULL. + % (optional) backends: A NULL-terminated string containing a + % comma-separated list of the backends to be scanned for + % contexts. If NULL, all the available backends are + % scanned. % % Returns: % On success, a pointer to an iio_scan structure. @@ -24,6 +25,26 @@ % prefix needed. % % libiio function: iio_scan + + if nargin == 0 + if coder.target('MATLAB') + ctxParamsPtr = libpointer; + backends = libpointer; + else + ctxParamsPtr = coder.opaque('const struct iio_context_params*', 'NULL'); + backends = coder.opaque('const char *', 'NULL'); + end + elseif nargin == 1 + if coder.target('MATLAB') + ctxParamsPtr = libpointer; + else + ctxParamsPtr = coder.opaque('const struct iio_context_params*', 'NULL'); + end + backends = varargin{1}; + elseif nargin == 2 + ctxParamsPtr = varargin{1}; + backends = varargin{2}; + end if coder.target('MATLAB') scanPtr = adi.libiio.helpers.calllibADI('iio_scan', ctxParamsPtr, backends); diff --git a/bindings/matlab/toplevel.m b/bindings/matlab/toplevel.m index 06d30cb1f..7b59b3be2 100644 --- a/bindings/matlab/toplevel.m +++ b/bindings/matlab/toplevel.m @@ -19,13 +19,13 @@ function iio_strerror(err, dstPtr, len) end end - function hasBackend = iio_has_backend(ctxParamsPtr, backend) + function hasBackend = iio_has_backend(varargin) % Check if the specified backend is available % % Args: - % ctxParamsPtr: A pointer to a iio_context_params structure - % that contains context creation information; can be - % NULL. + % (optional) ctxParamsPtr: A pointer to a iio_context_params + % structure that contains context creation information; + % can be NULL. % backend: The name of the backend to query. % % Returns: @@ -33,6 +33,18 @@ function iio_strerror(err, dstPtr, len) % % libiio function: iio_has_backend + if nargin == 1 + if coder.target('MATLAB') + ctxParamsPtr = libpointer; + else + ctxParamsPtr = coder.opaque('const struct iio_context_params*', 'NULL'); + end + backend = varargin{1}; + elseif nargin == 2 + ctxParamsPtr = varargin{1}; + backend = varargin{2}; + end + if coder.target('MATLAB') hasBackend = adi.libiio.helpers.calllibADI('iio_has_backend', ctxParamsPtr, backend); else