Skip to content

Instantly share code, notes, and snippets.

@sukesh-ak
Last active January 25, 2024 15:29
Show Gist options
  • Save sukesh-ak/c8325c4bb7ec3da40f24977526d513f8 to your computer and use it in GitHub Desktop.
Save sukesh-ak/c8325c4bb7ec3da40f24977526d513f8 to your computer and use it in GitHub Desktop.
Makerfabs ESP32-S3 4.3" 800x480 Parallel RGB565 TFT with Capacitive Touch
/*
Simple Graph + Touch Drawing sample for Makerfabs ESP32-S3 4.3" 800x480 Parallel RGB565 TFT ( E32S3RGB43 )
Product purchase link : https://bit.ly/42cuRO3
Requirements:
- Development board : Makerfabs ESP32-S3 4.3" 800x480 Parallel RGB565 TFT with Capacitive Touch
- Arduino Library - Display/Touch : LovyanGFX
- Board selected in Arduino : ESP32S3 Dev Module
- PSRAM : OPI PSRAM
*/
#define LGFX_USE_V1
#include <LovyanGFX.hpp>
#include <lgfx/v1/platforms/esp32s3/Panel_RGB.hpp>
#include <lgfx/v1/platforms/esp32s3/Bus_RGB.hpp>
#include <driver/i2c.h>
class LGFX : public lgfx::LGFX_Device
{
public:
lgfx::Bus_RGB _bus_instance;
lgfx::Panel_RGB _panel_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_GT911 _touch_instance;
LGFX(void)
{
{
auto cfg = _panel_instance.config();
cfg.memory_width = 800;
cfg.memory_height = 480;
cfg.panel_width = 800;
cfg.panel_height = 480;
cfg.offset_x = 0;
cfg.offset_y = 0;
_panel_instance.config(cfg);
}
{
auto cfg = _panel_instance.config_detail();
cfg.use_psram = 1;
_panel_instance.config_detail(cfg);
}
{
auto cfg = _bus_instance.config();
cfg.panel = &_panel_instance;
cfg.pin_d0 = GPIO_NUM_8; // B0
cfg.pin_d1 = GPIO_NUM_3; // B1
cfg.pin_d2 = GPIO_NUM_46; // B2
cfg.pin_d3 = GPIO_NUM_9; // B3
cfg.pin_d4 = GPIO_NUM_1; // B4
cfg.pin_d5 = GPIO_NUM_5; // G0
cfg.pin_d6 = GPIO_NUM_6; // G1
cfg.pin_d7 = GPIO_NUM_7; // G2
cfg.pin_d8 = GPIO_NUM_15; // G3
cfg.pin_d9 = GPIO_NUM_16; // G4
cfg.pin_d10 = GPIO_NUM_4; // G5
cfg.pin_d11 = GPIO_NUM_45; // R0
cfg.pin_d12 = GPIO_NUM_48; // R1
cfg.pin_d13 = GPIO_NUM_47; // R2
cfg.pin_d14 = GPIO_NUM_21; // R3
cfg.pin_d15 = GPIO_NUM_14; // R4
cfg.pin_henable = GPIO_NUM_40;
cfg.pin_vsync = GPIO_NUM_41;
cfg.pin_hsync = GPIO_NUM_39;
cfg.pin_pclk = GPIO_NUM_42;
cfg.freq_write = 14000000;
cfg.hsync_polarity = 0;
cfg.hsync_front_porch = 8;
cfg.hsync_pulse_width = 4;
cfg.hsync_back_porch = 16;
cfg.vsync_polarity = 0;
cfg.vsync_front_porch = 4;
cfg.vsync_pulse_width = 4;
cfg.vsync_back_porch = 4;
cfg.pclk_idle_high = 1;
_bus_instance.config(cfg);
}
_panel_instance.setBus(&_bus_instance);
{
auto cfg = _light_instance.config();
cfg.pin_bl = GPIO_NUM_2;
_light_instance.config(cfg);
}
_panel_instance.light(&_light_instance);
{
auto cfg = _touch_instance.config();
cfg.x_min = 0;
cfg.y_min = 0;
cfg.bus_shared = false;
cfg.offset_rotation = 0;
// I2C接続
cfg.i2c_port = I2C_NUM_1;
cfg.pin_sda = GPIO_NUM_17;
cfg.pin_scl = GPIO_NUM_18;
// for Board v1.3
cfg.pin_int = GPIO_NUM_NC;
cfg.pin_rst = GPIO_NUM_38;
cfg.x_max = 800;
cfg.y_max = 480;
/*
// for Board v1.1 / v1.2
cfg.pin_int = GPIO_NUM_38;
cfg.pin_rst = GPIO_NUM_NC;
cfg.x_max = 480;
cfg.y_max = 272;
//*/
cfg.freq = 400000;
_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance);
}
setPanel(&_panel_instance);
}
};
#include <vector>
#define LINE_COUNT 6
static LGFX lcd;
static int32_t x,y;
static std::vector<int> points[LINE_COUNT];
static int colors[] = { TFT_RED, TFT_GREEN, TFT_BLUE, TFT_CYAN, TFT_MAGENTA, TFT_YELLOW };
static int xoffset, yoffset, point_count;
int getBaseColor(int x, int y)
{
return ((x^y)&3 || ((x-xoffset)&31 && y&31) ? TFT_BLACK : ((!y || x == xoffset) ? TFT_WHITE : TFT_DARKGREEN));
}
void setup(void)
{
lcd.init();
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);
yoffset = lcd.height() >> 1;
xoffset = lcd.width() >> 1;
point_count = lcd.width() + 1;
for (int i = 0; i < LINE_COUNT; i++)
{
points[i].resize(point_count);
}
lcd.startWrite();
lcd.setAddrWindow(0, 0, lcd.width(), lcd.height());
for (int y = 0; y < lcd.height(); y++)
{
for (int x = 0; x < lcd.width(); x++)
{
lcd.writeColor(getBaseColor(x, y - yoffset), 1);
}
}
lcd.endWrite();
}
void loop(void)
{
static int prev_sec;
static int fps;
++fps;
int sec = millis() / 1000;
if (prev_sec != sec)
{
prev_sec = sec;
lcd.setCursor(0,0);
lcd.printf("fps:%03d", fps);
fps = 0;
}
static int count;
for (int i = 0; i < LINE_COUNT; i++)
{
points[i][count % point_count] = (sinf((float)count / (10 + 30 * i))+sinf((float)count / (13 + 37 * i))) * (lcd.height() >> 2);
}
++count;
lcd.startWrite();
int index1 = count % point_count;
for (int x = 0; x < point_count-1; x++)
{
int index0 = index1;
index1 = (index0 +1) % point_count;
for (int i = 0; i < LINE_COUNT; i++)
{
int y = points[i][index0];
if (y != points[i][index1])
{
lcd.writePixel(x, y + yoffset, getBaseColor(x, y));
}
}
for (int i = 0; i < LINE_COUNT; i++)
{
int y = points[i][index1];
lcd.writePixel(x, y + yoffset, colors[i]);
}
}
lcd.endWrite();
if (lcd.getTouch(&x, &y)) {
lcd.fillRect(x-2, y-2, 5, 5, TFT_RED);
}
lcd.setCursor(lcd.width()-100,0);
lcd.printf("Touch:(%03d,%03d)", x,y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment