mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Add SPI.transfer16(...) API's
This commit is contained in:
parent
c9b89e9fd6
commit
ed5597dad0
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user