@@ -326,11 +326,8 @@ void Adafruit_SPIDevice::endTransactionWithDeassertingCS() {
326
326
bool Adafruit_SPIDevice::write (const uint8_t *buffer, size_t len,
327
327
const uint8_t *prefix_buffer,
328
328
size_t prefix_len) {
329
- if (_spi) {
330
- _spi->beginTransaction (*_spiSetting);
331
- }
329
+ beginTransactionWithAssertingCS ();
332
330
333
- setChipSelect (LOW);
334
331
// do the writing
335
332
#if defined(ARDUINO_ARCH_ESP32)
336
333
if (_spi) {
@@ -350,11 +347,7 @@ bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
350
347
transfer (buffer[i]);
351
348
}
352
349
}
353
- setChipSelect (HIGH);
354
-
355
- if (_spi) {
356
- _spi->endTransaction ();
357
- }
350
+ endTransactionWithDeassertingCS ();
358
351
359
352
#ifdef DEBUG_SERIAL
360
353
DEBUG_SERIAL.print (F (" \t SPIDevice Wrote: " ));
@@ -391,17 +384,10 @@ bool Adafruit_SPIDevice::write(const uint8_t *buffer, size_t len,
391
384
*/
392
385
bool Adafruit_SPIDevice::read (uint8_t *buffer, size_t len, uint8_t sendvalue) {
393
386
memset (buffer, sendvalue, len); // clear out existing buffer
394
- if (_spi) {
395
- _spi->beginTransaction (*_spiSetting);
396
- }
397
387
398
- setChipSelect (LOW );
388
+ beginTransactionWithAssertingCS ( );
399
389
transfer (buffer, len);
400
- setChipSelect (HIGH);
401
-
402
- if (_spi) {
403
- _spi->endTransaction ();
404
- }
390
+ endTransactionWithDeassertingCS ();
405
391
406
392
#ifdef DEBUG_SERIAL
407
393
DEBUG_SERIAL.print (F (" \t SPIDevice Read: " ));
@@ -435,11 +421,7 @@ bool Adafruit_SPIDevice::read(uint8_t *buffer, size_t len, uint8_t sendvalue) {
435
421
bool Adafruit_SPIDevice::write_then_read (const uint8_t *write_buffer,
436
422
size_t write_len, uint8_t *read_buffer,
437
423
size_t read_len, uint8_t sendvalue) {
438
- if (_spi) {
439
- _spi->beginTransaction (*_spiSetting);
440
- }
441
-
442
- setChipSelect (LOW);
424
+ beginTransactionWithAssertingCS ();
443
425
// do the writing
444
426
#if defined(ARDUINO_ARCH_ESP32)
445
427
if (_spi) {
@@ -485,11 +467,7 @@ bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
485
467
DEBUG_SERIAL.println ();
486
468
#endif
487
469
488
- setChipSelect (HIGH);
489
-
490
- if (_spi) {
491
- _spi->endTransaction ();
492
- }
470
+ endTransactionWithDeassertingCS ();
493
471
494
472
return true ;
495
473
}
@@ -505,17 +483,9 @@ bool Adafruit_SPIDevice::write_then_read(const uint8_t *write_buffer,
505
483
* writes
506
484
*/
507
485
bool Adafruit_SPIDevice::write_and_read (uint8_t *buffer, size_t len) {
508
- if (_spi) {
509
- _spi->beginTransaction (*_spiSetting);
510
- }
511
-
512
- setChipSelect (LOW);
486
+ beginTransactionWithAssertingCS ();
513
487
transfer (buffer, len);
514
- setChipSelect (HIGH);
515
-
516
- if (_spi) {
517
- _spi->endTransaction ();
518
- }
488
+ endTransactionWithDeassertingCS ();
519
489
520
490
return true ;
521
491
}
0 commit comments