Skip to content

Instantly share code, notes, and snippets.

@sukesh-ak
Created November 30, 2022 16:04
Show Gist options
  • Save sukesh-ak/7bcafd2227a2c2fa727208f4ffa47308 to your computer and use it in GitHub Desktop.
Save sukesh-ak/7bcafd2227a2c2fa727208f4ffa47308 to your computer and use it in GitHub Desktop.
Makerfabs ESP32-S3 3.5" Parallel TFT - ESP32S335D - Test sample using LovyanGFX driver
/*
Simple Touch Drawing sample for Makerfabs ESP32-S3 3.5" Parallel TFT ( ESP32S335D )
Requirements:
- Development board : Makerfabs ESP32-S3 3.5" 16Bit Parallel TFT
- Arduino Library - Display/Touch : LovyanGFX
- Board selected in Arduino : ESP32S3 Dev Module
*/
#define LGFX_USE_V1 // set to use new version of library
#include <LovyanGFX.hpp> // main library
#include <driver/i2c.h>
// Portrait
#define TFT_WIDTH 320
#define TFT_HEIGHT 480
static constexpr int I2C_PORT_NUM = I2C_NUM_0;
static constexpr int I2C_PIN_SDA = 38;
static constexpr int I2C_PIN_SCL = 39;
static constexpr int I2C_PIN_INT = 40;
class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ILI9488 _panel_instance;
lgfx::Bus_Parallel16 _bus_instance;
lgfx::Light_PWM _light_instance;
lgfx::Touch_FT5x06 _touch_instance;
public:
LGFX(void)
{
{
auto cfg = _bus_instance.config();
cfg.port = 0;
cfg.freq_write = 20000000;
cfg.pin_wr = 35;
cfg.pin_rd = 48;
cfg.pin_rs = 36;
cfg.pin_d0 = 47;
cfg.pin_d1 = 21;
cfg.pin_d2 = 14;
cfg.pin_d3 = 13;
cfg.pin_d4 = 12;
cfg.pin_d5 = 11;
cfg.pin_d6 = 10;
cfg.pin_d7 = 9;
cfg.pin_d8 = 3;
cfg.pin_d9 = 8;
cfg.pin_d10 = 16;
cfg.pin_d11 = 15;
cfg.pin_d12 = 7;
cfg.pin_d13 = 6;
cfg.pin_d14 = 5;
cfg.pin_d15 = 4;
_bus_instance.config(cfg);
_panel_instance.setBus(&_bus_instance);
}
{
auto cfg = _panel_instance.config();
cfg.pin_cs = -1;
cfg.pin_rst = -1;
cfg.pin_busy = -1;
cfg.memory_width = TFT_WIDTH;
cfg.memory_height = TFT_HEIGHT;
cfg.panel_width = TFT_WIDTH;
cfg.panel_height = TFT_HEIGHT;
cfg.offset_x = 0;
cfg.offset_y = 0;
cfg.offset_rotation = 0;
cfg.dummy_read_pixel = 8;
cfg.dummy_read_bits = 1;
cfg.readable = true;
cfg.invert = false;
cfg.rgb_order = false;
cfg.dlen_16bit = true;
cfg.bus_shared = true;
_panel_instance.config(cfg);
}
{
auto cfg = _light_instance.config();
cfg.pin_bl = 45;
cfg.invert = false;
cfg.freq = 44100;
cfg.pwm_channel = 7;
_light_instance.config(cfg);
_panel_instance.setLight(&_light_instance);
}
{
auto cfg = _touch_instance.config();
cfg.x_min = 0;
cfg.x_max = TFT_WIDTH;
cfg.y_min = 0;
cfg.y_max = TFT_HEIGHT;
cfg.pin_int = I2C_PIN_INT;
cfg.bus_shared = true;
cfg.offset_rotation = 0;
cfg.i2c_port = I2C_PORT_NUM;
cfg.i2c_addr = 0x38;
cfg.pin_sda = I2C_PIN_SDA;
cfg.pin_scl = I2C_PIN_SCL;
cfg.freq = 400000;
_touch_instance.config(cfg);
_panel_instance.setTouch(&_touch_instance);
}
setPanel(&_panel_instance);
}
};
static LGFX lcd; // declare display variable
// Variables for touch x,y
static int32_t x,y;
void setup(void)
{
lcd.init();
// Setting display to landscape
if (lcd.width() < lcd.height()) lcd.setRotation(lcd.getRotation() ^ 1);
lcd.setCursor(0,0);
lcd.printf("Ready to touch & draw!");
}
void loop()
{
if (lcd.getTouch(&x, &y)) {
lcd.fillRect(x-2, y-2, 5, 5, TFT_RED);
lcd.setCursor(380,0);
lcd.printf("Touch:(%03d,%03d)", x,y);
}
}
@barnbrooksystems
Copy link

Finally an example that works for the Makerfabs 4.3 display - thank you. They should be paying you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment