Skip to content

Commit

Permalink
Added a process to automatically lower the communication speed of Ato…
Browse files Browse the repository at this point in the history
…mDisplay and ModuleDisplay.

( as a countermeasure for the problem of low communication performance in CoreV2.6 )
  • Loading branch information
lovyan03 committed Mar 21, 2023
1 parent e77a686 commit cc9606f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/M5AtomDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class M5AtomDisplay : public M5GFX
{
auto cfg = bus_spi->config();
cfg.freq_write = 80000000;
cfg.freq_read = 20000000;
cfg.freq_read = 16000000;
cfg.spi_host = spi_host;
cfg.spi_mode = 3;
#ifndef M5ATOMDISPLAY_SPI_DMA_CH
Expand Down
2 changes: 1 addition & 1 deletion src/M5ModuleDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class M5ModuleDisplay : public M5GFX
{
auto cfg = bus_spi->config();
cfg.freq_write = 80000000;
cfg.freq_read = 20000000;
cfg.freq_read = 16000000;
cfg.spi_host = spi_host;
cfg.spi_mode = 3;
#ifndef M5MODULEDISPLAY_SPI_DMA_CH
Expand Down
53 changes: 38 additions & 15 deletions src/lgfx/v1/panel/Panel_M5HDMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,21 +494,46 @@ namespace lgfx
startWrite();
_bus->beginRead();
while (_bus->readData(8) != 0xFF) {}
cs_control(true);
_bus->endRead();
cs_control(false);
_bus->writeData(CMD_READ_ID, 8); // READ_ID
_bus->beginRead();
while (_bus->readData(8) == 0xFF) {}
_bus->readData(8); // skip 0xFF
uint32_t data = _bus->readData(32);
(void)data; // suppress compiler warning.
ESP_LOGI(TAG, "FPGA ID:%02x %02x %02x %02x", (uint8_t)data, (uint8_t)(data >> 8), (uint8_t)(data >> 16), (uint8_t)(data >> 24));
cs_control(true);
_bus->endRead();
cs_control(false);
endWrite();
uint32_t fpga_id = ~0u;

uint32_t apbfreq = lgfx::getApbFrequency();
uint_fast8_t div_write = apbfreq / (_bus->getClock() + 1) + 1;
uint_fast8_t div_read = apbfreq / (_bus->getReadClock() + 1) + 1;

for (;;)
{
// ESP_LOGI(TAG, "FREQ:%lu , %lu DIV_W:%lu , %lu", _bus->getClock(), _bus->getReadClock(), div_write, div_read);
startWrite();
_bus->writeData(CMD_READ_ID, 8); // READ_ID
_bus->beginRead();
while (_bus->readData(8) == 0xFF) {}
_bus->readData(8); // skip 0xFF
fpga_id = _bus->readData(32);
endWrite();

ESP_LOGI(TAG, "FPGA ID:%02x %02x %02x %02x", (uint8_t)fpga_id, (uint8_t)(fpga_id >> 8), (uint8_t)(fpga_id >> 16), (uint8_t)(fpga_id >> 24));

// 受信したIDの先頭が "HD" なら正常動作
if (((fpga_id ) & 0xFF) == 'H'
&& ((fpga_id >> 8) & 0xFF) == 'D')
{
break;
}

if (fpga_id == 0 || fpga_id == ~0u)
{ // MISOが変化しない場合、コマンドが正しく受理されていないと仮定し送信速度を下げる。
_bus->setClock(apbfreq / ++div_write);
}
else
{ // 受信データの先頭が HD でない場合は受信速度を下げる。
_bus->setReadClock(apbfreq / ++div_read);
}
}

startWrite();
bool res = _init_resolution();
endWrite();

ESP_LOGI(TAG, "Initialize HDMI transmitter...");
if (!driver.init() )
Expand All @@ -517,8 +542,6 @@ namespace lgfx
return false;
}

endWrite();

return res;
}

Expand Down

0 comments on commit cc9606f

Please sign in to comment.