Skip to content

Instantly share code, notes, and snippets.

@tanmanh0707
Created May 10, 2025 17:40
Show Gist options
  • Select an option

  • Save tanmanh0707/762930d1f031cb6d8af402cd0d04e723 to your computer and use it in GitHub Desktop.

Select an option

Save tanmanh0707/762930d1f031cb6d8af402cd0d04e723 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include <LovyanGFX.hpp>
// Create a display class
class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ST7796 _panel_instance; // Change this to your LCD driver
lgfx::Bus_Parallel8 _bus_instance; // Parallel 8-bit bus
public:
LGFX(void)
{
{
auto cfg = _bus_instance.config();
cfg.freq_write = 4000000; // 4MHz
cfg.pin_wr = 12; // WR pin
cfg.pin_rd = 11; // No read pin
cfg.pin_rs = 7; // RS (D/C) pin
// Data bus pins (D0 - D7)
cfg.pin_d0 = 14;
cfg.pin_d1 = 13;
cfg.pin_d2 = 10;
cfg.pin_d3 = 9;
cfg.pin_d4 = 3;
cfg.pin_d5 = 4;
cfg.pin_d6 = 2;
cfg.pin_d7 = 1;
_bus_instance.config(cfg);
_panel_instance.setBus(&_bus_instance);
}
{ // Configure display panel
auto cfg = _panel_instance.config();
cfg.pin_cs = 5; // No CS pin required for parallel mode
cfg.pin_rst = 6; // Reset pin
cfg.invert = false; // Set `true` if colors are inverted
cfg.rgb_order = false; // RGB or BGR order
cfg.dlen_16bit = false; // Use 8-bit mode
cfg.bus_shared = false; // Parallel bus is not shared
_panel_instance.config(cfg);
}
setPanel(&_panel_instance);
}
};
LGFX _tft;
uint16_t *pBitmap = nullptr;
void setup()
{
Serial.begin(115200);
/* Enable LCD */
pinMode(48, OUTPUT); digitalWrite(48, HIGH);
/* Init LCD */
_tft.init();
_tft.fillScreen(TFT_BLACK);
/* Prepare data */
int32_t PIXELS_NUM = 150;
pBitmap = (uint16_t *)calloc(PIXELS_NUM, sizeof(uint16_t));
for (int i = 0; i < PIXELS_NUM; i++) {
pBitmap[i] = TFT_RED;
}
/* Draw one line */
_tft.setAddrWindow(0, 0, 131, 1 /* ONE line */);
_tft.pushPixels((const uint16_t *)pBitmap, 131);
// delay(1000); // No difference with or without delay
/* Draw another line */
_tft.setAddrWindow(0, 10, 130, 1 /* ONE line */);
_tft.pushPixels((const uint16_t *)pBitmap, 130);
/* Draw a red square */
_tft.fillRect(0, 20, 50, 50, TFT_RED);
}
void loop()
{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment