added write_and_read()

This method adds a wrapper for transfer() with CS-pin and
transaction management
This commit is contained in:
Christian Riggenbach 2021-12-31 11:05:29 +01:00
parent 9c5fcb76d6
commit c43e0ae83e
2 changed files with 29 additions and 0 deletions

View File

@ -440,4 +440,32 @@ bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer,
return true;
}
/*!
* @brief Write some data and read some data at the same time from SPI
* into the same buffer. This is basicaly a wrapper for transfer() with
* CS-pin and transaction management.
* This /does/ transmit-receive at the same time!
* @param buffer Pointer to buffer of data to write/read to/from
* @param len Number of bytes from buffer to write/read.
* @return Always returns true because there's no way to test success of SPI
* writes
*/
bool Adafruit_SPIDevice::write_and_read(uint8_t *buffer, size_t len) {
if (_spi) {
_spi->beginTransaction(*_spiSetting);
}
digitalWrite(_cs, LOW);
transfer(buffer, len);
digitalWrite(_cs, HIGH);
if (_spi) {
_spi->endTransaction();
}
return true;
}
#endif // SPI exists

View File

@ -82,6 +82,7 @@ public:
bool write_then_read(uint8_t *write_buffer, size_t write_len,
uint8_t *read_buffer, size_t read_len,
uint8_t sendvalue = 0xFF);
bool write_and_read(uint8_t *buffer, size_t len);
uint8_t transfer(uint8_t send);
void transfer(uint8_t *buffer, size_t len);