Skip to content

Commit

Permalink
bugfix I2C error with ESP32S3
Browse files Browse the repository at this point in the history
  • Loading branch information
lovyan03 committed Aug 14, 2023
1 parent 460fe47 commit b623410
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ namespace lgfx
break;
}

len = length < 64 ? length : 64;
len = length < 33 ? length : 33;
if (length == len && last_nack && len > 1) { --len; }

length -= len;
Expand All @@ -1355,31 +1355,27 @@ namespace lgfx
dev->ctr.trans_start = 1;
dev->int_clr.val = intmask;

uint32_t us = lgfx::micros();
taskYIELD();

#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
delayMicroseconds(us_limit >> 2); /// このウェイトを外すと受信失敗するケースがある;
#endif
auto delayus = (us_limit + 7) >> 3;
us = lgfx::micros() - us;
if (us < delayus) {
delayMicroseconds(delayus - us);
}
do
{
uint32_t us = lgfx::micros();
taskYIELD();
us = lgfx::micros() - us;
int delayus = ((us_limit + 7) >> 3) - us;
if (delayus > 0) {
delayMicroseconds(delayus);
}
while (0 == getRxFifoCount(dev) && !(dev->int_raw.val & intmask) && ((lgfx::micros() - us) <= us_limit + 1024))
{
taskYIELD();
}

if (0 == getRxFifoCount(dev))
{
uint32_t us = lgfx::micros();
do { taskYIELD(); } while (0 == getRxFifoCount(dev) && !(dev->int_raw.val & intmask) && ((lgfx::micros() - us) <= us_limit + 1024));
if (0 == getRxFifoCount(dev))
{
i2c_stop(i2c_port);
ESP_LOGW("LGFX", "i2c read error : read timeout");
res = cpp::fail(error_t::connection_lost);
i2c_context[i2c_port].state = cpp::fail(error_t::connection_lost);
return res;
}
i2c_stop(i2c_port);
ESP_LOGW("LGFX", "i2c read error : read timeout");
res = cpp::fail(error_t::connection_lost);
i2c_context[i2c_port].state = cpp::fail(error_t::connection_lost);
return res;
}
*readdata++ = *fifo_addr; //dev->fifo_data.data;
} while (--len);
Expand Down

0 comments on commit b623410

Please sign in to comment.