A quick look
int _mosiPin, _sclkPin, _ssPin, _ldacPin, _clrPin, _vRegBit, _channel, _channelsN, _clearCode;
Think a number of these internal variables can be uint8_t (byte), thereby reducing memory footprint
(memory is a valuable resource)
you can reduce footprint e.g. in the init is quite some double code.
void AD5668::init(int vRegBit, int channelsN)
{
if (_hwSPI)
{
SPI.begin();
SPI.setBitOrder(MSBFIRST);
}
else
{
digitalWrite(_mosiPin, LOW);
digitalWrite(_sclkPin, LOW);
}
_vRegBit = vRegBit;
digitalWrite(_ssPin, LOW);
if (_ldacPin > 0)
{
digitalWrite(_ldacPin, HIGH);
}
_channelsN = channelsN;
digitalWrite(_clrPin, LOW);
delayMicroseconds(1);
digitalWrite(_clrPin, HIGH);
delayMicroseconds(1);
writeDAC(SETUP_INTERNAL_REF, 0, 0, _vRegBit);
delayMicroseconds(1);
powerDAC_Normal(_channelsN);
}
slightly faster as shifts take one clock cycle per position.
byte b1 = B00000000|command; //padding at beginning of byte 1
byte b2 = address << 4 | data >> 12; //4 address bits and 4 MSBs of data
byte b3 = (data << 4) >> 8; // middle 8 bits of data
byte b4 = (data << 12) >> 8 | function;
could be
byte b1 = command;
byte b2 = address << 4 | data >> 12; // 4 address bits and 4 MSBs of data
byte b3 = data >> 4; // will be clipped automatically // middle 8 bits of data
byte b4 = 0xF0 & (data << 4) | function;
give it a try