function config_ftdi2(iomode)
%usage: config_ftdi(iomode)
%
%Configure the eight digital I/O lines of the FTDI UM245R module to
%the input/output pattern specified in the uint8 parameter 'iomode'.
%I/O lines DB7 thru DB0 are represented by iomode bits 8 thru 1,
%respectively.  Setting a bit to a value of '1' configures the
%corresponding UM245R line as a digital 'output' while setting it to a
%value of '0' configures the corresponding line as a digital 'input'.
%
%Example:  Configure DB7 and DB6 lines as outputs and lines DB5-DB0 as inputs.
%
%  iomode = uint8(bin2dec('11000000'));
%  config_ftdi2(iomode);
%
%Executing the example above configures the UM245R device as follows:
%
% Function  Pin   Mode
% --------  ---   ----
%    DB0      1   Input
%    DB1      5   Input
%    DB2      3   Input
%    DB3     10   Input
%    DB4      2   Input
%    DB5      8   Input
%    DB6      9   Output
%    DB7      6   Output
%    GND      7   Digital Ground
%
%Use config_ftdi() to initialize UM245R to the default I/O configuration
%See http://usd-apps.usd.edu/coglab/psyc770/USB245.html for detaills

%check range of I/O configuration parameter
if (iomode < 0) 
    display('Abort: IOMODE parm must be 0-255')
    return
end
if (iomode > 255)
    display('Abort: IOMODE parm must be 0-255');
    return
end

%save I/O configuration
global cogent;
cogent.io.ftdiIOMask = iomode;

%create USB245 interface object
cogent.io.ftdiObj = USB245();

%install the FTDI interface with standard I/O configuration
%status = 0 if installation successful
cogent.io.ftdiStatus = USB245(cogent.io.ftdiObj, cogent.io.ftdiIOMask);
if(cogent.io.ftdiStatus ~= 0)
    disp('FTDI installation failed!')
end

