Merge pull request #75 from eringerli/master

added write_and_read()
This commit is contained in:
Limor "Ladyada" Fried 2021-12-31 13:27:33 -05:00 committed by GitHub
commit 33ff0c4bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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; 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 #endif // SPI exists

View File

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