Skip to content

Commit 2551c6d

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 2551c6d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/utility/spi_drv.cpp

+7-4
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 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+
wd_start = millis();
225228
}
226229
}
227230
}

src/utility/spi_drv.h

+1-1
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)