diff --git a/boards/esp32s3.json b/boards/esp32s3.json new file mode 100644 index 00000000..555521bd --- /dev/null +++ b/boards/esp32s3.json @@ -0,0 +1,35 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld" + }, + "core": "esp32", + "extra_flags": "-DBOARD_HAS_PSRAM -DESP32_4M -DESP32S3", + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "dio", + "mcu": "esp32s3", + "variant": "esp32s3", + "partitions": "esp32_partition_app1856k_spiffs320k.csv" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "espidf", + "arduino" + ], + "name": "Espressif Generic ESP32-S3 4M Flash, Tasmota 1856k Code/OTA, 320k FS", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/", + "vendor": "Espressif" +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 92ca13b5..e2d0866b 100644 --- a/platformio.ini +++ b/platformio.ini @@ -41,6 +41,7 @@ upload_speed = 921600 monitor_speed = 115200 build_flags = + ;-v ; verbose -D PIOENV=\"${PIOENV}\" -Os ; Code Size Optimization ;-Og ; Code Debug Optimization diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 60ea0be8..2b228da5 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -13,7 +13,7 @@ extern "C" { #endif -#ifndef ESP32S2 +#if !defined(CONFIG_IDF_TARGET_ESP32S2) uint8_t temprature_sens_read(); #endif diff --git a/src/drv/tft/tft_driver_lovyangfx.cpp b/src/drv/tft/tft_driver_lovyangfx.cpp index 8974f319..461e4cf5 100644 --- a/src/drv/tft/tft_driver_lovyangfx.cpp +++ b/src/drv/tft/tft_driver_lovyangfx.cpp @@ -7,6 +7,16 @@ namespace dev { +void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) +{ + if(pin != -1) { + char buffer[64]; + snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), String(pinfunction).c_str(), + haspDevice.gpio_name(pin).c_str(), pin); + LOG_VERBOSE(TAG_TFT, buffer); + } +} + static void _pin_level(int_fast16_t pin, bool level) { lgfx::pinMode(pin, lgfx::pin_mode_t::output); @@ -35,201 +45,267 @@ static uint32_t _read_panel_id(lgfx::Bus_SPI* bus, int32_t pin_cs, uint32_t cmd return res; } -void LovyanGfx::init(int w, int h) +#if defined(ESP32S2) +static lgfx::Bus_Parallel16* init_parallel_16_bus(Preferences* prefs, int8_t data_pins[], uint8_t num) { + lgfx::Bus_Parallel16* bus = new lgfx::v1::Bus_Parallel16(); + auto cfg = bus->config(); // バス設定用の構造体を取得します。 + cfg.pin_rd = prefs->getInt("rd", TFT_RD); + cfg.pin_wr = prefs->getInt("wr", TFT_WR); + cfg.pin_rs = prefs->getInt("rs", TFT_DC); + cfg.freq_write = prefs->getUInt("write_freq", SPI_FREQUENCY); + uint8_t port = prefs->getUInt("port", 0); + switch(port) { +#if SOC_I2S_NUM > 1 + case 1: + cfg.i2s_port = I2S_NUM_1; + break; +#endif + default: + cfg.i2s_port = I2S_NUM_0; + } + for(uint8_t i = 0; i < num; i++) { + cfg.pin_data[i] = data_pins[i]; + } + bus->config(cfg); // The set value is reflected on the bus. + LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + return bus; +} +#endif // ESP32S2 + +static lgfx::Bus_Parallel8* init_parallel_8_bus(Preferences* prefs, int8_t data_pins[], uint8_t num) +{ + lgfx::Bus_Parallel8* bus = new lgfx::v1::Bus_Parallel8(); + auto cfg = bus->config(); // バス設定用の構造体を取得します。 + cfg.pin_rd = prefs->getInt("rd", TFT_RD); + cfg.pin_wr = prefs->getInt("wr", TFT_WR); + cfg.pin_rs = prefs->getInt("rs", TFT_DC); + cfg.freq_write = prefs->getUInt("write_freq", SPI_FREQUENCY); + uint8_t port = prefs->getUInt("port", 0); + switch(port) { +#if SOC_I2S_NUM > 1 + case 1: + cfg.i2s_port = I2S_NUM_1; + break; +#endif + default: + cfg.i2s_port = I2S_NUM_0; + } + for(uint8_t i = 0; i < num; i++) { + cfg.pin_data[i] = data_pins[i]; + } + bus->config(cfg); // The set value is reflected on the bus. + LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + return bus; +} + +static lgfx::Bus_SPI* init_spi_bus(Preferences* prefs) +{ + lgfx::Bus_SPI* bus = new lgfx::v1::Bus_SPI(); + auto cfg = bus->config(); // バス設定用の構造体を取得します。 + cfg.pin_miso = prefs->getInt("miso", TFT_MISO); + cfg.pin_mosi = prefs->getInt("mosi", TFT_MOSI); + cfg.pin_sclk = prefs->getInt("sclk", TFT_SCLK); + cfg.pin_dc = prefs->getInt("dc", TFT_DC); + cfg.spi_3wire = prefs->getBool("3wire", false); + cfg.use_lock = prefs->getBool("use_lock", true); + cfg.freq_write = prefs->getUInt("write_freq", SPI_FREQUENCY); + cfg.freq_read = prefs->getUInt("read_freq", SPI_READ_FREQUENCY); + cfg.dma_channel = prefs->getUInt("dma_channel", 0); + cfg.spi_mode = prefs->getUInt("spi_mode", 0); + uint8_t host = prefs->getUInt("host", 3); LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - Preferences preferences; - preferences.begin("gfx", false); + // #if CONFIG_IDF_TARGET_ESP32C3 + // #define FSPI 0 + // #define HSPI 1 + // #else + // #define FSPI 1 // SPI bus attached to the flash (can use the same data lines but different SS) + // #define HSPI 2 // SPI bus normally mapped to pins 12 - 15, but can be matrixed to any pins + // #if CONFIG_IDF_TARGET_ESP32 + // #define VSPI 3 // SPI bus normally attached to pins 5, 18, 19 and 23, but can be matrixed to any pins + // #endif + // #endif -#ifdef USE_DMA_TO_TFT - int dma_channel = 1; // Set the DMA channel (1 or 2. 0=disable) -#else - int dma_channel = 0; // Set the DMA channel (1 or 2. 0=disable) + // //alias for different chips, deprecated for the chips after esp32s2 + // #ifdef CONFIG_IDF_TARGET_ESP32 + // #define SPI_HOST SPI1_HOST + // #define HSPI_HOST SPI2_HOST + // #define VSPI_HOST SPI3_HOST + // #elif CONFIG_IDF_TARGET_ESP32S2 + // // SPI_HOST (SPI1_HOST) is not supported by the SPI Master and SPI Slave driver on ESP32-S2 and later + // #define SPI_HOST SPI1_HOST + // #define FSPI_HOST SPI2_HOST + // #define HSPI_HOST SPI3_HOST + // #endif + + switch(host) { +#ifdef CONFIG_IDF_TARGET_ESP32 + case 1: + // SPI_HOST (SPI1_HOST) is not supported by the SPI Master and SPI Slave driver on ESP32-S2 and later + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + cfg.spi_host = SPI1_HOST; + break; #endif + case 2: // HSPI on ESP32 and HSPI on ESP32-S2 + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + cfg.spi_host = SPI2_HOST; + break; + case 3: + default: // VSPI on ESP32 and FSPI on ESP32-S2 + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + cfg.spi_host = SPI3_HOST; + } + bus->config(cfg); // The set value is reflected on the bus. + bus->init(); + return bus; +} + +static void init_panel(lgfx::Panel_Device* panel, Preferences* prefs) +{ + auto cfg = panel->config(); // Get the structure for display panel settings. + + cfg.pin_cs = prefs->getInt("cs", TFT_CS); // CS required + cfg.pin_rst = prefs->getInt("rst", TFT_RST); // RST sum development board RST linkage + cfg.pin_busy = prefs->getInt("busy", TFT_BUSY); // Pin number to which BUSY is connected (-1 = disable) + + // The following setting values are set to general initial values for each panel, so please comment out any unknown + // items and try them. + + cfg.panel_width = prefs->getUInt("panel_width", TFT_WIDTH); // Actually displayable width + cfg.panel_height = prefs->getUInt("panel_height", TFT_HEIGHT); // Height that can actually be displayed + cfg.memory_width = prefs->getUInt("memory_width", cfg.panel_width); // Maximum width supported by driver IC + cfg.memory_height = prefs->getUInt("memory_height", cfg.panel_height); // Maximum height supported by driver IC + + cfg.offset_x = prefs->getUInt("offset_x", 0); // Amount of offset in the X direction of the panel + cfg.offset_y = prefs->getUInt("offset_y", 0); // Amount of offset in the Y direction of the panel + cfg.offset_rotation = prefs->getUInt("offset_rotation", 0); // Offset of the rotation 0 ~ 7 (4 ~ 7 is upside down) + + cfg.dummy_read_pixel = prefs->getUInt("dummy_read_pixel", 8); // Number of dummy read bits before pixel read + cfg.dummy_read_bits = + prefs->getUInt("dummy_read_bits", 1); // bits of dummy read before reading data other than pixels + cfg.readable = prefs->getBool("readable", false); // true if data can be read + +#ifdef INVERT_COLORS + cfg.invert = + prefs->getBool("invert", INVERT_COLORS != 0); // true if the light and darkness of the panel is reversed +#else + cfg.invert = prefs->getBool("invert", false); // true if the light and darkness of the panel is reversed +#endif +#ifdef TFT_RGB_ORDER + cfg.rgb_order = prefs->getBool("rgb_order", true); // true if the red and blue of the panel are swapped +#else + cfg.rgb_order = prefs->getBool("rgb_order", false); // true if the red and blue of the panel are swapped +#endif + cfg.dlen_16bit = prefs->getBool("dlen_16bit", false); // true for panels that send data length in 16-bit units + cfg.bus_shared = prefs->getBool("bus_shared", true); // true if the bus is shared with the SD card + // (bus control is performed with drawJpgFile etc.) + panel->config(cfg); +} + +void LovyanGfx::init(int w, int h) +{ + LOG_TRACE(TAG_TFT, F(D_SERVICE_STARTING)); + + Preferences preferences; + preferences.begin("tft", false); + + lgfx::IBus* bus; + { // Initialize the bus + char key[8]; + int8_t data_pins[16] = {TFT_D0, TFT_D1, TFT_D2, TFT_D3, TFT_D4, TFT_D5, TFT_D6, TFT_D7, + TFT_D8, TFT_D9, TFT_D10, TFT_D11, TFT_D12, TFT_D13, TFT_D14, TFT_D15}; + for(uint8_t i = 0; i < 16; i++) { + snprintf(key, sizeof(key), "d%d", i + 1); + data_pins[i] = preferences.getInt(key, data_pins[i]); + LOG_DEBUG(TAG_TFT, F("D%d: %d"), i + 1, data_pins[i]); + } + + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + bool is_8bit = true; + bool is_16bit = true; + for(uint8_t i = 0; i < 16; i++) { + if(i < 8) is_8bit = is_8bit && (data_pins[i] >= 0); + is_16bit = is_16bit && (data_pins[i] >= 0); + } + + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); +#if defined(ESP32S2) + if(is_16bit) { + is_8bit = false; + bus = init_parallel_16_bus(&preferences, data_pins, 16); + } else +#endif // ESP32S2 + if(is_8bit) { + is_16bit = false; + bus = init_parallel_8_bus(&preferences, data_pins, 8); + } else { + bus = init_spi_bus(&preferences); + } + } uint32_t tft_driver = preferences.getUInt("DRIVER", get_tft_driver()); switch(tft_driver) { - case 0x9341: - tft._panel_instance = new lgfx::Panel_ILI9341(); + case 0x9341: { + auto panel = new lgfx::Panel_ILI9341(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); break; - case 0x9481: - tft._panel_instance = new lgfx::Panel_ILI9481(); + } + case 0x9342: { + auto panel = new lgfx::Panel_ILI9342(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); break; - case 0x9488: - tft._panel_instance = new lgfx::Panel_ILI9488(); + } + case 0x9481: { + auto panel = new lgfx::Panel_ILI9481(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); break; - case 0x7796: - tft._panel_instance = new lgfx::Panel_ST7796(); + } + case 0x9488: { + auto panel = new lgfx::Panel_ILI9488(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); break; - case 0x8357D: - tft._panel_instance = new lgfx::Panel_HX8357D(); + } + case 0x7796: { + auto panel = new lgfx::Panel_ST7796(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); break; - default: { - LOG_ERROR(TAG_TFT, F("Unknown display driver")); // Needs to be in curly braces + } + case 0x8357D: { + auto panel = new lgfx::Panel_HX8357D(); + panel->setBus(bus); + init_panel(panel, &preferences); + tft.setPanel(panel); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + break; + } + default: { // Needs to be in curly braces + LOG_FATAL(TAG_TFT, F(D_SERVICE_START_FAILED ": %s line %d"), __FILE__, __LINE__); } } - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - -#ifdef ESP32_PARALLEL - { // Set 8-bit parallel bus control - auto bus = (lgfx::v1::Bus_Parallel8*)tft._bus_instance; - auto cfg = bus->config(); // バス設定用の構造体を取得します。 - cfg.i2s_port = I2S_NUM_0; - cfg.freq_write = 20000000; - cfg.pin_wr = TFT_WR; - cfg.pin_rd = TFT_RD; - cfg.pin_rs = TFT_DC; - cfg.pin_d0 = TFT_D0; - cfg.pin_d1 = TFT_D1; - cfg.pin_d2 = TFT_D2; - cfg.pin_d3 = TFT_D3; - cfg.pin_d4 = TFT_D4; - cfg.pin_d5 = TFT_D5; - cfg.pin_d6 = TFT_D6; - cfg.pin_d7 = TFT_D7; - bus->config(cfg); // 設定値をバスに反映します。 - tft._panel_instance->setBus(bus); // Set the bus on the panel. - } -#else - { // Set SPI bus control - auto bus = (lgfx::v1::Bus_SPI*)tft._bus_instance; - auto cfg = bus->config(); // Get the structure for bus configuration. - cfg.spi_host = FSPI_HOST; // Select the SPI to use (VSPI_HOST or HSPI_HOST) - cfg.spi_mode = 0; // Set SPI communication mode (0 ~ 3) - cfg.freq_write = SPI_FREQUENCY; // SPI clock during transmission (Max 80MHz, 80MHz Can be rounded to the value - // divided by an integer ) - cfg.freq_read = SPI_READ_FREQUENCY; // SPI clock when receiving - cfg.spi_3wire = (TFT_MOSI == -1); // true when receiving with MOSI pin - cfg.use_lock = true; // Set to true when using transaction lock - cfg.dma_channel = dma_channel; // Set the DMA channel (1 or 2. 0=disable) - cfg.pin_sclk = preferences.getChar("SCLK", TFT_SCLK); // Set SPI SCLK pin number - cfg.pin_mosi = preferences.getChar("MOSI", TFT_MOSI); // Set SPI MOSI pin number - cfg.pin_miso = preferences.getChar("MISO", TFT_MISO); // Set SPI MISO pin number (-1 = disable) - cfg.pin_dc = preferences.getChar("DC", TFT_DC); // Set SPI D/C pin number (-1 = disable) - bus->config(cfg); // The set value is reflected on the bus. - bus->init(); - int8_t cs = preferences.getChar("CS", TFT_CS); - _read_panel_id(bus, cs, 0x00); // NOP - _read_panel_id(bus, cs, 0x04); // ST7789/ILI9488: RDDID (04h): Read Display ID - _read_panel_id(bus, cs, 0x09); // ST7789/ILI9488: RDDST (09h): Read Display Status - _read_panel_id(bus, cs, 0xBF); // /ILI9481: Device Code Read - tft._panel_instance->setBus(bus); // Set the bus on the panel. - } -#endif - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - - { // Set the display panel control. - auto cfg = tft._panel_instance->config(); // Gets the structure for display panel settings. - cfg.pin_cs = preferences.getChar("CS", TFT_CS); // CS Pin Number (-1 = disable) - cfg.pin_rst = preferences.getChar("RST", TFT_RST); // RST Pin Number (-1 = disable) - cfg.pin_busy = -1; // BUSY Pin Number (-1 = disable) - cfg.memory_width = w; // Maximum width supported by driver IC - cfg.memory_height = h; // Maximum height supported by driver IC - cfg.panel_width = w; // Actually displayable width - cfg.panel_height = h; // Actually displayable height - cfg.offset_x = 0; // Amount of X-direction offset of the panel - cfg.offset_y = 0; // Amount of Y-direction offset of the panel - cfg.offset_rotation = 0; // Offset of values in the direction of rotation 0 ~ 7 (4 ~ 7 are upside down) - cfg.dummy_read_pixel = 8; // Number of dummy read bits before pixel reading - cfg.dummy_read_bits = 1; // Number of bits of dummy read before reading data other than pixels - cfg.readable = true; // Set to true if data can be read - cfg.invert = false; // Set to true if the light and darkness of the panel is reversed - cfg.rgb_order = false; // Set to true if the red and blue of the panel are swapped - cfg.dlen_16bit = false; // Set to true for panels that send data length in 16-bit units - cfg.bus_shared = - true; // Set to true if the bus is shared with the SD card (bus control is performed with drawJpgFile etc.) - tft._panel_instance->config(cfg); - } - - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - -#if 0 - { // Set the backlight control. (Delete if not needed) - auto cfg = tft._light_instance.config(); // Get the backlight structure for configuration. - - cfg.pin_bl = preferences.getChar("BCKL", TFT_BCKL); // Backlight Pin Number - cfg.invert = false; // True if you want to invert the brightness of the Backlight - cfg.freq = 44100; // Backlight PWM frequency - cfg.pwm_channel = 0; // PWM channel number to use - - tft._light_instance.config(cfg); - tft._panel_instance->setLight(&tft._light_instance); // Set the Backlight on the panel. - } -#endif - - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - - uint32_t touch_driver = preferences.getUInt("T_DRIVER", get_touch_driver()); - switch(touch_driver) { - case 0x0911: - tft._touch_instance = new lgfx::Touch_GT911(); - break; - case 0x5206: - case 0x6336: - tft._touch_instance = new lgfx::Touch_FT5x06(); - break; - case 0x2046: - tft._touch_instance = new lgfx::Touch_XPT2046(); - break; - case 0x0610: - tft._touch_instance = new lgfx::Touch_STMPE610(); - break; - default: { - LOG_ERROR(TAG_TFT, F("Unknown touch driver")); // Needs to be in curly braces - }; - } - - if(touch_driver == 0x2046 || touch_driver == 0x0610) { // Set the touch screen control. (Delete if not needed) - auto cfg = tft._touch_instance->config(); - cfg.pin_int = TOUCH_IRQ; // INT Pin Number - cfg.offset_rotation = 0; // Adjustment when the display and touch orientation do not match: - // Set with a value from 0 to 7 - cfg.bus_shared = true; // Set to true if you are using the same bus as the screen - cfg.spi_host = FSPI_HOST; // Select the SPI to use (HSPI_HOST or VSPI_HOST) - cfg.pin_sclk = TFT_SCLK; // SCLK Pin Number - cfg.pin_mosi = TFT_MOSI; // MOSI Pin Number - cfg.pin_miso = TFT_MISO; // MISO Pin Number - cfg.pin_cs = TOUCH_CS; // CS Pin Number - cfg.freq = SPI_TOUCH_FREQUENCY; // Set SPI clock - cfg.x_min = 0; // Minimum X value (raw value) obtained from touch screen - cfg.x_max = w - 1; // Maximum X value (raw value) obtained from touch screen - cfg.y_min = 0; // Minimum Y value (raw value) obtained from touch screen - cfg.y_max = h - 1; // Maximum Y value (raw value) obtained from touch screen - - tft._touch_instance->config(cfg); - tft._panel_instance->setTouch(tft._touch_instance); // Set the touch screen on the panel. - } - - if(touch_driver == 0x6336 || touch_driver == 0x5206 || - touch_driver == 0x0911) { // Set the touch screen control. (Delete if not needed) - auto cfg = tft._touch_instance->config(); - cfg.pin_int = TOUCH_IRQ; // INT Pin Number - cfg.offset_rotation = 0; // Adjustment when the display and touch orientation do not match: - - cfg.bus_shared = false; // Set to true if you are using the same bus as the screen - cfg.pin_sda = TOUCH_SDA; - cfg.pin_scl = TOUCH_SCL; - cfg.i2c_port = I2C_TOUCH_PORT; // Select I2C to use (0 or 1) - cfg.i2c_addr = I2C_TOUCH_ADDRESS; // I2C device address number - cfg.freq = I2C_TOUCH_FREQUENCY; // Set I2C clock - cfg.x_min = 0; // Minimum X value (raw value) obtained from touch screen - cfg.x_max = w - 1; // Maximum X value (raw value) obtained from touch screen - cfg.y_min = 0; // Minimum Y value (raw value) obtained from touch screen - cfg.y_max = h - 1; // Maximum Y value (raw value) obtained from touch screen - tft._touch_instance->config(cfg); - tft._panel_instance->setTouch(tft._touch_instance); // Set the touch screen on the panel. - } - - tft.setPanel(tft._panel_instance); // Set the panel to be used. - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); - preferences.end(); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); /* TFT init */ + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); tft.begin(); + LOG_DEBUG(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); tft.setSwapBytes(true); /* set endianess */ - - LOG_VERBOSE(TAG_TFT, F("%s - %d"), __FILE__, __LINE__); + LOG_INFO(TAG_TFT, F(D_SERVICE_STARTED)); } void LovyanGfx::show_info() @@ -240,27 +316,28 @@ void LovyanGfx::show_info() #ifdef ESP32_PARALLEL { - LOG_VERBOSE(TAG_TFT, F("Interface : Parallel")); - auto bus = (lgfx::v1::Bus_Parallel8*)tft._bus_instance; - auto cfg = bus->config(); // Get the structure for bus configuration. - tftPinInfo(F("TFT_WR"), cfg.pin_wr); - tftPinInfo(F("TFT_RD"), cfg.pin_rd); - tftPinInfo(F("TFT_RS"), cfg.pin_rs); + // LOG_VERBOSE(TAG_TFT, F("Interface : Parallel")); + // auto bus = _bus_instance; + // auto cfg = bus->config(); // Get the structure for bus configuration. + // tftPinInfo(F("TFT_WR"), cfg.pin_wr); + // tftPinInfo(F("TFT_RD"), cfg.pin_rd); + // tftPinInfo(F("TFT_RS"), cfg.pin_rs); - tftPinInfo(F("TFT_D0"), cfg.pin_d0); - tftPinInfo(F("TFT_D1"), cfg.pin_d1); - tftPinInfo(F("TFT_D2"), cfg.pin_d2); - tftPinInfo(F("TFT_D3"), cfg.pin_d3); - tftPinInfo(F("TFT_D4"), cfg.pin_d4); - tftPinInfo(F("TFT_D5"), cfg.pin_d5); - tftPinInfo(F("TFT_D6"), cfg.pin_d6); - tftPinInfo(F("TFT_D7"), cfg.pin_d7); + // tftPinInfo(F("TFT_D0"), cfg.pin_d0); + // tftPinInfo(F("TFT_D1"), cfg.pin_d1); + // tftPinInfo(F("TFT_D2"), cfg.pin_d2); + // tftPinInfo(F("TFT_D3"), cfg.pin_d3); + // tftPinInfo(F("TFT_D4"), cfg.pin_d4); + // tftPinInfo(F("TFT_D5"), cfg.pin_d5); + // tftPinInfo(F("TFT_D6"), cfg.pin_d6); + // tftPinInfo(F("TFT_D7"), cfg.pin_d7); } #else { LOG_VERBOSE(TAG_TFT, F("Interface : Serial")); - auto bus = (lgfx::v1::Bus_SPI*)tft._bus_instance; - auto cfg = bus->config(); // Get the structure for bus configuration. + auto panel = tft.getPanel(); + auto bus = (lgfx::Bus_SPI*)panel->getBus(); + auto cfg = bus->config(); // Get the structure for bus configuration. tftPinInfo(F("MOSI"), cfg.pin_mosi); tftPinInfo(F("MISO"), cfg.pin_miso); tftPinInfo(F("SCLK"), cfg.pin_sclk); @@ -269,14 +346,16 @@ void LovyanGfx::show_info() #endif { - auto cfg = tft._panel_instance->config(); // Get the structure for bus configuration. + auto panel = tft.getPanel(); + auto cfg = panel->config(); // Get the structure for panel configuration. tftPinInfo(F("TFT_CS"), cfg.pin_cs); tftPinInfo(F("TFT_RST"), cfg.pin_rst); } #ifndef ESP32_PARALLEL { - auto bus = (lgfx::v1::Bus_SPI*)tft._bus_instance; + auto panel = tft.getPanel(); + auto bus = (lgfx::Bus_SPI*)panel->getBus(); auto cfg = bus->config(); // Get the structure for bus configuration. uint32_t freq = cfg.freq_write / 100000; LOG_VERBOSE(TAG_TFT, F("Display SPI freq. : %d.%d MHz"), freq / 10, freq % 10); @@ -284,20 +363,20 @@ void LovyanGfx::show_info() #endif { - auto cfg = tft._touch_instance->config(); // Get the structure for bus configuration. - if(cfg.pin_cs != -1) { - tftPinInfo(F("TOUCH_CS"), cfg.pin_cs); - uint32_t freq = cfg.freq / 100000; - LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), freq / 10, freq % 10); - } - if(cfg.pin_sda != -1) { - tftPinInfo(F("TOUCH_SDA"), cfg.pin_sda); - } - if(cfg.pin_scl != -1) { - tftPinInfo(F("TOUCH_SCL"), cfg.pin_scl); - uint32_t freq = cfg.freq / 100000; - LOG_VERBOSE(TAG_TFT, F("Touch I2C freq. : %d.%d MHz"), freq / 10, freq % 10); - } + // auto cfg = tft._touch_instance->config(); // Get the structure for bus configuration. + // if(cfg.pin_cs != -1) { + // tftPinInfo(F("TOUCH_CS"), cfg.pin_cs); + // uint32_t freq = cfg.freq / 100000; + // LOG_VERBOSE(TAG_TFT, F("Touch SPI freq. : %d.%d MHz"), freq / 10, freq % 10); + // } + // if(cfg.pin_sda != -1) { + // tftPinInfo(F("TOUCH_SDA"), cfg.pin_sda); + // } + // if(cfg.pin_scl != -1) { + // tftPinInfo(F("TOUCH_SCL"), cfg.pin_scl); + // uint32_t freq = cfg.freq / 100000; + // LOG_VERBOSE(TAG_TFT, F("Touch I2C freq. : %d.%d MHz"), freq / 10, freq % 10); + // } } } @@ -445,6 +524,8 @@ const char* LovyanGfx::get_tft_model() { #if defined(ILI9341_DRIVER) return "ILI9341"; +#elif defined(ILI9342_DRIVER) + return "ILI9342"; #elif defined(ST7735_DRIVER) return "ST7735"; #elif defined(ILI9163_DRIVER) diff --git a/src/drv/tft/tft_driver_lovyangfx.h b/src/drv/tft/tft_driver_lovyangfx.h index 81b0f973..fa76ffc5 100644 --- a/src/drv/tft/tft_driver_lovyangfx.h +++ b/src/drv/tft/tft_driver_lovyangfx.h @@ -29,19 +29,85 @@ #define TOUCH_IRQ -1 #endif +#ifndef TFT_MOSI +#define TFT_MOSI -1 +#endif +#ifndef TFT_MISO +#define TFT_MISO -1 +#endif +#ifndef TFT_SCLK +#define TFT_SCLK -1 +#endif +#ifndef TFT_BUSY +#define TFT_BUSY -1 +#endif + +#ifndef TFT_D0 +#define TFT_D0 -1 +#endif +#ifndef TFT_D1 +#define TFT_D1 -1 +#endif +#ifndef TFT_D2 +#define TFT_D2 -1 +#endif +#ifndef TFT_D3 +#define TFT_D3 -1 +#endif +#ifndef TFT_D4 +#define TFT_D4 -1 +#endif +#ifndef TFT_D5 +#define TFT_D5 -1 +#endif +#ifndef TFT_D6 +#define TFT_D6 -1 +#endif +#ifndef TFT_D7 +#define TFT_D7 -1 +#endif +#ifndef TFT_D8 +#define TFT_D8 -1 +#endif +#ifndef TFT_D9 +#define TFT_D9 -1 +#endif +#ifndef TFT_D10 +#define TFT_D10 -1 +#endif +#ifndef TFT_D11 +#define TFT_D11 -1 +#endif +#ifndef TFT_D12 +#define TFT_D12 -1 +#endif +#ifndef TFT_D13 +#define TFT_D13 -1 +#endif +#ifndef TFT_D14 +#define TFT_D14 -1 +#endif +#ifndef TFT_D15 +#define TFT_D15 -1 +#endif +#ifndef TFT_RD +#define TFT_RD -1 +#endif +#ifndef TFT_WR +#define TFT_WR -1 +#endif +#ifndef TFT_DC +#define TFT_DC -1 +#endif +#ifndef SPI_READ_FREQUENCY +#define SPI_READ_FREQUENCY 0 +#endif + namespace dev { class LGFX : public lgfx::LGFX_Device { public: - // lgfx::Panel_ILI9481 _panel_instance; - lgfx::Panel_LCD* _panel_instance; - lgfx::IBus* _bus_instance; // SPIバスのインスタンス - lgfx::Light_PWM _light_instance; - lgfx::ITouch* _touch_instance; - - LGFX(void) - { - _bus_instance = new lgfx::v1::Bus_SPI(); - } + LGFX(void) + {} }; class LovyanGfx : BaseTft { @@ -61,10 +127,12 @@ class LovyanGfx : BaseTft { const char* get_tft_model(); - int32_t width(){ + int32_t width() + { return tft.width(); } - int32_t height(){ + int32_t height() + { return tft.height(); } @@ -81,16 +149,6 @@ class LovyanGfx : BaseTft { LOG_VERBOSE(TAG_TFT, F("R%u y offset = %i"), pin, y_offset); } } - - void tftPinInfo(const __FlashStringHelper* pinfunction, int8_t pin) - { - if(pin != -1) { - char buffer[64]; - snprintf_P(buffer, sizeof(buffer), PSTR("%-11s: %s (GPIO %02d)"), String(pinfunction).c_str(), - haspDevice.gpio_name(pin).c_str(), pin); - LOG_VERBOSE(TAG_TFT, buffer); - } - } }; } // namespace dev diff --git a/user_setups/esp32/_esp32.ini b/user_setups/esp32/_esp32.ini index ea718b66..2ca0862b 100644 --- a/user_setups/esp32/_esp32.ini +++ b/user_setups/esp32/_esp32.ini @@ -126,8 +126,7 @@ board_build.partitions = user_setups/esp32/partitions_16MB.csv ; -- The Arduino ESP32 v2.0.2 with 3 available flash sizes: [arduino_esp32_v2] framework = arduino -platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip -platform_packages = +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip board_build.embed_files = data/edit.htm.gz data/style.css.gz diff --git a/user_setups/esp32s2/_esp32s2.ini b/user_setups/esp32s2/_esp32s2.ini index f2c263c3..150721f1 100644 --- a/user_setups/esp32s2/_esp32s2.ini +++ b/user_setups/esp32s2/_esp32s2.ini @@ -92,7 +92,7 @@ fspi = -D TFT_MOSI=13 -D TFT_SCLK=14 -; -- The Arduino ESP32 v2.0.1 with 3 available flash sizes: +; -- The Arduino ESP32S2 v2.0.2 with 3 available flash sizes: [arduino_esp32s2_v2] framework = arduino platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2/platform-tasmota-espressif32-2.0.2.zip @@ -104,22 +104,56 @@ board_build.filesystem = littlefs ; ----- crash reporter monitor_filters = esp32_exception_decoder extra_scripts = - ${esp32.extra_scripts} + ${esp32s2.extra_scripts} [esp32s2_4mb_v2] -extends = exp32, arduino_esp32s2_v2 +extends = esp32s2, arduino_esp32s2_v2 board_upload.flash_size=4MB board_upload.maximum_size = 4194304 board_build.partitions = user_setups/esp32/partitions_4MB.csv [esp32s2_8mb_v2] -extends = exp32, arduino_esp32s2_v2 +extends = esp32s2, arduino_esp32s2_v2 board_upload.flash_size=8MB board_upload.maximum_size = 8388608 board_build.partitions = user_setups/esp32/partitions_8MB.csv [esp32s2_16mb_v2] -extends = exp32, arduino_esp32s2_v2 +extends = esp32s2, arduino_esp32s2_v2 +board_upload.flash_size = 16MB +board_upload.maximum_size = 16777216 +board_build.partitions = user_setups/esp32/partitions_16MB.csv + +; =========================== SOLO ============================================== + +; -- The Arduino ESP32S2-solo v2.0.2 with 3 available flash sizes: +[arduino_esp32s2-solo_v2] +framework = arduino +platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2.2solo1/platform-tasmota-espressif32-2.0.2solo1.zip +board_build.embed_files = + data/edit.htm.gz + data/style.css.gz + data/script.js.gz +board_build.filesystem = littlefs +; ----- crash reporter +monitor_filters = esp32_exception_decoder +extra_scripts = + ${esp32s2.extra_scripts} + +[esp32s2-solo_4mb_v2] +extends = esp32s2, arduino_esp32s2-solo_v2 +board_upload.flash_size=4MB +board_upload.maximum_size = 4194304 +board_build.partitions = user_setups/esp32/partitions_4MB.csv + +[esp32s2-solo_8mb_v2] +extends = esp32s2, arduino_esp32s2-solo_v2 +board_upload.flash_size=8MB +board_upload.maximum_size = 8388608 +board_build.partitions = user_setups/esp32/partitions_8MB.csv + +[esp32s2-solo_16mb_v2] +extends = esp32s2, arduino_esp32s2-solo_v2 board_upload.flash_size = 16MB board_upload.maximum_size = 16777216 board_build.partitions = user_setups/esp32/partitions_16MB.csv diff --git a/user_setups/esp32s2/makerfabs-tft-s2.ini b/user_setups/esp32s2/makerfabs-tft-s2.ini new file mode 100644 index 00000000..945ca498 --- /dev/null +++ b/user_setups/esp32s2/makerfabs-tft-s2.ini @@ -0,0 +1,56 @@ +;***************************************************; +; S2 Mini ESP32-S2 with Lolin TFT 2.4" ; +; - S2-mini board ; +; - ili9341 TFT ; +; - xpt2046 touch controller ; +;***************************************************; + +[env:makerfabs-tft-s2_ili9488] +extends = esp32s2-solo_16mb_v2 +board = esp32s2 + +build_flags = + ${env.build_flags} + ${esp32s2.build_flags} + +;region -- TFT_eSPI build options ------------------------ + -D ILI9488_DRIVER=1 + -D TFT_WIDTH=320 + -D TFT_HEIGHT=480 + -D TFT_ROTATION=0 ; Use default, see TFT_ROTATION values + -D SPI_FREQUENCY=40000000 + -D SPI_READ_FREQUENCY=20000000 + ;-D USER_SETUP_LOADED=1 + -D LGFX_USE_V1=1 + -D SUPPORT_TRANSACTIONS + -D SPI_TOUCH_FREQUENCY=0 + -D TOUCH_DRIVER=0x6336 ; FT6236 Capacitive touch panel driver + -D TFT_MISO=41 ;D6 Use default HSPI + -D TFT_MOSI=02 ;D7 Use default HSPI + -D TFT_SCLK=42 ;D5 Use default HSPI + -D TFT_DC=36 ;D8 + -D TFT_CS=37 ;D0 + -D TFT_RD=34 ;D0 + -D TFT_WR=35 ;D0 + -D TFT_BCKL=45 ;None, configurable via web UI (e.g. 2 for D4) + -D TOUCH_CS=0 ;D3 (can also be D1 or D2) + -D TOUCH_SDA=38 + -D TOUCH_SCL=39 + -D TOUCH_IRQ=40 + -D I2C_TOUCH_PORT=0 + -D I2C_TOUCH_ADDRESS=0x38 + -D I2C_TOUCH_FREQUENCY=400000 + -D TFT_RST=-1 ;RST +;endregion + +;region -- Library options ------------------------------- +lib_deps = + ${env.lib_deps} + ${esp32s2.lib_deps} + lovyan03/LovyanGFX @ ^0.4.12 + +lib_ignore = + ${env.lib_ignore} + ${esp32s2.lib_ignore} + TFT_eSPI +;endregion diff --git a/user_setups/esp32s2/wt32-86.ini b/user_setups/esp32s2/wt-86-32-3zw1_ili9488.ini similarity index 61% rename from user_setups/esp32s2/wt32-86.ini rename to user_setups/esp32s2/wt-86-32-3zw1_ili9488.ini index 6ec83a32..5a689966 100644 --- a/user_setups/esp32s2/wt32-86.ini +++ b/user_setups/esp32s2/wt-86-32-3zw1_ili9488.ini @@ -1,11 +1,11 @@ ;***************************************************; ; Wireless-Tag WT-86-32-3ZW1 ; ; - custom ESP32-S2 pcb ; -; - ili9488 TFT ; -; - ft???? touch controller ; +; - ili9488 TFT 8-bit ; +; - gls1680 touch controller ; ;***************************************************; -[env:wt32-86_ili9488] +[env:wt-86-32-3zw1_ili9488] extends = esp32s2_16mb_v2 board = esp32s2 @@ -18,15 +18,17 @@ build_flags = -D TFT_WIDTH=320 -D TFT_HEIGHT=320 -D TFT_ROTATION=6 ; Use default, see TFT_ROTATION values + -D SPI_FREQUENCY=80000000 + -D INVERT_COLORS=1 - -D TFT_BCKL=-1 ;None, configurable via web UI (e.g. 2 for D4) - -D TFT_CS=-1 ; Chip select control pin, connected to GND - -D TFT_DC=38 ; =RS; Data Command control pin - must use a pin in the range 0-31 - -D TFT_RST=37 ; Reset pin - -D TFT_WR=39 ; Write strobe control pin - must use a pin in the range 0-31 - -D TFT_RD=-1 ; Read pin, pulled-up - -D TFT_D0=36 ; Must use pins in the range 0-31 for the data bus - -D TFT_D1=35 ; so a single register write sets/clears all bits + -D TFT_BCKL=0 ; None, configurable via web UI (e.g. 2 for D4) + -D TFT_CS=3 ; Chip select control pin, connected to GND + -D TFT_DC=38 ; =RS; Data Command control pin + -D TFT_RST=37 ; Reset pin + -D TFT_WR=39 ; Write strobe control pin + -D TFT_RD=2 ; Read pin, pulled-up + -D TFT_D0=36 + -D TFT_D1=35 -D TFT_D2=34 -D TFT_D3=33 -D TFT_D4=21 @@ -39,13 +41,6 @@ build_flags = -D TOUCH_IRQ=13 -D TOUCH_RST=12 - ; dummy SPI - -D TFT_SCLK=-1 - -D TFT_MISO=-1 - -D TFT_MOSI=-1 - -D SPI_FREQUENCY=40000000 - -D SPI_READ_FREQUENCY=20000000 - ;-D USER_SETUP_LOADED=1 -D LGFX_USE_V1=1 -D SUPPORT_TRANSACTIONS @@ -53,7 +48,7 @@ build_flags = -D TOUCH_DRIVER=0x1680 ; GLS1680 Capacitive I2C touch panel driver -D I2C_TOUCH_PORT=0 - -D I2C_TOUCH_ADDRESS=0 + -D I2C_TOUCH_ADDRESS=0x40 -D I2C_TOUCH_FREQUENCY=400000 ;endregion