reuse beginTransactionWithAssertingCS()/endTransactionWithDeassertingCS()
This commit is contained in:
parent
c00ec13218
commit
f82f699c64
|
|
@ -326,11 +326,8 @@ void Adafruit_SPIDevice::endTransactionWithDeassertingCS() {
|
||||||
bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
|
bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
|
||||||
const uint8_t *prefix_buffer,
|
const uint8_t *prefix_buffer,
|
||||||
size_t prefix_len) {
|
size_t prefix_len) {
|
||||||
if (_spi) {
|
beginTransactionWithAssertingCS();
|
||||||
_spi->beginTransaction(*_spiSetting);
|
|
||||||
}
|
|
||||||
|
|
||||||
setChipSelect(LOW);
|
|
||||||
// do the writing
|
// do the writing
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
if (_spi) {
|
if (_spi) {
|
||||||
|
|
@ -350,11 +347,7 @@ bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
|
||||||
transfer(buffer[i]);
|
transfer(buffer[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setChipSelect(HIGH);
|
endTransactionWithDeassertingCS();
|
||||||
|
|
||||||
if (_spi) {
|
|
||||||
_spi->endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL
|
#ifdef DEBUG_SERIAL
|
||||||
DEBUG_SERIAL.print(F("\tSPIDevice Wrote: "));
|
DEBUG_SERIAL.print(F("\tSPIDevice Wrote: "));
|
||||||
|
|
@ -391,17 +384,10 @@ bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
|
||||||
*/
|
*/
|
||||||
bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
|
bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
|
||||||
memset(buffer, sendvalue, len); // clear out existing buffer
|
memset(buffer, sendvalue, len); // clear out existing buffer
|
||||||
if (_spi) {
|
|
||||||
_spi->beginTransaction(*_spiSetting);
|
|
||||||
}
|
|
||||||
|
|
||||||
setChipSelect(LOW);
|
beginTransactionWithAssertingCS();
|
||||||
transfer(buffer, len);
|
transfer(buffer, len);
|
||||||
setChipSelect(HIGH);
|
endTransactionWithDeassertingCS();
|
||||||
|
|
||||||
if (_spi) {
|
|
||||||
_spi->endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_SERIAL
|
#ifdef DEBUG_SERIAL
|
||||||
DEBUG_SERIAL.print(F("\tSPIDevice Read: "));
|
DEBUG_SERIAL.print(F("\tSPIDevice Read: "));
|
||||||
|
|
@ -435,11 +421,7 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
|
||||||
bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
|
bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
|
||||||
size_t write_len, uint8_t *read_buffer,
|
size_t write_len, uint8_t *read_buffer,
|
||||||
size_t read_len, uint8_t sendvalue) {
|
size_t read_len, uint8_t sendvalue) {
|
||||||
if (_spi) {
|
beginTransactionWithAssertingCS();
|
||||||
_spi->beginTransaction(*_spiSetting);
|
|
||||||
}
|
|
||||||
|
|
||||||
setChipSelect(LOW);
|
|
||||||
// do the writing
|
// do the writing
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
if (_spi) {
|
if (_spi) {
|
||||||
|
|
@ -485,11 +467,7 @@ bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
|
||||||
DEBUG_SERIAL.println();
|
DEBUG_SERIAL.println();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setChipSelect(HIGH);
|
endTransactionWithDeassertingCS();
|
||||||
|
|
||||||
if (_spi) {
|
|
||||||
_spi->endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -505,17 +483,9 @@ bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
|
||||||
* writes
|
* writes
|
||||||
*/
|
*/
|
||||||
bool Adafruit_SPIDevice::write_and_read(uint8_t *buffer, size_t len) {
|
bool Adafruit_SPIDevice::write_and_read(uint8_t *buffer, size_t len) {
|
||||||
if (_spi) {
|
beginTransactionWithAssertingCS();
|
||||||
_spi->beginTransaction(*_spiSetting);
|
|
||||||
}
|
|
||||||
|
|
||||||
setChipSelect(LOW);
|
|
||||||
transfer(buffer, len);
|
transfer(buffer, len);
|
||||||
setChipSelect(HIGH);
|
endTransactionWithDeassertingCS();
|
||||||
|
|
||||||
if (_spi) {
|
|
||||||
_spi->endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue