Skip to content

Commit

Permalink
SPI: add transfer16
Browse files Browse the repository at this point in the history
  • Loading branch information
scpcom committed Dec 9, 2020
1 parent 506d8f7 commit be47523
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions libraries/SPI/src/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ uint8_t SPIClass::transfer(uint8_t data)
return ret;
}

uint16_t SPIClass::transfer16(uint16_t data)
{
uint16_t ret;
uint8_t *txdata = (uint8_t *)&data;
uint8_t *rxdata = (uint8_t *)&ret;

if (_ssel_hard == 0 && _ssel_bank != 0) {
gpio_bit_reset(_ssel_bank, _ssel_bit);
}

for (size_t i = 0; i < 2; i++) {
while (!spi_i2s_flag_get(_dev, SPI_FLAG_TBE));
spi_i2s_data_transmit(_dev, *txdata);
txdata++;
while (!spi_i2s_flag_get(_dev, SPI_FLAG_RBNE));
*rxdata = spi_i2s_data_receive(_dev);
rxdata++;
}

if (_ssel_hard == 0 && _ssel_bank != 0) {
gpio_bit_set(_ssel_bank, _ssel_bit);
}

return ret;
}

void SPIClass::setBitOrder(uint8_t bitOrder) {
_bitOrder = bitOrder;
beginTransaction();
Expand Down
1 change: 1 addition & 0 deletions libraries/SPI/src/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class SPIClass {
void transfer(
uint8_t* txdata, uint8_t* rxdata, uint32_t size, uint32_t timeout = 1);
uint8_t transfer(uint8_t data);
uint16_t transfer16(uint16_t data);

void setBitOrder(uint8_t bitOrder);
void setDataMode(uint8_t dataMode);
Expand Down

0 comments on commit be47523

Please sign in to comment.