Skip to content

Commit

Permalink
SPI: fix transfer16
Browse files Browse the repository at this point in the history
Borrow implementation for samd core
Should fix arduino/ArduinoCore-nRF528x-mbedos#85
  • Loading branch information
facchinm committed Jul 3, 2020
1 parent 18a1d60 commit a15e621
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,18 @@ uint8_t arduino::MbedSPI::transfer(uint8_t data) {
}

uint16_t arduino::MbedSPI::transfer16(uint16_t data) {
uint8_t ret[2];
dev->write((const char*)&data, 2, (char*)ret, 2);
return ret[0] << 8 | ret[1];

union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
t.val = data;

if (settings.getBitOrder() == LSBFIRST) {
t.lsb = transfer(t.lsb);
t.msb = transfer(t.msb);
} else {
t.msb = transfer(t.msb);
t.lsb = transfer(t.lsb);
}
return t.val;
}

void arduino::MbedSPI::transfer(void *buf, size_t count) {
Expand Down

0 comments on commit a15e621

Please sign in to comment.