function varargout = calcSPIBaudRate(sysclkoutInMHz, LspclkDiv, BaudRateFactor)
%CALCSPIBAUDRATEPRESCALER Summary of this function goes here
%   Detailed explanation goes here


nargoutchk(1, 2);

lspclk = sysclkoutInMHz * 1e6 / LspclkDiv;

if BaudRateFactor > 127
    BaudRateFactor = 127;
elseif BaudRateFactor < 3
    BaudRateFactor = 3;
end

BaudRate = round(lspclk/(BaudRateFactor+1));


varargout{1} = BaudRate;
if nargout == 2
    varargout{2} = BaudRateFactor;
end
