#include "otFPGA.h"
#include "otSpi.h"
#include "otTimer.h"
#include "otAD5664.h"
#include "otPrintfLite.h"
otAD5664::otAD5664()
{
}
void otAD5664::init()
{
FpgaInit();
SpiChannel(SA_DAC, 10, 0, SPI_CPHA);
SpiSet(SA_DAC);
write(ALL, (U16) 0);
}
void otAD5664::write(Channel ch, U16 adu)
{
U32 value = ((U32) ch << 16) | adu | 0x100000;
SpiCs(true);
SSYNC;
SpiPut((value >> 16) & 0xFF);
SpiPut((value >> 8) & 0xFF);
SpiPut(value & 0xFF);
SSYNC;
SpiCs(false);
}
void otAD5664::write(Channel ch, float Volt)
{
U16 adu = mVto_adu((U32) (Volt * 1000));
write(ch, adu);
}
void otAD5664::write(Channel ch, U16 * data, U32 len)
{
for(U32 i = 0; i < len; i++)
write(ch, data[i]);
}