Skip to content

Commit b910ecc

Browse files
authored
Merge pull request #42 from Hutch67/fix-SPI-MUTEX-block
prevent device block in SPI_MUTEX_LOCK() at least on ESP32
2 parents 17e9ff2 + 7833cf1 commit b910ecc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Adafruit_EPD.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
315315
uint8_t c;
316316
// use SRAM
317317
sram.csLow();
318+
_isInTransaction = true;
318319
// send read command
319320
SPItransfer(MCPSRAM_READ);
320321
// send address
@@ -340,6 +341,7 @@ void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
340341
}
341342
csHigh();
342343
sram.csHigh();
344+
_isInTransaction = false;
343345
}
344346

345347
/**************************************************************************/
@@ -658,8 +660,10 @@ void Adafruit_EPD::csHigh() {
658660
digitalWrite(_cs_pin, HIGH);
659661
#endif
660662

661-
spi_dev->endTransaction();
662-
_isInTransaction = false;
663+
if (_isInTransaction) {
664+
spi_dev->endTransaction();
665+
_isInTransaction = false;
666+
}
663667
}
664668

665669
/**************************************************************************/
@@ -668,8 +672,11 @@ void Adafruit_EPD::csHigh() {
668672
*/
669673
/**************************************************************************/
670674
void Adafruit_EPD::csLow() {
671-
spi_dev->beginTransaction();
672-
_isInTransaction = true;
675+
676+
if (!_isInTransaction) {
677+
spi_dev->beginTransaction();
678+
_isInTransaction = true;
679+
}
673680

674681
#ifdef BUSIO_USE_FAST_PINIO
675682
*csPort &= ~csPinMask;

0 commit comments

Comments
 (0)