Skip to content

Commit 7833cf1

Browse files
authored
prevent device block in SPI_MUTEX_LOCK() at least on ESP32
ESP32 uses a MUTEX to handle SPI transactions. So calling beginTransaction twice in a row will block the device. This happens in current code, if SRAM is used or a display (like 2,7" tricolor IL91874) which uses singleByteTxns = true Both will call beginTransaction twice in a row and then the device will block for ever in cores\esp32\esp32-hal-spi.h SPI_MUTEX_LOCK(); To prevent this, I made some changes in Adafruit_EPD.cpp to track _isInTransaction properly, which was not used before. See also adafruit/Adafruit-PN532#53 for a similar bug.
1 parent b5b6fcf commit 7833cf1

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
@@ -316,6 +316,7 @@ void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
316316

317317
// use SRAM
318318
sram.csLow();
319+
_isInTransaction = true;
319320
// send read command
320321
SPItransfer(MCPSRAM_READ);
321322
// send address
@@ -334,6 +335,7 @@ void Adafruit_EPD::writeSRAMFramebufferToEPD(uint16_t SRAM_buffer_addr,
334335
}
335336
csHigh();
336337
sram.csHigh();
338+
_isInTransaction = false;
337339
}
338340

339341
/**************************************************************************/
@@ -646,8 +648,10 @@ void Adafruit_EPD::csHigh() {
646648
digitalWrite(_cs_pin, HIGH);
647649
#endif
648650

649-
spi_dev->endTransaction();
650-
_isInTransaction = false;
651+
if (_isInTransaction) {
652+
spi_dev->endTransaction();
653+
_isInTransaction = false;
654+
}
651655
}
652656

653657
/**************************************************************************/
@@ -656,8 +660,11 @@ void Adafruit_EPD::csHigh() {
656660
*/
657661
/**************************************************************************/
658662
void Adafruit_EPD::csLow() {
659-
spi_dev->beginTransaction();
660-
_isInTransaction = true;
663+
664+
if (!_isInTransaction) {
665+
spi_dev->beginTransaction();
666+
_isInTransaction = true;
667+
}
661668

662669
#ifdef BUSIO_USE_FAST_PINIO
663670
*csPort &= ~csPinMask;

0 commit comments

Comments
 (0)