#pragma once
#define LGFX_USE_V1
#include
// Example configuration for using LovyanGFX with custom settings on ESP32
/*
Please duplicate this file, give it a new name, and modify the settings according to your environment.
You can make it available for use by including the created file in your user program.
It is okay to place the duplicated file in the lgfx_user folder of the library,
but please note that it may be deleted when the library is updated.
If you want to operate safely, please make a backup or place it in the user project folder.
//*/
/// Create a class to perform custom settings derived from LGFX_Device.
class LGFX : public lgfx::LGFX_Device
{
/*
You can change the class name from "LGFX" to another name.
If used in conjunction with AUTODETECT, "LGFX" is already in use, so please change it to a name other than LGFX.
Also, if using multiple panels simultaneously, please give each of them a different name.
※ If you change the class name, you also need to change the constructor name to the same name.
You are free to choose the naming convention, but considering the possibility of increasing settings,
for example, if you set up an ILI9341 with SPI connection on ESP32 DevKit-C, name it like:
LGFX_DevKitC_SPI_ILI9341
By matching the filename and class name, it will be easier to use without confusion.
//*/
// Prepare an instance for the type of panel to be connected.
//lgfx::Panel_GC9A01 _panel_instance;
//lgfx::Panel_GDEW0154M09 _panel_instance;
//lgfx::Panel_HX8357B _panel_instance;
//lgfx::Panel_HX8357D _panel_instance;
//lgfx::Panel_ILI9163 _panel_instance;
//lgfx::Panel_ILI9341 _panel_instance;
//lgfx::Panel_ILI9342 _panel_instance;
//lgfx::Panel_ILI9481 _panel_instance;
//lgfx::Panel_ILI9486 _panel_instance;
//lgfx::Panel_ILI9488 _panel_instance;
//lgfx::Panel_IT8951 _panel_instance;
//lgfx::Panel_RA8875 _panel_instance;
//lgfx::Panel_SH110x _panel_instance; // SH1106, SH1107
//lgfx::Panel_SSD1306 _panel_instance;
//lgfx::Panel_SSD1327 _panel_instance;
//lgfx::Panel_SSD1331 _panel_instance;
//lgfx::Panel_SSD1351 _panel_instance; // SSD1351, SSD1357
lgfx::Panel_SSD1963 _panel_instance;
//lgfx::Panel_ST7735 _panel_instance;
//lgfx::Panel_ST7735S _panel_instance;
//lgfx::Panel_ST7789 _panel_instance;
//lgfx::Panel_ST7796 _panel_instance;
// Prepare an instance for the type of bus to connect the panel.
//lgfx::Bus_SPI _bus_instance; // Instance of SPI bus
//lgfx::Bus_I2C _bus_instance; // Instance of I2C bus (for ESP32 only)
lgfx::Bus_Parallel8 _bus_instance; // Instance of 8-bit parallel bus (for ESP32 only)
// If backlight control is possible, prepare an instance. (Delete if not needed)
//lgfx::Light_PWM _light_instance;
// Prepare an instance for the type of touch screen. (Delete if not needed)
//lgfx::Touch_CST816S _touch_instance;
//lgfx::Touch_FT5x06 _touch_instance; // FT5206, FT5306, FT5406, FT6206, FT6236, FT6336, FT6436
//lgfx::Touch_GSL1680E_800x480 _touch_instance; // GSL_1680E, 1688E, 2681B, 2682B
//lgfx::Touch_GSL1680F_800x480 _touch_instance;
//lgfx::Touch_GSL1680F_480x272 _touch_instance;
//lgfx::Touch_GSLx680_320x320 _touch_instance;
//lgfx::Touch_GT911 _touch_instance;
//lgfx::Touch_STMPE610 _touch_instance;
//lgfx::Touch_TT21xxx _touch_instance; // TT21100
lgfx::Touch_XPT2046 _touch_instance;
public:
// Create a constructor and perform various settings here.
// If you change the class name, please specify the same name for the constructor.
LGFX(void)
{
{ // Setting up bus control.
auto cfg = _bus_instance.config(); // Get the structure for bus settings.
/*
// SPI bus settings
cfg.spi_host = VSPI_HOST; // Select the SPI to use (for ESP32-S2, C3: SPI2_HOST or SPI3_HOST / for ESP32: VSPI_HOST or HSPI_HOST)
// ※ With the update of ESP-IDF, the description of VSPI_HOST and HSPI_HOST is deprecated. If an error occurs, please use SPI2_HOST or SPI3_HOST instead.
cfg.spi_mode = 0; // Set SPI communication mode (0 ~ 3)
cfg.freq_write = 40000000; // SPI clock during transmission (up to 80MHz, rounded to the nearest integer value of 80MHz)
cfg.freq_read = 16000000; // SPI clock during reception
cfg.spi_3wire = true; // Set to true if receiving is done via the MOSI pin
cfg.use_lock = true; // Set to true to use transaction lock
cfg.dma_channel = SPI_DMA_CH_AUTO; // Set the DMA channel to use (0=Not using DMA / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=Auto setting)
// ※ With the update of ESP-IDF, DMA channel SPI_DMA_CH_AUTO (automatic setting) is recommended. Specifying 1ch, 2ch is deprecated.
cfg.pin_sclk = 18; // Set the SCLK pin number of SPI
cfg.pin_mosi = 23; // Set the MOSI pin number of SPI
cfg.pin_miso = 19; // Set the MISO pin number of SPI (-1 = disable)
cfg.pin_dc = 27; // Set the D/C pin number of SPI (-1 = disable)
// If using the same SPI bus as the SD card, be sure to set MISO without omission.
//*/
/*
// I2C bus settings
cfg.i2c_port = 0; // Select the I2C port to use (0 or 1)
cfg.freq_write = 400000; // Clock during transmission
cfg.freq_read = 400000; // Clock during reception
cfg.pin_sda = 21; // Pin number to which SDA is connected
cfg.pin_scl = 22; // Pin number to which SCL is connected
cfg.i2c_addr = 0x3C; // I2C device address
//*/
//*
// 8-bit parallel bus settings
cfg.i2s_port = I2S_NUM_0; // Select the I2S port to use (I2S_NUM_0 or I2S_NUM_1) (Use ESP32's I2S LCD mode)
cfg.freq_write = 20000000; // Transmit clock (up to 20MHz, rounded to the nearest integer value of 80MHz)
cfg.pin_wr = 4; // Pin number to which WR is connected
cfg.pin_rd = 2; // Pin number to which RD is connected
cfg.pin_rs = 15; // Pin number to which RS (D/C) is connected
cfg.pin_d0 = 12; // Pin number to which D0 is connected
cfg.pin_d1 = 13; // Pin number to which D1 is connected
cfg.pin_d2 = 26; // Pin number to which D2 is connected
cfg.pin_d3 = 25; // Pin number to which D3 is connected
cfg.pin_d4 = 17; // Pin number to which D4 is connected
cfg.pin_d5 = 16; // Pin number to which D5 is connected
cfg.pin_d6 = 27; // Pin number to which D6 is connected
cfg.pin_d7 = 14; // Pin number to which D7 is connected
//*/
_bus_instance.config(cfg); // Reflect the settings to the bus.
_panel_instance.setBus(&_bus_instance); // Set the bus to the panel.
}
{ // Setting up display panel control.
auto cfg = _panel_instance.config(); // Get the structure for panel settings.
cfg.pin_cs = 33; // Pin number to which CS is connected (-1 = disable)
cfg.pin_rst = 32; // Pin number to which RST is connected (-1 = disable)
cfg.pin_busy = -1; // Pin number to which BUSY is connected (-1 = disable)
// ※ The following settings have default values set for each panel, so if you are unsure, try commenting them out and testing.
cfg.panel_width = 800; // Actual displayable width
cfg.panel_height = 480; // Actual displayable height
cfg.offset_x = 0; // X-direction offset of the panel
cfg.offset_y = 0; // Y-direction offset of the panel
cfg.offset_rotation = 0; // Offset value of rotation direction 0~7 (4~7 are upside-down)
cfg.dummy_read_pixel = 8; // Number of dummy reads before reading pixels
cfg.dummy_read_bits = 1; // Number of dummy reads before reading data other than pixels
cfg.readable = true; // Set to true if data reading is possible
cfg.invert = false; // Set to true if the panel's brightness is inverted
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 in 16-bit units via 16-bit parallel or SPI
cfg.bus_shared = true; // Set to true if sharing the bus with an SD card (bus control will be performed in drawJpgFile etc.)
// If the display shifts due to variable pixel counts like ST7735 or ILI9163, set only when necessary.
// cfg.memory_width = 240; // Maximum width supported by the driver IC
// cfg.memory_height = 320; // Maximum height supported by the driver IC
_panel_instance.config(cfg);
}
/*
{ // Setting up backlight control. (Delete if not needed)
auto cfg = _light_instance.config(); // Get the structure for backlight settings.
cfg.pin_bl = 32; // Pin number to which backlight is connected
cfg.invert = false; // Set to true to invert the brightness of the backlight
cfg.freq = 44100; // PWM frequency of the backlight
cfg.pwm_channel = 7; // PWM channel number to use
_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance); // Set the backlight to the panel.
}
//*/
//*
{ // Setting up touch screen control. (Delete if not needed)
auto cfg = _touch_instance.config();
cfg.x_min = 0; // Minimum X value obtained from the touch screen (raw value)
cfg.x_max = 799; // Maximum X value obtained from the touch screen (raw value)
cfg.y_min = 0; // Minimum Y value obtained from the touch screen (raw value)
cfg.y_max = 479; // Maximum Y value obtained from the touch screen (raw value)
cfg.pin_int = 34; // Pin number to which INT is connected
cfg.bus_shared = true; // Set to true if using a common bus with the screen
cfg.offset_rotation = 0;// Adjustment when display and touch orientations do not match, set from 0 to 7
// For SPI connection
cfg.spi_host = VSPI_HOST;// Select the SPI to use (HSPI_HOST or VSPI_HOST)
cfg.freq = 1000000; // Set SPI clock
cfg.pin_sclk = 18; // Pin number to which SCLK is connected
cfg.pin_mosi = 23; // Pin number to which MOSI is connected
cfg.pin_miso = 19; // Pin number to which MISO is connected
cfg.pin_cs = 5; // Pin number to which CS is connected
/*
// For I2C connection
cfg.i2c_port = 1; // Select the I2C to use (0 or 1)
cfg.i2c_addr = 0x38; // I2C device address
cfg.pin_sda = 23; // Pin number to which SDA is connected
cfg.pin_scl = 32; // Pin number to which SCL is connected
cfg.freq = 400000; // Set I2C clock
//*/
_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance); // Set the touch screen to the panel.
}
setPanel(&_panel_instance); // Set the panel to be used.
}
};