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


nargoutchk(1, 2);

lspclk = sysclkoutInMHz * 1e6 / LspclkDiv;

    
BaudRateFactor = round((lspclk/DesiredBaudRate) - 1);

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

varargout{1} = BaudRateFactor;
if nargout == 2
    varargout{2} = round(lspclk/(BaudRateFactor+1));
end
