only write MOSI if its changed

This commit is contained in:
lady ada 2020-07-18 15:57:15 -04:00
parent a830055740
commit a552fae34e
1 changed files with 7 additions and 3 deletions

View File

@ -123,6 +123,8 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
startbit = 0x80;
}
bool towrite, lastmosi = ! (buffer[0] & startbit);
// for softSPI we'll do it by hand
for (size_t i = 0; i < len; i++) {
// software SPI
@ -138,15 +140,17 @@ void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
// Serial.print(send, HEX);
for (uint8_t b = startbit; b != 0; b = (_dataOrder == SPI_BITORDER_LSBFIRST) ? b << 1 : b >> 1) {
if (_dataMode == SPI_MODE0 || _dataMode == SPI_MODE2) {
if (_mosi != -1) {
towrite = send & b;
if ((_mosi != -1) && (lastmosi != towrite)) {
#ifdef BUSIO_USE_FAST_PINIO
if (send & b)
if (towrite)
*mosiPort |= mosiPinMask;
else
*mosiPort &= ~mosiPinMask;
#else
digitalWrite(_mosi, send & b);
digitalWrite(_mosi, towrite);
#endif
lastmosi = towrite;
}
#ifdef BUSIO_USE_FAST_PINIO