Skip to content

Commit d68afb1

Browse files
SPIDrv improved waitForSlaveReady function
fixed beahviour of waitForSlaveReady: now watchdog timeout is calculated correctly. A timeout is added for the readiness call, that is defaulted to 0 (no timeout).
1 parent 36e41df commit d68afb1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utility/spi_drv.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,16 @@ void SpiDrv::waitForSlaveSign()
215215
while (!waitSlaveSign());
216216
}
217217

218-
void SpiDrv::waitForSlaveReady()
218+
void SpiDrv::waitForSlaveReady(unsigned long timeout = 0)
219219
{
220220
unsigned long const start = millis();
221-
while (!waitSlaveReady())
222-
{
223-
if ((millis() - start) < 10000) {
221+
unsigned long const wd_start = millis();
222+
constexpr long wd_timeout = 2000;
223+
224+
while (!waitSlaveReady() && (timeout != 0 || (millis() - start) < timeout)) {
225+
if ((millis() - wd_start) < wd_timeout) {
224226
WiFi.feedWatchdog();
227+
start = millis();
225228
}
226229
}
227230
}

src/utility/spi_drv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class SpiDrv
5959

6060
static char spiTransfer(volatile char data);
6161

62-
static void waitForSlaveReady();
62+
static void waitForSlaveReady(unsigned long timeout = 0); // timeout for wait, 0 means no timeout
6363

6464
//static int waitSpiChar(char waitChar, char* readChar);
6565

0 commit comments

Comments
 (0)