Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ad738x: add support for more parts in this family #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 8 additions & 150 deletions +adi/+AD7380/Rx.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
classdef Rx < adi.common.Rx & matlabshared.libiio.base & adi.common.Attribute
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7380 Precision ADC Class
%
% adi.AD7380.Rx Receives data from the AD7380 ADC.
%
% adi.AD7380.Rx Receives data from the AD7380 ADC
% The adi.AD7380.Rx System object is a signal source that can receive
% data from the AD7380.
%
Expand All @@ -10,161 +11,18 @@
%
% `AD7380 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7380-7381.pdf>`_

properties (Nontunable)
% SampleRate Sample Rate
% Baseband sampling rate in Hz, specified as a scalar
% in samples per second. Options are:
% '256000','128000','64000','32000','16000','8000','4000',
% '2000','1000'
SampleRate = '4000000'
SamplesPerFrame = 1024
end

properties (Hidden)
% Number of frames or buffers of data to capture
FrameCount = 1
end

% Channel names
properties (Nontunable, Hidden, Constant)
channel_names = {
'voltage0'
'voltage1'
}
Type = 'Rx'
end

% isOutput
properties (Hidden, Nontunable, Access = protected)
isOutput = false
end

properties (Constant, Hidden)
SampleRateSet = matlab.system.StringSet({'4000000', '256000', '128000', '64000', ...
'32000', '16000', '8000', '4000', '2000', '1000'})

end

properties (Nontunable, Hidden)
Timeout = Inf
kernelBuffersCount = 2
% dataTypeStr = 'int64';
dataTypeStr = 'int16'
channel_names = {'voltage0-voltage1','voltage2-voltage3'}
phyDevName = 'ad7380'
devName = 'ad7380'
end

properties (Hidden, Constant)
ComplexData = false
end

methods

%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
obj.enableExplicitPolling = false;
obj.EnabledChannels = 1;
obj.BufferTypeConversionEnable = true;
obj.uri = 'ip:analog.local';
end

function flush(obj)
flushBuffers(obj);
obj = [email protected](varargin{:});
end

% Check SamplingRate
function set.SampleRate(obj, value)
obj.SampleRate = value;
if obj.ConnectedToDevice
obj.setDeviceAttributeRAW('sampling_frequency', value);
end
end

end

%% API Functions
methods (Hidden, Access = protected)

function setupInit(obj)
% Write all attributes to device once connected through set
% methods
% Do writes directly to hardware without using set methods.
% This is required since Simulink support doesn't support
% modification to nontunable variables at SetupImpl

% obj.setDeviceAttributeRAW('sampling_frequency',num2str(obj.SampleRate));

end

function [data, valid] = stepImpl(obj)
% [data,valid] = rx() returns data received from the radio
% hardware associated with the receiver System object, rx.
% The output 'valid' indicates whether the object has received
% data from the radio hardware. The first valid data frame can
% contain transient values, resulting in packets containing
% undefined data.
%
% The output 'data' will be an [NxM] vector where N is
% 'SamplesPerFrame' and M is the number of elements in
% 'EnabledChannels'. 'data' will be complex if the devices
% assumes complex data operations.

capCount = obj.FrameCount;

if obj.ComplexData
kd = 1;
ce = length(obj.EnabledChannels);
[dataRAW, valid] = getData(obj);
data = complex(zeros(obj.SamplesPerFrame, ce));
for k = 1:ce
data(:, k) = complex(dataRAW(kd, :), dataRAW(kd + 1, :)).';
kd = kd + 2;
end
else
if obj.BufferTypeConversionEnable

dataRAW = zeros([length(obj.EnabledChannels) obj.SamplesPerFrame * capCount]);
for count = 1:capCount
[data_i, valid] = getData(obj);
dataRAW(:, obj.SamplesPerFrame * (count - 1) + ...
1:count * obj.SamplesPerFrame) = data_i;
end
disp("Finished grabbing data. Processing it now...");
% Channels must be in columns or pointer math fails
dataRAW = dataRAW.';
[D1, D2] = size(dataRAW);
data = coder.nullcopy(zeros(D1, D2, obj.dataTypeStr));
dataPtr = libpointer(obj.ptrTypeStr, data);
dataRAWPtr = libpointer(obj.ptrTypeStr, dataRAW);
% Convert hardware format to human format channel by
% channel
for l = 0:D2 - 1
chanPtr = getChan(obj, obj.iioDev, ...
obj.channel_names{obj.EnabledChannels(l + 1)}, false);
% Pull out column
tmpPtrSrc = dataRAWPtr + D1 * l;
tmpPtrDst = dataPtr + D1 * l;
setdatatype(tmpPtrSrc, obj.ptrTypeStr, D1, 1);
setdatatype(tmpPtrDst, obj.ptrTypeStr, D1, 1);
for k = 0:D1 - 1
iio_channel_convert(obj, chanPtr, tmpPtrDst + k, tmpPtrSrc + k);
end
end
data = dataPtr.Value;
else
dataRAW = zeros([length(obj.EnabledChannels) ...
obj.SamplesPerFrame * capCount]);
for count = 1:capCount
[data_i, valid] = getData(obj);
dataRAW(:, obj.SamplesPerFrame * (count - 1) + ...
1 : count * obj.SamplesPerFrame) = data_i;
end

