Skip to content

Add SPI.transfer16(...) API's to SAM #4081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hardware/arduino/sam/libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ byte SPIClass::transfer(byte _pin, uint8_t _data, SPITransferMode _mode) {
return d & 0xFF;
}

uint16_t SPIClass::transfer16(byte _pin, uint16_t _data, SPITransferMode _mode) {
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
uint32_t ch = BOARD_PIN_TO_SPI_CHANNEL(_pin);

t.val = _data;

if (bitOrder[ch] == LSBFIRST) {
t.lsb = transfer(_pin, t.lsb, _mode);
t.msb = transfer(_pin, t.msb, _mode);
} else {
t.msb = transfer(_pin, t.msb, _mode);
t.lsb = transfer(_pin, t.lsb, _mode);
}

return t.val;
}

void SPIClass::transfer(byte _pin, void *_buf, size_t _count, SPITransferMode _mode) {
if (_count == 0)
return;
Expand Down
2 changes: 2 additions & 0 deletions hardware/arduino/sam/libraries/SPI/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ class SPIClass {

// Transfer functions
byte transfer(byte _pin, uint8_t _data, SPITransferMode _mode = SPI_LAST);
uint16_t transfer16(byte _pin, uint16_t _data, SPITransferMode _mode = SPI_LAST);
void transfer(byte _pin, void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST);
// Transfer functions on default pin BOARD_SPI_DEFAULT_SS
byte transfer(uint8_t _data, SPITransferMode _mode = SPI_LAST) { return transfer(BOARD_SPI_DEFAULT_SS, _data, _mode); }
uint16_t transfer16(uint16_t _data, SPITransferMode _mode = SPI_LAST) { return transfer16(BOARD_SPI_DEFAULT_SS, _data, _mode); }
void transfer(void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST) { transfer(BOARD_SPI_DEFAULT_SS, _buf, _count, _mode); }

// Transaction Functions
Expand Down