Skip to content

Commit

Permalink
Merge pull request #494 from zingo/develop
Browse files Browse the repository at this point in the history
Support for esp-idf 5.3.0
  • Loading branch information
lovyan03 authored Dec 27, 2023
2 parents 1aa3200 + ef24544 commit e8924dc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/lgfx/v1/panel/Panel_M5HDMI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Original Source:
[tobozo](https://github.com/tobozo)
/----------------------------------------------------------------------------*/
#pragma once
#include <cstdint>

#include "Panel_Device.hpp"
#include "../platforms/common.hpp"
Expand Down
8 changes: 5 additions & 3 deletions src/lgfx/v1/platforms/esp32/Bus_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ Original Source:
#if defined (ESP_PLATFORM)
#include <sdkconfig.h>

#include "Bus_SPI.hpp"

/// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 ;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#endif
#elif defined ( CONFIG_IDF_TARGET_ESP32 ) || !defined ( CONFIG_IDF_TARGET )
#define LGFX_SPIDMA_WORKAROUND
#endif

#include "Bus_SPI.hpp"

#include "../../misc/pixelcopy.hpp"

#if __has_include (<soc/dport_reg.h>)
Expand Down
28 changes: 18 additions & 10 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ Original Source:
#if defined (ESP_PLATFORM)
#include <sdkconfig.h>

/// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 ;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#endif

#include "common.hpp"

#include <algorithm>
Expand All @@ -40,7 +35,11 @@ Original Source:
#include <soc/soc.h>
#include <soc/i2c_reg.h>
#include <soc/i2c_struct.h>
#include <soc/apb_ctrl_reg.h>
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
#include <soc/syscon_reg.h>
#else
#include <soc/apb_ctrl_reg.h>
#endif
#include <soc/efuse_reg.h>

#include <esp_log.h>
Expand Down Expand Up @@ -111,6 +110,10 @@ Original Source:
#endif
#endif

#if (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0))
#define SOC_GDMA_PAIRS_PER_GROUP_MAX SOC_GDMA_PAIRS_PER_GROUP
#endif

#if defined ( ARDUINO )
#if __has_include (<SPI.h>)
#include <SPI.h>
Expand Down Expand Up @@ -213,7 +216,7 @@ namespace lgfx
// SOC_GDMA_TRIG_PERIPH_SPI3
// SOC_GDMA_TRIG_PERIPH_LCD0
// GDMAペリフェラルレジスタの配列を順に調べてペリフェラル番号が一致するDMAチャンネルを特定する;
for (int i = 0; i < SOC_GDMA_PAIRS_PER_GROUP; ++i)
for (int i = 0; i < SOC_GDMA_PAIRS_PER_GROUP_MAX; ++i)
{
// ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
if ((*reg(DMA_OUT_PERI_SEL_CH0_REG + i * sizeof(GDMA.channel[0])) & 0x3F) == peripheral_select)
Expand All @@ -234,7 +237,7 @@ namespace lgfx
// SOC_GDMA_TRIG_PERIPH_SPI3
// SOC_GDMA_TRIG_PERIPH_LCD0
// GDMAペリフェラルレジスタの配列を順に調べてペリフェラル番号が一致するDMAチャンネルを特定する;
for (int i = 0; i < SOC_GDMA_PAIRS_PER_GROUP; ++i)
for (int i = 0; i < SOC_GDMA_PAIRS_PER_GROUP_MAX; ++i)
{
// ESP_LOGD("DBG","GDMA.channel:%d peri_sel:%d", i, GDMA.channel[i].out.peri_sel.sel);
if ((*reg(DMA_IN_PERI_SEL_CH0_REG + i * sizeof(GDMA.channel[0])) & 0x3F) == peripheral_select)
Expand Down Expand Up @@ -483,8 +486,12 @@ namespace lgfx
buscfg.flags = SPICOMMON_BUSFLAG_MASTER;
buscfg.intr_flags = 0;
#if defined (ESP_IDF_VERSION_VAL)
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0))
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
buscfg.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO;
#else
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 0))
buscfg.isr_cpu_id = INTR_CPU_ID_AUTO;
#endif
#endif
#endif
if (ESP_OK != spi_bus_initialize(static_cast<spi_host_device_t>(spi_host), &buscfg, dma_channel))
Expand Down Expand Up @@ -823,7 +830,8 @@ namespace lgfx
}
#if defined (CONFIG_IDF_TARGET_ESP32S3)
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 3) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 1, 0)) \
|| (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0))
|| (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 2, 0)) \
|| (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
(&dev->comd[0])[index].val = cmd_val;
#else
(&dev->comd0)[index].val = cmd_val;
Expand Down
9 changes: 7 additions & 2 deletions src/lgfx/v1/platforms/esp32/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ Original Source:
#include <esp_timer.h>

#if !defined ( REG_SPI_BASE )
//#define REG_SPI_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000)
#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE)
/// ESP32-S3をターゲットにした際にREG_SPI_BASEが定義されていなかったので応急処置 5.3まで;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
#else
//#define REG_SPI_BASE(i) (DR_REG_SPI0_BASE - (i) * 0x1000)
#define REG_SPI_BASE(i) (DR_REG_SPI2_BASE)
#endif
#endif

#if defined ( ESP_IDF_VERSION_VAL )
Expand Down
22 changes: 14 additions & 8 deletions src/lgfx/v1/platforms/esp32s3/Bus_Parallel16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Original Source:
#define DMA_OUTFIFO_EMPTY_CH0 GDMA_OUTFIFO_EMPTY_L3_CH0
#endif

#if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) )
#if !defined (LCD_CAM_LCD_UPDATE)
#define LCD_CAM_LCD_UPDATE LCD_CAM_LCD_UPDATE_REG
#endif
#endif

namespace lgfx
{
inline namespace v1
Expand Down Expand Up @@ -178,7 +184,7 @@ namespace lgfx
// dev->lcd_user.lcd_bit_order = false;
// dev->lcd_user.lcd_8bits_order = false;

dev->lcd_user.val = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG;
dev->lcd_user.val = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE;

_cache_flip = _cache[0];
}
Expand Down Expand Up @@ -210,7 +216,7 @@ namespace lgfx
dev->lcd_cmd_val.lcd_cmd_value = _align_data;
auto reg_lcd_user = &(dev->lcd_user.val);
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
}

bool Bus_Parallel16::writeCommand(uint32_t data, uint_fast8_t bit_length)
Expand All @@ -227,12 +233,12 @@ namespace lgfx
if (bit_length <= 16)
{
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
return true;
}

while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
return true;
}

Expand All @@ -247,7 +253,7 @@ namespace lgfx
_has_align_data = false;
dev->lcd_cmd_val.val = _align_data | (data << 8);
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
if (--bytes == 0) { return; }
data >>= 8;
}
Expand All @@ -258,11 +264,11 @@ namespace lgfx
if (bytes == 4)
{
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
return;
}
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
if (bytes == 2) { return; }
data >>= 16;
}
Expand Down Expand Up @@ -414,7 +420,7 @@ namespace lgfx

while (*_dma_outstatus_reg & DMA_OUTFIFO_EMPTY_CH0 ) {}

*reg_lcd_user = LCD_CAM_LCD_ALWAYS_OUT_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_DOUT | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_ALWAYS_OUT_EN | LCD_CAM_LCD_2BYTE_EN | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_DOUT | LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
} while (length & ~1u);
}
if (length)
Expand Down
20 changes: 13 additions & 7 deletions src/lgfx/v1/platforms/esp32s3/Bus_Parallel8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ Original Source:
#define DMA_OUTFIFO_EMPTY_CH0 GDMA_OUTFIFO_EMPTY_L3_CH0
#endif

#if ( ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) )
#if !defined (LCD_CAM_LCD_UPDATE)
#define LCD_CAM_LCD_UPDATE LCD_CAM_LCD_UPDATE_REG
#endif
#endif

namespace lgfx
{
inline namespace v1
Expand Down Expand Up @@ -183,7 +189,7 @@ namespace lgfx
// dev->lcd_user.lcd_bit_order = false;
// dev->lcd_user.lcd_8bits_order = false;

dev->lcd_user.val = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG;
dev->lcd_user.val = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE;

_cache_flip = _cache[0];
}
Expand Down Expand Up @@ -217,7 +223,7 @@ namespace lgfx
dev->lcd_cmd_val.lcd_cmd_value = data;
data >>= 8;
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
} while (--bytes);
return true;
}
Expand All @@ -234,20 +240,20 @@ namespace lgfx
dev->lcd_cmd_val.lcd_cmd_value = data;
data >>= 8;
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
if (0 == --bytes) { return; }
}

dev->lcd_cmd_val.lcd_cmd_value = (data & 0xFF) | (data << 8);
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
bytes >>= 1;
if (--bytes)
{
data >>= 16;
dev->lcd_cmd_val.lcd_cmd_value = (data & 0xFF) | (data << 8);
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;
}
}

Expand Down Expand Up @@ -351,7 +357,7 @@ namespace lgfx
dev->lcd_cmd_val.lcd_cmd_value = data[0] | data[1] << 16;
uint32_t cmd_val = data[2] | data[3] << 16;
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE_REG | LCD_CAM_LCD_START;
*reg_lcd_user = LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE | LCD_CAM_LCD_START;

if (use_dma)
{
Expand All @@ -376,7 +382,7 @@ namespace lgfx
}
dev->lcd_cmd_val.lcd_cmd_value = cmd_val;
dev->lcd_misc.lcd_cd_data_set = !dc;
*reg_lcd_user = LCD_CAM_LCD_ALWAYS_OUT_EN | LCD_CAM_LCD_DOUT | LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE_REG;
*reg_lcd_user = LCD_CAM_LCD_ALWAYS_OUT_EN | LCD_CAM_LCD_DOUT | LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_UPDATE;
while (*reg_lcd_user & LCD_CAM_LCD_START) {}
*reg_lcd_user = LCD_CAM_LCD_ALWAYS_OUT_EN | LCD_CAM_LCD_DOUT | LCD_CAM_LCD_CMD | LCD_CAM_LCD_CMD_2_CYCLE_EN | LCD_CAM_LCD_START;
} while (length);
Expand Down

0 comments on commit e8924dc

Please sign in to comment.