data = dataRAW.';
end
end
end

end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7380_4/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7380-4 Precision ADC Class
%
% adi.AD7380_4.Rx Receives data from the AD7380-4 ADC
% The adi.AD7380_4.Rx System object is a signal source that can receive
% data from the AD7380-4.
%
% `rx = adi.AD7380_4.Rx;`
% `rx = adi.AD7380_4.Rx('uri','192.168.2.1');`
%
% `AD7380-4 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7380-4.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 4
channel_names = {'voltage0-voltage1','voltage2-voltage3','voltage4-voltage5','voltage6-voltage7'}
phyDevName = 'ad7380-4'
devName = 'ad7380-4'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7381/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7381 Precision ADC Class
%
% adi.AD7381.Rx Receives data from the AD7381 ADC
% The adi.AD7381.Rx System object is a signal source that can receive
% data from the AD7381.
%
% `rx = adi.AD7381.Rx;`
% `rx = adi.AD7381.Rx('uri','192.168.2.1');`
%
% `AD7381 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-7381.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 2
channel_names = {'voltage0-voltage1','voltage2-voltage3'}
phyDevName = 'ad7381'
devName = 'ad7381'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7381_4/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7381-4 Precision ADC Class
%
% adi.AD7381_4.Rx Receives data from the AD7381-4 ADC
% The adi.AD7381_4.Rx System object is a signal source that can receive
% data from the AD7381-4.
%
% `rx = adi.AD7381_4.Rx;`
% `rx = adi.AD7381_4.Rx('uri','192.168.2.1');`
%
% `AD7381-4 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7381-4.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 4
channel_names = {'voltage0-voltage1','voltage2-voltage3','voltage4-voltage5','voltage6-voltage7'}
phyDevName = 'ad7381-4'
devName = 'ad7381-4'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7383/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7383 Precision ADC Class
%
% adi.AD7383.Rx Receives data from the AD7383 ADC
% The adi.AD7383.Rx System object is a signal source that can receive
% data from the AD7383.
%
% `rx = adi.AD7383.Rx;`
% `rx = adi.AD7383.Rx('uri','192.168.2.1');`
%
% `AD7383 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-7384.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 2
channel_names = {'voltage0','voltage1'}
phyDevName = 'ad7383'
devName = 'ad7383'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7383_4/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7383-4 Precision ADC Class
%
% adi.AD7383_4.Rx Receives data from the AD7383-4 ADC
% The adi.AD7383_4.Rx System object is a signal source that can receive
% data from the AD7383-4.
%
% `rx = adi.AD7383_4.Rx;`
% `rx = adi.AD7383_4.Rx('uri','192.168.2.1');`
%
% `AD7383-4 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-4-ad7384-4.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 4
channel_names = {'voltage0','voltage1','voltage2','voltage3'}
phyDevName = 'ad7383-4'
devName = 'ad7383-4'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7384/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7384 Precision ADC Class
%
% adi.AD7384.Rx Receives data from the AD7384 ADC
% The adi.AD7384.Rx System object is a signal source that can receive
% data from the AD7384.
%
% `rx = adi.AD7384.Rx;`
% `rx = adi.AD7384.Rx('uri','192.168.2.1');`
%
% `AD7384 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7383-7384.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 2
channel_names = {'voltage0','voltage1'}
phyDevName = 'ad7384'
devName = 'ad7384'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
28 changes: 28 additions & 0 deletions +adi/+AD7384_4/Rx.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
classdef Rx < adi.common.Rx & adi.common.RxTx ...
& adi.AD738X.Base
% AD7384-4 Precision ADC Class
%
% adi.AD7384_4.Rx Receives data from the AD7384-4 ADC
% The adi.AD7384_4.Rx System object is a signal source that can receive
% data from the AD7384-4.
%
% `rx = adi.AD7384_4.Rx;`
% `rx = adi.AD7384_4.Rx('uri','192.168.2.1');`
%
% `AD7384-4 Datasheet <https://www.analog.com/media/en/technical-documentation/data-sheets/ad7384-4-ad7384-4.pdf>`_

properties (Nontunable, Hidden)
kernelBuffersCount = 4
channel_names = {'voltage0','voltage1','voltage2','voltage3'}
phyDevName = 'ad7384-4'
devName = 'ad7384-4'
end

methods
%% Constructor
function obj = Rx(varargin)
obj = [email protected](varargin{:});
end
end

end
Loading