1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Add SPI.transfer16(...) API's

This commit is contained in:
Sandeep Mistry 2015-11-04 15:49:08 -05:00
parent c9b89e9fd6
commit ed5597dad0
2 changed files with 19 additions and 0 deletions

View File

@ -196,6 +196,23 @@ byte SPIClass::transfer(byte _pin, uint8_t _data, SPITransferMode _mode) {
return d & 0xFF; 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) { void SPIClass::transfer(byte _pin, void *_buf, size_t _count, SPITransferMode _mode) {
if (_count == 0) if (_count == 0)
return; return;

View File

@ -82,9 +82,11 @@ class SPIClass {
// Transfer functions // Transfer functions
byte transfer(byte _pin, uint8_t _data, SPITransferMode _mode = SPI_LAST); 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); void transfer(byte _pin, void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST);
// Transfer functions on default pin BOARD_SPI_DEFAULT_SS // 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); } 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); } void transfer(void *_buf, size_t _count, SPITransferMode _mode = SPI_LAST) { transfer(BOARD_SPI_DEFAULT_SS, _buf, _count, _mode); }
// Transaction Functions // Transaction Functions