Skip to content

Commit

Permalink
matlab bindings:
Browse files Browse the repository at this point in the history
 replace input arguments with varargin to handle optional inputs

Signed-off-by: Pagadarai <[email protected]>
  • Loading branch information
SrikanthPagadarai committed Sep 16, 2024
1 parent 320439c commit 5d223f9
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 36 deletions.
97 changes: 95 additions & 2 deletions bindings/matlab/attribute.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions bindings/matlab/block.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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
%{
Expand Down
10 changes: 5 additions & 5 deletions bindings/matlab/channel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
%
Expand Down Expand Up @@ -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.
Expand Down
62 changes: 52 additions & 10 deletions bindings/matlab/context.m
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -101,18 +113,28 @@ 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
major = coder.ceval('iio_context_get_version_major', 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.
Expand All @@ -123,18 +145,28 @@ 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
minor = coder.ceval('iio_context_get_version_minor', 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.
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5d223f9

Please sign in to comment.