added write_and_read()
This method adds a wrapper for transfer() with CS-pin and transaction management
This commit is contained in:
parent
9c5fcb76d6
commit
c43e0ae83e
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue